VirtualMemory OS Stallings - Modified
VirtualMemory OS Stallings - Modified
Virtual Memory
Hardware and Control Structures
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
◼ Program and data references within a process tend to cluster
◼ Avoids thrashing
Paging Behavior
◼ 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:
◼ 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
◼ 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
R elationships
Policies for Virtual Memory
◼ Key issue: Performance
▪ minimize page faults
◼ Determines when a
page should be Two main
brought into types:
memory
Demand
Prepaging
Paging
Demand Paging
◼ Demand Paging
◼ only brings pages into main memory when a reference is made
to a location on the page
◼ many page faults when process is first started
◼ 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
◼ Prepaging
◼ pages other than the one demanded by a page fault are brought
in
◼ exploits the characteristics of most secondary memory devices
◼ 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
◼ ineffective if extra pages are not referenced
◼ should not be confused with “swapping”
Placement Policy
◼ Determines where in real memory a process
piece is to reside
◼ Important design issue in a segmentation system
◼ Paging or combined paging with segmentation
placing is irrelevant because hardware performs
functions with equal efficiency
◼ For NUMA systems an automatic placement
strategy is desirable
Replacement Policy
◼ Deals with the selection of a page in main memory
to be replaced when a new page must be brought in
◼ objective is that the page that is removed be the page
least likely to be referenced in the near future
◼ Difficult to implement
◼ one approach is to tag each page with the time of last
reference
◼ this requires a great deal of overhead
L R U Example
First-in-First-out ( F IF O )
◼ 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
◼ Necessary to decide ahead of time the amount of
allocation to give a process
◼ If allocation is too small, there will be a high page fault
rate
Key elements:
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
Multiprogramming
◼ If the degree of multiprogramming is to be reduced, one or more
of the currently resident processes must be swapped out
S
paV virtual memoryschemes:
gedR
• paging system
• kernel memory allocator
Paging system Kernel Memory
Allocator
UNIX SVR4
Memory
Management
Parameters
Table 8.6
UNIX SVR4
Memory
Management
Parameters
◼ The page frame data table is used for page replacement
Replacement
Linux
Memory Management
◼ Shares many characteristics with Unix
◼ Is quite complex
• process virtual
memory
Two main • kernel memory
aspects allocation
◼ Three level page table structure:
process has a single page may span multiple pages may also span multiple pages
directory
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