336
◾
Linux with
Operating System Concepts
consecutive pages of a program necessarily be located in two consecutive frames of the
memory.
The computer needs a mechanism to translate from the memory address as viewed from
the program’s point of view to the actual memory address. We refer to these addresses as
the
virtual
or
logical address
and the
physical address
. A mapping process is used to convert
from the virtual/logical address into the physical address. Operating systems maintain for
each process a page table. The
page table
records the location of page in the memory (if it
is currently in memory).
In Figure 8.15, we see an example of two processes that consist of five and seven pages,
respectively, whereas memory consists of only four frames. Thus,
to run both processes
will require 12 total frames of memory, but there are only four. The operating system must
decide which of the pages should be loaded at any one time. Imagine, for instance, that
process A begins and the OS loads four of its five pages into the four frames. Later, if the
processor switches from process A to process B, then some of A’s pages must be swapped
out in favor of B’s pages.
As time goes on, pages may be moved into and out of memory and
then back into memory. Eventually, pages of a process may become more and more dis-
persed in terms of the frames that store them. In Figure 8.15, for instance, we see process
A’s first page (page 0 as we start our numbering at 0 instead of 1) is located in frame 1 while
its fourth page (page 3) is located in frame 3.
The page table indicates in which frame
the page is currently loaded, if any, so that the
address can be modified appropriately. In Figure 8.15, we see that three of process A’s pages
are currently loaded into memory while only one page of process B is in memory. The fig-
ure also indicates whether pages had previously been loaded into memory and discarded.
The page table for these two processes is provided in Table 8.2. In the table, N/A indicates
that the given page is not currently in memory.
How many pages and frames might there be? This depends in part on the page/frame
size, the size of a program, and the size of memory. Let us assume that we have a computer
Pages currently in memory
Process A
DRAM
Swap space
Process B
Pages
previously in memory
(swapped out)
Pages not (yet) in memory
FIGURE 8.15
Paging example. (From Fox, R.
Information Technology: An Introduction for Today’s
Digital World
, FL: CRC Press, 2013.)
Installing Linux
◾
337
whose page/frame size is 4096 bytes (4 Kbytes). We want to run a program that is 32 MBytes
in size on a computer with 8 GBytes of memory. The number of pages is
32 MBytes/4 KBytes
=
8 K pages or 8192 pages
The number of frames is
8 GBytes/4 KBytes
=
2 M or roughly 2 million frames
So, this computer has over 2 million frames and this program requires 8192 of those
frames to fit the entire program.
Will the operating system load an entire program or part of it? This depends on avail-
ability (how many free frames are there?) that itself is partially dependent
on the number
of programs currently in memory, the size of the program, and the need of which pages the
program might need during its execution. It is likely that the full 32 MByte program would
be loaded into memory because it is relatively small compared to the size of memory. If we
instead had a large program, say 512 MBytes in size, it is unlikely
that the entire program
would be loaded into memory at one time. This idea of only loading pages into memory
when needed is sometimes also referred to as
demand paging
.
Virtual memory is a great idea in that it allows us to run multiple programs whose total
size is larger than that of the main memory. But there is a price to pay with virtual memory.
The paging process itself is time consuming because of the disk access time required to
copy a page from swap space to memory. Disk access is among the slowest activities of a
computer. We want to minimize disk access as much as possible. Virtual memory provides
a compromise between spending more money on memory and
reducing the efficiency of
our computer.
There are solutions to improve the performance of virtual memory. These include utiliz-
ing an intelligent strategy for page replacement (i.e., selecting a page to discard to free up
a frame in a manner that decreases the total number of page faults) and formatting and
organizing the swap space data differently from the rest of the file system. This is one of
the many reasons why swap space is on a different partition from the rest of the operating
system and data files.
TABLE 8.2
Page Tables for Processes in Figure 8.15
Do'stlaringiz bilan baham: