• Hugh Dickins's avatar
    mm,thp,rmap: subpages_mapcount of PTE-mapped subpages · be5ef2d9
    Hugh Dickins authored
    Patch series "mm,thp,rmap: rework the use of subpages_mapcount", v2.
    
    
    This patch (of 3):
    
    Following suggestion from Linus, instead of counting every PTE map of a
    compound page in subpages_mapcount, just count how many of its subpages
    are PTE-mapped: this yields the exact number needed for NR_ANON_MAPPED and
    NR_FILE_MAPPED stats, without any need for a locked scan of subpages; and
    requires updating the count less often.
    
    This does then revert total_mapcount() and folio_mapcount() to needing a
    scan of subpages; but they are inherently racy, and need no locking, so
    Linus is right that the scans are much better done there.  Plus (unlike in
    6.1 and previous) subpages_mapcount lets us avoid the scan in the common
    case of no PTE maps.  And page_mapped() and folio_mapped() remain scanless
    and just as efficient with the new meaning of subpages_mapcount: those are
    the functions which I most wanted to remove the scan from.
    
    The updated page_dup_compound_rmap() is no longer suitable for use by anon
    THP's __split_huge_pmd_locked(); but page_add_anon_rmap() can be used for
    that, so long as its VM_BUG_ON_PAGE(!PageLocked) is deleted.
    
    Evidence is that this way goes slightly faster than the previous
    implementation for most cases; but significantly faster in the (now
    scanless) pmds after ptes case, which started out at 870ms and was brought
    down to 495ms by the previous series, now takes around 105ms.
    
    Link: https://lkml.kernel.org/r/a5849eca-22f1-3517-bf29-95d982242742@google.com
    Link: https://lkml.kernel.org/r/eec17e16-4e1-7c59-f1bc-5bca90dac919@google.comSigned-off-by: default avatarHugh Dickins <hughd@google.com>
    Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    Acked-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Cc: Dan Carpenter <error27@gmail.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: James Houghton <jthoughton@google.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: John Hubbard <jhubbard@nvidia.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Miaohe Lin <linmiaohe@huawei.com>
    Cc: Mike Kravetz <mike.kravetz@oracle.com>
    Cc: Mina Almasry <almasrymina@google.com>
    Cc: Muchun Song <songmuchun@bytedance.com>
    Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev>
    Cc: Peter Xu <peterx@redhat.com>
    Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Yang Shi <shy828301@gmail.com>
    Cc: Yu Zhao <yuzhao@google.com>
    Cc: Zach O'Keefe <zokeefe@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    be5ef2d9
transhuge.rst 7.69 KB