4

What i know is that size of Virtual memory is only limited by the number of address lines. But in Operating System internals and design principals by William Stallings i read that virtual memory is also limited by size of secondary memory .
1.How?
2.Is swapping( between main memory and secondary memory) a necessary condition for virtual memory ? I mean if swapping is not allowed then still can we call it virtual memory though the benefits will be limited ?
Then i have few follow up questions based on the answer.

Edit:


I think i must have quoted the exact words of the book:

A storage allocation scheme in which secondary memory can be addressed as though it were part of main memory. The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify physical storage sites, and program-generated addresses are translated automatically to the corresponding machine addresses. The size of virtual storage is limited by the addressing scheme of the computer system and by the amount of secondary memory available and not by the actual number of main storage locations.

Is there some sort of playing of words here in "virtual memory" and "size of virtual storage"?

Community
  • 1
  • 1
Terminal
  • 1,969
  • 5
  • 21
  • 37

2 Answers2

3

The size of virtual storage is limited by the addressing scheme of the computer system and by the amount of secondary memory available and not by the actual number of main storage locations.

The book seems to assume (incorrectly) that you won't allocate virtual memory that you don't plan to use. So, it warns that the physical memory and hard disk used for swap limit the usable virtual memory (of course, from the perspective of your process, so do the other demands on that resource pool - the OS and other processes).

In practice, it's often useful to allocate more virtual memory than you could actually use, because you may want to, for example:

  • use virtual memory for a sparse array, where you directly index in to a few scattered addresses,
  • let the page faulting fail when the system resources actually run out, rather that complicating your code with some attempt to track available memory (remember this is dynamic with other processes etc.) or a pessimistic limit that means you fail to aggressively utilise your system capabilities
  • let every program enjoy the benefits of believing it's been loaded at the address it was compiled for, so it can use absolute address for jump instructions etc. rather than relative

Relating that back to your specific questions:

1.[virtual memory is also limited by size of secondary memory] How?

Again, it's limited in the sense that attempts to use more will fail when memory - both physical and swap - is exhausted.

2.Is swapping( between main memory and secondary memory) a necessary condition for virtual memory ?

That's a little vague... virtual memory can only increase the overall amount of memory processes can transparently use by swapping physical memory content out to make space for new memory demands, and for reloading swapped-out content from the secondary memory. But, even if there's no swap disk space (and hence no swapping), or you don't have enough demand for memory to have done any swapping yet, processes can still benefit from virtual addressing as per sparse arrays, huge stack/heap areas with room to grow on demand, etc..

I mean if swapping is not allowed then still can we call it virtual memory though the benefits will be limited ?

Maybe. You can still benefit from virtual addressing, but it depends on whose terminology you adopt whether that classifies as virtual memory: there's a reasonable argument that "virtual memory" means you're pretending to have more physical RAM, so without the swap you wouldn't qualify even though you may be using the virtual addressing component supporting virtual memory.

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252
2

Regarding the book excerpt, I can see the source of your confusion. I had to read through it a couple times to see what he's saying. A clearer explanation might be: Virtual memory is an abstraction that allows a program to allocate memory without being bothered by the physical constraints of the system on which it runs. Programs access virtual memory naively; the abstraction (virtual memory) distinguishes between virtual memory locations that map directly to physical locations, and those that map to secondary memory locations. Or, it could map to absolutely nowhere, and you have a segfault on your hands.

Number 2 is certaintly not true. Virtual memory is there, "available" for use by programs, whether it has the physical backing or not. When he says limited... by the amount of secondary memory available I don't quite follow that part. One could certainly design a virtual memory layer that has a 100 gigashizzles of address space and that'd be just fine.

If I traded correctness for clarity, then apologies. My explanation wasn't very academic, and it sounds like you're in school, but there you go. Regardless, hope that helps.

-tjw

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
  • So virtual memory is all about separation of logical and physical address space. Things like swapping make the use of virtual memory more useful but they are not the property of virtual memory itself. Am i right? – Terminal Apr 13 '11 at 07:07
  • @Dark yes, the actual physical backing is merely an implementation detail of the virtual memory abstraction. I wouldn't say it's the *separation* between physical and logical, but that it's a layer of indirection that allows the user programs to not have to manage the details of this separation themselves. – Travis Webb Apr 13 '11 at 12:29