Lecture-39 memory management
Lecture-39 memory management
The slides are based on the book: Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
PAGING
❏ Physical address space of a process can be noncontiguous; process is allocated physical
memory whenever the latter is available
❏ Avoids external fragmentation
❏ Avoids problem of varying sized memory chunks
❏ Divide physical memory into fixed-sized blocks called frames
❏ Size is power of 2, between 512 bytes and 16 Mbytes
❏ Divide logical memory into blocks of same size called pages
❏ Keep track of all free frames
❏ To run a program of size N pages, need to find N free frames and load program
❏ Set up a page table to translate logical to physical addresses
❏ Backing store likewise split into pages
❏ Still have Internal fragmentation
BACKGROUND
Code needs to be in memory to execute, but entire program rarely used
Error code, unusual routines, large data structures; are all seldom used
Ex: declared array of size 100 cells but only 10 cells are used
Entire program code not needed (in main memory) at the same time Consider ability to execute
partially-loaded program
Program no longer constrained by limits of physical memory Each program takes less
Logical address space can therefore be much larger than physical address space
More programs running concurrently; increased multi-programming and/or time-sharing Less I/O needed to load
Process starts at address 0 with contiguous addresses until end of its address space Meanwhile, physical
memory organized in page frames; not contiguous MMU maps logical pages to physical pages (i.e., frames) in
memory
Demand paging
Demand segmentation
VIRTUAL MEMORY THAT IS LARGER THAN PHYSICAL MEMORY
DEMAND PAGING
Lazy swapper – never swaps a page into memory unless page will be
needed
Memory is being used up by process pages; both, user and kernel processes
Also memory is in demand from the kernel, I/O buffers, etc
Solution: Page replacement; when paging in pages of a process but no free frames
Find currently un-used frame to free it; Page it out and page in process page
Replacing the un-used memory page with the new page
Performance – want an algorithm which will result in minimum number of page faults
Same page may be brought into memory several times
NEED FOR PAGE REPLACEMENT
BASIC PAGE REPLACEMENT ALGORITHM
The page-fault service routine is modified to include page replacement
Use modify (dirty) bit to reduce overhead of page transfers – only modified
pages are written to disk
Page replacement completes separation between logical memory and physical memory – large virtual
memory can be provided on a smaller physical memory
A user process of 20 pages can be executed in 10 frames simply by using demand-paging and using a
page-replacement algorithm to find a free frame whenever necessary
PAGE- REPLACEMENT AND FRAME-ALLOCATION ALGORITHMS
Two major demand-paging problems : frame allocation and page replacement
Page-replacement algorithm
We want an algorithm which yields the lowest page-fault rate
Each page brought into memory is also inserted into a first-in first-out queue
Page to be replaced is the oldest page; the one at the head of the queue
Belady’s Anomaly
FIFO ILLUSTRATING BELADY’S ANOMALY
OPTIMAL PAGE REPLACEMENT ALGORITHM
[REFERENCE STRING = 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 AND MEMORY = 3 FRAMES]
Replace the page that will not be used for longest period of time
OPR is used only for comparing with new algorithms; how close to the optimal?
LRU PAGE REPLACEMENT ALGORITHM
[REFERENCE STRING = 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 AND MEMORY = 3 FRAMES]
Use the recent past as an approximation of the near future
Replace the page that has not been used for the longest period of time
That is, the least recently used page
Associate time of last use with each page
Our example yields 12 page faults – better than FIFO but worse than OPT
Generally good algorithm and frequently used
Algorithm is feasible but not easy to implement.
LRU algorithm may require substantial hardware support
THANK YOU!
24