From patchwork Tue Apr 23 17:03:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13640394 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 9BF1BC4345F for ; Tue, 23 Apr 2024 17:04:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 239206B014D; Tue, 23 Apr 2024 13:04:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2D06B014F; Tue, 23 Apr 2024 13:04:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F31156B0150; Tue, 23 Apr 2024 13:04:25 -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 CF7FC6B014D for ; Tue, 23 Apr 2024 13:04:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8E6BAA10C9 for ; Tue, 23 Apr 2024 17:04:25 +0000 (UTC) X-FDA: 82041420090.13.32444B5 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf02.hostedemail.com (Postfix) with ESMTP id B435A80016 for ; Tue, 23 Apr 2024 17:04:23 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jKhoyNwC; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713891863; h=from:from:sender:reply-to: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=QrfJLtSyOHzdWNwAoeEt63qAvh/YvWPDSOmG3agvpH8=; b=VFx74fOT93AHula+6C6r7GvXXUB935u3SkCACRsJyAiIoGX9kdkTfXtBn4FYbD3ldpk/GB izf4sAqNjXySYiq1ewCqsNdeb7gc9VpdPaePFLz155tlB7/MzC+u+0mO2Hn/FbwRgIx2vy /rS5hbF9ITQPrKJWcmEvQtcnEBQRNtY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713891863; a=rsa-sha256; cv=none; b=XC8BIYbAlCdqpiKQNWKmOfZmWE1PNTs72zipb3K1qw49gfXL1Vem7lTilTTnw1sXon6h3c 1+j/dJQMY+HD/xfOVLDL4KHAxlTrEWHLZKiuQntzyBWFRlShwsm83nTgxFIBrh662PfoWy 3Jb5Dud54Y1q/Qd41EqOyF1qWy4Zfkg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jKhoyNwC; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5c66b093b86so58591a12.0 for ; Tue, 23 Apr 2024 10:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891862; x=1714496662; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=QrfJLtSyOHzdWNwAoeEt63qAvh/YvWPDSOmG3agvpH8=; b=jKhoyNwCbAqO+wGeVEYy/zZ7NU0aplGp8PezUnNS5RM6iozyyKJG3NLfBeuVjhCoj9 m/in19oUiJ9r7yV6quNO7UoqL7bOn2i0iYwxdqBYEB8MGj0BpOyAwTXWksIzpSxQ3ukG mVb+iaxe6fa1xEoe71gs8YGsE3CDAJlO3Ggy0Z/jGQZkPw3Im8Z+RxQG1kNN8WG+DP6K 6otnYQwAP+U3j0OmJFtHDJs5qOV+BKhBWbUnv5QtcSsp9SBnGXugmKRTUh0vPS+3Pehx BZ7GxhSxaTtjcethm+npNHpzIR5MEyra57g/3TkHumHVp2QgP2BGgYnPdXMYvjauTWoQ E+Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891862; x=1714496662; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QrfJLtSyOHzdWNwAoeEt63qAvh/YvWPDSOmG3agvpH8=; b=ZE5rIRznt0XSrWOxv6HHCcwSdm5D5zyKzhx+xpR9yeSffeqpqqOaexgebcFy/N4Q6a 4K37jhApNNFM/gar3RkPg8orQKPYPVzjtK12PSe+/37iJtXvoHy5ze/NBNeP/Y9vWSu2 wAfJDODOXgH7Lr0N3/w9Ef2D00M6jT4pNSeq6o7wuy/N9QR82yUsN3aBHLx43QVjnnm/ pSCU4I7cNziQlF+9rSMAEzanlRDUG3FKPeyTEKmhLMhTODFb284d71bfiIfBfdF/alpi Ku2tXcCj0MN/XWi1w7rA2/RdJ4Vr+bNVdZ7ztWHNr2knHQn6Aa3PUG6IBlD4V1j7rMkp /KEQ== X-Gm-Message-State: AOJu0YxicuTbvvCCf6nG2qdHD25PK9TSAYRicqXFVequj3fHtXGfP1T9 B5FasQ79EH2Xu11vnG/LyEEWJl1boLwKIvaObLRq41DQtSO+R1YuqDt5569XW8V5Uw== X-Google-Smtp-Source: AGHT+IHl29mA2dJ+DAVqdOiUnUGnuaMZJ8DMUB92M2KECrfDvhzldwg40C7x44GzkGKAl0R+XjVRbg== X-Received: by 2002:a17:90a:f40f:b0:2a5:506f:161c with SMTP id ch15-20020a17090af40f00b002a5506f161cmr104445pjb.4.1713891862010; Tue, 23 Apr 2024 10:04:22 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:21 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , Hugh Dickins , David Hildenbrand , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 7/8] mm: drop page_index/page_file_offset and convert swap helpers to use folio Date: Wed, 24 Apr 2024 01:03:38 +0800 Message-ID: <20240423170339.54131-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Stat-Signature: 9or1tdbb5j7i9mkpe3qfbja698m8p39c X-Rspamd-Queue-Id: B435A80016 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713891863-739628 X-HE-Meta: U2FsdGVkX191Etr7RAPgxADtFXy6rhHR084OdttprWtfv8B85OR8ApEOijIbqNTgrstEEe0J/G762zZW+GbqDdloz8RFobdLVlZQobs6YIAPWq5HkfUv6Zks6DiGCBLDq2iJRMnHUJ6h1xx+JG+qqLCHDWG+bUCa1Kpy4D/jDfMF2r5bT3GYPK1daK6dVih8OC2+PJ7HrgM2dOP7rFT5DrDpt5pJ+9H2J9fL3RYPhOsOT3kvwcM2AoCabqcp0QKLsYpXQypMWaJxhMxN486AcKLoIJN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OVbKzlIqkfSDQPLm36A06jwkhIMtu5kbpzJ46fYd3iJv5ndbMxUf01ZIrcFhPm1S22bugu3s9DikesKxJ6Y+2+EaP297qzt1Z19H5n+yF2kQWm0ucPIlHWm6Yl0WFO7kTDIW3txi4uNNj0mN4DOxtTUHWlLntS1O6C4UuNK3mUKXsb6S0wjQjjUSQbp52qHQYn7/JcVp8alTUtIA01QFo6Rh5lUVyZIfShln+On78FBLWDIYu/j+blS+7A9h1K8oGem0NVAywXR3SdTySIXWUiNfCJ9m7uz1TTfsEP6PPz1KQ= 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: From: Kairui Song There are four helpers for retrieving the page index within address space, or offset within mapped file: - page_index - page_file_offset - folio_index (equivalence of page_index) - folio_file_pos (equivalence of page_file_offset) And they are only needed for mixed usage of swap cache & page cache (eg. migration, huge memory split). Else users can just use folio->index or folio_pos. This commit drops page_index and page_file_offset as we have eliminated all users, and converts folio_index and folio_file_pos (they were simply wrappers of page_index and page_file_offset, and implemented in a not very clean way) to use folio internally. After this commit, there will be only two helpers for users that may encounter mixed usage of swap cache and page cache: - folio_index (calls __folio_swap_cache_index for swap cache folio) - folio_file_pos (calls __folio_swap_dev_pos for swap cache folio) The index in swap cache and offset in swap device are still basically the same thing, but will be different in following commits. Signed-off-by: Kairui Song --- include/linux/mm.h | 13 ------------- include/linux/pagemap.h | 19 +++++++++---------- mm/swapfile.c | 13 +++++++++---- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0436b919f1c7..797480e76c9c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2245,19 +2245,6 @@ static inline void *folio_address(const struct folio *folio) return page_address(&folio->page); } -extern pgoff_t __page_file_index(struct page *page); - -/* - * Return the pagecache index of the passed page. Regular pagecache pages - * use ->index whereas swapcache pages use swp_offset(->private) - */ -static inline pgoff_t page_index(struct page *page) -{ - if (unlikely(PageSwapCache(page))) - return __page_file_index(page); - return page->index; -} - /* * Return true only if the page has been allocated with * ALLOC_NO_WATERMARKS and the low watermark was not diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2df35e65557d..a7d025571ee6 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -780,7 +780,7 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, mapping_gfp_mask(mapping)); } -#define swapcache_index(folio) __page_file_index(&(folio)->page) +extern pgoff_t __folio_swap_cache_index(struct folio *folio); /** * folio_index - File index of a folio. @@ -795,9 +795,9 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, */ static inline pgoff_t folio_index(struct folio *folio) { - if (unlikely(folio_test_swapcache(folio))) - return swapcache_index(folio); - return folio->index; + if (unlikely(folio_test_swapcache(folio))) + return __folio_swap_cache_index(folio); + return folio->index; } /** @@ -920,11 +920,6 @@ static inline loff_t page_offset(struct page *page) return ((loff_t)page->index) << PAGE_SHIFT; } -static inline loff_t page_file_offset(struct page *page) -{ - return ((loff_t)page_index(page)) << PAGE_SHIFT; -} - /** * folio_pos - Returns the byte position of this folio in its file. * @folio: The folio. @@ -934,6 +929,8 @@ static inline loff_t folio_pos(struct folio *folio) return page_offset(&folio->page); } +extern loff_t __folio_swap_dev_pos(struct folio *folio); + /** * folio_file_pos - Returns the byte position of this folio in its file. * @folio: The folio. @@ -943,7 +940,9 @@ static inline loff_t folio_pos(struct folio *folio) */ static inline loff_t folio_file_pos(struct folio *folio) { - return page_file_offset(&folio->page); + if (unlikely(folio_test_swapcache(folio))) + return __folio_swap_dev_pos(folio); + return ((loff_t)folio->index << PAGE_SHIFT); } /* diff --git a/mm/swapfile.c b/mm/swapfile.c index 4919423cce76..2387f5e131d7 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3419,12 +3419,17 @@ struct address_space *swapcache_mapping(struct folio *folio) } EXPORT_SYMBOL_GPL(swapcache_mapping); -pgoff_t __page_file_index(struct page *page) +pgoff_t __folio_swap_cache_index(struct folio *folio) { - swp_entry_t swap = page_swap_entry(page); - return swp_offset(swap); + return swp_offset(folio->swap); } -EXPORT_SYMBOL_GPL(__page_file_index); +EXPORT_SYMBOL_GPL(__folio_swap_cache_index); + +loff_t __folio_swap_dev_pos(struct folio *folio) +{ + return swap_dev_pos(folio->swap); +} +EXPORT_SYMBOL_GPL(__folio_swap_dev_pos); /* * add_swap_count_continuation - called when a swap count is duplicated