Page Frame Reclaiming Swapping - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Page Frame Reclaiming Swapping

Description:

Swapping. Swap-in: asynchronous. Swap-out: sync(kswapd)/async(Buddy failure) Main Issues ... of free, page slots in all active swap areas. Swapped-out page ID ... – PowerPoint PPT presentation

Number of Views:93
Avg rating:3.0/5.0
Slides: 23
Provided by: shihku
Category:

less

Transcript and Presenter's Notes

Title: Page Frame Reclaiming Swapping


1
Page Frame ReclaimingSwapping
  • Swap-in asynchronous
  • Swap-out sync(kswapd)/async(Buddy failure)

2
Main Issues
  • Which Kind of page to swap out
  • How to distribute pages in the swap area
  • How to select pages to be swapped out
  • When to perform page swap-out

3
Which Kind of Pages to Swap out
  • Anonymous memory regions (user mode stack or
    heap)
  • Dirty (Modified) pages of a process (private
    memory mapping)
  • IPC shared memory region
  • Other considerations
  • Swap to files map files on disk
  • No swap for pages used by the kernel

4
How to distribute pages in the swap areas
  • Slots for each page store pages in contiguous
    slots
  • Multiple swap area faster disk for a higher
    priority, searching from the highest priority area

5
How to select the page to be swapped out
  • Steal pages from the process with the largest
    number of pages in RAM
  • Steal pages in the process according to some
    criterion
  • LRU (least recently used), associated with a
    counter for each page table entry
  • For X86, Linux uses Accessed flag.

6
The main function of the PFRA
Low on Memory Reclaiming
Periodic Reclaiming
Hibernation Reclaiming
Low memory on buffer allocation __getblk() alloc_
page_buffers()
Low memory on page allocation __alloc_pages()
Suspend to disk __pm_suspend_disk()
kswapd kernel thread
reap_work work queue
kswapd()
cache_reap()
free_more_memory()
balance_pgdat()
try_to_free_pages()
slab_destroy()
shrink_slab()
shrink_caches
shrink_zone()
out_of_memory()
shrink_cache()
refill_inactive_zone()
shrink_list()
page_referenced()
pageout()
7
When to Perform Page Swap-out
  • Kernel thread kswaped, activated once every
    second when free page below a predefined
    threshold
  • When Buddy system cant be satisfied due to below
    a predefined threshold.

8
Swap Area
  • Disk partition or a file
  • MAX_SWAPFILES
  • 4k byes slot
  • Swap area descriptor, swap_info_struct,

9
Main functions
  • Swap-in
  • do_swap_page(), swap_in(), read_swap_cache_async()
  • Swap-out
  • swap_out(),swap_out_process(),swap_out_vma(),swap_
    out_pgd(), swap_out_pmd(),try_to_swap_out()
  • rw_swap_page() low-level swapping function
    ,brw_page() block device driver function

10
Swap_info_struct
  • swap_map array of counter,
  • 0 page slot is free
  • Positive with a swap-out page
  • SWAP_MAP_MAX permanent, cant be removed
  • SWAP_MAP_BAD unusable
  • Prio goodness of the swap area

11
Variables
  • swap_infoMAX_SWAPFIELS of swap_info_struct
  • nr_swapfiles, indexd of the last array element
  • swap_list, sorted by swap area priority
  • nr_swap_pages, total number of free, page slots
    in all active swap areas

12
Swapped-out page ID
  • Index of swap_info
  • Index of page slot in the swap area
  • SWP_ENTRY(type, offset) -- ID
  • SWP_TYPE, SWP_OFFSET
  • Page ID value in page table entry
  • Null entry not valid in any process
  • Last 2 equal to 0 page swapped out
  • Least 1 equal to 1 page is in RAM

13
Swap_duplicate()
  • SWP_TYPE to extract partition type
  • SWP_OFFSET to extract page slot index
  • Judge If it is a valid ID
  • Increment swap_infotype.swap_mapoffset. If
    counter equal to SWAP_MAP_MAX or SWAP_MAP_BAD
    unchanged

14
Swap area utility functions
  • sys_swapon()
  • sys_swapoff()
  • Finding a free page slot
  • Always from the beginning of the swap area (add
    seek time for swap out functions)
  • Always from the last allocated page slot (add
    seek time for swap in functions)
  • Linux always from the last allocated page slot
    unless
  • End of the swap area reached
  • SWPFILE_CLUSTER free page slots allocated after
    the last restart from the beginning of the swap
    area

15
Scan_swap_map()
  • 1. If cluster_nr positive, scan swap_map array of
    counters at cluster_next, if null found,
    decrement cluster_nr, go to 3
  • 2. Rescan from lowest_bit , set cluster_nr to
    SWAPFILE_CLUSTER
  • 3. Put 1 in the entry, decrement nr_swap_pages,
    update lowest_bit, highest_bit, and cluster_next

16
Allocate and Releasing a page slot
  • Get_swap_page index of a newly allocated page
    slot
  • Swap_free decrement the corresponding swap_map
    counter when swap in

17
SWAP Cache
  • Shared page frame
  • Shared memory mapping (file mapping)
  • Copy on Write
  • IPC shared memory

18
Transferring swap page
  • rw_swap_page
  • read_swap_cache_async
  • rw_swap_page_nocache

19
Page swap out
  • Swap_out
  • Swap_out_process
  • Swap_out_vma
  • Swap_out_pgd
  • Swap_out_pmd
  • Try_to_swap_out

20
Page Swap_in
  • Page address valid
  • Page not in memory
  • Page table entry is not null

21
Freeing Page Frames
  • Reclaim unused page frame in a cache
  • Shrink_mmap
  • Shrink_dcache_memry
  • Shrink_cache_reap
  • Swapping out a page of anonymous memory
  • Swapping out a page of IPC

22
Kswaped kernel thread
  • nr_free_pages gt freepages.high
Write a Comment
User Comments (0)
About PowerShow.com