From patchwork Mon Apr 8 18:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13621505 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 2A270CD1296 for ; Mon, 8 Apr 2024 18:40:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAA5A6B008A; Mon, 8 Apr 2024 14:40:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5A356B008C; Mon, 8 Apr 2024 14:40:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AE4C6B0092; Mon, 8 Apr 2024 14:40:12 -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 67DDD6B008A for ; Mon, 8 Apr 2024 14:40:12 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 352D3120146 for ; Mon, 8 Apr 2024 18:40:12 +0000 (UTC) X-FDA: 81987229464.12.213B1D1 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 91FFF1C001D for ; Mon, 8 Apr 2024 18:40:10 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf20.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712601610; 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; bh=bLoGWHtb5wa44C9WqM71mAr6Jt41pD2YDY/H0/kn8tY=; b=PcM6/eqcuwMSqTztWxuI/jNEt5dsLAGPin/w5EID3kUKwNQpj0ELaJ/0DD7kuDMVGYPjQt +TKaMYPREt95jKZIwxyz3L/YTJZiHcE0/mQ8Q4rVNzjJ4eHFr3XL4JbeCVC1LLMJ5xOoNz Bdfvec+Yb4YZy0x0N5iLvJ3IQJG+vC8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf20.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712601610; a=rsa-sha256; cv=none; b=LO1Z+mt50lr2GyWrpQzWv19tsfP76gl8fyBgCEx8KrfmP0PVojoc/QuEDMVqqaf1J85HXc oTrXm6s2kwASsrXMxZUPfznYiE77Cq6H3lc44Uywr1wi5WMuNeozfbzvL+ny7MLXr91Ttz XC8qlmalzRkxwKYDEqzMbCGXBHbVJjQ= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9D363DA7; Mon, 8 Apr 2024 11:40:40 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CC963F766; Mon, 8 Apr 2024 11:40:08 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Chris Li , Lance Yang Cc: Ryan Roberts , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 4/7] mm: swap: Update get_swap_pages() to take folio order Date: Mon, 8 Apr 2024 19:39:43 +0100 Message-Id: <20240408183946.2991168-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240408183946.2991168-1-ryan.roberts@arm.com> References: <20240408183946.2991168-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 91FFF1C001D X-Stat-Signature: wnkbn9qors9gcgzjxg88w3nim9ip8i57 X-HE-Tag: 1712601610-163894 X-HE-Meta: U2FsdGVkX1/pVDKtCs3o6SVHItKws8zxgRGCoMp1zmGocE3mjlxZbtIB2oBlyeAXItXUrPh5MUGQX3AMhT7KBklorGK+L55YtVJGrWfGsF5JjUdn7ZOiKLCLTDSCmiu1pv0nh6YnUzwVHlxklniI9sRnBdzl0GFBK5eFVBAyYtpFyNaJ2ilM2APx69nWm1U9SAex28sC1fsutYVHnf4AE78E7G7fsGy1CgFw1y0+Y+fyg357mdgv83+5HyOxlkLbjqCU+WvcrX0153LE1w0o+UOCNP4zlC+vVrEodR6bjNFNtn61rSROqFYbZDANJb4g7rHcLdwlooqY5E4jSbDioaoBZqo5RDYYH7Du636JQX8K+foqh2sv+O1UhdOoGyeupMfqtBFTfH2muJ+qOg8cPkTw4Yien4FHkKyaoCvtRXig0xWnoUwVRqs4inFfOgZeabr2O/IKoISrT/c7Cfiu0FHEUbcsKouXQvATo3MGqqws1iAQonAxOOrPZ2fa+PxkEI/v1zyWU+PVvdiLJ84sFn6eiyjK2+55yxbow5GuWzi2Mv/NOrYPFzlEOIEMwDpDbPJZPTn3wyPcMG+5wGUAnlkjksSlhBf7Yse1nRPwxaSNW33ZW6kke06tby2qF46O1hokIBUTUJAIuLTzkNYGopxZW2n6OBpJbqA+dfOVxLm+2E4OVcigsFfcD+06ZXcoJKi97m91/5L2/mcAY3lpVZDFTiAPwo7rsKWnGAOnENTbNAy27Bepl3Mdz7msmQ++nUKLevvcx62Uh34blITkKpqUAN7+ZxH96Mm3MSY1m1WB3W+g3DNvReLXps5COfL4DnDlNSDY/fniD0rX0G4wRyAf8N89jXgpVa3arIUEX/DSks14peIDNCLfKPzwpswL4sRURbbdXA9f3zOlYOn0gNxZF/1VPTJut4ZpOFWji5iRIXPxlB79NWlEdsYJCumj/ECt+pBwlxfvFymJY4H NQiPa4IA n1/il5MwLec5ufDPXTFbf6xiDu1bso8NGWF3pviNz9Cb+PmpBVFm8+OampVyoD6mKnT+VNmU1Sdriy2n1dyKjtLBrav8eXUfP6LINnOS6p7LmVuEL8NDuD8VzxMpIG7fX7FRNzpVxWvKgthgJxG8JjoLHBX01Bm8FSgFSZK2fd9oQY9uy/Hf/ymOjY2eNfjERpqCmjCsaOvFH+sPAKbdLVnU/X3+GpWo3vhBmVzaHkEr6eJs= 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: We are about to allow swap storage of any mTHP size. To prepare for that, let's change get_swap_pages() to take a folio order parameter instead of nr_pages. This makes the interface self-documenting; a power-of-2 number of pages must be provided. We will also need the order internally so this simplifies accessing it. Reviewed-by: "Huang, Ying" Signed-off-by: Ryan Roberts Reviewed-by: David Hildenbrand --- include/linux/swap.h | 2 +- mm/swap_slots.c | 6 +++--- mm/swapfile.c | 13 +++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 5e1e4f5bf0cb..b888e1080a94 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -471,7 +471,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio); bool folio_free_swap(struct folio *folio); void put_swap_folio(struct folio *folio, swp_entry_t entry); extern swp_entry_t get_swap_page_of_type(int); -extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size); +extern int get_swap_pages(int n, swp_entry_t swp_entries[], int order); extern int add_swap_count_continuation(swp_entry_t, gfp_t); extern void swap_shmem_alloc(swp_entry_t); extern int swap_duplicate(swp_entry_t); diff --git a/mm/swap_slots.c b/mm/swap_slots.c index 53abeaf1371d..13ab3b771409 100644 --- a/mm/swap_slots.c +++ b/mm/swap_slots.c @@ -264,7 +264,7 @@ static int refill_swap_slots_cache(struct swap_slots_cache *cache) cache->cur = 0; if (swap_slot_cache_active) cache->nr = get_swap_pages(SWAP_SLOTS_CACHE_SIZE, - cache->slots, 1); + cache->slots, 0); return cache->nr; } @@ -311,7 +311,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio) if (folio_test_large(folio)) { if (IS_ENABLED(CONFIG_THP_SWAP)) - get_swap_pages(1, &entry, folio_nr_pages(folio)); + get_swap_pages(1, &entry, folio_order(folio)); goto out; } @@ -343,7 +343,7 @@ swp_entry_t folio_alloc_swap(struct folio *folio) goto out; } - get_swap_pages(1, &entry, 1); + get_swap_pages(1, &entry, 0); out: if (mem_cgroup_try_charge_swap(folio, entry)) { put_swap_folio(folio, entry); diff --git a/mm/swapfile.c b/mm/swapfile.c index e3f855475278..d2e3d3cd439f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -278,15 +278,15 @@ static void discard_swap_cluster(struct swap_info_struct *si, #ifdef CONFIG_THP_SWAP #define SWAPFILE_CLUSTER HPAGE_PMD_NR -#define swap_entry_size(size) (size) +#define swap_entry_order(order) (order) #else #define SWAPFILE_CLUSTER 256 /* - * Define swap_entry_size() as constant to let compiler to optimize + * Define swap_entry_order() as constant to let compiler to optimize * out some code if !CONFIG_THP_SWAP */ -#define swap_entry_size(size) 1 +#define swap_entry_order(order) 0 #endif #define LATENCY_LIMIT 256 @@ -1042,9 +1042,10 @@ static void swap_free_cluster(struct swap_info_struct *si, unsigned long idx) swap_range_free(si, offset, SWAPFILE_CLUSTER); } -int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) +int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_order) { - unsigned long size = swap_entry_size(entry_size); + int order = swap_entry_order(entry_order); + unsigned long size = 1 << order; struct swap_info_struct *si, *next; long avail_pgs; int n_ret = 0; @@ -1349,7 +1350,7 @@ void put_swap_folio(struct folio *folio, swp_entry_t entry) unsigned char *map; unsigned int i, free_entries = 0; unsigned char val; - int size = swap_entry_size(folio_nr_pages(folio)); + int size = 1 << swap_entry_order(folio_order(folio)); si = _swap_info_get(entry); if (!si)