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?

0

1 Answer 1

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.)

5
  • 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... Aug 5, 2010 at 23:21
  • @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.
    May 19, 2011 at 20:15
  • @JeffF.: Applications do have a choice, it's just memory management. May 19, 2011 at 20:17
  • @Tom :P I'm not arguing either way, just clarifying.
    – Jeff F.
    May 19, 2011 at 20:35
  • 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. Feb 10, 2016 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .