Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp740794lqb; Wed, 17 Apr 2024 09:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWR7cnxedvxmqprPhBEaqQbC3Jy5owNSeA/neooDBW3QcFY02I6RVfJKLV1MC0wEUwZAEmoOvG8jmKyIgC720FtiIvkY7yM1D92x1J+Bg== X-Google-Smtp-Source: AGHT+IFFyV+sVhJJvMrCFOtPfG1xJpKo9++/tRwkB5CdDxrLcQhIIuAxuPAi2JYNQAxPN5t2if2+ X-Received: by 2002:a50:8d17:0:b0:56d:c73f:98ab with SMTP id s23-20020a508d17000000b0056dc73f98abmr69176eds.19.1713370912518; Wed, 17 Apr 2024 09:21:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713370912; cv=pass; d=google.com; s=arc-20160816; b=QsFXZ8KnSNDZFocr0rV9J7KtAJJDJVPlybQ0rdgJS7rqKv8gvSS0vlZk1Gy5d5guQW bJp++KZUGkjLj4soxMnj2ThUHNFKAz9vsvNavrc15C89OpvUbSfDgMLEAu+lUo0nunnS 7ibI3xMoi/qtmlZbqObJm3vXaKw7sxi3izK4fPa5tuhHAvGwJ3veYKdrotdhauctzE4a PWRuQ9lqwSsYVvAbjUf3Ai0C/4S5U0jsCQ6UhC59cTT6T1dj1mRhv/KlI2w1qomWDMTS U8yOW8+laMogPWNTWn4CGV0fAf4kXDVremb9gIJTO/e+Eyf2Q20D6Jp6WRX21BQai+Ls qTLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=yWtogKRbykZjVeWYRJzwDv6D8U3YfbstN+EZdpM/Zng=; fh=iFPGr8a2200Kbj4roD7/Lf7YuSetArNWVfu+7ivCe6U=; b=LqBizJN51uYiLeQJgOlNM1C28VJwy6ARuWOb/hJyUYhK0+IZhc0MF4zfdOr3r2cZWO Ha7o4grfr0DJr8XVhOb1cS5FVkG9XAyB9TIuHS4nQRDDJYeMUtIJAYc2oGzZ521AP+Ii 9FWq9814vz+kxW3GIHq+Z2vhYdipbGRphxXS7l+RQf7Mi1eyGIErB0GYkqur4VQInFKA dKdsXfQJ/uyu75xg99iC6Q8MSxpIfsaBR9nZUzxWh3yAPKdk311YuXXPlem+aRr/0Q/v J7YhPqijZi2743e7g9EqHFWZINvd/3yrS28WCxBob/mFJ5ISVbUV7cpDiECHQ/4UAu0n lWDg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WCyYBqVA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-148883-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148883-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w8-20020a056402268800b00570241f6321si3672541edd.611.2024.04.17.09.21.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148883-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WCyYBqVA; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-148883-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148883-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D7D2C1F24C6A for ; Wed, 17 Apr 2024 16:12:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8138615E5B5; Wed, 17 Apr 2024 16:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WCyYBqVA" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 297BF14901F; Wed, 17 Apr 2024 16:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370213; cv=none; b=h1n7KJrIQlKoQ7DMlQIlBnux+SyKD0LUP6U8gWmK3YhF8q5WlMXaxirUr8hKG/Diog/7pdEn8Uolesry/K2kSlAF5e+UWmnQR4oGgjtro2RlA75E/atu2Ib1u0MaV2hg2woMUFhoZMapnamoKoEtPisRlKMzy4KNPijOgIIqeEc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713370213; c=relaxed/simple; bh=5jEmnmpH4K1VGhhKveCTQ+ItuA927FSFJoiRaE+xlvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hfGj7U6BniefFOuFCVr5WsMTGEx69xjmX3pySP9YfYfNl1eJonGQo6JvTDAiEpf2nV0fn41GFz/uFMLthmcOEMSEzLcDyOyA2ftEdf04v5BzLR/bnhTV7aub1KBSt4FFRnRnGEbO/owEbzYLt6dglIHbcnTCW2J63IvOdGndim0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WCyYBqVA; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2a87bd53dc3so2895501a91.2; Wed, 17 Apr 2024 09:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713370211; x=1713975011; darn=vger.kernel.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=WCyYBqVAM45DFZ74CCmCuPWB99FgBK+RwYmeOn8DcD5FEXEFRsxZAAr17nnWSswYGQ pLeDa9jAhxTA7LkGiTU2BhNRP5Oeg8RPJs4RPZdJQW3vbDaFmVLQMCGHzuV+ppnXu1xx UlQTTVh0/+rL5SssAiTZ4mIirGF3D6KsA0/f7FTgnAGtdNsa3rNZGJyT0M1AauH8N+vZ DXWk3JZ7AvHSfvrbcpnaq9drLLrkCaSFqqoDiMRFnI2Ws8Eq1OEFVumrBE0FyJyoomXL P/SZpyxnkHvuUQHzP6m5QTRLYR/iMRL+TEWuMOIzxDHrZnNsdlPJecaZ3Ckps44qk3c3 zI1g== 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=bcBTMtqSiaNcUzSQtICPPqi7rJeSFb59KkwFLOB9Te7NjbsreQhx8VItHGH8nk3+Mw jYAjg6pxO4YaRt+wKZZekZlDVL2elEg7CS3x+8T8gXhZBhz6tyFW4JhDF9k+oU2Q0+Bm 9dK3lSOqhX4dNqN20Fma4+8Yumr7o1f/BLPM+qL6q5411vDU1WeR1XfQVoJl0CE4RuTv atuLtmP3BAuxAOQhq9uXcI9bXyg2kfL6qNX3PQujBFrs9nHxr+1NAW3MeBnSe9fKj2da 0u1nxaI0Rq31XMWUrpvHUNrNVupY86CQNW9is3e7Quab6Wm/WN++KO9n8nC3xg2P1oWA 4cJg== X-Forwarded-Encrypted: i=1; AJvYcCXySZdsLEBUoXGz5zn3oPX310kI22t1knfzdgd0J8VnwkmM4qs4Rwd+szxpEVuw/wctwrMSnEfppteKRAGYuG4wL1T47CL1/D8OtZgS6lUWrkjYftYlwpBDX7xt40N2bHPMW+VrymxSVcqBBA== X-Gm-Message-State: AOJu0YzSlqeiKSYqwTg4c7wrYLL6HIwHtgveC+oygJcdWytlyIOi5GBl Rk9n2MynHCSwbJ/3ybv0QIrsV91KT55lkKvx8qTgbHX4ysJgJScH 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -- 2.44.0