From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B5D3606A68C for ; Thu, 3 Dec 2026 18:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Q1TT8g+e Received: by kanga.kvack.org (Postfix) id D3A686B05CA; Thu, 3 Dec 2026 13:14:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEA906B05CB; Thu, 3 Dec 2026 13:14:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD9CC6B05CC; Thu, 3 Dec 2026 13:14:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4AF026B05CA for ; Thu, 3 Dec 2026 13:14:52 -0500 (EST) Received: from smtpin26.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3AC9BC0162 for ; Thu, 3 Dec 2026 18:14:51 +0000 (UTC) X-FDA: 85503472782.26.8D5A490 Received: from mta0.migadu.com (out-45.mta0.migadu.com [91.218.175.45]) by imf27.hostedemail.com (Postfix) with ESMTP id 30FEA40012 for ; Thu, 3 Dec 2026 18:14:48 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Q1TT8g+e; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.45 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796321689; b=TbA5e5ZKECcf1ZIK6HU+a9vTRRIX/3dPC65WQx0etjhVzHRwcOt2JhzZKo/a96G5z67LDT aQJGOcK0fW7lrk/9ytgLe37S0F8Bl8yC0cOAbW0nEhvPKxo+WCWkokvdO6ZhAeDPV4TP0h w/cmPTiFv902TRURU/LQ0lBzHFE8Gdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796321689; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EyuR7LOx2TPsC+zSpyejChjlfd2EiwjD9qPn6zMgneY=; b=bB40LTWbhtZRjcKUrxEXr6TARjQESA0THK7y1mxk7Buy/QpvoavpwdyK0NBpSSzQ67jlPE XReeLvVzi9Hej5+EruX5xQAuYWDC4upPd5jKCbzCzLZNlGMRCjrq4fZHHfOlUzfkBe22ay Nt0+vDMPicJKAmjeFi3lSbw2Bu1Jjyc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Q1TT8g+e; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.45 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=ZxJP2/d2AzhUNna0P03DRadkcDFLABMEf4+dAvIuaGg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796321687; v=1; x=1796926487; b=Q1TT8g+eVXQMwOggmKfI8dobNKQeSAG4L9P8UbD45mRYBtyENuyc3M+Z0KqusxC2J7K+7OZt 0FMXkqdaWm4EOA13PM0VQMz9H/kkrRWtBsO9cCtVwBhwuwM7jh/9aLV6rFqGLeOyX/M9NkLTkzS nc2cw6Pcqp8AYR3ESpxG8M0I= X-Envelope-To: linux-mm@kvack.org Received: by mta10.migadu.com with ESMTPS id c01bbc62ea6eb51a; Thu, 03 Dec 2026 18:14:47 +0000 X-Mizu-Trace-ID: c01bbc62ea6eb51a X-Migadu-Flow: FLOW_OUT From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org, kasong@tencent.com, hannes@cmpxchg.org, corbet@lwn.net, yosry@kernel.org, nphamcs@gmail.com, muchun.song@linux.dev, baohua@kernel.org, youngjun.park@lge.com, hughd@google.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, Baoquan He Subject: [PATCH v2 13/32] mm, swap: pass the folio order through the swap slot allocator Date: Fri, 4 Dec 2026 02:13:00 +0800 Message-ID: <20261203181319.901844-14-baoquan.he@linux.dev> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261203181319.901844-1-baoquan.he@linux.dev> References: <20261203181319.901844-1-baoquan.he@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam05 X-Rspam-User: X-Rspamd-Queue-Id: 30FEA40012 X-Stat-Signature: rix5ko5zcfc4czz6zhwb17expo56jifq X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796321688-487506 X-HE-Meta: U2FsdGVkX19i27NwOC5UoXaBmMccnM9MmkL2mfI3ULPVMkhILcFVrTXRC4PlE/0W0PcFHY+y6CNss3OcBKmNCKfrYQLYJYHbzThuJ0S//i9Fl7CHN/Uvct9o3yEDjxC7VPMwERjJs+MKgc/xVSma7diyNbf/OJNZ1fFwF0R03jxFssi19mptaUqWkl0nFqLk3/fstwvEHo+QE0SUSgGmFdkcueEMnhfM9okOok0AUg6MNK4qCjj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wK0ibiyooEw3jcfrsiJM12mqkv+Vv9hufI2vM6fzlaQMVIvNmqrjddrM9+oN8AFXflAGJaapUafsLZTERhHOta9eadp1cDMt+E+jsjgaodEjOq84qD Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Baoquan He The allocation helpers derive the order from the folio. A physical xswap slot has no folio of its own, so pass the order explicitly. Callers that have a folio pass folio_order(); hibernation and the order-0 xswap backend pass 0. No functional change. Signed-off-by: Baoquan He --- mm/swapfile.c | 60 ++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 7e0bdde39ab0..195fdc879311 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1170,10 +1170,9 @@ static bool cluster_scan_range(struct swap_info_struct *si, static bool __swap_cluster_alloc_entries(struct swap_info_struct *si, struct swap_cluster_info *ci, struct folio *folio, - unsigned int ci_off) + unsigned int ci_off, unsigned int order) { - unsigned int order; - unsigned long nr_pages; + unsigned long nr_pages = 1UL << order; lockdep_assert_held(&ci->lock); @@ -1192,14 +1191,10 @@ static bool __swap_cluster_alloc_entries(struct swap_info_struct *si, * freed by its owner. */ if (likely(folio)) { - order = folio_order(folio); - nr_pages = 1 << order; swap_cluster_assert_empty(ci, ci_off, nr_pages, false); __swap_cache_add_folio(ci, folio, swp_entry(si->type, ci_off + cluster_offset(si, ci))); } else { - order = 0; - nr_pages = 1; swap_cluster_assert_empty(ci, ci_off, 1, false); /* Owned by hibernation or the xswap backend; never cached. */ __swap_table_set(ci, ci_off, SWP_TB_HIB); @@ -1232,13 +1227,13 @@ static bool swap_prefer_free_cluster(struct swap_info_struct *si) static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si, struct swap_cluster_info *ci, struct folio *folio, - unsigned long offset, bool no_cache) + unsigned long offset, + unsigned int order, bool no_cache) { unsigned long next = SWAP_ENTRY_INVALID, found = SWAP_ENTRY_INVALID; unsigned long start = ALIGN_DOWN(offset, SWAPFILE_CLUSTER); - unsigned int order = likely(folio) ? folio_order(folio) : 0; unsigned long end = start + SWAPFILE_CLUSTER; - unsigned int nr_pages = 1 << order; + unsigned long nr_pages = 1UL << order; bool need_reclaim, ret, usable; lockdep_assert_held(&ci->lock); @@ -1261,7 +1256,8 @@ static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si, if (!ret) continue; } - if (!__swap_cluster_alloc_entries(si, ci, folio, offset % SWAPFILE_CLUSTER)) + if (!__swap_cluster_alloc_entries(si, ci, folio, + offset % SWAPFILE_CLUSTER, order)) break; found = offset; offset += nr_pages; @@ -1288,7 +1284,8 @@ static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si, static unsigned long alloc_swap_scan_list(struct swap_info_struct *si, struct list_head *list, struct folio *folio, - bool scan_all, bool no_cache) + unsigned int order, bool scan_all, + bool no_cache) { unsigned long found = SWAP_ENTRY_INVALID; @@ -1299,7 +1296,7 @@ static unsigned long alloc_swap_scan_list(struct swap_info_struct *si, if (!ci) break; offset = cluster_offset(si, ci); - found = alloc_swap_scan_cluster(si, ci, folio, offset, + found = alloc_swap_scan_cluster(si, ci, folio, offset, order, no_cache); if (found) break; @@ -1386,11 +1383,10 @@ static void swap_reclaim_work(struct work_struct *work) * cluster for current CPU too. */ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, - struct folio *folio, + struct folio *folio, unsigned int order, bool no_cache) { struct swap_cluster_info *ci; - unsigned int order = likely(folio) ? folio_order(folio) : 0; unsigned long offset = SWAP_ENTRY_INVALID, found = SWAP_ENTRY_INVALID; #ifdef CONFIG_XSWAP bool retried = false; @@ -1422,7 +1418,7 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, if (cluster_is_usable(ci, order)) { if (cluster_is_empty(ci)) offset = cluster_offset(si, ci); - found = alloc_swap_scan_cluster(si, ci, folio, offset, + found = alloc_swap_scan_cluster(si, ci, folio, offset, order, no_cache); } else { swap_cluster_unlock(ci); @@ -1440,26 +1436,28 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, */ if ((!folio || no_cache) && order < PMD_ORDER) { found = alloc_swap_scan_list(si, &si->frag_clusters[order], - folio, false, no_cache); + folio, order, false, no_cache); if (found) goto done; } if (swap_prefer_free_cluster(si)) { - found = alloc_swap_scan_list(si, &si->free_clusters, folio, false, no_cache); + found = alloc_swap_scan_list(si, &si->free_clusters, + folio, order, false, no_cache); if (found) goto done; } if (order < PMD_ORDER) { found = alloc_swap_scan_list(si, &si->nonfull_clusters[order], - folio, true, no_cache); + folio, order, true, no_cache); if (found) goto done; } if (!swap_prefer_free_cluster(si)) { - found = alloc_swap_scan_list(si, &si->free_clusters, folio, false, no_cache); + found = alloc_swap_scan_list(si, &si->free_clusters, + folio, order, false, no_cache); if (found) goto done; } @@ -1475,7 +1473,8 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, * failure is not critical. Scanning one cluster still * keeps the list rotated and reclaimed (for clean swap cache). */ - found = alloc_swap_scan_list(si, &si->frag_clusters[order], folio, false, no_cache); + found = alloc_swap_scan_list(si, &si->frag_clusters[order], + folio, order, false, no_cache); if (found) goto done; } @@ -1489,11 +1488,13 @@ static unsigned long cluster_alloc_swap_entry(struct swap_info_struct *si, * Clusters here have at least one usable slots and can't fail order 0 * allocation, but reclaim may drop si->lock and race with another user. */ - found = alloc_swap_scan_list(si, &si->frag_clusters[o], folio, true, no_cache); + found = alloc_swap_scan_list(si, &si->frag_clusters[o], + folio, order, true, no_cache); if (found) goto done; - found = alloc_swap_scan_list(si, &si->nonfull_clusters[o], folio, true, no_cache); + found = alloc_swap_scan_list(si, &si->nonfull_clusters[o], + folio, order, true, no_cache); if (found) goto done; } @@ -1726,7 +1727,7 @@ static bool swap_alloc_fast(struct folio *folio, bool may_zswap) if (cluster_is_usable(ci, order)) { if (cluster_is_empty(ci)) offset = cluster_offset(si, ci); - alloc_swap_scan_cluster(si, ci, folio, offset, false); + alloc_swap_scan_cluster(si, ci, folio, offset, order, false); } else { swap_cluster_unlock(ci); } @@ -1753,7 +1754,8 @@ static void swap_alloc_slow(struct folio *folio, bool may_zswap) plist_requeue(&si->avail_list, &swap_avail_head); spin_unlock(&swap_avail_lock); if (get_swap_device_info(si)) { - cluster_alloc_swap_entry(si, folio, !may_zswap); + cluster_alloc_swap_entry(si, folio, folio_order(folio), + !may_zswap); put_swap_device(si); if (folio_test_swapcache(folio)) return; @@ -2639,12 +2641,12 @@ swp_entry_t swap_alloc_hibernation_slot(int type) ci = swap_cluster_lock(si, pcp_offset); if (cluster_is_usable(ci, 0)) offset = alloc_swap_scan_cluster(si, ci, NULL, pcp_offset, - false); + 0, false); else swap_cluster_unlock(ci); } if (!offset) - offset = cluster_alloc_swap_entry(si, NULL, false); + offset = cluster_alloc_swap_entry(si, NULL, 0, false); local_unlock(&percpu_swap_cluster.lock); if (offset) entry = swp_entry(si->type, offset); @@ -4687,14 +4689,14 @@ static unsigned long xswap_alloc_slot_local(struct swap_info_struct *si) ci = swap_cluster_lock(si, pcp_offset); if (cluster_is_usable(ci, 0)) offset = alloc_swap_scan_cluster(si, ci, NULL, - pcp_offset, + pcp_offset, 0, true); else swap_cluster_unlock(ci); } } if (offset == SWAP_ENTRY_INVALID) - offset = cluster_alloc_swap_entry(si, NULL, true); + offset = cluster_alloc_swap_entry(si, NULL, 0, true); local_unlock(&percpu_swap_cluster.lock); return offset; -- 2.54.0