Chapter 8: Virtual Memory

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

characteristics fundamental to memory management

1) all memory references are logical addresses that are dynamically translated into physical addresses at run time 2) a process may be broken up into a number of pieces that don't need to be contiguously located in main memory during execution

Thrashing

A state in which the system spends most of its time swapping process pieces rather than executing instructions. To avoid this, the operating system tries to guess, based on recent history, which pieces are least likely to be used in the near future.

Virtual Memory

A storage allocation scheme in which secondary memory can be addressed as though it were part of main memory. The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify physical storage sites, and program-generated addresses are translated automatically to the corresponding machine addresses. The size of virtual storage is limited by the addressing scheme of the computer system and by the amount of secondary memory available and not by the actual number of main storage locations.

Basic Algorithms

Algorithms used for the selection of a page to replace: • Optimal • Least recently used (LRU) • First-in-first-out (FIFO) • Clock

Cleaning Policy

Concerned with determining when a modified page should be written out to secondary memory

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 The more elaborate the replacement policy the greater the hardware and software overhead to implement it

Load Control

Determines the number of processes that will be resident in main memory - multiprogramming level Critical in effective memory management Too few processes, many occasions when all processes will be blocked and much time will be spent in swapping Too many processes will lead to thrashing

Fetch Policy

Determines when a page should be brought into main memory Two main types: - Demand Paging - Prepaging

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

Segment Organization

Each segment table entry contains the starting address of the corresponding segment in main memory and the length of the segment A bit is needed to determine if the segment is already in main memory Another bit is needed to determine if the segment has been modified since it was loaded in main memory

Translation Lookaside Buffer (TLB)

Each virtual memory reference can cause two physical memory accesses: - one to fetch the page table entry - one to fetch the data To overcome the effect of doubling the memory access time, most virtual memory schemes make use of a special high-speed cache called a translation lookaside buffer This cache functions in the same way as a memory cache and contains those page table entries that have been most recently used.

Variable Allocation Global Scope

Easiest to implement - adopted in a number of operating systems OS maintains a list of free frames Free frame is added to resident set of process when a page fault occurs If no frames are available the OS must choose a page currently in memory One way to counter potential problems is to use page buffering

Variable-interval Sampled Working Set (VSWS)

Evaluates the working set of a process at sampling instances based on elapsed virtual time Driven by three parameters: - the minimum duration of the sampling interval - the maximum duration of the sampling interval - the number of page faults that are allowed to occur between sampling instances.

Policies for Virtual Memory

Fetch Policy Placement Policy Replacement Policy Resident Set Management Cleaning Policy Load Control

Resident Set Size

Fixed-allocation: Gives a process a fixed number of frames in main memory within which to execute - when a page fault occurs, one of the pages of that process must be replaced Variable-allocation: Allows the number of page frames allocated to a process to be varied over the lifetime of the process

support needed for virtual memory

For virtual memory to be practical and effective: - hardware must support paging and segmentation - operating system must include software for managing the movement of pages and/or segments between secondary memory and main memory

Process Suspension

If the degree of multiprogramming is to be reduced, one or more of the currently resident processes must be swapped out Six possibilities exist: • Lowest-priority process • Faulting process • Last process activated • Process with the smallest resident set • Largest process • Process with the largest remaining execution window

Page Buffering

Improves paging performance and allows the use of a simpler page replacement policy

Combined Paging and Segmentation

In a combined paging/segmentation system, a user's address space is broken up into a number of segments. Each segment is, in turn, broken up into a number of fixed-size pages, which are equal in length to a main memory frame. Segmentation is visible to the programmer. Paging is transparent to the programmer.

Simple Segmentation

Main memory not partitioned. Program segments specified by the programmer to the compiler (i.e., the decision is made by the programmer). No internal fragmentation. External fragmentation. Operating system must maintain a segment table for each process showing the load address and length of each segment. Operating system must maintain a list of free holes in main memory. Processor uses segment number, offset to calculate absolute address. All the segments of a process must be in main memory for process to run, unless overlays are used.

Virtual Memory Segmentation

Main memory not partitioned. Program segments specified by the programmer to the compiler (i.e., the decision is made by the programmer). No internal fragmentation. External fragmentation. Operating system must maintain a segment table for each process showing the load address and length of each segment. Operating system must maintain a list of free holes in main memory. Processor uses segment number, offset to calculate absolute address. Not all segments of a process need be in main memory for the process to run. Segments may be read in as needed. Reading a segment into main memory may require writing one or more segments out to disk.

Simple Paging

Main memory partitioned into small fixed-size chunks called frames. Program broken into pages by the compiler or memory management system. Internal fragmentation within frames. No external fragmentation. Operating system must maintain a page table for each process showing which frame each page occupies. Operating system must maintain a free frame list. Processor uses page number, offset to calculate absolute address. All the pages of a process must be in main memory for process to run, unless overlays are used.

Virtual Memory Paging

Main memory partitioned into small fixed-size chunks called frames. Program broken into pages by the compiler or memory management system. Internal fragmentation within frames. No external fragmentation. Operating system must maintain a page table for each process showing which frame each page occupies. Operating system must maintain a free frame list. Processor uses page number, offset to calculate absolute address. Not all pages of a process need be in main memory frames for the process to run. Pages may be read in as needed. Reading a page into main memory may require writing a page out to disk.

Execution of a Proces Implications

More processes may be maintained in main memory - only load in some of the pieces of each process - with so many processes in main memory, it is very likely a process will be in the Ready state at any particular time A process may be larger than all of 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 If allocation is too large, there will be too few programs in main memory: - increased processor idle time - increased time spent in swapping

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.

Execution of a Process

Operating system brings into main memory a few pieces of the program Resident set - portion of process that is in main memory An interrupt is generated when an address is needed that is not in main memory Operating system places the process in a blocking state Piece of process that contains the logical address is brought into main memory - operating system issues a disk I/O Read request - another process is dispatched to run while the disk I/O takes place - an interrupt is issued when disk I/O is complete, which causes the operating system to place the affected process in the Ready state

Inverted Page Table

Page number portion of a virtual address is mapped into a hash value - hash value points to inverted page table Fixed proportion of real memory is required for the tables regardless of the number of processes or virtual pages supported Structure is called inverted because it indexes page table entries by frame number rather than by virtual page number

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"

Principle of Locality

Program and data references within a process tend to cluster Only a few pieces of a process will be needed over a short period of time Therefore it is possible to make intelligent guesses about which pieces will be needed in the future Avoids thrashing

Least Recently Used (LRU)

Replaces the page that has not been referenced for the longest time By the principle of locality, this should 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

page-fault frequency (PFF)

Requires a use bit to be associated with each page in memory Bit is set to 1 when that page is accessed When a page fault occurs, the OS notes the virtual time since the last page fault for that process Does not perform well during the transient periods when there is a shift to a new locality

Clock Policy

Requires the association of an additional bit with each frame - referred to as the use bit When a page is first loaded in memory or referenced the use bit is set to 1. The set frames is considered to be a circular buffer. Any frame with a use bit of 1 is passed over by the algorithm. Page frames visualized as laid out in a circle.

Segmentation

Segmentation allows the programmer to view memory as consisting of multiple address spaces or segments Advantages: - simplifies handling of growing data structures - allows programs to be altered and recompiled independently - lends itself to sharing data among processes - lends itself to protection

Protection and Sharing

Segmentation lends itself to the implementation of protection and sharing policies Each entry has a base address and length so inadvertent memory access can be controlled Sharing can be achieved by segments referencing multiple processes

Optimal Policy

Selects the page for which the time to the next reference is the longest Produces three page faults after the frame allocation has been filled

Resident Set Management

The OS must decide how many pages to bring into main memory - the smaller the amount of memory allocated to each process, the more processes can reside in memory - small number of pages loaded increases page faults - beyond a certain size, further allocations of pages will not effect the page fault rate

Associative Mapping

The TLB only contains some of the page table entries so we cannot simply index into the TLB based on page number - each TLB entry must include the page number as well as the complete page table entry. The processor is equipped with hardware that allows it to interrogate simultaneously a number of TLB entries determine if there is a match on page number.

virtual address

The address assigned to a location in virtual memory to allow that location to be accessed as though it were part of main memory.

real address

The address of a storage location in main memory.

Operating System Software

The design of the memory management portion of an operating system depends on three fundamental areas of choice: • Whether or not to use virtual memory techniques • The use of paging or segmentation or both • The algorithms employed for various aspects of memory management

Page Replacement

The page frame data table is used for page replacement Pointers are used to create lists within the table - all available frames are linked together in a list of free frames available for bringing in pages - when the number of available frames drops below a certain threshold, the kernel will steal a number of frames to compensate

address space

The range of memory addresses available to a process.

Replacement Scope

The scope of a replacement strategy can be categorized as global or local - both types are activated by a page fault when there are no free page frames Local: chooses only among the resident pages of the process that generated the page fault Global: considers all unlocked pages in main memory

Page Size

The smaller the page size, the lesser the amount of internal fragmentation - however, more pages are required per process - more pages per process means larger page tables - for large programs in a heavily multiprogrammed environment some portion of the page tables of active processes must be in virtual memory instead of main memory - the physical characteristics of most secondary-memory devices favor a larger page size for more efficient block transfer of data

Paging

The term virtual memory is usually associated with systems that employ paging Use of paging to achieve virtual memory was first reported for the Atlas computer Each process has its own page table each page table entry contains the frame number of the corresponding page in main memory

virtual address space

The virtual storage assigned to a process.

First-In, First-Out (FIFO)

Treats page frames allocated to a process as a circular buffer Pages are removed in round-robin style - simple replacement policy to implement Page that has been in memory the longest is replaced

Frame Locking

When a frame is locked the page currently stored in that frame may not be replaced - Kernel of the OS as well as key control structures are held in locked frames. - I/O buffers and time critical areas may be locked into main memory frames. - Locking is achieved by associating a lock bit with each frame.

Variable Allocation Local Scope

When a new process is loaded into main memory, allocate to it a certain number of page frames as its resident set When a page fault occurs, select the page to replace from among the resident set of the process that suffers the fault Reevaluate the allocation provided to the process and increase or decrease it to improve overall performance Decision to increase or decrease a resident set size is based on the assessment of the likely future demands of active processes Key elements: - criteria used to determine resident set size - the timing of changes

Replacement Policy and Cache Size

With large caches, replacement of pages can have a performance impact - if the page frame selected for replacement is in the cache, that cache block is lost as well as the page that it holds - in systems using page buffering, cache performance can be improved with a policy for page placement in the page buffer - most operating systems place pages by selecting an arbitrary page frame from the page buffer

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

Page Table Entry Include

• Page number: This is the page number portion of the virtual address. • Process identifier: The process that owns this page. The combination of page number and process identifier identify a page within the virtual address space of a particular process. • Control bits: This field includes flags, such as valid, referenced, and modified; and protection and locking information. • Chain pointer: This field is null (perhaps indicated by a separate bit) if there are no chained entries for this entry. Otherwise, the field contains the index value (number between 0 and 2 m - 1) of the next entry in the chain.


Ensembles d'études connexes

UCSD CSE12 Quiz 1 W19 Gary Gillespie

View Set

Foundations Exam 2 Chapter 16 PrepU

View Set

Med Surg Ch. 36 HIV/AIDS patient management

View Set

NA23- Patterns & General Rules 1

View Set