From patchwork Mon Nov 6 15:49:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13447145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E26B7C4332F for ; Mon, 6 Nov 2023 15:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 810FA8E0006; Mon, 6 Nov 2023 10:51:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C0A58E0001; Mon, 6 Nov 2023 10:51:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B04D8E0006; Mon, 6 Nov 2023 10:51:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5CB958E0001 for ; Mon, 6 Nov 2023 10:51:01 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 142A5160706 for ; Mon, 6 Nov 2023 15:51:01 +0000 (UTC) X-FDA: 81427967922.25.014D6DC Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf25.hostedemail.com (Postfix) with ESMTP id 85665A001B for ; Mon, 6 Nov 2023 15:50:58 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699285859; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ZbcxIplLz2/cFjSStN8lhzNVnpkbIW45XoB8UcboTY=; b=RdGERe1Nwtd87SwaWVXyWl6zbITUb9ru7INfuGYD9YM9U7TcyR4mDikePNq9xO6moSDrdy +qUnVmkUwYnOc9i5X+FprhkyIAnY7eZJPRO9zZyBdSVvUJ0yuVsnrSevaovkENOtWvvNcg PqkttwVo8f5AUEL+YOETFDYGFYLdq0k= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699285859; a=rsa-sha256; cv=none; b=KcPJHXE/EFHYuIw884Y9mZ89n+gL/xctsDX4GWtDZ0pSNFSgWgA0F4npGJulSUXX6JEg6V W+ntCydVffop8pIHA9Q/2iNMFRzZ6Clki1a1df7wUdhFBEK4iba6CsSwndcan67eONgmst FoyX7ouznq89e+1i1QPP+5wQmu7CW/0= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SPG1b3kWqz1P7xD; Mon, 6 Nov 2023 23:46:59 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 6 Nov 2023 23:50:02 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH 10/10] mm: convert mm_counter_file() to take a folio Date: Mon, 6 Nov 2023 23:49:50 +0800 Message-ID: <20231106154950.3399469-11-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231106154950.3399469-1-wangkefeng.wang@huawei.com> References: <20231106154950.3399469-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 85665A001B X-Stat-Signature: hbhetac3mm1gh1xa71ehweti35ogksgf X-HE-Tag: 1699285858-990559 X-HE-Meta: U2FsdGVkX18safudIAlJF2OnTaZPYbrJGUZCvHp3CGcq5O6D6RAj6fQXDUMaUSkGG0HPMdn5pq15sz+61L9ZKJOlE4F4p3WLVUcOJ5l16rqf7Offr7SeWJAMJUSiXtcoDPi5xfAyloPgey0/5ESF8Ti7PGqzgUJ9a4Me0aNcawfs8fbavU57tFQycPYZ27rhec0XWUYbIzrHgZBvu2ysQQjodYufAfTF7hVL36G+hv2r1KD125Gp4B7ebbhbdoN752oSbVxmUykhtBpU0T73lfYSduDCWtDOI5dufRO5ACAGjoqJz1U7i42PYQvRxwvVn40vfUkoa/tcTYMlpUAYE7wyMI7r1OeUBeEJjV57g4MF34LX6wWWJCiHyRsJvRZqdhxxkWeduzb217I8RD+YetzAZJl8tkL5tq9mrR8+fQ9jOoePTDhjbDR9DUEzsNTKV7h2OCkQEeckj84AwB8KpOaNSa9MVZqUJLpg/RG35Eus5/M4BWQbfToP7egJHuwdTxpgjzKPMIWioYsTd6WG7WUG+Z56UUfSom7zaCB+kDmx3HeXlnwUWsNpWp7lO9e0vk4hA6rWhSKd8xz5HNw3rblir4Aghe86n/0aF1H94tZnea4zXOAL5EacpyX9YezZFRGRk0uajGCHuWDkK3DcLNaHcCLSgcHCpSOPSJAlOPmgKz07npFm+v6suJ83j/bVPixYqKjCnPVNUVxyLqJzvaU/mjpcAkgzTYT4QImWl1fDr+TivQxuMUG/Zt8Aht0KX+FGs6aGASCmmma5A+dQyi2NfZ54c/AyPm49V9qAnup/srttVqdPEWLY/vFVbbOd0x6caoI2XYHGEHrfb0mObozrqpJjiY9SZmMseXFP/aSxyGrPhQkrIfrWnNJFYCTODGnYMDeLECSxsCFBFGiH7PCSD7dmsfUDAV9YgIJeAEi70szotz91tUHK5c6POPl3I+WAHpGBJVTXq5CfKFN LzEoV4xh QKnyvdpv1YneLJ7pnuB7JXjmE05Tuu6Pic7wVW4QO5ruoCYabTuGVh1noaoEQt+90bbhpZGUzVGU05LHrtT8aLjQLhRcOzbe4juGhxl+KlUtCf2EtVxWdZt9YTLxwDCpGb9BaHWNiODK9ZXqvmTFeKhpUS0515f0IjsrcRNO3L3lFzsUemO8y5P7P73Z2Ozh4vtmz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since all mm_counter_file() callers with a folio, let's convert mm_counter_file() to take a folio. Signed-off-by: Kefeng Wang --- include/linux/mm.h | 8 ++++---- kernel/events/uprobes.c | 2 +- mm/huge_memory.c | 5 +++-- mm/khugepaged.c | 4 ++-- mm/memory.c | 10 +++++----- mm/rmap.c | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index fea78900bf84..95573065a46b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2583,10 +2583,10 @@ static inline void dec_mm_counter(struct mm_struct *mm, int member) mm_trace_rss_stat(mm, member); } -/* Optimized variant when page is already known not to be PageAnon */ -static inline int mm_counter_file(struct page *page) +/* Optimized variant when folio is already known not to be anon */ +static inline int mm_counter_file(struct folio *folio) { - if (PageSwapBacked(page)) + if (folio_test_swapbacked(folio)) return MM_SHMEMPAGES; return MM_FILEPAGES; } @@ -2595,7 +2595,7 @@ static inline int mm_counter(struct folio *folio) { if (folio_test_anon(folio)) return MM_ANONPAGES; - return mm_counter_file(&folio->page); + return mm_counter_file(folio); } static inline unsigned long get_mm_rss(struct mm_struct *mm) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 435aac1d8c27..ce251e3a4ae6 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -188,7 +188,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, dec_mm_counter(mm, MM_ANONPAGES); if (!folio_test_anon(old_folio)) { - dec_mm_counter(mm, mm_counter_file(old_page)); + dec_mm_counter(mm, mm_counter_file(old_folio)); inc_mm_counter(mm, MM_ANONPAGES); } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 78a00fe22c2d..88420d067477 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1742,7 +1742,8 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, } else { if (arch_needs_pgtable_deposit()) zap_deposited_table(tlb->mm, pmd); - add_mm_counter(tlb->mm, mm_counter_file(page), -HPAGE_PMD_NR); + add_mm_counter(tlb->mm, mm_counter_file(folio), + -HPAGE_PMD_NR); } spin_unlock(ptl); @@ -2143,7 +2144,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, page_remove_rmap(&folio->page, vma, true); folio_put(folio); } - add_mm_counter(mm, mm_counter_file(&folio->page), -HPAGE_PMD_NR); + add_mm_counter(mm, mm_counter_file(folio), -HPAGE_PMD_NR); return; } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 064654717843..39393f4262b2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1630,7 +1630,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, /* step 3: set proper refcount and mm_counters. */ if (nr_ptes) { folio_ref_sub(folio, nr_ptes); - add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes); + add_mm_counter(mm, mm_counter_file(folio), -nr_ptes); } /* step 4: remove empty page table */ @@ -1661,7 +1661,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, if (nr_ptes) { flush_tlb_mm(mm); folio_ref_sub(folio, nr_ptes); - add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes); + add_mm_counter(mm, mm_counter_file(folio), -nr_ptes); } if (start_pte) pte_unmap_unlock(start_pte, ptl); diff --git a/mm/memory.c b/mm/memory.c index 3ffef84dd7bb..bf4ea31150a9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -961,7 +961,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, } else if (page) { folio_get(folio); page_dup_file_rmap(page, false); - rss[mm_counter_file(page)]++; + rss[mm_counter_file(folio)]++; } /* @@ -1861,7 +1861,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, folio = page_folio(page); /* Ok, finally just insert the thing.. */ folio_get(folio); - inc_mm_counter(vma->vm_mm, mm_counter_file(page)); + inc_mm_counter(vma->vm_mm, mm_counter_file(folio)); page_add_file_rmap(page, vma, false); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); return 0; @@ -3170,7 +3170,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) if (likely(vmf->pte && pte_same(ptep_get(vmf->pte), vmf->orig_pte))) { if (old_folio) { if (!folio_test_anon(old_folio)) { - dec_mm_counter(mm, mm_counter_file(&old_folio->page)); + dec_mm_counter(mm, mm_counter_file(old_folio)); inc_mm_counter(mm, MM_ANONPAGES); } } else { @@ -4363,7 +4363,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) if (write) entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); - add_mm_counter(vma->vm_mm, mm_counter_file(page), HPAGE_PMD_NR); + add_mm_counter(vma->vm_mm, mm_counter_file(folio), HPAGE_PMD_NR); page_add_file_rmap(page, vma, true); /* @@ -4426,7 +4426,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, folio_add_new_anon_rmap(folio, vma, addr); folio_add_lru_vma(folio, vma); } else { - add_mm_counter(vma->vm_mm, mm_counter_file(page), nr); + add_mm_counter(vma->vm_mm, mm_counter_file(folio), nr); folio_add_file_rmap_range(folio, page, nr, vma, false); } set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr); diff --git a/mm/rmap.c b/mm/rmap.c index 7a563490ce08..9e3d0eff8b05 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1801,7 +1801,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, * * See Documentation/mm/mmu_notifier.rst */ - dec_mm_counter(mm, mm_counter_file(&folio->page)); + dec_mm_counter(mm, mm_counter_file(folio)); } discard: page_remove_rmap(subpage, vma, folio_test_hugetlb(folio));