From patchwork Wed Apr 12 02:18:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 13208366 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 BD09BC76196 for ; Wed, 12 Apr 2023 02:18:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00079900002; Tue, 11 Apr 2023 22:18:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF2AF6B0075; Tue, 11 Apr 2023 22:18:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE0F3900002; Tue, 11 Apr 2023 22:18:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D19DE6B0074 for ; Tue, 11 Apr 2023 22:18:30 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 81BEFAAD67 for ; Wed, 12 Apr 2023 02:18:30 +0000 (UTC) X-FDA: 80671129980.23.A2FD419 Received: from out-37.mta1.migadu.com (out-37.mta1.migadu.com [95.215.58.37]) by imf15.hostedemail.com (Postfix) with ESMTP id A279AA0015 for ; Wed, 12 Apr 2023 02:18:27 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=EVpb+ENN; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.37 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681265908; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=W/v2ryAK8CZAUHZdTuLslXGytUbsEmu0tAq5CoDbGJs=; b=o1sJuBxZlcFyy3HjGAxcpGr3POxVqHzvSbR3ehqvC5XzlXsYBY7aRc1UQcoo263WifHIpT wXLdRlPczdXEPQnUwc/xRhU2wzmh701X2Cn9bvO+AWCD6qbbV80O5PpREWuTNZbzyJr1US lCdfsLK3q/ysmhZC/i8JuKvp6LXiBEc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=EVpb+ENN; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of yajun.deng@linux.dev designates 95.215.58.37 as permitted sender) smtp.mailfrom=yajun.deng@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681265908; a=rsa-sha256; cv=none; b=28UWFrTkCJWqsw+E6JEgY5i/ioEQ1uf7w1GFZbGB774ngjeEL61/iZbd6weqhvvNEFJhBV rw/VDhmVPnvX//HXxBBkjPa0d4IkmTBuAujx+AJtIhVvFCUcAikzUcuig5X7DZWUpDAt43 luRENbijA+UsCxfTUEv2vG7dtMoGURI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1681265905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=W/v2ryAK8CZAUHZdTuLslXGytUbsEmu0tAq5CoDbGJs=; b=EVpb+ENN6jARMNpd9ix9+37hPTwMi456eyAuIvSLabLqBeRfKRmP6p6QyuVbSN2FEoJ9kN bQ1+GzDLNdrLqAhkz5QLTZcMPzYdNw8qDfLrXWPI1mOTVkDEhMD9kwGwRe3Dzv7cxRiumv yUWTnwmeTyd2PPTkQ5z1D8UEeOfd4cI= From: Yajun Deng To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH] mm/rmap: convert __page_{set, check}_anon_rmap() to folios Date: Wed, 12 Apr 2023 10:18:11 +0800 Message-Id: <20230412021811.1503281-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: A279AA0015 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: sabbz9iwejqxbo13h57ifjuwi5mgk5mk X-HE-Tag: 1681265907-639523 X-HE-Meta: U2FsdGVkX1995NsSaH0317p96yfZ97JnKjI4SUISCTkUh+h0IpC3lkThT91bNQvJahStx18CihIiVL3Oq8hdfiScM7VryLNQGa7yT0TVKO6xDVlabZ3u+QCHuxJeq1nqH+s90adpEjC/Q/vNpA8UV5XEv6krypQA3XMw4q6Bz7OoCRHzbiSUDvPcbZqjaC2JuNAMqPHV4k3h8Ea6A7AIT0HOo2gpAadSDvwrXMcm9lA/yr5YVAIYCGMlqDMLfCUqlhIshT4e8xhBIMHaVJQ6I1T1xOJK+YF00Jlk8cWgTraQ5DsH7DRf3sUEPj/jox6dDSrTvOVNYRozxs5GClUi6Ce7UH0Y08U01UtVyoqHq/Fpw2HBCmfjWEOmqKL0Ws0XqLSGYEPTL0G0eaS5MtDLI0sT3LfTGDDstlgBj0TbXYIJx3eXeaK0PuREDurp8RojpKboJlJx/WZ4pI3EZiCQq+wJ1nayT20Cl/K6DHsg4lUcyafzmOPpm6Ta/ocnoXThfwYCx163ShFz9HUwVsm0IE6GbHhQJEpoejw37Wwb0KRV4VDraV9hOwAQoHLnKlRuf3Cg26E2HsYTsnhKt3guxcDhtRtSUMWS76EtApTFGRj7eZA51mzPcPO401I8S86m4Q/vcQI/YQRUN8QZ0QqYIgVncAWFDuUK6K3pK9RxqPP56Lx575ERtx9T3X9MPjf49InexS5SAi2obYe9v5KTfHuq0Nx0EMt9Vegz8IDMHWWCouAMZNuqSmGKf1fGiMIBI0nxP7JaK1eIY5SHju4yWCNXSBU+mpQboeKqHSHm/sJxjKysLkFL/IshXUNdV0flGY9Nouw/H8FJ00ITC0cFsmTWAPD3T8mpMMHvaQie4V8VDNEvFR+YkTNP/mSEKRsyxI1p1Faih5NMcWMSq/XqQalXF6srRd4BCpuCbYhvybHvo5zQ2XcZG3ugXa5j4uewd7Soft0hZiIXmzOFm4J fCH1r9xL Q4CrS22dZOk3bZr0rtUup9PNPYAHeDL/gNYoMzv4eUJYmjGYVcm9DhksYfaft6jBg+RnQqf5mAzVAdj4VtJVICxkNFwpxsjee7jfWDizrHd07vvSeR523qdkMslsO0zYX/4MyAjLoSrhE5Pc= 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: The 2nd parameter in __page_set_anon_rmap() is only used by SetPageAnonExclusive(), so there is no need to put SetPageAnonExclusive() in __page_set_anon_rmap(). Remove SetPageAnonExclusive() from __page_set_anon_rmap() and modify __page_set_anon_rmap() to __folio_set_anon_rmap(). Since __page_check_anon_rmap() needs a folio, we can directly use and change it to __folio_check_anon_rmap(). Signed-off-by: Yajun Deng --- mm/rmap.c | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index ba901c416785..8dc71caa208f 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1129,14 +1129,13 @@ void page_move_anon_rmap(struct page *page, struct vm_area_struct *vma) } /** - * __page_set_anon_rmap - set up new anonymous rmap - * @folio: Folio which contains page. - * @page: Page to add to rmap. + * __folio_set_anon_rmap - set up new anonymous rmap + * @folio: Folio to add to rmap. * @vma: VM area to add page to. * @address: User virtual address of the mapping * @exclusive: the page is exclusively owned by the current process */ -static void __page_set_anon_rmap(struct folio *folio, struct page *page, +static void __folio_set_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address, int exclusive) { struct anon_vma *anon_vma = vma->anon_vma; @@ -1144,7 +1143,7 @@ static void __page_set_anon_rmap(struct folio *folio, struct page *page, BUG_ON(!anon_vma); if (folio_test_anon(folio)) - goto out; + return; /* * If the page isn't exclusively mapped into this vma, @@ -1163,21 +1162,17 @@ static void __page_set_anon_rmap(struct folio *folio, struct page *page, anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON; WRITE_ONCE(folio->mapping, (struct address_space *) anon_vma); folio->index = linear_page_index(vma, address); -out: - if (exclusive) - SetPageAnonExclusive(page); } /** - * __page_check_anon_rmap - sanity check anonymous rmap addition - * @page: the page to add the mapping to + * __folio_check_anon_rmap - sanity check anonymous rmap addition + * @folio: the folio to add the mapping to * @vma: the vm area in which the mapping is added * @address: the user virtual address mapped */ -static void __page_check_anon_rmap(struct page *page, +static void __folio_check_anon_rmap(struct folio *folio, struct vm_area_struct *vma, unsigned long address) { - struct folio *folio = page_folio(page); /* * The page's anon-rmap details (mapping and index) are guaranteed to * be set up correctly at this point. @@ -1191,8 +1186,8 @@ static void __page_check_anon_rmap(struct page *page, */ VM_BUG_ON_FOLIO(folio_anon_vma(folio)->root != vma->anon_vma->root, folio); - VM_BUG_ON_PAGE(page_to_pgoff(page) != linear_page_index(vma, address), - page); + VM_BUG_ON_FOLIO(folio_pgoff(folio) != linear_page_index(vma, address), + folio); } /** @@ -1214,6 +1209,7 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, atomic_t *mapped = &folio->_nr_pages_mapped; int nr = 0, nr_pmdmapped = 0; bool compound = flags & RMAP_COMPOUND; + bool exclusive = !!(flags & RMAP_EXCLUSIVE); bool first = true; /* Is page being mapped by PTE? Is this its first map to be added? */ @@ -1243,7 +1239,7 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, } } - VM_BUG_ON_PAGE(!first && (flags & RMAP_EXCLUSIVE), page); + VM_BUG_ON_PAGE(!first && exclusive, page); VM_BUG_ON_PAGE(!first && PageAnonExclusive(page), page); if (nr_pmdmapped) @@ -1253,11 +1249,12 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma, if (likely(!folio_test_ksm(folio))) { /* address might be in next vma when migration races vma_merge */ - if (first) - __page_set_anon_rmap(folio, page, vma, address, - !!(flags & RMAP_EXCLUSIVE)); - else - __page_check_anon_rmap(page, vma, address); + if (first) { + __folio_set_anon_rmap(folio, vma, address, exclusive); + if (exclusive) + SetPageAnonExclusive(page); + } else + __folio_check_anon_rmap(folio, vma, address); } mlock_vma_folio(folio, vma, compound); @@ -1297,7 +1294,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, } __lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr); - __page_set_anon_rmap(folio, &folio->page, vma, address, 1); + __folio_set_anon_rmap(folio, vma, address, 1); + SetPageAnonExclusive(&folio->page); } /** @@ -2533,17 +2531,20 @@ void hugepage_add_anon_rmap(struct page *page, struct vm_area_struct *vma, { struct folio *folio = page_folio(page); struct anon_vma *anon_vma = vma->anon_vma; + bool exclusive = !!(flags & RMAP_EXCLUSIVE); int first; BUG_ON(!folio_test_locked(folio)); BUG_ON(!anon_vma); /* address might be in next vma when migration races vma_merge */ first = atomic_inc_and_test(&folio->_entire_mapcount); - VM_BUG_ON_PAGE(!first && (flags & RMAP_EXCLUSIVE), page); + VM_BUG_ON_PAGE(!first && exclusive, page); VM_BUG_ON_PAGE(!first && PageAnonExclusive(page), page); - if (first) - __page_set_anon_rmap(folio, page, vma, address, - !!(flags & RMAP_EXCLUSIVE)); + if (first) { + __folio_set_anon_rmap(folio, vma, address, exclusive); + if (exclusive) + SetPageAnonExclusive(page); + } } void hugepage_add_new_anon_rmap(struct folio *folio, @@ -2553,6 +2554,7 @@ void hugepage_add_new_anon_rmap(struct folio *folio, /* increment count (starts at -1) */ atomic_set(&folio->_entire_mapcount, 0); folio_clear_hugetlb_restore_reserve(folio); - __page_set_anon_rmap(folio, &folio->page, vma, address, 1); + __folio_set_anon_rmap(folio, vma, address, 1); + SetPageAnonExclusive(&folio->page); } #endif /* CONFIG_HUGETLB_PAGE */