From patchwork Wed Apr 17 16:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13633571 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 0DC2DC4345F for ; Wed, 17 Apr 2024 16:10:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F9966B009E; Wed, 17 Apr 2024 12:10:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85C136B00A1; Wed, 17 Apr 2024 12:10:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FBD46B00A2; Wed, 17 Apr 2024 12:10:15 -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 525DD6B009E for ; Wed, 17 Apr 2024 12:10:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1AC6740A4D for ; Wed, 17 Apr 2024 16:10:15 +0000 (UTC) X-FDA: 82019510790.08.BDD9FFE Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf25.hostedemail.com (Postfix) with ESMTP id 360ACA0009 for ; Wed, 17 Apr 2024 16:10:13 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=St2cZsr2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713370213; 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=yWtogKRbykZjVeWYRJzwDv6D8U3YfbstN+EZdpM/Zng=; b=Ca/tsP52yCFdWMhDpe47nARZRK9PCsTdNYzOXr/dIH8UKxwF5tvaHcPtr1em0BhtIPC/7M Mgq//CqfMqpHrJ0QB1LDdBSRG9s5H2pz001lE2LfFVjKicyBkdwt+UvhBW6dPprC5RLt5E AogU94H0BZnRxTaifLdTqq8POvicX38= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=St2cZsr2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713370213; a=rsa-sha256; cv=none; b=d5EL8W6T/5H9BWIdPAXZhvo4zZ8DQSDuV6S7fLBE/Re8GJ+os9AU3S9xLqnLbRgMZXSkqa yqvp/++5Xmn/71HkSpo5E5hNwvQAVHZZJO71W6T/FAildlIGeQPxNvdDGl1q2lOxdM3LyA JGZPyrST+yy5om3Hf584OCp/svI3C+g= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so3875410a12.1 for ; Wed, 17 Apr 2024 09:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713370211; x=1713975011; 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=yWtogKRbykZjVeWYRJzwDv6D8U3YfbstN+EZdpM/Zng=; b=St2cZsr2tUbP8L+myoOvstdWH8fbi9gUxNT5tIKkZTgBMnMjcg8co8Ef2irx6Z/J8j hA1ecXMeVL1rZcfUPJDlCWbLavviUxVwSRXrZoZ/WeRSQI8oZD/S/Sdez8ZtzE03ecA/ KCemgVAqCvJ0nXJat/ShbAy79ws4FbFpKAG9YjZcEOlASN8ICjfeCEfBx/9tKf/NkHWk g64J/dAn+w/NBzr/J/lscyiWP8X4Ij8+Zc0GT6E4DO6wUOVBIbibjLJZO28DoXBqTRFM 0asO27HpYUsj4htdvjTq7jul9qhqb6X4fmZjuZ4LmhdogDflSJw035hiPfkLqj9AZtqZ T2Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713370211; x=1713975011; 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=yWtogKRbykZjVeWYRJzwDv6D8U3YfbstN+EZdpM/Zng=; b=kivsponcOWQ8aw92reumuHGBV7/16j2rGiGEE+OBeSlcZYIF8ecpj1kH3k6u/OMKLh GjhZ4ZHEyZfHREA277urk5GETgOjU5v6zu5J9rRaewNeXHmOwRaMckLOq5COFahQuula 8866uXFc8s/Mni+cpiZggb5RMeYJyQXH9SAVc4hE/lWr/u2P4Z0FdTXMOx80ooHmOIrJ GzcS6iDbrBYEjuRdTTPBqeofbvCIwrO8v8P7JeJPgpGejXyDB55u5VcdxnmVlEeV8VER Kdhsq/4+jgZMrgvfbIoivbwVvTipJ1XA8NVKLGS/KjAwRwHDo/w37eY4i3doBcE5CSX6 hO/w== X-Gm-Message-State: AOJu0Yze5q3qHG5tCd0ywf2tCCOntXw+lcRPhjen30rf5pbp5gGI6+Um BSM/TGVQtNhqk+aC++2IG2IcZ1UYk/E6gftGA6nYDg1qJGAEXdC0xuwWVYvEqe5Z0g== X-Google-Smtp-Source: AGHT+IG64Mg+h0HLvsWvmsefrKZFQIaXKNBvLrGP2U2HIqBvzsee7fMoaAAuubQ+ziUMJdC/6NC8Ug== X-Received: by 2002:a17:90a:128d:b0:2a5:492b:847e with SMTP id g13-20020a17090a128d00b002a5492b847emr13549505pja.1.1713370211442; Wed, 17 Apr 2024 09:10:11 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([115.171.40.106]) by smtp.gmail.com with ESMTPSA id h189-20020a6383c6000000b005f75cf4db92sm5708366pge.82.2024.04.17.09.10.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Apr 2024 09:10:10 -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 7/8] mm: drop page_index/page_file_offset and convert swap helpers to use folio Date: Thu, 18 Apr 2024 00:08:41 +0800 Message-ID: <20240417160842.76665-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417160842.76665-1-ryncsn@gmail.com> References: <20240417160842.76665-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 360ACA0009 X-Rspam-User: X-Stat-Signature: w4nh6y4ijhmbxjezus64qjxosex4io7f X-HE-Tag: 1713370213-33993 X-HE-Meta: U2FsdGVkX19zW5XksdoOoBF7otAEJQCdEweGkal7lhz5cx5UAk0EmTbS8VU0FM8LlCMODUG1fRR8xRebV6iU4an6sFxC2qdhuGuilhnxeiGayBrYdMLUZV/ghfWH6yXkwBKUBcPXIznp4pwyH4bUw++2DBZHTQk2UtQisng9H+wUrHee4pQebK5iRyHyKMSGwxu+15GAD6C4jg7eJetEa2UP6HgGINb3HfL5Cm+eRkreCQowCItLVvilrHk33MOYRzwR6i1Bd4hUKViQDWTc9PxcsfT4m525M6lfpqQ3Z/iqCAGir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gypvRj5W1l1+QyLRh1GHfvA9nskM5TWAWI3xsuoVWg115cImb99KZ1kCauniMObVhGv3eP8XhDFRVOu5PS9PVsyeLatcQtg28E95L7eNjd9tkV4dyvSiNgfabs70EG9rttlhd1VEG8M3UOodNRFuMUFusehqRNdMMneD90RQtlej3EiIscmqlr/SDXn8g4c+ljRcvxD3LJyGGiDajPZKbfRnwTMRkOrR3Wv/WM0N1DmQnV5pBhsXnehtQPaRdYQUFWO0x4TVJTVy5++56qEJyq/NDhnn2MjJ5AVQjPQ= 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 When applied on swap cache pages, page_index / page_file_offset was used to retrieve the swap cache index or swap file offset of a page, and they have their folio equivalence version: folio_index / folio_file_pos. We have eliminated all users for page_index / page_file_offset, everything is using folio_index / folio_file_pos now, so remove the old helpers. Then convert the implementation of folio_index / folio_file_pos to to use folio natively. After this commit, all users that might encounter mixed usage of swap cache and page cache will only use following two helpers: folio_index (calls __folio_swap_cache_index) folio_file_pos (calls __folio_swap_file_pos) The offset in swap file and index in swap cache is still basically the same thing at this moment, 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..313f3144406e 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_file_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_file_pos(folio); + return ((loff_t)folio->index << PAGE_SHIFT); } /* diff --git a/mm/swapfile.c b/mm/swapfile.c index 4919423cce76..0c36a5c2400f 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_file_pos(struct folio *folio) +{ + return swap_file_pos(folio->swap); +} +EXPORT_SYMBOL_GPL(__folio_swap_file_pos); /* * add_swap_count_continuation - called when a swap count is duplicated