On 11/06/10 02:03, Brent Hilpert<hilpert at cs.ubc.ca> wrote:
Flogging a dead horse perhaps, as I believe the
discussion is simply a
matter of differing definitions of the phrase "virtual memory", but
let's try a different approach:
Nothing like flogging dead horses... :-)
Suppose we have a machine which at the instruction
level provides
32-bit addresses, that is, it presents a 32-bit address space (4GB) to
the user. However, there is only 1 MB of physical RAM memory in the
machine.
That is one scenario, but definitely not the only one. Part of the
problem is that people seems to want to limit them self to this
scenario, and of course, if you start at that end, then you will more or
less always end up in the same place you just do here. :-)
Without trying to go through the whole history of OS
development
(leaving out things such as overlays, shared libs, etc.), and without
accounting for memory required by the kernel/OS for simplicity,
consider several scenarios:
- 1. User addresses map directly to physical addresses.
User address 0 is physical address 0. The user address space is
obviously
limited to 1MB or less of memory and the user will be aware of such
if an
attempt to address beyond that is made.
Yes. And if you have several processes, they are all aware of each
others memory space, and care must be taken that they do not wander
outside their own confinements and clobber things in the system
(including the OS). Programs must be written to be memory aware, and
either PIC, or else linked to run at a specific address, since there is
no virtual memory.
- 2. We add an MMU to map addresses.
Multiple user address spaces may exist and can be mapped to different
areas in physical memory. User address 0 may or may not ref physical
address 0.
A user is still aware of a limited address space dictated by the 1MB
of
physical memory. The total of the user address spaces cannot exceed
1MB.
Indeed. And it can be an arbitrary lower limit than 1 MB as well. And at
this point, programs can be written to not be memory aware. All programs
can be written without consideration to what addresses they use. All can
be linked to start at the same address, and run in parallel. They are
not aware of, nor do they see other programs memory space. They can be
PIC, or position dependent. They can clobber all their memory, and the
system itself is not affected.
- 3. We add swapping-to-disk.
The system as a whole is no longer limited to 1MB of memory, there
may be
multiple user address spaces totalling more than 1MB of memory. Each
user
however, is still limited to a max of 1MB of address space, i.e.
each user
is still aware of the limited physical memory.
Right. Adding swap does nothing more than grow the capacity of the
system total. For a single process, it is invisible.
- 4. We add address-faulting, demand-paging -
whatever one wants to
call it.
The user address space is no longer limited by physical memory. The
user can
hit any address in their 32-bit space and (magically) find a valid
memory
location there. More physical memory can be added (or removed)
'underneath'
the user(s) without their awareness.
Except, or course, the OS can still limit you to use less than 1 MB.
Adding paging does nothing for the individual program as such. It is
totally invisible. You might argue that it gives you the possibility to
use more memory than physically available, and that is true, but that is
at the discretion of the OS. To get more memory, you will need to call
the OS to request more memory, and the OS can allow or deny this
request. Same as in #2 above.
By the nomenclature I grew up with or suffer under,
the term "virtual
memory" only applies in scenario 4, although "virtual addresses" could
be said to have been introduced in scenario 2.
The difference between 2 and 4 is only that the OS *can* allow you to
use more memory in scenario 4, not that it necessarily will allow it.
Or, scenario 4 was my understanding of the
*commonly-agreed-upon
application* of the phrase "virtual memory", although I would not argue
that in a very general sense it may be applied to scenario 2 or 3.
The difference between 2, 3 and 4 is actually extremely vague. The only
actual difference is that the OS *can* allow you to use more memory. But
let's say that the OS will not. Does that suddenly mean that you don't
have virtual memory, even though it is indeed using page demand loading
and all that fancy stuff?
And this also totally ignores the scenario that exists under the PDP-11,
and which started this thread. What if you have more physical memory
than can be addressed by virtual memory?
That's a whole different ballgame, and is not covered by any of your
scenarios...
All in good spirit. :-)
Johnny