paging: design issues. readings r silbershatz et al: 8.4-8.5, 9.5-9.10
TRANSCRIPT
![Page 1: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/1.jpg)
Paging: Design Issues
![Page 2: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/2.jpg)
Readings
Silbershatz et al: 8.4-8.5, 9.5-9.10
![Page 3: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/3.jpg)
Outline
Frame Allocation Case Studies
![Page 4: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/4.jpg)
Thrashing A process causing page faults every few
instructions is said to be thrashing If a process does not have “enough”
pages, the page-fault rate is very high. This leads to: low CPU utilization; operating system thinks that it needs to
increase the degree of multiprogramming; another process added to the system;
To minimize thrashing requires that we carefully consider issues related to frame allocation
![Page 5: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/5.jpg)
Frame Allocation
How do we allocate the fixed amount of memory among the various processes
What is the minimum number of frames?
How many frames should a process get?
Should a process replace a page being used by another process?
![Page 6: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/6.jpg)
Minimum Number of Frames Each process needs a minimum number of pages Example: 6 pages needed by one instruction
Instruction might span 2 pages 1st argument spans 2 pages 2nd argument spans 2 pages
We must have enough frames to hold all the different pages that any single instruction can reference
The minimum number of frames is defined by the computer architecture
![Page 7: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/7.jpg)
Global vs Local Allocation We have discussed several algorithms for
choosing a page to replace when a page fault occurs
However, we have not discussed how memory should be allocated among the current executing processes
For example, should a process only be allowed to replace any page or only its pages? Global vs Local
![Page 8: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/8.jpg)
Global vs. Local Allocation Global replacement
Process selects a replacement frame from the set of all frames
A process can take a frame from another based on some priority scheme
Allows for the number of frames assigned to a process to dynamically vary
A process cannot control its own page-fault rate
![Page 9: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/9.jpg)
Global vs. Local Allocation Local replacement
Each process selects from only its own set of allocated frames
Corresponds to allocating every process a fixed fraction of memory
This assumes a fixed allocation of frames to a process
A process that thrashes cannot cause another process to thrash by stealing its frames
![Page 10: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/10.jpg)
Global vs. Local Allocation Which is better global or local? On the surface it may seem that local is
better since thrashing problems can’t spread but ….. I/O Competition:
• Other thrashing processes • Processes that may page fault but are not
necessarily thrashing This implies a average longer wait for the
disk read
![Page 11: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/11.jpg)
Global vs. Local Allocation
The number of pages actually needed (working set) varies over time
Global usually means better utilization If the working set shrinks local algorithms
waste memory Global algorithms are usually used but
some operating systems use a mix
![Page 12: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/12.jpg)
Global Allocation If a global algorithm is used the
operating system must decide how many frames to assign to each process Fixed vs proportional
![Page 13: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/13.jpg)
Fixed vs Proportional Allocation
All processes are started with the same number of pages (fixed)
Does it really make sense to start a small process with the same number as a large process Allocate based on process size (proportional)
![Page 14: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/14.jpg)
Other Considerations Prepaging
A page fault occur when a page is not found in memory
You can bring that page in as well as adjacent pages
In reading from disk most of the overhead is in waiting for the disk to be in a position to read the data
The actual transfer of data is relatively slow Why not then read several pages into
memory?
![Page 15: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/15.jpg)
Other Considerations Copy-on-Write
Remember that the fork() system call works by creating a copy of the parent’s address space for the child
You can allow the parent and the child to initially share the same pages
When a child needs a page then a copy is made.
![Page 16: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/16.jpg)
Other Considerations I/O Interlock
Pages must sometimes be locked into memory
Consider I/O - Pages that are used for copying a file from a device must be locked from being selected for eviction by a page replacement algorithm
![Page 17: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/17.jpg)
Case Study – Windows Virtual memory with demand page Can support 32 or 64 bit Has a pool of free frames Uses prepaging (called clustering) What happens if the amount of free
memory falls below some threshold? Each process has a minimum number of
processes Windows will take away pages that exceed
that minimum Applies LRU Locally
![Page 18: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/18.jpg)
Case Study - Window Each process is guaranteed to have a
minimum number of frames Each process has a maximum number
of frames If a page fault occurs for a process that
has the maximum number of frames a local replacement policy is used
If a page fault occurs for a process that is below its working set maximum a free frame is used.
![Page 19: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/19.jpg)
Case Study – Windows Uses LRU Implementation depends on
architecture Supports copy-on-write
![Page 20: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/20.jpg)
Case Study – Solaris Virtual memory with demand paging Can support 32 or 64 bit Global replacement
![Page 21: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/21.jpg)
Case Study – Solaris Maintains a list of free frames A free frame is is assigned to a process
that page faults. If the number of free pages falls below
a treshold value (lotsfree) a process called pageout starts.
pageout process Scans all pages and sets a reference bit to 0 Later it checks the pages to determine if it
has been written to. If not it is freed.
Pages that are shared are not freed.
![Page 22: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/22.jpg)
Case Study - Linux
Virtual memory with demand paging Can support 32 or 64 bit Global replacement Replacement
Least frequently used (LFU) policy Different implementations for different
systems
![Page 23: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/23.jpg)
Case Study-Android, IoS PCs and Servers: Support some form of
swapping Mobile devices -- Rely a lot on flash
memory for persistent storage It’s fast Flash memory can tolerate a limited number
of writes before it becomes unreliable Support
Typically no swapping Paged systems
![Page 24: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/24.jpg)
Case Study-Android
No swap space for memory Does have
Paging Memory Mapping (map file to virtual
memory) Implications
Modified data (e.g., stack is not removed) Read-only data (e.g., code) can be removed
from the system and reloaded from flash memory
![Page 25: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/25.jpg)
Case Study -- Android Sharing Memory
Each app is forked from an existing process called Zygote• Zygote loads framework code• RAM pages allocated for framework code is
shared by application processes Static data (e.g., code) is often mapped to
specific pages Some dynamic memory is explicitly shared
by Android and applications• Example: Window surfaces use shared memory
between the app and screen compositor
![Page 26: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/26.jpg)
Case Study - Android
Allocating and Reclaiming Memory Heaps
• Heap size is limited• Can grow stack but only to some maximum
number• Unused heap pages are reclaimed by a garbage
collector
![Page 27: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/27.jpg)
Case Study - Android
Switching applications Android keeps processes that are not
hosting a foreground ("user visible") app component in a least-recently used (LRU) cache.
The system keeps the process cached, so if the user later returns to the app, the process is reused for faster app switching.
As the system runs low on memory, it may kill processes in the LRU cache beginning with the process least recently used
![Page 28: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/28.jpg)
Case Study-Android
Implications Developers must carefully allocate and
release memory to ensure that their applications do not use too much memory or suffer from memory leaks
![Page 29: Paging: Design Issues. Readings r Silbershatz et al: 8.4-8.5, 9.5-9.10](https://reader036.vdocuments.us/reader036/viewer/2022062511/5519c954550346695e8b4a0b/html5/thumbnails/29.jpg)
Summary
This section studied how page tables are implemented
Case Studies are presented