4

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

kashikai
  • 135
  • 6
  • This is more a computer science question than programming, and there's a separate site for that, but I think this would be better directed at the [Unix and Linux](//unix.stackexchange.com) site. In short, if you're using more virtual > RAM+swap, it's due to over-commit. In your case, swap==0, but just plug that into the inequality. It may be that your measurement is counting shared segments (e.g. program text) for each process and simply adding; that would push the figures out, too. – Toby Speight Aug 04 '16 at 17:46

2 Answers2

5

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.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Great answer! So the word "virtual" is implemented with swap, share, or copy-on-write, only swap needs hd, others are just page table magics – TingQian LI Apr 29 '19 at 23:24
1

It sounds like you are suffering from the conflation of two distinct concepts: virtual memory and logical address translation.

In logical address translation (logical memory) the CPU presents to each process a unique linear address space. The operating system manage a set of page tables that translate logical addresses to physical memory.

Virtual memory is the process of simulating physical memory by using a secondary storage device. Virtual memory handles the situation where a logical address has no corresponding physical address.

Sadly, most processor documentation conflates those two term.

Virtually memory requires a secondary storage. Logical memory does not. Thus you can have logical memory translation when there is no secondary storage. Such translations can end up being called "virtual" when they are technically "logical."

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • 1
    Thank you, I finally got it! You are right, I thought the 2 concepts were actually the same. – kashikai Aug 05 '16 at 09:18
  • *"most processor documentation conflates those two term"* -- I think you're "blaming" the wrong source. My old college textbooks (circa 1970s) and even more recent technical articles do the same. IOW it's probably more widespread and established than you mention. AFAIK it's Microsoft (and its acolytes) that promote the same concepts that you wrote. – sawdust Jan 25 '17 at 07:59