From nobody Mon Feb 9 11:47:01 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 E34F32F0685 for ; Sun, 25 Jan 2026 17:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769363940; cv=none; b=FTmUeePw1zo9i7APU1y8vOEybtKw3izbgqe9fpJ2vwIHd4zaYsY6aD7/QTgM3zd+wwP5qSLVHKb0gsK1Zk3PIJ/fdcuW1gosrXppy+z37gva7zAPak1nG7VXElTM86YCjV30jYTsqQyzlRqf00LG5iYIsl7Nde0Sd0+xWY1jX4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769363940; c=relaxed/simple; bh=IJVFHWTeAE64r9NlkLITh4dLk1+AofYxHk5oUGHO5b4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iQHLzKE/rOdW5496TuvMnSTsRhKoAE9jlU4yutZvwPzvCM5qHXgw3xvb9lIgzhonT09js9nyWOpQdjYp4yDdtA4C9u9yLB2BT3hShFiNGTRpK3a52N/qTtPmzQ9h+vOyNsX/0bg1m2B79HpDHnDh1Vfhseytl9oT3dEJtnjcccU= 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=ed1iuAa+; arc=none smtp.client-ip=209.85.216.49 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="ed1iuAa+" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-352ccc61658so1687962a91.0 for ; Sun, 25 Jan 2026 09:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769363938; x=1769968738; 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=WshGWNJYF++wijTnl4L4ygl5/AaRqG4ZVzkhCy8zUn0=; b=ed1iuAa+Z4y/Vea/oSjoAEmbUHWPwCRXOaMFZPgOQItXj+gcEUfaer4mr/c3G4PFzw LaMJMuUIgVaWQE5zUhTdrqQhGLrNpptBPx410xUGOKgUlNybPaQDcJkRVwuUeSUlTTQP EELT56kO6LfEJEyXheeJWRttyvAtbc/10VcPCBtXtrP1sMdPefS1zB6JcCCZJfyCCctp ztJHSnHHbD7aHLGM/jDYves5gunWAoq5GESsZahCE/XzL/L3pWhd5eeG3BlGg38sM+bh 3USFrA1hdCi10hbpRUKzUo5b32nQW8dgyj91SBQ/nNxWal8aaevYrAH4cwqVfZJXGzrS z4eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769363938; x=1769968738; 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=WshGWNJYF++wijTnl4L4ygl5/AaRqG4ZVzkhCy8zUn0=; b=ZNQqFYYyrbL103ElEIqoV2BZzBhXyC5tgTtpQ4vPeIr4Llf3AY8fyVvm0OHNg4C5z6 NzwNxxhf3wXXsAkYYEQSEv5JxS14a3oz/ieiHib55OSh/Z60dKi6twubauWNZ/Bz/J0f o/vgu/mvg0W0PuwbtbApaLUArgcpTpYicylUD9jhKkuB666gb6QGaF+QLUDzC68g9O/A MBOtBt7DZR5Cj+9mSx9PpYk5Z/5DdbMB2vM6fO0yKJz6NcaRI5DO9B3ve30wQAt+CmOy /iHbtMO3GaqGKjL4zN0YBkBmCmC6jEDh5gwSrmX7NrFvlI/LRicHtnCvwkw62KHSUdEg hvnw== X-Forwarded-Encrypted: i=1; AJvYcCW172XfVOymXOm8EW+722aR1yri1ChFcM8aK8V1h4DUd4FzXvMsz02eYQfRqFm3p24uX726i/KvuYuZmbg=@vger.kernel.org X-Gm-Message-State: AOJu0YwyeSp9x36gnw5afqQivC0lJElT6uhQ0Kq1A/sjX80WD6qECCqw Qe3YJnZvOacdQV5ABGIxtH8uc+qK/dqT+9rMFPlhL7rlah/nYVDNyTk+ X-Gm-Gg: AZuq6aIF8q4J3smzGWxy6FsDT97BfSpqAuorzBxH7CzJ2UGwRqllhkRpd5AyCm7CWBA IxZn5506wDxpCJVGt1ElExX3aI1POmpWVqieVp9o9Fi6PytOTi+NI0yoYWsonLSUWCRFpnhNZpD IaJslQ/L1BHyNGxvBW/XKctHMaQpUjCQJiyX1wFSXd4pKV2Je/eIVoMJ0+DdzxUFr5znwkToJxU xcGXTgB/VktS55ynNUnKcs989YVn8T/mqUUSXtcS1qlJJNgn1AjDGxq9zo2OySR6djaRZ1IztDE vVHeePy1X8Vl43LIn0lDeAK/2SPjTfudUKHQ7dfHw/2uKqmmcuzKpw5fgOjS/JEs9zkxgM6k9Do DgAnN8ju7J0zYK3IWZjjiMYCUZ+i4WtPTjpgn2sSjhp5LZUrCuy7/npLH7Y8EeD7fI1OqhnjYVB G5Hu3QC1BVU+5ftliSzuCOkvWMK+xJPbn4RD/LGKa5FaPdQJhl+gVblCWYMy8= X-Received: by 2002:a17:90b:3c05:b0:33b:cfac:d5c6 with SMTP id 98e67ed59e1d1-353c4182f32mr1864176a91.29.1769363938190; Sun, 25 Jan 2026 09:58:58 -0800 (PST) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8231876e718sm7405963b3a.62.2026.01.25.09.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 09:58:57 -0800 (PST) From: Kairui Song Date: Mon, 26 Jan 2026 01:57:35 +0800 Subject: [PATCH 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: <20260126-swap-table-p3-v1-12-a74155fab9b0@tencent.com> References: <20260126-swap-table-p3-v1-0-a74155fab9b0@tencent.com> In-Reply-To: <20260126-swap-table-p3-v1-0-a74155fab9b0@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Johannes Weiner , David Hildenbrand , Lorenzo Stoakes , linux-kernel@vger.kernel.org, Chris Li , Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769363877; l=3144; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=N+Tk0tXxMjVdLEG5ORllLHnt9dnHiUYojx+HV4QDfJ0=; b=i9jf9SH6BTPb7v7w5NstkVhNdATjfP9CoAhJRvX0yoJ/dpS/eDKY6k9RsGncAQq/k3RI9llO+ Cfh0llN/mwoC/CbIZ2iNwEuCWHabMS4vr/ZkvGUe3MNPYcq3SCECwKN 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 3395c2aa1956..087cef49cf69 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 f2b5013c7692..82b152d7c4c5 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