Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual memory without any swap partition

There are few other threads on this subject but I couldn't find a clear answer.

On Linux, how can the virtual memory work when there is no swap partition to perform Paging, even no secondary I/O device (HDD, SSD, etc.)?

If I take my example: I'm running a custom distribution (from initramfs) on an embedded target which hasn't got any swap partition or secondary storage. In top, I can clearly see that the running processes are consuming a lot more of virtual addresses (VIRT) than physical ones (RSS), e.g. 500MB vs 20MB.

Is the difference between VIRT and RSS just the memory allocated but never accessed (hence never mapped by the OS)? (memory over-commitment)

I thought Virtual Memory needed Paging (not talking about swapping) to work but I'm starting to believe that I was wrong (and that there is lot of crap online about Linux memory management).

Does it mean that a Page Fault in such configuration will systematically invoke the oom-killer?

Cheers

like image 549
kashikai Avatar asked Mar 11 '23 12:03

kashikai


1 Answers

Virtual Memory is just what the process sees in its memory space. This includes a lot of things:

  • Actual used RAM
  • Swapped memory
  • Memory mapped real files
  • Memory mapped devices
  • Copy-on-write anonymous mmaps used for large mallocs
  • Copy-on-write memory from a forked process
  • Shared memory
  • Loaded libraries shared between processes

Only swapped pages and mmapped pages from real files requires hitting a disk on page fault.

If two processes share libc, they will immediately have VIRT > RSS without any overcommitment.

like image 58
that other guy Avatar answered Mar 25 '23 07:03

that other guy