htop icon indicating copy to clipboard operation
htop copied to clipboard

[Help] Memory-mapped files and process memory monitoring confusion

Open HanabishiRecca opened this issue 4 years ago • 0 comments

This question is not directly related to htop and more about general Linux behavior. But maybe will bring some thoughts.

The thing is, it's possible to get into such situation:

qb-st

As you can see resident memory size of the process is reported as 7G, but overall system memory utilization reported as 1G. This is the result of using memory-mapped files via mmap. Situation is strange enough.

From the process perspective it's really considered as resident memory:

$ cat /proc/1339/status

Name:	qbittorrent
Pid:	1339
...
VmRSS:	 7400124 kB
RssAnon:	  230708 kB
RssFile:	 7160268 kB
RssShmem:	    9148 kB
...

VmRSS I belive is the field htop gets RES value from (it's just the sum of next 3 values). RssFile is where all this excessive amount comes from. And here is an example how it looks in the process memory map:

$ pmap -x 1339

1339:   /usr/bin/qbittorrent
Address           Kbytes     RSS   Dirty Mode  Mapping
...
00007f583665a000 9402888 5147336   54688 rw-s- file-name-here
...

So this is definitely RSS.

But the system itself doesn't consider it as used memory:

$ free -wh

               total        used        free      shared     buffers       cache   available
Mem:            15Gi       1.2Gi       153Mi       116Mi       0.0Ki        14Gi        13Gi
Swap:             0B          0B          0B

In fact memory-mapped file goes to cache, so memory can be reclaimed as with regular disk cache.

Can't really say what to do about it. It's not critical, but looks scary at monitoring, when a particular process seemingly consumes all the memory available. Will be good to hear any thoughs.

HanabishiRecca avatar Jan 14 '22 12:01 HanabishiRecca