From patchwork Sat Oct 5 20:01:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13823464 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 BF4E6CFB42B for ; Sat, 5 Oct 2024 20:01:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD5366B0325; Sat, 5 Oct 2024 16:01:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C84C46B0326; Sat, 5 Oct 2024 16:01:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD8636B0328; Sat, 5 Oct 2024 16:01:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 824AC6B0325 for ; Sat, 5 Oct 2024 16:01:46 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 373201C54FF for ; Sat, 5 Oct 2024 20:01:46 +0000 (UTC) X-FDA: 82640619012.06.3813708 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 9C3FD12000B for ; Sat, 5 Oct 2024 20:01:44 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="ARz/99bn"; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728158463; a=rsa-sha256; cv=none; b=ob753kztL9/RGjxXmh5Fqcw91EYDN3gYi7fU1QvcuJ6biaNNZv+acPZJOOrX4+PkzCB1C0 b6gch/s6uOCIl+ZkK0OqQq4Onzw9Xr6AQDcvWRPt/v3OCgVssS+l5YBl+cS8uLHYFabPHn eBA1SEpzgjBBxBZETuiPle83vDso5SQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="ARz/99bn"; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728158463; 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:in-reply-to:references:references:dkim-signature; bh=rfkeX8rptI2zZl5dAxALrVG785z0+T7WXF1RMTEorUM=; b=52VFRF4n3t0Q/RuxcgA6YMVEDf3Z7yY2DLAznnkK4ZI4mdQn1r7hrVOcjkmneyVJwsHIuj XY9WpT1v3isEPa8b8XUi46NaPlXlC/32InSkY5jmKrMLjE3YabMFxQQd3QRJrQgb2PeFzg tjr9iRJ2mI+2CoQOWWsbUyaGaG1Dm48= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=rfkeX8rptI2zZl5dAxALrVG785z0+T7WXF1RMTEorUM=; b=ARz/99bn8NdjGsNcFp3jDQIAf4 rRwkXNa5ZklzAKKPX6Af9ksde3A8wfzr1CMihyre0nq28rxX8j801kultfDOi/tKfa3NDjksWTYqy nWgpEkLv0ruk65edkZKdGHgWBmDZ/lknHCA6aUb5iQhJP+eUrPgvu/Nhb9QvJu5BXfWAHzcvC62vI kqQ0Bj5WOtpoi/sUILZTRXtd1l3tmSEM/HNqH9CmASMym4sy5XLrHshgkMjFzjMjdDVUjpojHdPG5 1haKywhR6VHHFRvJfeQd7gLyXgcp+yPqcJXXYvt2VMsJJlfAFfrjmS1iXNp/cj3OmBuFtbyVvkunq o/9UdXbA==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sxAxw-0000000DYZb-1zGR; Sat, 05 Oct 2024 20:01:24 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 1/7] mm: Convert page_to_pgoff() to page_pgoff() Date: Sat, 5 Oct 2024 21:01:12 +0100 Message-ID: <20241005200121.3231142-2-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241005200121.3231142-1-willy@infradead.org> References: <20241005200121.3231142-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 9C3FD12000B X-Rspamd-Server: rspam01 X-Stat-Signature: 8ptmo1d376k9dg93hmch67t3ouiwitmj X-HE-Tag: 1728158504-136959 X-HE-Meta: U2FsdGVkX1+y+v2WXHgNjZU0bywry4OWRGh7/S27zcRMYciBz4eUg4HD3+fymdq/b09huG6B8crJg/o/dxe3Dx30Llrj/UK+MzuFMk5rpB2yCjr6ENUltebqZ7zT+YwqXB1TjvXphqtXo4X0lEqM3RYu19xwc2uRuTe6nu78FWMPbusmAc/q+D1SwTvoumzhWKoeT9IDbFJ8cWTYAeKAZKSEL8cj8rUqeRJYdCr2rZ1q/4DtzLvSgYfhuqzHJmVWuhOYdq11Oz3DueRCAJ1mWHVB/zEewqPCYCnDeOmfSsy9kQuAsbqO6Jn1OWuA27NsDHcG7IXNID+GHO4ZapDEfpVaE2WNgOwAd/5sGZx7ssg1nHKA6uMniFmQMs+qunAT/7CbKt2+5Im/4rcI5GN6VMXRxu1WeUhb57q+c9K7XlVuaEbyyCn8bl6IgC5ehXvNZTZkmjrXlTFE3Gypu/BO90Xf6m9PGftvgURN96VGNmbOWzM2jy9KbdsikNlv1FLUMO38Ih4mc/Lx2Odo8+Qk1/1+2UA+Vvqnd1QaYEbpF9oUyETtsTT56pTZifaQoYg+/gXrBOOhcdcYazinpZ0yIwQ152/ZOrEIMo5D4KMNCcoFzBFmerrmZInVqd902QQHOKRPoJfS2xDn0VTjsBWYYQIlifWR/P7gILPpNW1CSY/rFK6LKPIMnRR72XtTOAK9xrrJZMGOOzG0+O/OLdByXdKijpw7b2XHUQQ8dJ4lnYJ0RxivUcioGSHkEJA092b4JtxgzyKWCK4ibW3MpnpChSS272q1vJM/vGvVlt7jX9SYvyI6rEfVNgjQGIQYCVdrGO4L+a+ww2XWBwrnsRfD0JhiBxSCrGOOb61neyyCFFq+IwaceQgCrFb8Of6RdcgMtVSvddTPtMWTwC31GVOwli4KHGuLG0TfQC0vaJf366d//9WLrIEDBnD+yPl2dE4RkKjDp54ALmI9ElUCvZJ AEwakFKt XAIBcuHJQY/6DMMAIRiKPXETrLW0kvQfrvOX9R3Xw3GYrRXvolIyq+ZfVLq9NHWbLW5ZuG0Vj9YC1DDwzfexDCChcYVCBrjKPJRQKmXDIabFjieC4FytFDWrzqhzt8u5nuRljmPxsQiUVaH/2LGxfw0uArGckiLJOvWTZXNKIP4DqYnJh2JQFmk8KFcZkSXl8SNg2q9Zz8IBjDqIC3GbY4+Rc+DYIuD1FbFeSY14MQwFzfUKnT5fzfIdSqPPrmxI90eUY5inp/sxiEg6aC4YIEeslOLlUvog1Ghh7 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: Change the function signature to pass in the folio as all three callers have it. This removes a reference to page->index, which we're trying to get rid of. And add kernel-doc. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 2 +- include/linux/pagemap.h | 31 +++++++++++++++++-------------- mm/memory-failure.c | 4 ++-- mm/rmap.c | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ecf63d2b0582..664c01850c87 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1895,7 +1895,7 @@ static inline unsigned long page_to_section(const struct page *page) * * Return: The Page Frame Number of the first page in the folio. */ -static inline unsigned long folio_pfn(struct folio *folio) +static inline unsigned long folio_pfn(const struct folio *folio) { return page_to_pfn(&folio->page); } diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 68a5f1ff3301..bcf0865a38ae 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1011,22 +1011,25 @@ static inline struct folio *read_mapping_folio(struct address_space *mapping, return read_cache_folio(mapping, index, NULL, file); } -/* - * Get the offset in PAGE_SIZE (even for hugetlb pages). +/** + * page_pgoff - Calculate the logical page offset of this page. + * @folio: The folio containing this page. + * @page: The page which we need the offset of. + * + * For file pages, this is the offset from the beginning of the file + * in units of PAGE_SIZE. For anonymous pages, this is the offset from + * the beginning of the anon_vma in units of PAGE_SIZE. This will + * return nonsense for KSM pages. + * + * Context: Caller must have a reference on the folio or otherwise + * prevent it from being split or freed. + * + * Return: The offset in units of PAGE_SIZE. */ -static inline pgoff_t page_to_pgoff(struct page *page) +static inline pgoff_t page_pgoff(const struct folio *folio, + const struct page *page) { - struct page *head; - - if (likely(!PageTransTail(page))) - return page->index; - - head = compound_head(page); - /* - * We don't initialize ->index for tail pages: calculate based on - * head page - */ - return head->index + page - head; + return folio->index + folio_page_idx(folio, page); } /* diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 96ce31e5a203..58a3d80961a4 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -617,7 +617,7 @@ static void collect_procs_anon(struct folio *folio, struct page *page, if (av == NULL) /* Not actually mapped anymore */ return; - pgoff = page_to_pgoff(page); + pgoff = page_pgoff(folio, page); rcu_read_lock(); for_each_process(tsk) { struct vm_area_struct *vma; @@ -653,7 +653,7 @@ static void collect_procs_file(struct folio *folio, struct page *page, i_mmap_lock_read(mapping); rcu_read_lock(); - pgoff = page_to_pgoff(page); + pgoff = page_pgoff(folio, page); for_each_process(tsk) { struct task_struct *t = task_early_kill(tsk, force_early); unsigned long addr; diff --git a/mm/rmap.c b/mm/rmap.c index a8797d1b3d49..3b11f8b6935d 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1280,7 +1280,7 @@ static void __page_check_anon_rmap(struct folio *folio, 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), + VM_BUG_ON_PAGE(page_pgoff(folio, page) != linear_page_index(vma, address), page); }