Resident memory not released

fredr nginx-forum at forum.nginx.org
Tue Jul 30 14:46:26 UTC 2019


Maxim Dounin Wrote:
-------------------------------------------------------
> 
> Whether or not allocated (and then freed) memory will be returned 
> to the OS depends mostly on your system allocator and its 
> settings.

That is very interesting! I had no idea, thanks!


Maxim Dounin Wrote:
-------------------------------------------------------
> On Linux with standard glibc allocator, consider tuning 
> MALLOC_MMAP_THRESHOLD_ and MALLOC_TRIM_THRESHOLD_ environment 
> variables, as documented here:
> 
> http://man7.org/linux/man-pages/man3/mallopt.3.html

I've been playing around with MALLOC_MMAP_THRESHOLD_ and
MALLOC_TRIM_THRESHOLD_ without much success. I noticed that when setting a
low value on MALLOC_TRIM_THRESHOLD_, nginx would allocate more memory, and
then when disconnecting release about half of that. So a bit of progress I
guess.

I then tried setting MALLOC_CHECK=1, and that magically solved it, it seems.
When disconnecting the websockets, all memory was reclaimed by the OS. But I
don't understand why, from reading the man pages you linked, I thought it
would only trigger some logging of memory related errors.

I haven't gotten it to work with the kubernetes nginx ingress yet, it seems
the environment variables isn't passed to the nginx processes for some
reason. But I'm working on that.

Thanks for your help! 
If anyone knows more about MALLOC_CHECK and if it is not recommended to set
in a production environment, please let me know.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285025,285036#msg-285036



More information about the nginx mailing list