When a process isn't using virtual memory, does it have the kernel or user memory in RAM?

2

A process can use upto 4 GB of virtual memory (including user and kernel) but when it's not using virtual memory does it have the kernel and user memory in ram?

cps

Posted 2010-08-05T14:35:49.273

Reputation: 51

Answers

3

Using virtual memory is not optional, an application cannot avoid it. Assuming we're talking about x86 protected memory which is what most current operating systems such as Linux, OS X and Windows use on x86.

Basically, each process sees a 4 GB virtual address space (VAS). The OS, in conjunction with the hardware, sets up so-called page descriptor tables (PDT) that describe how that VAS is mapped, with page granularity (typically 4 KB). A page may be mapped to physical memory, it might be mapped to a file (meaning that when the process tries to read from that part of the VAS, it will trap into the OS which will then read the page from the file on disk and place it into memory), or it might not be mapped at all in which case trying to access that part of the VAS will cause the process to crash. And, as an aside, while the kernel memory is mapped into the process, the process cannot access it directly and will crash if it attempts to do so.

And, the OS might use a page file, or swap partition, allowing the OS to move less used memory pages to disk and use the memory for something more useful. Again, if it does this, the PDT's have to be updated accordingly, and similar to memory mapped files, if the process tries to access pages that have been swapped out, it will trap into the OS which will bring the page back into memory. (While the ability to swap is often conflated with virtual memory per se, the fundamental idea behind virtual memory is the concept of the virtual addresses being distinct from physical memory addresses.)

janneb

Posted 2010-08-05T14:35:49.273

Reputation: 987

Whether or not you have a page file or swap partition has nothing to do with whether you're using virtual memory. Virtual memory is far, far more than "using a page file or swap partition". Not having a page file or swap partition merely eliminates one out of dozens or hundreds of files that are involved in paging I/O. And no, applications don't have a choice either. – Jamie Hanrahan – 2016-02-10T21:05:01.363

I can choose not to have a page file or swap partition, how is virtual memory optional in that sense? At least if virtual memory is what the Google query "define:virtual memory" provides me... – Tamara Wijsman – 2010-08-05T23:21:13.300

@Tom I think janneb is saying the application has no choice to whether or not it exists in VRam or not. Not that you can't disable it. – Jeff F. – 2011-05-19T20:15:32.577

@JeffF.: Applications do have a choice, it's just memory management. – Tamara Wijsman – 2011-05-19T20:17:01.903

@Tom :P I'm not arguing either way, just clarifying. – Jeff F. – 2011-05-19T20:35:37.753