From nobody Mon Feb 9 16:45:19 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 65C8234D3B0 for ; Wed, 28 Jan 2026 09:31:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769592677; cv=none; b=KxzzOS5pg/rlli4p1g6teL6xFIQ+lwl1EwVQ3DrmnC0CrcYnq86ndbXz9yGfUl0YQ1ZXcrJwqhuotXoPV4QqbCBhr+eftegxyHYxqjpEThZHMJSoEShUhTE6OO8QcGYJPRE8ZY/IO6VH4PPKC73+Eg4+xbeW27eVs2QIAbV194M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769592677; c=relaxed/simple; bh=lSB9Ksu9nN+FS2aMiv+c7ve7THffbKJgLEimLksoXJ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JnDzrjp9n/67w0G5hETG6Q8ZScmoULY006ZNrcSCDOz6xIGDNJw5XmhtTFbb4pcgbPPy/Ki7mQh8gDtg+ddbWvjo/pbM6g6Lx4vS8v7lAqmXMs6fvbMwVPTMA9q2w4+nQKD0fayY3TPiFfu/gaCvFvUUmi/eT445SpxWXb8ByFY= 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=IjdAUrKW; arc=none smtp.client-ip=209.85.210.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IjdAUrKW" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-81ecbdfdcebso3577584b3a.1 for ; Wed, 28 Jan 2026 01:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769592676; x=1770197476; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CaANuFojWwiJkS5m+OWCuKgIqQ4Dc/6b0DoNriahO70=; b=IjdAUrKW9GSCqhe4ZTJjKhdFec32GGhYFhXWNgHpVhf4v9tn8zbrM9NTfy3Vf/QwB8 5ufdJhTVICQzwPjmgsdp4xEH8qPxbKv7g30mZlerpeIfYE6OVmXKFRTx9iyA4DEwnnwG 9ivaPCQeL5TFO2cMhOVIdvFZCXB7P+VRFgMMc9nmHNJ7FrKbkZ8yN19lNHbgl4P7mXfw S+/1bvJDcmkzbPCzmVW4v06dko2AVyeB99hY8/V0/G8f75lGnKl67oPfeecH1FJ00cHr Hj9hDnz2hcBWN6dgr3GQjuJOG0gFbCqn0aOr6paRR0qQUR0hY0tHok+qYMOiNdSvpt5J NOMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769592676; x=1770197476; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=CaANuFojWwiJkS5m+OWCuKgIqQ4Dc/6b0DoNriahO70=; b=XMdGwxW93kOjt8PWHFrS+U1yafo1t17f/aVXbRQ7hCQ4pYFL0z/VG0O8CAQH/Xu+/h 5gb5BR8LbAlyQrKh2fCrz/F7XnkrROEGbVj3cKE3UXbMlbRwwzu5DyunJPdIBYiBk5XC DcogB42uWFSUAuVgLMuJQc6WsjSvqNDEo1dILKoLeGXWPgakewTWUZCJrn4v6Ynhrp0V FZsx80aE0BDNynKssdKdDLBp/nXYqOc0HF7l/ZEcUf80e3peZ71Khibci+EIQtquiPPp ILe/Zeqj5a+Z51zvq3+xaDHqrWLFgw3JDG69YXW8GYcKwSY1Cs7/g7u5kNWoxGtOfF1z lokA== X-Forwarded-Encrypted: i=1; AJvYcCV1E0peSCgjkAPGS1uxxPjPcrLOqFvEq23xY1Nq1OPxnw2Q97mkTym3fOoKHQzk7eeQYhyNHfLXVOnNtGM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy96699ym/0YGbTjnDxMUHQ0p3ScQZOXBWqoQPVHuoi8ewN5Vpa OR8mmO1prZpbNRDDX10NsS1bsKPkZg6l8EmAcobxvqISDhotbXTj4544 X-Gm-Gg: AZuq6aLmTcahEzCJ7/KVPd8tYrt8vUcvGcBFN7RlrPSG6iRDHMLJu+aAAbpmcUa7/Ls VUWR6O0HQTaH/QwTfJyB8v1hltqJeYJqj1oD6JNHjh6101tAge5M4d2LcVrbNNFexvIwQEz0uxv XIKGPTTVGiABOkV8qBy16Zn3EJfa80rf2iXYSfHLtZUJY+hP6m5yH9YFvmbjmIrIfraDEmXkCHc yesuFwFP6KAiz6+/AIa7XATnoENpAfn29uxr0wW1OaZf52mYgf1tk/V/h4LW1fkMkV1OHCwQlTy dY2yqX0JYBQPHf6NgxeSlyUzLi0psz4zVGqRoPENtqObzNR+NAzBiP5E0bGq/QWt0lTLJOcNiY8 9T8G29dqqMNpDcWjWBCl56a+AHhd5ihPyZtll2SHuvRVafBEfPTKS5WHKCnb6PaJKsTkMELfg9i zjYxi3ZV9qzf1CR/I6zJMB7ZATbBW4wl9Gqku6pvNuXXhZZSelKihwHqUfHg== X-Received: by 2002:a05:6a20:9c9b:b0:38d:ebdc:3555 with SMTP id adf61e73a8af0-38ec654e764mr3944319637.66.1769592675707; Wed, 28 Jan 2026 01:31:15 -0800 (PST) Received: from [127.0.0.1] ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3540f3eca6dsm1872235a91.15.2026.01.28.01.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 01:31:15 -0800 (PST) From: Kairui Song Date: Wed, 28 Jan 2026 17:28:36 +0800 Subject: [PATCH v2 12/12] mm, swap: no need to clear the shadow explicitly Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260128-swap-table-p3-v2-12-fe0b67ef0215@tencent.com> References: <20260128-swap-table-p3-v2-0-fe0b67ef0215@tencent.com> In-Reply-To: <20260128-swap-table-p3-v2-0-fe0b67ef0215@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Johannes Weiner , David Hildenbrand , Lorenzo Stoakes , Youngjun Park , linux-kernel@vger.kernel.org, Chris Li , Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769592628; l=3144; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=YZtJiA9aWsbTiyi4phkoPFbj1sojs0mkWm2jrsSQgE0=; b=TNp8hdi2S5UVTWhtAIwWtT+XrIsAbY3NGTmnWtYTe6EB0kGmkxeKGKsio4vdo10XAeo80SooH giH5KHUbLpyBJyCok7oCHwBjFQrvuDsP5UP1Z5/vuNZXNfi3DPbBpYo X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= From: Kairui Song Since we no longer bypass the swap cache, every swap-in will clear the swap shadow by inserting the folio into the swap table. The only place we may seem to need to free the swap shadow is when the swap slots are freed directly without a folio (swap_put_entries_direct). But with the swap table, that is not needed either. Freeing a slot in the swap table will set the table entry to NULL, which erases the shadow just fine. So just delete all explicit shadow clearing, it's no longer needed. Also, rearrange the freeing. Signed-off-by: Kairui Song --- mm/swap.h | 1 - mm/swap_state.c | 21 --------------------- mm/swapfile.c | 2 -- 3 files changed, 24 deletions(-) diff --git a/mm/swap.h b/mm/swap.h index 3ee761ee8348..386a289ef8e7 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -290,7 +290,6 @@ void __swap_cache_del_folio(struct swap_cluster_info *c= i, struct folio *folio, swp_entry_t entry, void *shadow); void __swap_cache_replace_folio(struct swap_cluster_info *ci, struct folio *old, struct folio *new); -void __swap_cache_clear_shadow(swp_entry_t entry, int nr_ents); =20 void show_swap_cache_info(void); void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry, int n= r); diff --git a/mm/swap_state.c b/mm/swap_state.c index c808f0948b10..20c4c2414db3 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -350,27 +350,6 @@ void __swap_cache_replace_folio(struct swap_cluster_in= fo *ci, } } =20 -/** - * __swap_cache_clear_shadow - Clears a set of shadows in the swap cache. - * @entry: The starting index entry. - * @nr_ents: How many slots need to be cleared. - * - * Context: Caller must ensure the range is valid, all in one single clust= er, - * not occupied by any folio, and lock the cluster. - */ -void __swap_cache_clear_shadow(swp_entry_t entry, int nr_ents) -{ - struct swap_cluster_info *ci =3D __swap_entry_to_cluster(entry); - unsigned int ci_off =3D swp_cluster_offset(entry), ci_end; - unsigned long old; - - ci_end =3D ci_off + nr_ents; - do { - old =3D __swap_table_xchg(ci, ci_off, null_to_swp_tb()); - WARN_ON_ONCE(swp_tb_is_folio(old) || swp_tb_get_count(old)); - } while (++ci_off < ci_end); -} - /* * If we are the only user, then try to free up the swap cache. * diff --git a/mm/swapfile.c b/mm/swapfile.c index f5474ddbba36..d77c00c4b511 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1287,7 +1287,6 @@ static void swap_range_alloc(struct swap_info_struct = *si, static void swap_range_free(struct swap_info_struct *si, unsigned long off= set, unsigned int nr_entries) { - unsigned long begin =3D offset; unsigned long end =3D offset + nr_entries - 1; void (*swap_slot_free_notify)(struct block_device *, unsigned long); unsigned int i; @@ -1312,7 +1311,6 @@ static void swap_range_free(struct swap_info_struct *= si, unsigned long offset, swap_slot_free_notify(si->bdev, offset); offset++; } - __swap_cache_clear_shadow(swp_entry(si->type, begin), nr_entries); =20 /* * Make sure that try_to_unuse() observes si->inuse_pages reaching 0 --=20 2.52.0