130 likes | 218 Views
CS 6560 Operating System Design. Lecture 15 Process Address Space Page Cache. References. Textbook, chapters 14 and 15. The Memory Descriptor. Called mm_struct and referenced by current->mm_struct Represents a process’ address space Contains Reference to memory areas As a linked list
E N D
CS 6560 Operating System Design Lecture 15 Process Address Space Page Cache
References • Textbook, chapters 14 and 15
The Memory Descriptor • Called mm_struct and referenced by current->mm_struct • Represents a process’ address space • Contains • Reference to memory areas • As a linked list • Reference to search tree • Reference counts for • Users and processes • Start and end addresses for • Code • Data • Heap • Stack • Command arguments • Environmental variables • Paging information
Memory Descriptor • Sharing • Can be shared within thread group • Allocation • by mm_struct slab allocator • Deallocation • Decrement reference count • If zero, put back in mm_struct cache • Use by kernel threads • Current->mm_struct is null • Share page tables with whatever process was last
Memory Areas • Virtual Memory Area = VMA • VMA_struct represents single memory area (object) over a contiguous interval in an address space. • Has • Reference to address space • Start and end address • Reference for membership in a list of memory areas • Access permissions • Inode reference • Flags • Operations • File reference
VMA Flags • Many flags control properties (page: read, write, execute, shared; growth: up down; file: write and execute; locking; device type; and more • VM_READ - pages can be read • VM_WRITE - pages can be written to • VM_EXEC - pages can be executed • VM_SHARED - pages can be shared • VM_MAYREAD - VM_READ flag can be set • …. (see page 257)
VMA Operations • Operations • Open - invoked when this VMA is added to address space • Close - invoked when this VMA is removed from address space • Nopage - invoked by page fault handler when a page is not present in memory • Populate - called when remap_pages system call is called. (see man 2 mremap)
Example • Use pmap or /proc/xxx/maps, where xxx is the PID of a process
System Calls • Mmap, mmap • Establishes a mapping between a memory interval on the process’ address space and a file or shared memory object. • creates a new linear address interval. Either joins existing VMA or creates new one. • Implemented by do_mmap. • Uses page tables to do the mapping • Mmap • Removes memory mappings. • Implemented by do_mmunmap
Page Cache • Page cache is used for caching virtual memory pages between primary and secondary storage. • Consists of physical pages in RAM • Pages originate in a variety of actions • Reading and writing regular files • Blocks of block devices • Memory-mapped files
Reading and Writing Pages • Reads happen immediately, but writes are delayed. • Generic code for reading and writing is in mm/filemap.c page: • do_generic_readpage • Searches cache for page • If the page exists get the data • If the page does not exit, creates new structure, adds it to the cache, reads page from disk and return data to user buffer • Writing • Whenever page is modified, call set_dirty • Writing is delayed and done in stages, placing the data in the page cache each time.
Page Cache and Block I/O • Each page can consist of several blocks in the block I/O system.
Page Daemons • Pdflush • Writes dirty pages to disk • When free memory is smaller than a limit, writes dirty pages to disk • When dirty data gets too old • Can spawn multiple copies of itself and terminate threads as needed.