Memory Management Basics Implementing Paged Segmentation Are We Done?
Individual segments can be implemented as a paged, virtual Segmentation allows sharing address space A segment address address is a pair (s, va) or a triple (s, (p, o)) … but allocation/deallocation of arbitrary size segments is s — segment number complex p — page number (pmax pages) Yields external fragmentation o — page offset (omax bytes/pages)
How can we improve memory management?
Solution: Paged segmentation! Partition segments into fixed-size pages n 0 Allocate and deallocate pages Contiguous pages in VAS need not be contiguous in PAS s p o No external fragmentation, but internal fragmentation possible
Virtual address = (s ×pmax +p) × omax + o 18 19
Implementing Paged Segmentation Sharing in Paged-Segmented Systems Combining segmentation and paging Sharing segments
Add one additional level of indirection to the page table If segments are paged then page tables are automatically shared Processes need only agree on a number for the shared segment CCPPUU MMeemmoorryy s p o f o Virtual Physical Addresses Addresses 19 15 9 0 11 9 shared seg (p,o) 0 heap seg s f = 2 code seg f = 0 57 A’s Segment Table f = 1 f SSTTBBRR ++ page table ++ shared seg s p heap seg Shared Segment s jmp (p,o) code seg Page Table Process P’s Segment S’s B’s Segment Table Physical Memory Segment Table Page Table 20 21 Virtual Memory Concept
2n-1 Key problem: How can one support programs that require more memory than is physically available?
Hide all physical aspects of memory from users Memory is a logically unbounded virtual address space of 2n bytes Program Virtual Memory and Only portions of VAS are in physical memory at any one time P’s Address Translation VAS Issues Placement strategies Where to place programs in physical memory Replacement strategies What to do when there exist more processes than can fit in memory Load control strategies Determining how many processes can be in memory at 0 one time
1 2
Realizing Virtual Memory Physical Address Specifications Paging Frame/Offset pair v. An absolute index
(f -1,o -1) MAX MAX Example: A 16-bit address space with (o Physical memory partitioned into equal max =) 512 byte page frames sized page frames Addressing location (3, 6) = 1,542 (3,6) 1,542 (f,o) o A memory address is a pair (f, o) o f — frame number (f frames) 3 6 max Physical o — frame offset (o bytes/frames) max Memory Physical address = o ×f + o Physical max PA: Memory 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 16 10 9 1 f f PA: 1,542 1 log2 (fmax × omax) log2 omax
(0,0) 0 f o (0,0) 3 4 Realizing Virtual Memory Paging Paging Mapping virtual addresses to physical addresses 2n-1 = (p -1,o -1) MAX MAX Pages map to frames A process’s virtual address space is Pages are contiguous in a VAS... partitioned into equal sized pages Virtual But pages are arbitrarily located page = page frame (p,o) Address in physical memory, and (f ,o ) Not all pages mapped at all times 1 1 o Space A virtual address is a pair (p, o) p — page number (p pages) Virtual max Physical o — page offset (omax bytes/pages) Address (p2,o2) Memory Virtual address = omax×p + o Space
p (p1,o1) (f2,o2) VA: 1 log2 (pmax×omax) log2 oMAX
(0,0) p o 5 6
Paging Virtual Address Translation Details Virtual address translation Page table structure
PPrrogrograamm A page table maps virtual 1 table per process Contents: (f,o) PP pages to physical frames Part of process’s state Flags — dirty bit, resident bit, clock/reference bit Frame number
CCPPUU CCPPUU
P’s p o f o p o f o Virtual Physical Address 20 10 9 1 16 10 9 1 Memory 20 10 9 1 16 10 9 1 Space Virtual Virtual Addresses (p,o) Physical Addresses Physical Addresses Addresses f PPTTBBRR + 0 1 0 f p p
Page Table 7 Page Table 8 Virtual Address Translation Details Virtual Address Translation Example Performance Issues
A system with 16-bit addresses (4,1023) 32 KB of physical memory Problem — VM reference requires 2 memory references! 1024 byte pages One access to get the page table entry (4,0) One access to get the data (3,1023) Page table can be very large; a part of the page table can be CCPPUU Physical Addresses on disk!! P’s p o f o For a machine with 64-bit addresses and 1024 byte pages, what Virtual Physical is the size of a page table? Address 15 11 10 0 15 1110 0 Memory Space Virtual What to do? Addresses Most computing problems are solved by some form of… Caching 0 1 0 0 0 0 0 0 Indirection 0 1 0 0 0 1 0 0
(0,0) Page Table 9 10