From patchwork Thu Jan 11 11:12:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13517218 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 082A1C4725D for ; Thu, 11 Jan 2024 11:13:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD95E6B009E; Thu, 11 Jan 2024 06:13:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3BA76B009F; Thu, 11 Jan 2024 06:13:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B5A56B00A1; Thu, 11 Jan 2024 06:13:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 67FA66B009E for ; Thu, 11 Jan 2024 06:13:46 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 30AA2C0A15 for ; Thu, 11 Jan 2024 11:13:46 +0000 (UTC) X-FDA: 81666770052.04.3302235 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf19.hostedemail.com (Postfix) with ESMTP id CD2981A0003 for ; Thu, 11 Jan 2024 11:13:42 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1704971623; 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=67896kKKZq+e8pFZOsbKwompVoQWD/wMy3wcQ6ATEuM=; b=Fh02Bvm9TTwV+v4iihZf4WglDPdIV0pfSlP3JNlXXZ5QC8GWceICgNnbNBZxRsXHw2roUX DwWrLP8bRMQywQk5H2/divmMFe9s+Y4J2X0yOejlw93R1p4COaZNaDJBTIU2+jvZ+ILedi s2rF+Q4myn8iQQOaRbjP3wGNrEH/emw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704971623; a=rsa-sha256; cv=none; b=a6IM51ltq49ep9nOfGLhlVveb+Z2kdtjrEYdVDd9V1osuJmY6FJOmsltD+BgcG4PdDSbdZ OE1zkAb8lHWkZHSyClngeaai60Qqtic12zUZbuE5K7jiTj8kEn2Gy5Y/THZ4wOj3GLX6Ti mfFSVsVyUM9ryTH8WRP5FkYYro/t2Go= Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4T9hkt2xsVz1FJFx; Thu, 11 Jan 2024 19:09:26 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id E976A18001F; Thu, 11 Jan 2024 19:13:33 +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.35; Thu, 11 Jan 2024 19:13:33 +0800 From: Kefeng Wang To: Andrew Morton , CC: , , , , Kefeng Wang Subject: [PATCH v2 8/8] mm: convert mm_counter_file() to take a folio Date: Thu, 11 Jan 2024 19:12:39 +0800 Message-ID: <20240111111239.2453282-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240111111239.2453282-1-wangkefeng.wang@huawei.com> References: <20240111111239.2453282-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-Rspam-User: X-Stat-Signature: apngdycwti61itxpsf8a53swo3q86tdj X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CD2981A0003 X-HE-Tag: 1704971622-808022 X-HE-Meta: U2FsdGVkX1+sCjXGGw/2yR849Na2IGe9PUlhMLqVtpW+8qoMQBHNiQIKmywb/mf0v8BAt0z49PvE5M5sTjjd6QzfMoynGQ/K+U2yx66kUxZGr+EqOD3b2hf/z4QyRqsO4BLKhwJNb7rm89pCyBTKuWG6ppneOLIMVG/meaU5E6Yn3HeHa9evg36QNTley4pm4P1BM0r1cxWakCQIlOQzlVrzN6sKMvohMfzn3COAmvFJpGCT4ODf4cijmEgew6r7X4+xw0IhEOZbIDbJCCFYKCJyAJyPOaxz9oqBvus/Ulm2PrW0mnd66BTeRcSx0VpBGVkXxBAC4KeZzfVjoAQa6z1+phLTUF5vYHmCZ0XebMFx+1E1TWPR8zcs+bk0jhDXRwgsErAZP+pxI1lMbskI2j7zTRdv1nhwJYgXQhLmyLuHzNUykqF/ycx63Q9xomgUiCEWTgiN2oMuYZl0bIkE/seHKoBsMEmW9VsB5pxUhHEmb9ik3j6KSQE+0j63YHVzy9xqhxRpawa5M8/Rao2Z7D5TfZKljeriXlukx42fVxTx0HSGpSIDtsqwwYnB9riVd35L/i9KE2XFSMbGSaqTDOFTg/78jQZjWvC4mS1bMBT3qHr8aeskG5IkGjSJ84CaSwFP5551E1j/k31j7m/Z8qjoh7+cTvO3yniwSS0JJO9Ud/7Loxqza9EF5MdNqjJ9GaEjJiclHJR0kGYA99aNdY033iAgWLrvAn8TNY16kYFHPSQPR7zzTfXODhPa1cntZuSA9ofzpsrZ9AXqiiLFDYKVBL/7ZMrzZiGOF83yo6T/MuU+qLxsFP/MLhBsLEgw4uAGwATSPFAix4sZixRmOz67L+kEYZ5GIwEm3KJAo6AfDirVvRLw8vLbHybO7YTdzbSSdU7ODt9cCv2W8FW8qD35sK3YxgYKqHIfyWfToUxI0MFMlqccL+Gl9Fd/8i109hQL8rGNCtCJ01VNaGm Zz1nmSee PH4MTLfzLtI/PUkZwRpiUg/ST3CKrQe7teftoyh+hd6pByDpHT+auCjLBggSbyEyrf9yVm1E+SNeVZCWPDn87sdNI6xgw7H4iqKmQJQMkBRvNK9nuOTOubANuTeva9J6OLHVbOgqK3to/04TMvhQon9mnxztzmxsLD9+cm3yJFjrjkXyZSP9IcVvEhF6kiV0brbBH 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 | 4 ++-- mm/khugepaged.c | 4 ++-- mm/memory.c | 10 +++++----- mm/rmap.c | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 22e597b36b38..ac6b71cbdffb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2595,10 +2595,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; } @@ -2607,7 +2607,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 485bb0389b48..948c2e064ca3 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 b024edb55855..f40137f927dd 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1921,7 +1921,7 @@ 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(&folio->page), + add_mm_counter(tlb->mm, mm_counter_file(folio), -HPAGE_PMD_NR); } @@ -2446,7 +2446,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, folio_remove_rmap_pmd(folio, page, vma); 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 2b219acb528e..fe43fbc44525 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1634,7 +1634,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 */ @@ -1665,7 +1665,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 2f858263e5a2..033035c58b8d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -966,7 +966,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, } else if (page) { folio_get(folio); folio_dup_file_rmap_pte(folio, page); - rss[mm_counter_file(page)]++; + rss[mm_counter_file(folio)]++; } /* @@ -1873,7 +1873,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, return -EBUSY; /* 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)); folio_add_file_rmap_pte(folio, page, vma); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); return 0; @@ -3178,7 +3178,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 { @@ -4463,7 +4463,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); folio_add_file_rmap_pmd(folio, page, vma); /* @@ -4526,7 +4526,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_ptes(folio, page, nr, vma); } set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr); diff --git a/mm/rmap.c b/mm/rmap.c index 4648cf1d8178..1cf2bffa48ed 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1903,7 +1903,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: if (unlikely(folio_test_hugetlb(folio)))