mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-22 20:21:28 +02:00
Use malloc_trim
This commit is contained in:
parent
4f178cf325
commit
c0fb6b1435
9
free_memory.go
Normal file
9
free_memory.go
Normal file
@ -0,0 +1,9 @@
|
||||
// +build !linux
|
||||
|
||||
package main
|
||||
|
||||
import "runtime/debug"
|
||||
|
||||
func freeMemory() {
|
||||
debug.FreeOSMemory()
|
||||
}
|
20
free_memory_linux.go
Normal file
20
free_memory_linux.go
Normal file
@ -0,0 +1,20 @@
|
||||
// +build linux
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <features.h>
|
||||
#ifdef __GLIBC__
|
||||
#include <malloc.h>
|
||||
#else
|
||||
void malloc_trim(size_t pad){}
|
||||
#endif
|
||||
*/
|
||||
import "C"
|
||||
import "runtime/debug"
|
||||
|
||||
func freeMemory() {
|
||||
debug.FreeOSMemory()
|
||||
|
||||
C.malloc_trim(0)
|
||||
}
|
3
main.go
3
main.go
@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
@ -38,7 +37,7 @@ func main() {
|
||||
var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
|
||||
|
||||
for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
|
||||
debug.FreeOSMemory()
|
||||
freeMemory()
|
||||
|
||||
if logMemStats {
|
||||
var m runtime.MemStats
|
||||
|
Loading…
x
Reference in New Issue
Block a user