Virtual Memory OSedition 7 Stallings Book
Virtual Memory OSedition 7 Stallings Book
Systems:
Internals
and Design Chapter 8
Principles Virtual Memory
Seventh Edition
William Stallings
Operating Systems:
Internals and Design Principles
— Steven Spielberg,
JAWS, 1975
Hardware and Control Structures
Continued . . .
Execution of a Process
n Piece of process that contains the logical address is brought into
main memory
n operating system issues a disk I/O Read request
n another process is dispatched to run while the disk I/O takes
place
n an interrupt is issued when disk I/O is complete, which causes
the operating system to place the affected process in the Ready
state
Implications
n More processes may be maintained in main memory
n only load in some of the pieces of each process
n with so many processes in main memory, it is very likely a
process will be in the Ready state at any particular time
Real memory
• main memory, the actual RAM
Virtual memory
• memory on disk
• allows for effective multiprogramming and relieves the
user of tight constraints of main memory
Table 8.2
Characteristics of
Paging and
Segmentation
To avoid this, the
A state in which operating system tries
the system spends to guess, based on
most of its time recent history, which
swapping process pieces are least likely
pieces rather than to be used in the near
executing future
instructions
Principle of Locality
n Program and data references within a process tend to cluster
n Avoids thrashing
Paging Behavior
n Contemporary programming
techniques used in large
programs tend to decrease the most obvious on
personal computers
locality of references within a where applications are
process becoming increasingly
complex
Segmentation
Advantages:
n Segmentation • simplifies handling
allows the of growing data
programmer to structures
view memory as • allows programs to
consisting of be altered and
multiple address recompiled
independently
spaces or
• lends itself to
segments sharing data
among processes
• lends itself to
protection
Segment Organization
n Each segment table entry contains the starting address of the
corresponding segment in main memory and the length of the
segment
In a combined
paging/segmentation system Segmentation is visible to the
a user’s address space is programmer
broken up into a number of
segments. Each segment is
broken up into a number of
fixed-sized pages which are Paging is transparent to the
equal in length to a main programmer
memory frame
Address Translation
Combined Segmentation
and Paging
Protection and Sharing
n Segmentation lends itself to the implementation of protection
and sharing policies
Demand
Prepaging
Paging
Demand Paging
n Demand Paging
n only brings pages into main memory when a reference is made
to a location on the page
n many page faults when process is first started
n principle of locality suggests that as more and more pages are
brought in, most future references will be to pages that have
recently been brought in, and page faults should drop to a very
low level
Prepaging
n Prepaging
n pages other than the one demanded by a page fault are brought
in
n exploits the characteristics of most secondary memory devices
n if pages of a process are stored contiguously in secondary
memory it is more efficient to bring in a number of pages at
one time
n ineffective if extra pages are not referenced
n should not be confused with “swapping”
Placement Policy
n Determines where in real memory a process
piece is to reside
n Important design issue in a segmentation system
n Paging or combined paging with segmentation
placing is irrelevant because hardware performs
functions with equal efficiency
n For NUMA systems an automatic placement
strategy is desirable
Replacement Policy
n Deals with the selection of a page in main memory
to be replaced when a new page must be brought in
n objective is that the page that is removed be the page
least likely to be referenced in the near future
n Difficult to implement
n one approach is to tag each page with the time of last
reference
n this requires a great deal of overhead
LRU Example
First--in-
First in-First-
First-out (FIFO)
n Treats page frames allocated to a process as a circular buffer
a simpler page
replacement
policy
Free page list Modified page list
Local
• chooses only among the resident pages of the process that generated
the page fault
Global
• considers all unlocked pages in main memory
Fixed Allocation, Local Scope
n Necessary to decide ahead of time the amount of
allocation to give a process
n If allocation is too small, there will be a high page fault
rate
n When a page fault occurs, select the page to replace from among
the resident set of the process that suffers the fault
Key elements:
Working Set
of Process as
Defined by
Window Size
Page Fault Frequency
(PFF)
n Requires a use bit to be associated with each page in memory
n When a page fault occurs, the OS notes the virtual time since the
last page fault for that process
n Does not perform well during the transient periods when there is
a shift to a new locality
n Evaluates the working set of a process at sampling instances based
on elapsed virtual time
the number of
the minimum the maximum page faults that
duration of the duration of the are allowed to
sampling sampling occur between
interval interval sampling
instances
Cleaning Policy
n Concerned with determining when a modified page should be
written out to secondary memory
Demand Cleaning
a page is written out to secondary memory only when it has been selected for
replacement
Precleaning
allows the writing of pages in batches
Load Control
n Determines the number of processes that will be resident in main
memory
n multiprogramming level
UNIX SVR4
Memory
Management
Parameters
(page 1 of 2)
Table 8.6
UNIX SVR4
Memory
Management
Parameters
(page 2 of 2)
n The page frame data table is used for page replacement
• process virtual
memory
Two main • kernel memory
aspects allocation
n Three level page table structure:
each entry points to one page each entry points to one page each entry refers to one
of the page middle directory in the page table virtual page of the process