6

I am working on an embedded system with 512MB of RAM and enough swap memory to support the application. From the kernel, I have restricted the RAM size from the kernel cmd argument to 130MB. And disabled the swap using swapoff -a. I also disabled kernel overcommit, so that the application can run in physical memory alone. I verified the changes from /proc/cmdline and /proc/meminfo. Now when I run the application and check the top values, VSZ for my application is 177m which is more than the actual memory!! How is this possible? Where did this memory came from?

iqstatic
  • 2,322
  • 3
  • 21
  • 39
jsaji
  • 900
  • 1
  • 15
  • 31

1 Answers1

7

VSZ is virtual memory size which is used by the process. It's normal that it's higher than the size of your physical memory because this is one of the main ideas of this. You should rather look at Resident size (RSS) which is the actual physical memory used by the process.

Look at this example:

I have an nginx process running:

 ps -o rss,vsz,cmd ax | grep -i nginx | head -n1
  956  31248 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

rss - 956 kB
vsz - 31248 kB

So, it means this process is using 956kB of physical memory, and 31MB of virtual memory.

Disabling swap (swapoff -a), like you did, doesn't disable using virtual memory.

Read about virtual memory here: Virtual memory

Allenaz
  • 1,013
  • 10
  • 14
RaFD
  • 688
  • 6
  • 14
  • 1
    I don't think you explained why `swapoff -a` doesn't result in VMM use. *swap* is only used for *read-write* memory or program data. For program code, the Linux *virtual file system* has a way to locate (re-load) a page. If code jumps to an address, then the code *faults* and the data is loaded from disk. In this way, when a program starts the whole thing doesn't load to memory; only the *start* address page. Similarly when under memory pressure, seldom used code can get bumped. – artless noise Nov 04 '14 at 19:27