Download presentation
Presentation is loading. Please wait.
Published byMilton Glenn Modified over 9 years ago
1
Memory Management in Linux David Chang OS Lab., NCTU,Taiwan
2
Agenda Initialization Page Fault Handling Page Cache and Swap Cache Swap Area Management Copying Virtual Address Spaces
3
Initialization paging_init() –set up the page tables to map in all the available physical memory –Kernel has the virtual address from 3G~4G –physical address = virtual address - 3G (see figure) free_area_init() –allocate and initialize the page structures Linux use a page structure for one physical page all page structures are marked as DMAable and RESERVED –allocate and initialize the swap cache and free area list
4
Address Mapping in Kernel Virtual address Physical address 0 3G 4G E.g. 16M
5
Initialization mem_init() –fixup the page structures and make all the available pages free….
6
Page Fault Handling do_page_fault() –this routine is a dispatcher that is invoked when page fault occurs –Works: find out the faulting address find out the reason for the fault and call the right routine –protection fault: do_wp_page() –page-not-present fault: do_no_page()
7
Page Fault Handling do_wp_page() –handle write protection fault –Copy-On-Write if necessary do_no_page() –used to page-in a page – determine the source of the page Executable file? Swap area ? Or Anonymous page?
8
Page Fault Handling Page-in from an executable file –When an executable file is opened, Linux will attach the file operations for the file. The file operations include a mmap( ) function –For UFS, this mmap() function points to generic_file_mmap( ) –After opening the file, Linux maps segments by do_mmap( ) –do_mmap() will actually call the mmap() file operation to attach the vm_operations for the vma –The vm operation contains a nopage( ) which is called when page fault occurs( see filemap_nopage() )
9
Page Fault Handling do_mmap() –construct a vma –insert the vma->vm_op by calling file->f_op->mmap() –brings in pages if VM_LOCKED is specified filemap_nopage() –look for the page from page cache first –read-in the page if cache miss –read-ahead if necessary
10
Swap Area Management do_swap_page() –determine if the vma that contains the faulting page has swapin() vm_operation –call swap_in() if the vma doesn’t have swapin() vm operation swap_in() –the default swap in operation: allocate a free page and get the content of the page from the swap area –de-allocate the swap page in swap area!!!!!!!
11
Swap Area Organization swap_info lockmap A swap area 1111111111111… 111……………… 111……00000000 00SWAP-SPACE
12
Swap Area Management swap_on() –enable a swap area –allocate pages for lockmap and swapmap –insert the swap area into the swap list
13
Copying Virtual Address Spaces When Linux create a new process by fork(), it will call copy_mm() to copy the address space from the father to the child. The child can share the same address space with its father if the CLONE_VM is specified copy_mm() –new_page_tables( ) allocate a page for PTEs and copy the kernel-part PTEs –dup_mmap( ) duplicate the mmap
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.