The patch titled Subject: mm: re-unify the simplified page_zap_*_rmap() function has been added to the -mm mm-unstable branch. Its filename is mm-re-unify-the-simplified-page_zap__rmap-function.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-re-unify-the-simplified-page_zap__rmap-function.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Subject: mm: re-unify the simplified page_zap_*_rmap() function Date: Sun Oct 30 15:14:43 2022 -0700 Now that we've simplified both the anonymous and file-backed page zap functions, they end up being identical except for which page statistic they update, and we can re-unify the implementation of that much simplified code. To make it very clear that this is only for the final pte zapping (since a lot of the simplifications depended on that), name the unified function 'page_zap_pte_rmap()'. Link: https://lore.kernel.org/all/B88D3073-440A-41C7-95F4-895D3F657EF2@xxxxxxxxx/ Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Cc: Nadav Amit <nadav.amit@xxxxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: John Hubbard <jhubbard@xxxxxxxxxx> Cc: Alexander Gordeev <agordeev@xxxxxxxxxxxxx> Cc: Aneesh Kumar <aneesh.kumar@xxxxxxxxxxxxx> Cc: Christian Borntraeger <borntraeger@xxxxxxxxxxxxx> Cc: Gerald Schaefer <gerald.schaefer@xxxxxxxxxxxxx> Cc: Heiko Carstens <hca@xxxxxxxxxxxxx> Cc: Nick Piggin <npiggin@xxxxxxxxx> Cc: Sven Schnelle <svens@xxxxxxxxxxxxx> Cc: Vasily Gorbik <gor@xxxxxxxxxxxxx> Cc: Will Deacon <will@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/rmap.h | 3 +-- mm/memory.c | 5 ++--- mm/rmap.c | 39 +++++++++------------------------------ 3 files changed, 12 insertions(+), 35 deletions(-) --- a/include/linux/rmap.h~mm-re-unify-the-simplified-page_zap__rmap-function +++ a/include/linux/rmap.h @@ -196,8 +196,7 @@ void page_add_new_anon_rmap(struct page unsigned long address); void page_add_file_rmap(struct page *, struct vm_area_struct *, bool compound); -void page_zap_file_rmap(struct page *); -void page_zap_anon_rmap(struct page *); +void page_zap_pte_rmap(struct page *); void page_remove_rmap(struct page *, struct vm_area_struct *, bool compound); --- a/mm/memory.c~mm-re-unify-the-simplified-page_zap__rmap-function +++ a/mm/memory.c @@ -1402,9 +1402,8 @@ again: if (pte_young(ptent) && likely(!(vma->vm_flags & VM_SEQ_READ))) mark_page_accessed(page); - page_zap_file_rmap(page); - } else - page_zap_anon_rmap(page); + } + page_zap_pte_rmap(page); munlock_vma_page(page, vma, false); rss[mm_counter(page)]--; if (unlikely(page_mapcount(page) < 0)) --- a/mm/rmap.c~mm-re-unify-the-simplified-page_zap__rmap-function +++ a/mm/rmap.c @@ -1413,47 +1413,26 @@ static void page_remove_anon_compound_rm } /** - * page_zap_file_rmap - take down non-anon pte mapping from a page + * page_zap_pte_rmap - take down a pte mapping from a page * @page: page to remove mapping from * - * This is the simplified form of page_remove_rmap(), with: - * - we've already checked for '!PageAnon(page)' - * - 'compound' is always false - * - the caller does 'munlock_vma_page(page, vma, compound)' separately - * which allows for a much simpler calling convention. + * This is the simplified form of page_remove_rmap(), that only + * deals with last-level pages, so 'compound' is always false, + * and the caller does 'munlock_vma_page(page, vma, compound)' + * separately. * - * The caller holds the pte lock. - */ -void page_zap_file_rmap(struct page *page) -{ - if (!atomic_add_negative(-1, &page->_mapcount)) - return; - - lock_page_memcg(page); - __dec_lruvec_page_state(page, NR_FILE_MAPPED); - unlock_page_memcg(page); -} - -/** - * page_zap_anon_rmap(page) - take down non-anon pte mapping from a page - * @page: page to remove mapping from - * - * This is the simplified form of page_remove_rmap(), with: - * - we've already checked for 'PageAnon(page)' - * - 'compound' is always false - * - the caller does 'munlock_vma_page(page, vma, compound)' separately - * which allows for a much simpler calling convention. + * This allows for a much simpler calling convention and code. * * The caller holds the pte lock. */ -void page_zap_anon_rmap(struct page *page) +void page_zap_pte_rmap(struct page *page) { - /* page still mapped by someone else? */ if (!atomic_add_negative(-1, &page->_mapcount)) return; lock_page_memcg(page); - __dec_lruvec_page_state(page, NR_ANON_MAPPED); + __dec_lruvec_page_state(page, + PageAnon(page) ? NR_ANON_MAPPED : NR_FILE_MAPPED); unlock_page_memcg(page); } _ Patches currently in -mm which might be from torvalds@xxxxxxxxxxxxxxxxxxxx are mm-introduce-simplified-versions-of-page_remove_rmap.patch mm-inline-simpler-case-of-page_remove_file_rmap.patch mm-re-unify-the-simplified-page_zap__rmap-function.patch mm-delay-rmap-removal-until-after-tlb-flush.patch