From patchwork Tue Jul 23 15:34:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13740176 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 8C40FC3DA49 for ; Tue, 23 Jul 2024 15:35:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37C946B00BC; Tue, 23 Jul 2024 11:35:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32DAC6B00BD; Tue, 23 Jul 2024 11:35:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CD006B00BE; Tue, 23 Jul 2024 11:35:19 -0400 (EDT) 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 EBAD86B00BC for ; Tue, 23 Jul 2024 11:35:18 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5166DC0216 for ; Tue, 23 Jul 2024 15:35:18 +0000 (UTC) X-FDA: 82371416316.12.2237666 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id 98E9618000C for ; Tue, 23 Jul 2024 15:35:16 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=t2NcawX7; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721748854; 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=89pFi3YoXttaW6Nlt14NSpO+XS/DUE2E9c0ExHdBGgg=; b=O8BfTUTCSzFq+bXK4x5VZInuIbKE3diVQQSPwIK72VCNJ4vjxiI7mR70VKBq9+RwQavAHg +1/ypp+ML+HT9AvR0lLkr/yXSxra8RxXvj+ZqOaTwAxpBDwORvSCh/BMOnu0GwfSCjDbKW TKd0km7Dg864KZ+AdxjTG/iYPB+2cG4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=t2NcawX7; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721748854; a=rsa-sha256; cv=none; b=q8NLxMNcp3Bo3fe2aXrqRqoS8/DCUTc37uV8jkix9jvRf0sv99rGP5s9AejYukovOLVrpf +ck2D5ChRxj1Pl/n/+W9vhHc7xd/jxOg4Q59pTa80RANn05NOITpHEWYRwH6T72Lz8y8eR m1fiettmi+H54+RNXCXbgb0K2UZJ/co= 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=89pFi3YoXttaW6Nlt14NSpO+XS/DUE2E9c0ExHdBGgg=; b=t2NcawX7UZY0lc+eRmWHNWJd0h fivgS9E44PtBmFx55ZLubABKr0q/ruUv9uRHrY478gTRM5AJKBNaUUFdrO4j58AeMbLDO0tG2NwMn CZz3HFj4YodbWIGo21JAIOYpA+IB0GOdTa3SfOE4GwsTqPuv8yqDELseoeQuqELON/++zsMqq1Kpx 9dBtI1fedmU9rogz3bU5kRQ0KTiVQ7bqm2oZd/XUoGqMi3GB2APdA49nsahj2MrOxKrxeqr/1N+Zb Hz6AARtfWsBQMuVOKHeQFfiaQCyQtHDJxu/Nf5kdHSzaK0GBJreIiirOYWFQShHo3cfg1/lM5M7Hf O+HXB+TQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWHXd-000000070LK-0xiu; Tue, 23 Jul 2024 15:35:05 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 3/6] mm: Convert page_to_pgoff() to page_pgoff() Date: Tue, 23 Jul 2024 16:34:58 +0100 Message-ID: <20240723153503.1669586-4-willy@infradead.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723153503.1669586-1-willy@infradead.org> References: <20240723153503.1669586-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 98E9618000C X-Stat-Signature: 4wscugjizrhzbarpn3fydrjofnu7wwjy X-Rspam-User: X-HE-Tag: 1721748916-679284 X-HE-Meta: U2FsdGVkX1+XCVIrUjtgyxXdgOMFMmuGk3CjFoIZsjq4CGbZgDQ4ZtFE4y68mJVO+C8vtSsHYcS85e2Empwv2HSzC+Qf8BN9ZbGD6EtMZ9i2AIoewKze2jm8MJPCwsdenMrALoxnWnjFDZEUmJ81ITeivp1rIXSFTORmKiK0QYZTvYp+q6r3huih83OUTLTlTExt+lru2tK1FN6N+ozjP4TOqWjVRFJH1JxlwNvvjBOMKCcoKv5Rjhx7fV5dGeTL+68G3V5QF2VC8mX4Y45rFkeF2pQdXawngpjIqNKGRY+f3wsuZxv5OUma1ZoxNwHeOXLFNMMR2xgtn/Kd0Cs2oZdsJIEncYSeKxm/lQ6fXuniu3sEQQO+H+8fxV/IiiWBGJfb0HMYqrieZStBS9dCfqeXS3Zna5lTmb0PWiMQboK6SdFBxnZ66OMATrd7XXH9q2AEFh/AGGtAq4eMEpPrAv+9fLXwhMjuxEYzWR9bQFKPMCe/ciZM2BttaLk00SCj8Enx8oB/crisrXToV1IvRVeIn1Cx55mZ0VloShP0Cua4yqJNkpMpre9hagrGV032RjIkliSgX+yyvF1MTCtT8nE/l0VbH/CDAX9BMoppFYXpyob3OMUrqDR60s4vF1/g72Dm5JzeLld2bpShIu3bIdHENa2tLlEzGKGPCzF4WTybKp7Iai4m0NK7O3cP9dL7c80HDeXqc5zSxrEkNNFjc2/SbXmGzN2j4JXzHXOdlzffvmVBdK+dQ2QiQGYhvMmCvTGN0t6BZA9rETO8PwhBxUMHlfbSwHPrMv2p5IKVlCe9ADbuEtyBqgR3KTyLt4jyezHWq+3RU8giPwpaIQWJPHQvypdAcdauXfMMkUJal728IqfEuTxvlhzIS60skqhfhbr6zfoxdCtgv4ni6cRR0IfQhlnFZf1P0ribotF7d35Way+jmPbG8sacxbuw4FZ2pIvfdC3sFM+sw8zMpnM RLHlpkAx dchp7H41/mrH17LmbdiQc0wEeCum60kNVLlF4K30WV+KPW9ownkhnmKc/bhr8vGApyHDXctIpkydR+vWSkwLjRY+SayMY2UUD2kn6L8oRcJTnWopXNdoD0v/U8+HmLB0f94Ovo1I5HBidl59XjDgN0Wg2OV5ISm3ZFK4hQPl8qaoNS8e2pJNpBJsoJvBV/ezUcRjmZ+M1oJYMPD8+jaHgFhLwkUO0X+eME/AFS1S+L0cYMb8GtFPvumeytkU3w9o37ECdcT/X1PGPi2E= 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. Also move page_pgoff() to mm/internal.h as code outside mm has no business calling it. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 18 ------------------ mm/internal.h | 6 ++++++ mm/memory-failure.c | 4 ++-- mm/rmap.c | 2 +- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 483a191bb4df..1f295ef7d10d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -913,24 +913,6 @@ 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). - */ -static inline pgoff_t page_to_pgoff(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 byte-offset into filesystem object for page. */ diff --git a/mm/internal.h b/mm/internal.h index e511708b2be0..8dfd9527ac1e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -919,6 +919,12 @@ void mlock_drain_remote(int cpu); extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma); +static inline pgoff_t page_pgoff(const struct folio *folio, + const struct page *page) +{ + return folio->index + folio_page_idx(folio, page); +} + /** * vma_address - Find the virtual address a page range is mapped at * @vma: The vma which maps this object. diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 581d3e5c9117..572c742ecf48 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 886bf67ba382..ba1920291ac6 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1266,7 +1266,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); }