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 229E8606A335 for ; Thu, 3 Dec 2026 18:14:59 +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=MWSjsB0a Received: by kanga.kvack.org (Postfix) id 4615D6B05CC; Thu, 3 Dec 2026 13:14:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 411526B05CD; Thu, 3 Dec 2026 13:14:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9146B05CE; Thu, 3 Dec 2026 13:14:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AE7C46B05CC for ; Thu, 3 Dec 2026 13:14:57 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 408201406CC for ; Thu, 3 Dec 2026 18:14:57 +0000 (UTC) X-FDA: 85503473034.21.04803A6 Received: from mta0.migadu.com (out-50.mta0.migadu.com [91.218.175.50]) by imf07.hostedemail.com (Postfix) with ESMTP id 42A4B4000E for ; Thu, 3 Dec 2026 18:14:54 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=MWSjsB0a; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.50 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=1796321695; b=CKnngpF3GhiZR3t5wJ6FpWe110pCvxe59r1luSxomu4QKHQeYGxhjBBreR8t6hmedT5zm1 OQ4oJ3KdTPgPSJAWEKx8wDINbhn3n5SYsV2XIWSQ61uUy4eNgiGxrMBFldnb4pHNhzhUK3 dSHAudYP6mZIZd3Ri3uV5EXCYcX01JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796321695; 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=sg7UyVe7iRvn3+tTRPNXwUChiImtCESrABLlxb6R250=; b=wBssJLCWwLrKa4xBtfLeDV2o2A88E9m0iKhl0qdtP5wHHvwBFSGYQSRpJiYAN7eMy+DStg 9MVCpK/zc+AcTYZHCcgc+JafR6DFDgEIWZbK/yO/ImrvHGpcsVYkOowpOGXc4YBc7hjJmi krmH5RjoQiyVv5sKHqaiC8WwHJaFIhQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=MWSjsB0a; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of baoquan.he@linux.dev designates 91.218.175.50 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=sEACQg/w8hiAA7UZyBxLG3uAylxKT5YHOEnHrSYUeh4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796321694; v=1; x=1796926494; b=MWSjsB0abGXItZ+TZaloaJHF1UgW83QpwmAQcBG18b/AF9e6FAQv91jODkFWvP9YHJNbInw9 1PKHZDG6kYRUQmsn9NDI66B04dqRHfsqfYxasHsA21IkF1J8FVJbWNZa4MrJvlyp+K5t2Pt4XfH kQ+t0WLcMIu7YsXEY/lS4JIA= X-Envelope-To: linux-mm@kvack.org Received: by mta10.migadu.com with ESMTPS id de8aebe023b1ca1d; Thu, 03 Dec 2026 18:14:54 +0000 X-Mizu-Trace-ID: de8aebe023b1ca1d 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 14/32] mm, swap: allocate a multi-slot range without a folio Date: Fri, 4 Dec 2026 02:13:01 +0800 Message-ID: <20261203181319.901844-15-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-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-Rspamd-Server: rspam08 X-Stat-Signature: j9xtidanrd443uedf74ceieakrsct3g6 X-Rspam-User: X-Rspamd-Queue-Id: 42A4B4000E X-HE-Tag: 1796321694-844682 X-HE-Meta: U2FsdGVkX1+or5lfLTlUyC17Dmm/qWNfvlY0TVawY89XljgYrnX1yGTW3uh/myYJiKgzQxgKUmCw63nDw1FNWe64Qk8ctbHQFV4E93glfntv3dHgM3KabsGF8BJDzwcwg8zdGdXIL6K8Us65rVrsCTcLFDr4UMD1pK6b3NFBByV7YXW5OLeF9SFWoEOeMl9qutkEoGKUuN+5NDpg0O4QHLXRh5TPISqkEojZwdxa6NXq+UzIYPEV2CjQ2ibn0rzBUFOeSxPL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XQ3q+ezbEARlw0Flj4whOL39N5ux9Ye+G1GJ5oZxOV1aCA6RkzlFaLl4vGUY6gV8k/G539HHpijkBTVkhQHQMeP/bj4znXFsGdmBgJW24Uc6 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 physical range backing a large xswap folio has no folio of its own. Teach the exclusive allocation path to initialise every slot in the range instead of only the first. Existing callers are still order 0. Signed-off-by: Baoquan He --- mm/swapfile.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 195fdc879311..0e4b468ad87b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1173,6 +1173,7 @@ static bool __swap_cluster_alloc_entries(struct swap_info_struct *si, unsigned int ci_off, unsigned int order) { unsigned long nr_pages = 1UL << order; + unsigned long i; lockdep_assert_held(&ci->lock); @@ -1181,29 +1182,23 @@ static bool __swap_cluster_alloc_entries(struct swap_info_struct *si, /* * All mm swap allocation starts with a folio (folio_alloc_swap), - * it's also the only allocation path for large orders allocation. - * Such swap slots starts with count == 0 and will be increased - * upon folio unmap. + * it's also the allocation path for large orders. Such swap slots + * starts with count == 0 and will be increased upon folio unmap. * - * Else, it's an exclusive order 0 allocation for a slot that has - * no folio of its own: hibernation, and the physical slot that - * backs an xswap entry. The slot carries no swap count and is - * freed by its owner. + * Else, it's an exclusive allocation for a range of slots that has no + * folio of its own: hibernation, and the range that backs an xswap + * folio. The slots carry no swap count and are freed by their owner. */ + swap_cluster_assert_empty(ci, ci_off, nr_pages, false); if (likely(folio)) { - 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 { - 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); + for (i = 0; i < nr_pages; i++) + __swap_table_set(ci, ci_off + i, SWP_TB_HIB); } - /* - * The first allocation in a cluster makes the - * cluster exclusive to this order - */ if (cluster_is_empty(ci)) ci->order = order; ci->count += nr_pages; @@ -1256,8 +1251,7 @@ 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, order)) + if (!__swap_cluster_alloc_entries(si, ci, folio, offset % SWAPFILE_CLUSTER, order)) break; found = offset; offset += nr_pages; -- 2.54.0