Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 2 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 3
Virtual memory Missing pages
Virtual memory (sub-)system can be implemented as What happens when an executing program references an
an extension of paged or segmented memory address that is not in main memory? Here, both hardware
management or sometimes as a combination of both. (H/W) and software (S/W) cooperate and solve the problem:
• The page table is extended with an extra bit, present.
In this scheme, the operating system has the ability Initially, all the present bits are cleared (H/W and S/W).
to execute a program which is only partially loaded in • While doing the address translation, the MMU checks to see
memory. if this bit is set. Access to a page whose present bit is not
set causes a special hardware trap, called page fault
Note: the idea was originally explored earlier in (H/W).
“overlays”. However now, with virtual memory, the
• When a page fault occurs the operating system brings the
fragmentation and its management is done by the page into memory, sets the corresponding present bit, and
operating system. restarts the execution of the instruction (S/W).
Most likely, the page carrying the address will be on the
paging device, but possibly does not exist at all!
Jan’0 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 4 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 5
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 6 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 7
Page fault handling—by picture Additional hardware support
Page
Table
Address Despite the similarities between paging or segmentation
invalid
Reference Operating Segmentation and virtual memory, there is a small but an important
1 Page System fault
0 k fault problem that requires additional hardware support.
pi
1 Consider the following M68030 instruction:
Restart
execution Page is on
Paging Device
DBEQ D0, Next ; Decrement and Branch if Equal
Which can be micro-coded as:
pk
Update the
Fetch (instruction); decrement D0;
page table if D0 is zero, set PC to “Next” else increment PC.
fe Find an empty
frame and bring in
What if the instruction itself and the address Next are
Program’s
fj the missing page
Paging on two different pages and the latter page was not in
Logical
Address
Device memory? Page fault... From where and how to restart
Space the instruction? (Note: D0 is already decremented.)
Logical page i (pi )
Main resides in frame j (f j)
Memory pk resides in f e
Jan’0 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 8 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 9
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 10 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 11
Allocation policy Fetch policy
In general, the allocation policy deals with conflicting • Demand paging
requirements: – Start a program with no pages loaded; wait until it
references a page; then load the page (this is the
• The fewer the frames allocated for a program, the most common approach used in paging systems).
higher the page fault rate. • Request paging
• The fewer the frames allocated for a program, the more – Similar to overlays, let the user identify which pages
are needed (not practical, leads to over estimation
programs can reside in memory; thus, decreasing the and also user may not know what to ask for.)
need of swapping.
• Pre-paging
• Allocating additional frames to a program beyond a – Start with one or a few pages pre-loaded. As pages
certain number results in little or only moderate gain in are referenced, bring in other (not yet referenced)
performance. pages too.
Opposite to fetching, the cleaning policy deals with
The number of allocated pages (also known as determining when a modified (dirty) page should be
resident set size) can be fixed or can be variable written back to the paging device.
during the execution of a program.
Jan’0 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 12 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 13
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 14 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 15
More on replacement policy algorithm
• Replacement scope: 0
All the frames, along with a used bit,
1 1 are kept in a circular queue. A
– Global—select a victim among all processes.
pointer indicates which page was just
– Local—select a page from the faulted process. 0 1 0
replaced. When a frame is needed,
t
las
• Frame locking—frames that belong to resident the pointer is advanced to the first
1 0 frame with a zero used bit. As the
kernel, or are used for critical purposes, may be next
pointer advances, it clears the used
locked for improved performance. 1 bits. Once a victim is found, the page
1
• Page buffering—victim frames are grouped into is replaced and the frame is marked
0 1
two categories: those that hold unmodified (clean) 0 as used (i.e., its used bit is set to
one.)
pages and modified (dirty) pages (VAX/VMS uses
this approach.) The hardware, on the other hand,
This is also known as sets the used bit each time an
2nd chance algorithm. address in the page is referenced.
Used ==> accessed (read or written)
Jan’0 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 16 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 17
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 18 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 19
Thrashing continued Working sets continued
The only way to eliminate The working set of a program is the set of pages that
thrashing is to reduce the are accessed by the last D memory references at a given
1.0 Optimum performance
multiprogramming level by
time t and denoted by W(t, D ).
Processor Utilization
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 20 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 21
by the process since last access to the page) where, T is the critical inter-page
fault time. When the process runs
• Every once in a while (e.g., every few seconds), scan all
Number of frames allocated N below the lower bound, a frame is
pages of a process. For each used bit on, clear page’s
taken away from it (i.e., its
idle time; otherwise, add process’ CPU time since the
resident set size is reduced).
last scan to idle time. Turn off all the used bits. T i = average time between page Similarly, an additional frame is
• The collection of pages with the lowest idle time is the faults for process Pi
assigned to a process which runs
working set. above its upper bound.
Jan’0 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 22 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 23
Current trends A case study—paging in BSD UNIX
• Larger physical memory Page fault handling is separated from page replacement.
– page replacement is less important
– better hardware support for replacement policies Page fault also occurs when there is plenty of memory
– larger page sizes available. Instead of loading a program for execution, the
· better TLB coverage system simply builds its logical address space with all
· smaller page tables, fewer pages to manage pages marked as invalid.
• Larger address spaces Program’s image (code and data) is fetched into memory
– sparse address spaces in response to page faults.
– single (combined) address space (part for the OS Dynamic data and stack are allocated as the program uses
part for the user processes) them.
• File systems using virtual memory
Consequently, in many cases, the system does not have
– memory mapped files
to look for a victim page when there is a page fault.
– file caching with VM
Jan’0 1
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 24 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 25
Jan’0 1
Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 26 Copyright © 1998-2001 by Eskicioglu & Marsland Virtual Memory 27