1
0
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:
DarthSim 2020-01-10 20:52:40 +06:00
parent 4f178cf325
commit c0fb6b1435
3 changed files with 30 additions and 2 deletions

9
free_memory.go Normal file
View File

@ -0,0 +1,9 @@
// +build !linux
package main
import "runtime/debug"
func freeMemory() {
debug.FreeOSMemory()
}

20
free_memory_linux.go Normal file
View 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)
}

View File

@ -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