0

Does virtual memory exists somewhere in our computer system in reality(i.e on hard disk )?

if not how a mapping from virtual memory to real data in hard disk is made if data is not in main memory i.e.( page fault occurs ).Is there any table that maintains the mapping from virtual memory to hard disk data..

Rahul Kumar Dubey
  • 788
  • 1
  • 6
  • 19
  • 1
    See http://stackoverflow.com/questions/7253659/why-the-address-of-variable-of-child-process-and-parent-process-is-same/7253711#7253711 – paxdiablo Jan 29 '13 at 08:03
  • It depends upon the abstraction level you use when looking at a computer. Your computer is also a big mess of atoms, but looking at it that way don't help... Likewise, you could ask : do files really exist??? – Basile Starynkevitch Jan 29 '13 at 08:22

5 Answers5

2
  1. Memory is so called virtual because a process sees its address-space as a contiguous chunk of available memory, using all the breadth of the underlying address bus width, let say 4GB for a 32bits system. So every single process has a 4GB address-space, yet this memory is not fully backed by physical memory on a 1-to1 basis. And even though you have 4GB of physical memory to back the 4GB address-space of the process, where would go the kernel, the others process? This memory has to be virtual.
  2. Yes, tables maintain the process address-space. To make it simple, some of the pages are currently mapped on the volatile physical memory, but some others are not. They are backed by a memory file on the HDD. When a page-fault occurs, the page-fault will check if that page is mapped on the physical-memory (usually it’s a bit inside the page’s attributes), and if not, it will fetch it from the memory mapped file on the HDD, and replace with it an old page mapped to the physical memory.

Hope this help.

Benny
  • 4,095
  • 1
  • 26
  • 27
1

Yes virtual memory really does exist and yes there is a table that maintains the mapping. Look for page table in wikipedia for instance. In fact most of the virtual memory article will answer your question in full.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
1

Most of your questions are answered by http://en.wikipedia.org/wiki/Virtual_memory.

  1. A backing store must exist for virtual memory. This is usually a hard disk. Basically its some other device that ua usually slower than RAM but is much bigger in capacity.
  2. When a page fault occurs, the page is obtained from the backing store
  3. The page table contains information on where in the backing store the page is to found
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
  • That was my first answer as well.. but there may be cases in which this is not true. You may not have enough disk to back all your Virtual Memory, after all... – Lorenzo Dematté Jan 29 '13 at 08:04
  • A backing store must exist for virtual memory -> I would say "A backing store must exist for *allocated* (reserved, on some OSes) virtual memory" – Lorenzo Dematté Jan 29 '13 at 08:10
  • @dema80 Most VM implementations pre-allocate the VM space on the backing store to avoid OOM issues. – Richard Schneider Jan 29 '13 at 08:14
  • I disagree. How can you pre-allocate 2^64 bytes on a 64 bit os? You do not even have enough disk space! I know for sure that neither Linux nor Windows pre-allocate the entire address space.. Linux and Windows let you run with no swap space at all! (not advisable, but possible) – Lorenzo Dematté Jan 29 '13 at 08:18
  • @dema80, I should have said "pre-allocate some of the VM space". See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_perform_change_vmpagefile.mspx?mfr=true – Richard Schneider Jan 29 '13 at 08:22
  • "some" makes a big difference.. :) and anyway, the page you linked is for setting the initial size of the page file. I do not see how it is linked to pre-allocation.. – Lorenzo Dematté Jan 29 '13 at 08:25
0

Short answer, no :) Virtual Memory is virtual! Especially if you consider virtual memory as "the memory that can be addressed by a process". On 64 bit systems, the whole disk hardly could back the entire virtual memory. So "in reality", as you asked, I would say no.

Long(-ish) answer: virtual memory exists as a series of data structures in the kernel. They mostly keep trace of which page/segment is currently reserved, allocated, mapped to a file or mapped to physical memory. Also, the answer is different if what you look at is "allocated virtual memory". This always exists in one form or another (usually, pages backed by hard-disk swap space).

Lorenzo Dematté
  • 7,638
  • 3
  • 37
  • 77
0

Yes, most used bytes of virtual memory exist somewhere. I say "most" because pages that map registers of some special hardware can have holes. But all memory allocated by you app exists either in RAM or on hard disk.

The wikipedia article explains all the details: http://en.wikipedia.org/wiki/Virtual_memory

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • The key here is "allocated". Which is, in many cases, far from "most bits". At least, if you read "virtual memory" as "the whole process address space" – Lorenzo Dematté Jan 29 '13 at 08:05
  • 1
    @dema80: I see your point. If you think of virtual memory as the whole 32bit/64bit address space that you can reach with a pointer, then you're correct. But unless you have a bug, you don't access most of that memory, so my gut feeling is that this "doesn't matter" as much. – Aaron Digulla Jan 29 '13 at 08:12
  • 1
    that's true, especially on 64 bit systems (32 bit is different: you can run out of address space quickly for server applications). But as a concept, "Virtual memory" is the address space, IMHO. It is the "big array" indexed by 32/64 bit pointers; of course, if you really access a give location, that needs to be allocated before, and therefore backed by either ram or disk. – Lorenzo Dematté Jan 29 '13 at 08:16