Upload
eric-thompson
View
216
Download
1
Embed Size (px)
Citation preview
ICOM 5007 - Noack
Memory management
Virtual memoryPaging and segmentation
Demand pagingMemory management hardware
ICOM 5007 - Noack
Virtual memory
Virtual memoryReasons
No program relocation – just remap memory
Security – hardware keeps processes from interfering
Efficiency – only needed memory is loaded
AddressesVirtual address – what the CPU
seesPhysical address – to physical
memoryPage fault interrupt – whenever
virtual address doesn’t map into physical address
Normal operationFirst few lookups cause page faults
and loading of memory blocksAfter a short time, repeated
accesses in same blocks of memory usually work
CPU
Addresstranslation
Physicalmemory
Virtualaddress
Physicaladdress
PageFault
interrupt
ICOM 5007 - Noack
The working set hypothesis
Programs live monotonous livesSmall loops of code or calling same function – these small blocks of code are
used heavilyArrays or structures – program typically works in a few heavily used data areasStack – activity is at the stack top
Common statisticsHit ratio – percent of memory accesses that do not cause page fault interrupts
(or cache hit ratio)Amount of memory needed vs block sizeHit ratio vs number of blocks allowed and block size
Typical tradeoffsPerformance - block size – hit ratio – memory required for
Various program typesNumber of processesAmount of physical memory
ICOM 5007 - Noack
Paging and segmentation
Ideas are familiar to 8086 programmersSegment
Not of fixed size
Access attributes – ownership, access rights (RO, RW, kernel/user)
Few for any given process
Each usually has a purpose
PageFixed size – always a power of 2 – often 4096 bytes
Access attributes – ownership, access rights (RO, RW, kernel/user)
Status and physical page number for each virtual page number
As many as needed
CPU Segmentation Paging Physicalmemory
Virtual address Linear address Physical address
ICOM 5007 - Noack
Demand paging
Basic idea – don’t load it until you need itFeasible because working set hypothesis is valid
Won’t keep working unless some form of page replacement is used to eliminate unused physical pages
Normal operationFirst few lookups cause page faults and loading of memory
blocks
After a short time, repeated accesses in same blocks of memory usually work
Page table formatsDirect – virtualphysical
Inverse - physical virtual
Multilevel - virtual page directory page table physical
ICOM 5007 - Noack
How paging works
Address partsPage number
which pageTranslated by paging
hardware or software
OffsetLength=log2(page size)Not translated by paging
– page is handled as a unit
Translation – directVirtual address used as
index to page table – page table entry says either
Physical page number is…
Or I am on disk at …
Or I am not valid
Page number offset
Address – virtual or physical
offsetPage
number
Directorynumber
Address into multilevel page table
ICOM 5007 - Noack
Multilevel paging and lookaside
Steps Directory base is in a register
Virtual directory number is used to look up page table base
Page table is used to look up page table entry
This gives physical page number or how to find it on disk
ConsequencesThree memory accesses for each real memory transaction
Remedy Transaction lookup buffer in hardware
This remembers last few paging lookups
This is what hit ratios are about
ICOM 5007 - Noack
Page tables and page table entries
Page table entryPhysical page number or device/block location on disk
StatusValid
Modified (also called dirty)
Accessed recently
Privilege level
Page directory entryBase of page table
Privilege level
Size of page table (if not fixed)
ICOM 5007 - Noack
The page frame table
An inverse table for all of physical memoryEach page table entry results in a page frame table entry
Not changed at context switch (why)
Contains accessed and modified bits
Used to find pages to swap out or discardDirty pages are written back
Clean ones are discarded
Used to allocate clean pages and by pagedaemon
ICOM 5007 - Noack
Memory management hardware
ICOM 5007 - Noack
Memory management in Linux
Hardware-independent memory management layerAdapts to 32 and 64-bit address widths
Method is three-level page tablesEntity 64 bit 32 bit
Page directory 10 bits 10 bits
Page middle 10 bits 0 bits
Page table 10 bits 10 bits
Page size 13 bits 12 bits
Note: not all the 64 bits are used 43 bits already gives a 43
Tbyte space
Page middle directory has size 1 for 32-bit architectures
This allows same system calls for 32-bit and 64-bit architectures
ICOM 5007 - Noack
Segmentation in Linux
Almost doesn’t existThe main segments are all 4 GB, spanning the entire address space
Kernel memory is actually in top GB (above 3 GB)
User memory is in bottom 3 GB
Register assignments are CS – either user or kernel code segment