Results (
Thai) 2:
[Copy]Copied!
The basic idea behind paging is quite simple: Allocate physical memory to
processes in fixed size chunks (page frames) and keep track of where the various
pages of the process reside by recording information in a page table. Every
process has its own page table that typically resides in main memory, and the
page table stores the physical location of each virtual page of the process. The
page table has N rows, where N is the number of virtual pages in the process. If
there are pages of the process currently not in main memory, the page table indicates
this by setting a valid bit to 0; if the page is in main memory, the valid bit is
set to 1. Therefore, each entry of the page table has two fields: a valid bit and a
frame number.
Additional fields are often added to relay more information. For example, a
dirty bit (or a modify bit) could be added to indicate whether the page has been
changed. This makes returning the page to disk more efficient, because if it is not
modified, it does not need to be rewritten to disk. Another bit (the usage bit) can
be added to indicate the page usage. This bit is set to 1 whenever the page is
accessed. After a certain time period, the usage bit is set to 0. If the page is referenced
again, the usage bit is set to 1. However, if the bit remains 0, this indicates
that the page has not been used for a period of time, and the system might benefit
by sending this page out to disk. By doing so, the system frees up this page’s
location for another page that the process eventually needs (we discuss this in
more detail when we introduce replacement algorithms).
Virtual memory pages are the same size as physical memory page frames.
Process memory is divided into these fixed size pages, resulting in potential internal
fragmentation when the last page is copied into memory. The process may not
actually need the entire page frame, but no other process may use it. Therefore,
the unused memory in this last frame is effectively wasted. It might happen that
the process itself requires less than one page in its entirety, but it must occupy an
entire page frame when copied to memory. Internal fragmentation is unusable
space within a given partition (in this case, a page) of memory.
Now that you understand what paging is, we will discuss how it works. When
a process generates a virtual address, the operating system must dynamically
translate this virtual address into the physical address in memory at which the
data actually resides. (For purposes of simplicity, let’s assume we have no cache
memory for the moment.) For example, from a program viewpoint, we see the
final byte of a 10-byte program as address 9, assuming 1-byte instructions and 1-
byte addresses, and a starting address of 0. However, when actually loaded into
memory, the logical address 9 (perhaps a reference to the label X in an assembly
language program) may actually reside in physical memory location 1239, implying
the program was loaded starting at physical address 1230. There must be an
easy way to convert the logical, or virtual, address 9 to the physical address 1230.
To accomplish this address translation, a virtual address is divided into two
fields: a page field and an offset field, to represent the offset within that page where
the requested data is located. This address translation process is similar to the
process we used when we divided main memory addresses into fields for the cache
mapping algorithms. And similar to cache blocks, page sizes are usually powers of
2; this simplifies the extraction of page numbers and offsets from virtual addresses.
To access data at a given virtual address, the system performs the following steps:
1. Extract the page number from the virtual address.
2. Extract the offset from the virtual address.
3. Translate the page number into a physical page frame number by accessing the
page table.
A. Look up the page number in the page table (using the virtual page number
as an index).
B. Check the valid bit for that page.
1. If the valid bit = 0, the system generates a page fault and the operating
system must intervene to
a. Locate the desired page on disk.
b. Find a free page frame (this may necessitate removing a “victim”
page from memory and copying it back to disk if memory is full).
c. Copy the desired page into the free page frame in main memory.
d. Update the page table. (The virtual page just brought in must have its
frame number and valid bit in the page table modified. If there was a
“victim” page, its valid bit must be set to zero.)
e. Resume execution of the process causing the page fault, continuing
to Step B2.
Being translated, please wait..
