NGINX Worker RES Size Growing Over Time – Guidance Needed

Hi Team,

I am developing a custom module that performs health checks by sending an HTTPS request to each upstream at the configured interval.

However, I am noticing that the RES value of each worker is steadily increasing, along with the SIZE value shown in the top command. I tested with Valgrind, and there appears to be no memory leak during reload. I now need to verify whether the worker process is accumulating memory when NGINX runs without reloads.

Could you please advise on how to debug which allocations are causing the RES value to increase? Additionally, is there any tool that can provide a visual view of how memory is being allocated inside NGINX?

Hi,

You could try monitoring the memory usage over time with the smem(1) utility which will probably be a bit more accurate than top(1) (assuming your on Linux).

smem should be packaged for your distribution (may be installed by default). Try running it like

$ smem -ak -P nginx
   PID User   Command                              Swap     USS     PSS     RSS 
433769 andrew nginx: worker process                   0  320.0K  708.0K    2.2M 
433768 andrew nginx: master process ./sbin/ngin       0  708.0K    1.1M    3.6M 
439655 andrew /usr/bin/python3 /usr/bin/smem -a       0    8.1M    8.5M   15.3M 

To quote the man-page

smem reports physical memory usage, taking shared memory pages into ac‐
count. Unshared memory is reported as the USS (Unique Set Size).
Shared memory is divided evenly among the processes sharing that memory.
The unshared memory (USS) plus a process’s proportion of shared memory
is reported as the PSS (Proportional Set Size). The USS and PSS only
include physical memory usage. They do not include memory that has been
swapped out to disk.

2 Likes