Memory%20Management%20in%20Linux - PowerPoint PPT Presentation

About This Presentation
Title:

Memory%20Management%20in%20Linux

Description:

The vm operation contains a nopage( ) which is called when page fault occurs ... construct a vma. insert the vma- vm_op by calling file- f_op- mmap ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 14
Provided by: db2a3
Category:

less

Transcript and Presenter's Notes

Title: Memory%20Management%20in%20Linux


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 3G4G
  • 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
0 3G 4G
E.g. 16M
Virtual address Physical address
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-gtvm_op by calling
    file-gtf_op-gtmmap()
  • 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 doesnt 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
A swap area
1111111111111 1111111111111 111 11100000
000 00SWAP-SPACE
lockmap
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
Write a Comment
User Comments (0)
About PowerShow.com