mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-03-27 20:30:27 +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"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -38,7 +37,7 @@ func main() {
|
|||||||
var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
|
var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
|
||||||
|
|
||||||
for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
|
for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
|
||||||
debug.FreeOSMemory()
|
freeMemory()
|
||||||
|
|
||||||
if logMemStats {
|
if logMemStats {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
|
Loading…
x
Reference in New Issue
Block a user