I came across this stackoverflow post:
https://stackoverflow.com/questions/10400751/how-do-vmrss-and-resident-set-size-match
The answer voted correctly states the following:
"So, VSS should be greater than RSS. If they are close to equal, that means your process is sitting comfortably in memory. If VSS is much larger, that means there isn't enough memory and parts of it have to be swapped out to disk (i.e., because of a competing process, etc.)."
That statement confuses me a lot because when I inspect my system, I notice the following.
First, I notice I have a lot of free memory:
$ cat /proc/meminfo
MemTotal: 6113156 kB
MemFree: 3668992 kB
That means I have 3.5 gigabytes of pure memory (no swap, no disk, etc)
However, when I look at my spawned apache2 child processes, I come to a surprise:
$ ps aux | grep apache2
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1130 0.0 0.1 149080 10600 ? Ss Jul11 0:03 /usr/sbin/apache2 -k start
www-data 23211 0.0 0.3 163408 23784 ? S 10:34 0:03 /usr/sbin/apache2 -k start
www-data 23215 0.0 0.4 164436 24832 ? S 10:34 0:02 /usr/sbin/apache2 -k start
www-data 23287 0.0 0.3 163608 23992 ? S 10:36 0:02 /usr/sbin/apache2 -k start
www-data 23351 0.0 0.3 163660 24064 ? S 10:40 0:01 /usr/sbin/apache2 -k start
www-data 23440 0.0 0.3 161580 23588 ? S 10:46 0:00 /usr/sbin/apache2 -k start
www-data 24393 0.0 0.3 163620 23496 ? S 11:32 0:00 /usr/sbin/apache2 -k start
www-data 25377 0.0 0.2 150656 12316 ? S 12:20 0:00 /usr/sbin/apache2 -k start
www-data 25378 0.0 0.3 158224 18400 ? S 12:20 0:00 /usr/sbin/apache2 -k start
www-data 27038 0.0 0.1 149360 7816 ? S 13:01 0:00 /usr/sbin/apache2 -k start
www-data 27041 0.0 0.1 149368 7660 ? S 13:01 0:00 /usr/sbin/apache2 -k start
1000 27124 0.0 0.0 8112 900 pts/0 S+ 13:04 0:00 grep apache2
(Note that grep removes column headers, so I artificially add them back)
Look how much larger virtual memory is compared to resident memory. I mean, for example, for the apache parent process (the parent process is 1130):
$ ps xao pid,ppid,pgid,sid,comm | grep apache2
1130 1 1130 1130 apache2
23211 1130 1130 1130 apache2
23440 1130 1130 1130 apache2
27038 1130 1130 1130 apache2
27041 1130 1130 1130 apache2
27183 1130 1130 1130 apache2
27242 1130 1130 1130 apache2
27349 1130 1130 1130 apache2
27405 1130 1130 1130 apache2
27456 1130 1130 1130 apache2
27457 1130 1130 1130 apache2
That parent process is taking up 146 megabytes of virtual memory compared to 10 megabytes of resident memory. That is a difference of 136 megabytes of swap space being used!
So this doesn't make sense to me. I have so much free memory, but it's using so much more swap space?? According to the post on stackoverflow, he says "means there isn't enough memory". Well that's not true. I have plenty of memory.