Thanks again Maxim! You're really providing some valuable insights for me.
> This is because mmap()-based individual allocations imply additional
> overhead. Using mmapAnd this is are costly.
That's what I figured might be going on. I assume there are also some negative impacts on performance with accessing memory that is allocated via mmap. Is that right?
> On FreeBSD you'll see that _virtual_ memory usage grows on reload,
> but the actual memory is returned to the system and can be used by
> other processes.
Actually, I see an increase in virtual and resident. Here are my tests from FreeBSD.
--------------------------------------------------------------------------------
service nginx restart; sleep 10; echo; ps aux|grep -v grep|egrep 'RSS|nginx'
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 923 0.0 5.4 121840 110368 - Ss 08:10 0:00.00 nginx: master process /usr/local/
www 924 0.0 5.4 121840 110372 - S 08:10 0:00.01 nginx: worker process (nginx)
--------------------------------------------------------------------------------
service nginx reload; sleep 10; echo; ps aux|grep -v grep|egrep 'RSS|nginx'
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 923 0.0 10.2 219828 209388 - Ss 08:10 0:00.44 nginx: master process /usr/local/
www 940 0.0 10.2 219828 209384 - S 08:10 0:00.01 nginx: worker process (nginx)
--------------------------------------------------------------------------------
Those tests look exactly like the Linux tests and it's definitely not released back to the system.
I think a big part of this is the 2 heaps that Anoop found. Nginx seems to be using those 2 heaps in a round robin way when it reloads. It looks like it's doing this.
Startup: 1st heap is created
1st Reload: 2nd heap is created
2nd Reload: 1st heap is cleared and used but 2nd heap stays in memory.
So on the 2nd reload is does indeed clear that memory for the heap it is using. Is there any way for us to manually clear the unused heap?
Even in the case of my test VM using the adjusted malloc, it still creates the second heap and does not clear it. It's just not putting much in the heap in my test VM.
You may be asking why I'm even looking into this and I've had a lot of push back and questions as to why I'm doing this. My point is this. Even if Nginx on my server is only using 50M of ram, wouldn't it better for it to use only 25M when that's all it needs? That's clearly a problem in my mind. Can you address why that is not a problem?