Title: Virtual Memory
1Virtual Memory
2Methods for Data Transfer
- Paging fixed sized data being swapped
- Segmentation variable sized memory blocks
3Comparison
Paging Segmentation
Words per address One Two
Programmer Visible? Invisible to application programmer May be visible to application programmer
Replacing a block Trivial (all blocks are the same size) Hard (must find contiguous, variable-size, unused portion of main memory)
Memory use inefficiency Internal fragmentation (unused portion of page) External fragmentation (unused portion of main memory)
Efficient disk traffic Yes (adjust page size to balance access time and transfer time) Not always (small segments may transfer just a few bytes)
4Translation Lookaside Buffer
- TLB a special cache used to keep track of
recently used translation - use bit monitor usage for replacement
- dirty bit monitor alterations
5Page Table Actions
6Virtual Memory Summary
CPU
virtual address
TLB
Page table
physical address
Cache
DRAM
physical address
disk address
Disk
7Paged Virtual Memory
- Page Tables
- Paging
- Dynamic Address Translation
- Paging Supervisor
- Permanently Resident Pages
8Page Tables
- Used to translate virtual addresses seen by the
application program into physical addresses
9Paging
- Process of saving inactive virtual memory pages
to disk and restoring them to real memory when
required
10Dynamic Address Translation
- Translates address of particular instructions at
virtual address to corresponding physical address
(MMU), raises a page fault exception when page
tables indicate that the virtual memory page
isnt currently in real memory
11Paging Supervisor
- Part of the OS that creates and manages page
tables - When the dynamic address translation hardware
raises page fault exception, paging supervisor
searches the paged files (on disk) and reads it
into physical memory
12Permanently Resident Pages
- Memory that can not be swapped out for secondary
storage - Interrupt
- Page tables
- Data buffer
- Timing-dependent kernel/application
13Page Replacement Algorithms
- Local selects for replacement some page that
belongs to that same process or group of
processes sharing a memory partition - Global free to select any page in memory to
replace
14Algorithms
- Not recently Used
- First-in, First-out
- Second-chance
- Clock
- Least recently used (and variants of it)
- Random
- Ageing
15Not recently used
- Favours keeping pages in memory that have been
recently used. - Class 0 not referenced, not modified
- Class 1 not referenced, modified
- Class 2 referenced, not modified
- Class 3 referenced, modified
- Randomly picks from lowest category for removal
16First-in, first-out
- Pages in memory are kept in a queue, pages in the
front gets replaced first
17Second-chance
- Similar to first-in, first-out except that
theres a reference bit, if front of queues
pages reference bit is not set, it will be
swapped out, else it is moved to the back of the
queue
18Clock
- Even more efficient version of FIFO
- Has an iterator pointing at oldest page, if
reference bit is not set, it gets replace, else
iterator is incremented to next
19Least recently used
- Replaces the least recently used pages in memory
20Random
- Just replaces a random page in memory
21Not frequently used
- Every page has a counter
- All pages that have been referenced gets counter
incremented - Page with lowest counter is swapped out
22Ageing
- Descendant of not frequently used
- Pages with closer to present time has higher
impact as to it being swapped out or not - Page with lowest counter and oldest references
get swapped out
23Thrashing
- Shuffling blocks of virtual memory between real
memory and disks
24