Of
Bca-mca
COMPUTER ORGANISATION AND
ARCHITECTURE
on
topic
VIRTUAL MEMORY ARCHITECTURE
First and foremost I thank my teacher who has assign me this term
Note that "virtual memory" is more than just "using disk space to extend
physical memory size" - that is merely the extension of the memory
hierarchy to include hard disk drives. Extending memory to disk is a normal
consequence of using virtual memory techniques, but could be done by other
means such as overlays or swapping programs and their data completely out
to disk while they are inactive. The definition of "virtual memory" is based
on redefining the address space with a contiguous virtual memory addresses
to "trick" programs into thinking they are using large blocks of contiguous
addresses.
The term "virtual memory" is often confused with "memory swapping" (or
"page/swap file" use), probably due in part to the prolific Microsoft
Windows family of operating systems referring to the enabling/disabling of
memory swapping as virtual memory. In fact, Windows uses paged memory
and virtual memory addressing, even if the so called "virtual memory" is
disabled.
In the 1940s and 1950s, before the development of a virtual memory, all
larger programs had to contain logic for managing two-level storage
(primary and secondary, today's analogies being RAM and hard disk), such
as overlaying techniques. Programs were responsible for moving overlays
back and forth from secondary storage to primary.
The main reason for introducing virtual memory was therefore not simply to
extend primary memory, but to make such an extension as easy to use for
programmers as possible.
Many systems already had the ability to divide the memory between
multiple programs (required for multiprogramming and multiprocessing),
provided for example by "base and bounds registers" on early models of the
PDP-10, without providing virtual memory. That gave each application a
private address space starting at an address of 0, with an address in the
private address space being checked against a bounds register to make sure
it's within the section of memory allocated to the application and, if it is,
having the contents of the corresponding base register being added to it to
give an address in main memory. This is a simple form of segmentation
without virtual memory.
In 1961, Burroughs released the B5000, the first commercial computer with
virtual memory. It used segmentation rather than paging.
Like many technologies in the history of computing, virtual memory was not
accepted without challenge. Before it could be implemented in mainstream
operating systems, many models, experiments, and theories had to be
developed to overcome the numerous problems. Dynamic address translation
required a specialized, expensive, and hard to build hardware, moreover
initially it slightly slowed down the access to memory. There were also
worries that new system-wide algorithms of utilizing secondary storage
would be far less effective than previously used application-specific ones.
By 1969 the debate over virtual memory for commercial computers was
over. An IBM research team led by David Sayre showed that the virtual
memory overlay system consistently worked better than the best manually
controlled systems.
Virtual memory was introduced to the x86 architecture with the protected
mode of the Intel 80286 processor. At first it was done with segment
swapping, which became inefficient with larger segments. The Intel 80386
introduced support for paging underneath the existing segmentation layer.
The page fault exception could be chained with other exceptions without
causing a double fault.
Like many technologies in the history of computing, virtual memory was not
accepted without challenge. Before it could be regarded as a stable entity,
many models, experiments, and theories had to be developed to overcome
the numerous problems with virtual memory. Specialized hardware had to be
developed that would take a "virtual" address and translate it into an actual
physical address in memory (secondary or primary). Some worried that this
process would be expensive, hard to build, and take too much processor
power to do the address translation.
By 1969 the debates over virtual memory for commercial computers were
over. An IBM research team, lead by David Sayre, showed that the virtual
memory overlay system worked consistently better than the best manual-
controlled systems.
Paged virtual memory
Page tables
Almost all implementations use page tables to translate the virtual addresses
seen by the application program into physical addresses (also referred to as
"real addresses") used by the hardware to process instructions. Each entry in
the page table contains a mapping for a virtual page to either the real
memory address at which the page is stored, or an indicator that the page is
currently held in a disk file. (Although most do, some systems may not
support use of a disk file for virtual memory.)
Systems can have one page table for the whole system or a separate page
table for each application. If there is only one, different applications which
are running at the same time share a single virtual address space, i.e. they
use different parts of a single range of virtual addresses. Systems which use
multiple page tables provide multiple virtual address spaces - concurrent
applications think they are using the same range of virtual addresses, but
their separate page tables redirect to different real addresses.
Paging supervisor
This part of the operating system creates and manages the page tables. If the
dynamic address translation hardware raises a page fault exception, the
paging supervisor searches the page space on secondary storage for the page
containing the required virtual address, reads it into real physical memory,
updates the page tables to reflect the new location of the virtual address and
finally tells the dynamic address translation mechanism to start the search
again. Usually all of the real physical memory is already in use and the
paging supervisor must first save an area of real physical memory to disk
and update the page table to say that the associated virtual addresses are no
longer in real physical memory but saved on disk. Paging supervisors
generally save and overwrite areas of real physical memory which have been
least recently used, because these are probably the areas which are used least
often. So every time the dynamic address translation hardware matches a
virtual address with a real physical memory address, it must put a time-
stamp in the page table entry for that virtual address.
Permanently resident pages
All virtual memory systems have memory areas that are "pinned down", i.e.
cannot be swapped out to secondary storage, for example:
Some systems, such as the Burroughs large systems, do not use paging to
implement virtual memory. Instead, they use segmentation, so that an
application's virtual address space is divided into variable-length segments.
A virtual address consists of a segment number and an offset within the
segment.
Avoiding thrashing
Abstract
Background
Most computers possess four kinds of memory : registers in the CPU, CPU
cache s (generally some kind of static RAM ) both inside and adjacent to the
CPU, main memory (generally dynamic RAM ) which the CPU can read and
write to directly and reasonably quickly; and disk storage , which is much
slower, but also much larger. CPU register use is generally handled by the
compiler and this isn't a huge burden as data doesn't generally stay in them
very long. The decision of when to use cache and when to use main memory
is generally dealt with by hardware so generally both are regarded together
by the programmer as simply physical memory .
One option is for the application software itself to be responsible both for
deciding which information is to be kept where, and also for moving it back
and forth. The programmer would do this by determining which sections of
the program (and also its data) were mutually exclusive , and then arranging
for loading and unloading the appropriate sections from physical memory, as
needed. The disadvantage of this approach is that each application's
programmer must spend time and effort on designing, implementing, and
debugging this mechanism, instead of focusing on his or her application; this
hampers programmer's efficiency. Also, if any programmer could truly
choose which of their items of data to store in the physical memory at any
one time, they could easily conflict with the decisions made by another
programmer, who also wanted to use all the available physical memory at
that point.
Another option is to store some form of handles to data rather than direct
pointers and let the OS deal with swapping the data associated with those
handles between the swapfile and physical memory as needed. This works
but has a couple of problems, namely that it complicates application code,
that it requires applications to play nice (they generally need the power to
lock the data into physical memory to actually work on it) and that it stops
the languages standard library doing its own suballocations inside large
blocks from the OS to improve performance. The best known example of
this kind of arrangement is probably the 16-bit versions of Windows .
This makes the job of the application programmer much simpler. No matter
how much memory the application needs, it can act as if it has access to a
main memory of that size and can place its data wherever in that virtual
space that it likes. The programmer can also completely ignore the need to
manage the moving of data back and forth between the different kinds of
memory.
Basic operation
When virtual memory is used, or when a main memory location is read or
written to by the CPU, hardware within the computer translates the address
of the memory location generated by the software (the virtual memory
address ) into either:
Also on most modern systems virtual address space can be mapped to disk
storage other than the swapfile. This allows parts of executables to be paged
in as needed direct from the executable saving the need to load the entire
executable at application load time and reducing the demand for swap space.
It also allows the operating system to keep one copy of an executable in
memory at once rather than loading it separately for each running instance
thereby reducing the pressure on physical memory.
Details
The hardware that supports virtual memory almost always supports memory
protection mechanisms as well. The MMU may have the ability to vary its
operation according to the type of memory reference (for read, write or
execution), as well as the privilege mode of the CPU at the time the memory
reference was made. This allows the operating system to protect its own
code and data (such as the translation tables used for virtual memory) from
corruption by an erroneous application program and to protect application
programs from each other and (to some extent) from themselves (e.g. by
preventing writes to areas of memory which contain code).
Also many systems run multiple instances of the same program using the
same physical copy of the program in physical memory but separate virtual
address spaces. This is possible because the separate virtual address spaces
can all have the same layout and thus avoid the need to relocate the code at
load time. Some operating systems take this even further implementing copy
on write systems to allow a process to fork into two copies of itself without a
complete copy of its data being created immediately.
For this reason a range of consecutive addresses in the virtual address space
whose size is a power of two will be translated in a corresponding range of
consecutive physical addresses. The memory referenced by such a range is
called a page . The page size is typically in the range of 512 to 8192 bytes
(with 4K currently being very common), though page sizes of 4 megabytes
or larger may be used for special purposes. (Using the same or a related
mechanism, contiguous regions of virtual memory larger than a page are
often mappable to contiguous physical memory for purposes other than
virtualization, such as setting access and caching control bits.)
The operating system stores the address translation tables, the mappings
from virtual to physical page numbers, in a data structure known as a page
table .
The page swap operation involves a series of steps. First it selects a page in
memory, for example, a page that has not been recently accessed and
(preferably) has not been modified since it was last read from disk or the
swap area. (See page replacement algorithms for details.) If the page has
been modified, the process writes the modified page to the swap area. The
next step in the process is to read in the information in the needed page (the
page corresponding to the virtual address the original program was trying to
reference when the exception occurred) from the swap file. When the page
has been read in, the tables for translating virtual addresses to physical
addresses are updated to reflect the revised contents of the physical memory.
Once the page swap completes, it exits, and the program is restarted and
continues on as if nothing had happened, returning to the point in the
program that caused the exception.
It is also possible that a virtual page was marked as unavailable because the
page was never previously allocated. In such cases, a page of physical
memory is allocated and filled with zeros, the page table is modified to
describe it, and the program is restarted as above.
Windows example
• www.wikipedia.com
• www.ask.com
• www.livemint.com
• www.script.com