Possible memory leak?

Maxim Dounin mdounin at mdounin.ru
Thu Feb 28 20:07:45 UTC 2019


Hello!

On Thu, Feb 28, 2019 at 01:43:18PM -0500, wkbrad wrote:

> We're running Nginx version 1.15.8 but we've been seeing similar issues with
> other versions too and on all of our servers that have a high number of
> vhosts.
> 
> The issue is that when you do an nginx reload it ends up using almost 2x the
> ram as it was previously.  Here is a test I ran.
> --------------------------------------------------------------------------------
>  21.3 MiB +   1.4 GiB =   1.4 GiB	nginx (3)
>  21.3 MiB +   1.4 GiB =   1.4 GiB	nginx (3)
> 484.2 MiB +   1.4 GiB =   1.9 GiB	nginx (3)
> 588.1 MiB +   1.4 GiB =   2.0 GiB	nginx (3)
> 720.3 MiB +   1.4 GiB =   2.1 GiB	nginx (3)
>   1.4 GiB +   1.4 GiB =   2.8 GiB	nginx (3)
>  18.0 MiB +   2.7 GiB =   2.7 GiB	nginx (3)
>  20.8 MiB +   2.7 GiB =   2.7 GiB	nginx (3)
>  20.8 MiB +   2.7 GiB =   2.7 GiB	nginx (3)
> --------------------------------------------------------------------------------
> 
> I expect the ram usage to increase while the reload is happening but after
> it's done shouldn't the ram usage go back to about the same level?
> 
> This issue is completely reproducible across all of our servers and if I do
> a full restart, ram usage goes back down to normal.
> 
> Any thoughts?

Configuration reload implies that master process parses the 
configuration and creates new configuration structures in memory.  
That is, memory usage is expected to be 2x compared to a clean 
startup assuming most of the memory is used for the configuration.

Once the configuration is correctly parsed and applied, master 
process will free the old configuration.  At this point memory 
usage is expected to be the same as after a clean start, but given 
memory allocation details it is almost never the case.

For example, assuming the system allocator simply uses sbrk() 
without any caching, after the configuration reload the new 
configuration will use addresses higher than the original one 
used, so allocator will not be able to release no-longer-needed 
memory (previously used by the original configuration) to the 
system.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list