Presentation is loading. Please wait.

Presentation is loading. Please wait.

Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.

Similar presentations


Presentation on theme: "Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations."— Presentation transcript:

1 Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations

2 Virtual Memory 2 Introduction Memory management unit (MMU) –Responsible for getting data to and from main memory Virtual memory –The notion of an address space as distinct from memory locations –Translation tables –Page-based

3 Virtual Memory 3 Introduction (cont) Memory management in the Stone Age –Software overlay –Swapping –Demand paging –Segmentation

4 Virtual Memory 4 Demand Paging Primary goal –To allow a process to run in a virtual address space –To perform translations from virtual to physical addresses transparently to the process Functional requirements –Address space management fork( ), exec( ) –Address translation Virtual address  Virtual page number + offset

5 Virtual Memory 5 Demand Paging (cont) –Physical memory management –Memory protection –Memory sharing –Monitoring system load –Other facilities Memory-mapped files Dynamically linked shared libraries etc.

6 Virtual Memory 6 Demand Paging (cont) executable file main memory swap area on disk text and initialized data uninitialized data pages zero-filled on first access stack and heap pages allocated on first access dirty pages saved initialized data subsequent faults on outswapped pages Page swapping

7 Virtual Memory 7 Demand Paging (cont) Translation maps hardware address translations address space map physical memory map backup store map process + virtual page number physical page number Data page fault

8 Virtual Memory 8 Demand Paging (cont) Page replacement policies –Local v.s. global replacement policy –Locality of reference –Concept of working set –Least recently used (LRU) policy

9 Virtual Memory 9 Hardware Requirements MMU –Translation of virtual addresses –Using page tables or TLBs Page table entry –Physical page frame number –Protection information –a valid bit –a modified bit –a referenced bit

10 Virtual Memory 10 Hardware Requirements (cont) Page table –Hardware-prescribed –Located in main memory –MMU uses only the active tables, whose locations are loaded in h/w page table registers –Typically, on a uniprocessor, there are two active page tables - one for kernel and one for the currently running process –Paging the page table to reduce the required memory

11 Virtual Memory 11 Hardware Requirements (cont) Address translation may fail for three reasons –Bounds error –Validation error –Protection error MMU caches –A high-speed cache that is searched before each memory access –Translation lookaside buffer (TLB)

12 Virtual Memory 12 Hardware Requirements (cont) Intel x86 –Unix implementations on the x86 hides the notion of segmentation from user processes, who see a flat address space –Two-level page table –4k byte page size –Control register CR3 stores the physical page number of the current page directory –CR3 register needs to be reset on each context switch

13 Virtual Memory 13 Hardware Requirements (cont) –Page table entry Physical page number, protection field Valid, referenced, and modified bit –x86 supports 4 privilege levels of which UNIX uses only two –The kernel runs in the innermost ring, which is the most privileged –User code runs in the outermost, least privileged ring

14 Virtual Memory 14 Address Translation on Intel x86 CR3 PFN 31110 PFN 31110 DIRPAGEOFFSET 3121110 PFNOFFSET 31110 page directory of current process one of the page tables of current process virtual address physical address

15 Virtual Memory 15 Intel x86 Page Table Entry PFN 31126 PFNPage Frame Number DDirty AAccessed (Referenced) UUser (0) / Supervisor (1) WRead (0) / Write (1) PPresent (valid) DAUWP 5210

16 Virtual Memory 16 4.3BSD Target platform: VAX-11 –Several BSD-based implementations emulate the VAX memory architecture in software, including its address space layout and page table entry format Core map –Describes physical memory Page tables –Describe virtual memory

17 Virtual Memory 17 4.3BSD (cont) Disk maps –Describe the swap areas Resource maps –Manage allocation of resources such as page tables and swap space

18 Virtual Memory 18 4.3BSD Physical Memory nonpaged pool error buffer paged pool cmap[ ] (in nonpaged pool)

19 Virtual Memory 19 4.3BSD Physical Memory (cont) Core map: struct cmap –Is a kernel data structure, allocated at boot time and resident in the nonpaged pool –One entry for each frame in the paged pool Core map entry –Name –Text page cache –Synchronization

20 Virtual Memory 20 4.3BSD Physical to Virtual address Translation type = data owner VPN … type = data owner VPN … cmap[ ] proc[ ] text[ ] page table page table

21 Virtual Memory 21 4.3BSD Address Space Uses VAX-11 address space model –32-bit machine with 512-byte page size –4 Giga byte address space is divided into four regions of equal size –P0 Program region Text and data section of the process

22 Virtual Memory 22 4.3BSD Address Space (cont) –P1 Control region User stack, u area, kernel stack –S0 System region Kernel text and data –4th region Reserved and not supported by current VAX h/w

23 Virtual Memory 23 4.3BSD Page Tables Single system page table –Map the kernel text and data Each process has two page tables to map its P0 and P1 –Mapped by a set of contiguous PTEs in the Userptmap section of the system page table State of a particular page of a process –Resident The page is in physical memory, and the page table entry contains its physical page frame number

24 Virtual Memory 24 4.3BSD Page Tables (cont) –Fill-on-demand Fill-from-text: Text and initialized data pages are read in from the executable file upon first access Zero-fill: Uninitialized data, heap, and stack pages are created and filled with zero when required –Outswapped These pages may be recovered from their swap area locations

25 Virtual Memory 25 4.3BSD Page Tables (cont) Kernel maintains information about all nonresident pages –For swapped out pages Kernel must stores their location on the swap device –For zero-fill pages Kernel only needs to recognize them as such –For fill-from-text pages Kernel must determine their location in the filesystem

26 Virtual Memory 26 4.3BSD Page Tables (cont) Page table entry –Since all nonresident pages have the valid bit clear, other fields can be replaced by other information that tracks these pages –Kernel maintains separate swap maps to locate those pages on the swap device

27 Virtual Memory 27 Page Frame Number (PFN)PROT 312620 VMunused 0 valid modified Page Frame Number (PFN)PROT 312620 VM 0 valid modified (a) VAX-11 page table entry format (b) Ordinary page table entry File System Block NumberPROT 312623 V 0 0 1F 25 fill-on-demand fill-from-text (1) or zero-fill (0) (c) Fill-on-demand page table entry 4.3BSD Page Tables Entry

28 Virtual Memory 28 4.3BSD Swap Space Per region dmap structure data region swap space dmap 0 dmmin 2*dmmin 4*dmmin

29 Virtual Memory 29 4.3BSD Swap Space (cont) Text pages –Once the page is brought into memory, the fill- on-demand PTE is overwritten by the page frame number –As a result, retrieving the page from the file involving recomputing its location and perhaps, accessing one or more indirect blocks –To avoid that, such pages are saved in swap as well

30 Virtual Memory 30 4.3BSD Swap Space (cont) U area holds the maps for the data and stack region The text region swap map is part of the text structure

31 Virtual Memory 31 4.3BSD Memory Management Operations Process creation –Swap space, u area –Page tables Kernel must allocate contiguous PTEs in Userptmap to map page tables for their process –Text region The child is added to the list of processes sharing the text structure used by the parent –Data and Stack Data and stack must be copied one page at a time Copy-on-write, vfork( )

32 Virtual Memory 32 4.3BSD Memory Management Operations (cont) Page table handling –Two types of page faults validation, protection –Validation No PTE for that page (bounds error) PTE is marked invalid –Pagein( ) is called to handle the fault The faulting virtual address  PTE

33 Virtual Memory 33 Pagein( ) (1/2) start Fill on demand? NoYes (next page) PFN == 0? No Yes text page on hash queue? (next page) Yes No allocate new page read page from swap in transit text page? No on free list? Yes take page off free list Yes set wanted flag sleep on text struct start over when woken up set valid bit No

34 Virtual Memory 34 Pagein( ) (2/2) fill it with zeros Fill on demand? Yes zero-fill? Yes allocate new page mark page modified text page on hash queue? No page in buffer cache? No Read page from file Yes flush cache copy to disk Yes take page off free list (previous page)

35 Virtual Memory 35 4.3BSD Memory Management Operations (cont) Free page list –Ideally, to keep all garbage pages at the head of the free list, followed by some useful pages in LRU order –4.3BSD replaces the least recently used policy by a not recently used policy Uses referenced bit and two passes over each page VAX-11 does not support a referenced bit in the h/w, so BSD simulates the referenced bit in software Pagedaemon process is responsible for page replacement

36 Virtual Memory 36 4.3BSD Memory Management Operations (cont) Swapping –Problem of thrashing –Swapper process monitors the system load, and swap processes in and out when needed –Swapper will swap out a process in the following cases Userptmap fragmentation Memory shortfall Inactive processes

37 Virtual Memory 37 4.3BSD Memory Management Operations (cont) –Swapper performs the following task when swapping out a process Allocates swap space for the u area, kernel stack, and page tables Detach the process from its text region Save the resident data and stack on swap Release the system PTEs in Userptmap Record the swap location of the u area in the proc structure

38 Virtual Memory 38 Analysis of 4.3BSD No support for execution of remote programs No support for sharing of memory vfork( ) is not a true substitute for fork( ) –The lack of copy-on-write hurts the performance of Ap that rely extensively on fork No support for memory mapped files

39 Virtual Memory 39 Analysis of 4.3BSD (cont) Reserves enough swap space in advance to page out very single page in the process address space No support for using swap space on remote nodes


Download ppt "Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations."

Similar presentations


Ads by Google