• Yin Fengwei's avatar
    mm: handle large folio when large folio in VM_LOCKED VMA range · 1acbc3f9
    Yin Fengwei authored
    If large folio is in the range of VM_LOCKED VMA, it should be mlocked to
    avoid being picked by page reclaim.  Which may split the large folio and
    then mlock each pages again.
    
    Mlock this kind of large folio to prevent them being picked by page
    reclaim.
    
    For the large folio which cross the boundary of VM_LOCKED VMA or not fully
    mapped to VM_LOCKED VMA, we'd better not to mlock it.  So if the system is
    under memory pressure, this kind of large folio will be split and the
    pages ouf of VM_LOCKED VMA can be reclaimed.
    
    Ideally, for large folio, we should mlock it when the large folio is fully
    mapped to VMA and munlock it if any page are unmampped from VMA.  But it's
    not easy to detect whether the large folio is fully mapped to VMA in some
    cases (like add/remove rmap).  So we update mlock_vma_folio() and
    munlock_vma_folio() to mlock/munlock the folio according to vma->vm_flags.
    Let caller to decide whether they should call these two functions.
    
    For add rmap, only mlock normal 4K folio and postpone large folio handling
    to page reclaim phase.  It is possible to reuse page table iterator to
    detect whether folio is fully mapped or not during page reclaim phase. 
    For remove rmap, invoke munlock_vma_folio() to munlock folio unconditionly
    because rmap makes folio not fully mapped to VMA.
    
    Link: https://lkml.kernel.org/r/20230918073318.1181104-3-fengwei.yin@intel.comSigned-off-by: default avatarYin Fengwei <fengwei.yin@intel.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Cc: Yang Shi <shy828301@gmail.com>
    Cc: Yosry Ahmed <yosryahmed@google.com>
    Cc: Yu Zhao <yuzhao@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    1acbc3f9
internal.h 38.6 KB