• Kirill A. Shutemov's avatar
    khugepaged: add support of collapse for tmpfs/shmem pages · f3f0e1d2
    Kirill A. Shutemov authored
    This patch extends khugepaged to support collapse of tmpfs/shmem pages.
    We share fair amount of infrastructure with anon-THP collapse.
    
    Few design points:
    
      - First we are looking for VMA which can be suitable for mapping huge
        page;
    
      - If the VMA maps shmem file, the rest scan/collapse operations
        operates on page cache, not on page tables as in anon VMA case.
    
      - khugepaged_scan_shmem() finds a range which is suitable for huge
        page. The scan is lockless and shouldn't disturb system too much.
    
      - once the candidate for collapse is found, collapse_shmem() attempts
        to create a huge page:
    
          + scan over radix tree, making the range point to new huge page;
    
          + new huge page is not-uptodate, locked and freezed (refcount
            is 0), so nobody can touch them until we say so.
    
          + we swap in pages during the scan. khugepaged_scan_shmem()
            filters out ranges with more than khugepaged_max_ptes_swap
    	swapped out pages. It's HPAGE_PMD_NR/8 by default.
    
          + old pages are isolated, unmapped and put to local list in case
            to be restored back if collapse failed.
    
      - if collapse succeed, we retract pte page tables from VMAs where huge
        pages mapping is possible. The huge page will be mapped as PMD on
        next minor fault into the range.
    
    Link: http://lkml.kernel.org/r/1466021202-61880-35-git-send-email-kirill.shutemov@linux.intel.comSigned-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    f3f0e1d2
shmem_fs.h 3.99 KB