From nobody Tue Sep 29 06:08:34 2026 Received: from lgeamrelo03.lge.com (lgeamrelo03.lge.com [156.147.51.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 735D22C11CA for ; Tue, 11 Aug 2026 13:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.51.102 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454544; cv=none; b=gY+JNmHyqy0eO7EFBtLa3ETNZDFgfABKYXSikKrYDueEisO9UFORfFayg1swC2Ex8DeRuDfHOie7FXkinBPipo8xGgFNCqv4NZoV+ugOEAbMuypHenfeFTghccJ300FnBnUB2uWEvmyZxBPzrI3k8IpujXE3IHVgnBRCWMI+WHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454544; c=relaxed/simple; bh=xhGuLRvLj8smcgZAjpNxl2k9r7i+qqyKJat52jZHjcM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jO4R4bwDVoZ1sSuFS2P0hKB0+w3J7Yjod/TYzynPJtnZLZ8XLFtZV9Por9pa+QcOTGnceI/Gp7jTKLc3NfnZeQ+vrsGRpqJoB7dO0J20YkRjhKKhl42/f0i79tJ4/Khd9nJ6x2XUBK+6d7Gx8VF+JwpBDK62kJLgjUOh5mkAYZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.51.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330.lge.net) (10.177.112.156) by 156.147.51.102 with ESMTP; 11 Aug 2026 22:22:12 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com From: Youngjun Park To: Andrew Morton Cc: Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Jianyue Wu , her0gyugyu@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Youngjun Park , stable@vger.kernel.org Subject: [PATCH v3 1/4] mm, swap: don't free a hibernation slot that is in the swap cache Date: Tue, 11 Aug 2026 22:22:06 +0900 Message-Id: <20260811132209.2862708-2-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260811132209.2862708-1-youngjun.park@lge.com> References: <20260811132209.2862708-1-youngjun.park@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A slot with a folio in the swap cache is freed when the folio leaves the cache, not when its count drops. swap_put_entries_cluster() follows that rule. swap_free_hibernation_slot() does not, it calls __swap_cluster_free_entries() whether or not a folio sits on the slot. Cluster readahead can put one there. It walks a raw page_cluster sized window of offsets around the faulting entry, and a hibernation slot passes __swap_cache_add_check() because it is not a folio and its count is not zero. Freeing the slot then clears the entry under that folio. The folio is now unreachable from the swap table, and the offset goes back to the allocator. The folio is still on the LRU though, so reclaim can pick it up later. It then takes the old offset out of folio->swap and overwrites the table entry there, which by then may belong to someone else. Check for a cached folio before freeing. The slot is then left in the ordinary state where only the swap cache holds it, and it is freed when the folio leaves the cache, either through the reclaim below or through normal reclaim later. Fixes: 0d6af9bcf383 ("mm, swap: use the swap table to track the swap count") Cc: Acked-by: Kairui Song Signed-off-by: Youngjun Park --- mm/swapfile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index dea2d3b36e06..f5dfc7e59191 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2202,7 +2202,14 @@ void swap_free_hibernation_slot(swp_entry_t entry) =20 ci =3D swap_cluster_lock(si, offset); __swap_cluster_put_entry(ci, offset % SWAPFILE_CLUSTER); - __swap_cluster_free_entries(si, ci, offset % SWAPFILE_CLUSTER, 1); + /* + * A slot with a folio in the swap cache is freed when the folio + * leaves the cache, the same rule swap_put_entries_cluster() follows. + * Readahead can put a folio here, and freeing the slot now would + * leave that folio with no entry behind it. + */ + if (!swp_tb_is_folio(__swap_table_get(ci, offset % SWAPFILE_CLUSTER))) + __swap_cluster_free_entries(si, ci, offset % SWAPFILE_CLUSTER, 1); swap_cluster_unlock(ci); =20 /* In theory readahead might add it to the swap cache by accident */ --=20 2.48.1 From nobody Tue Sep 29 06:08:34 2026 Received: from lgeamrelo03.lge.com (lgeamrelo03.lge.com [156.147.51.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7869E2F8BEE for ; Tue, 11 Aug 2026 13:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.51.102 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454543; cv=none; b=R3/NQ3scZMQxB6+eTDOf/bgMgnjzHZl3zWQsE9CsgXV90TlGOFdMmxBEOWc63GSXmT9o+WWENn41RBNEDMF1+RDaI+24qNhujIxbAXuwuDh7o5tmMuTb2SJwt9BAYx0pDUDvt50fxJBSRReT0mAlpYZkc3OlWo9+oggYQf6GWok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454543; c=relaxed/simple; bh=gIvGudZKv/OPSsFraPrbTQSGlFISjutEMRaF2paXHUI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G2Hq9pph76VB/l6Qn6PtpItIIDN/RD+n3yeC4clVS3DZl2reKy0KZxLe0tw5u1yj6rPm3Od8U09mlXxeCyRauGBRGRehIi7EEZ1d1tD5Id9ioZM3axu8xL6fdlPuP+Mf2VVH4abqByemfT07Cfwyv9+yibdJOf3p3vwsCfoFogE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.51.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330.lge.net) (10.177.112.156) by 156.147.51.102 with ESMTP; 11 Aug 2026 22:22:13 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com From: Youngjun Park To: Andrew Morton Cc: Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Jianyue Wu , her0gyugyu@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Youngjun Park Subject: [PATCH v3 2/4] mm, swap: only allow swapped-out slots into the swap cache Date: Tue, 11 Aug 2026 22:22:07 +0900 Message-Id: <20260811132209.2862708-3-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260811132209.2862708-1-youngjun.park@lge.com> References: <20260811132209.2862708-1-youngjun.park@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __swap_cache_add_check() turns away folio entries and slots with no count and lets everything else in. That is safe only when the caller owns the slot. Cluster readahead owns nothing, it walks a raw page_cluster sized window of offsets around the faulting entry, so it can land on any slot. A bad slot gets in. The check reads the count with __swp_tb_get_count(), which shifts the count bits out without looking at the type, and SWP_TB_BAD has all of them set, so the slot reads as SWP_TB_COUNT_MAX. Readahead then allocates a folio and reads the offset off the device for a slot nothing will ever swap in, and the folio entry that replaces it drops the bad marker. Readahead used to be guarded by swap_entry_swapped(), which goes through swp_tb_get_count() and gets -EINVAL for a bad slot. That call went away when the swap cache checks moved into __swap_cache_add_check(), and the raw accessor there does not do the same type test. Require a shadow entry instead. A slot dropped from the swap cache always gets one, empty if there is no workingset value. The type test runs first, so the count is only read off a countable entry, and the check as a whole runs before the folio allocation in __swap_cache_alloc(). The large folio walk in the same function does the same raw reads. A bad slot cannot be in its range, but the range is not pinned, so a slot freed and then taken by hibernation still trips the countable assertion there. Give the walk the same shadow test, the folio check folds into it. Reproduced with a badpages list written into the swap header by hand. Readahead took over four bad slots before this patch and none after. It needs a crafted header, so a normal setup will not hit it. Fixes: e1e6750df3b4 ("mm, swap: add support for stable large allocation in = swap cache directly") Acked-by: Kairui Song Signed-off-by: Youngjun Park --- mm/swap_state.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index b76eb3d876fd..6341f1bfffa2 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -181,9 +181,14 @@ static int __swap_cache_add_check(struct swap_cluster_= info *ci, old_tb =3D __swap_table_get(ci, ci_off); if (swp_tb_is_folio(old_tb)) return -EEXIST; - if (!__swp_tb_get_count(old_tb)) + /* + * Only a swapped-out slot may be brought into the swap cache. + * Cluster readahead walks raw offset ranges, so it can land on + * slots that are free, bad, or owned by hibernation. + */ + if (!swp_tb_is_shadow(old_tb) || !__swp_tb_get_count(old_tb)) return -ENOENT; - if (shadowp && swp_tb_is_shadow(old_tb)) + if (shadowp) *shadowp =3D swp_tb_to_shadow(old_tb); if (memcg_id) *memcg_id =3D __swap_cgroup_get(ci, ci_off); @@ -196,7 +201,7 @@ static int __swap_cache_add_check(struct swap_cluster_i= nfo *ci, ci_end =3D ci_off + nr; do { old_tb =3D __swap_table_get(ci, ci_off); - if (unlikely(swp_tb_is_folio(old_tb) || + if (unlikely(!swp_tb_is_shadow(old_tb) || !__swp_tb_get_count(old_tb) || is_zero !=3D __swap_table_test_zero(ci, ci_off) || (memcg_id && *memcg_id !=3D __swap_cgroup_get(ci, ci_off)))) --=20 2.48.1 From nobody Tue Sep 29 06:08:34 2026 Received: from lgeamrelo03.lge.com (lgeamrelo03.lge.com [156.147.51.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ED6E188CC9 for ; Tue, 11 Aug 2026 13:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.51.102 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454544; cv=none; b=PegAayZeIWBlyJw21jB03scYcp3dvpps49fspY6nFT8vjsiQzPdRp3T8sjQbuS23akzeGJ9amAwvwvUu6TFTNHWoi5Mrj6lBoR+6g1+/yFOq767Li9nd/KLpeDtatWQ7sd/lONmhPNCxhuhUP1UhyHo1hWjrQVFpqvm28l+V1KU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454544; c=relaxed/simple; bh=1ns5UMjx9CQMcpLYkIJG5q1LkHlIFm86V5j01ouIZhc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FqSjg3SAPC2sZTZK3OxMDvtXwHLPMySmf6RxTRRrGoGue2T2yT5HBv1tXIXnWmUzSB6BtjmjJfU8zcidGlFYqNdoC62hjOTNQiaAoKfoCpDx7uz2FEl0i1DDHC+BPoMyk26yovDrST7FTLnh2zOocfS3krnAR9YoQZR6QoWUd98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.51.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330.lge.net) (10.177.112.156) by 156.147.51.102 with ESMTP; 11 Aug 2026 22:22:13 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com From: Youngjun Park To: Andrew Morton Cc: Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Jianyue Wu , her0gyugyu@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Youngjun Park Subject: [PATCH v3 3/4] mm, swap: give hibernation swap slots their own swap table entry type Date: Tue, 11 Aug 2026 22:22:08 +0900 Message-Id: <20260811132209.2862708-4-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260811132209.2862708-1-youngjun.park@lge.com> References: <20260811132209.2862708-1-youngjun.park@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" swap_alloc_hibernation_slot() stores a fake shadow in the slot it hands out. An anon slot swapped out with no workingset shadow looks exactly the same, so nothing in mm can tell the two apart. Give hibernation slots their own type. Bit 4 and every bit above it are set, except the count field, which stays 0. Bits 0 to 3 are taken by the shadow, PFN, pointer and bad marks, so bit 4 is the first free one. The type holds no data, so the value alone says what it is. The entry has no swap count. Hibernation only allocates and frees a slot, so a count would never change. swap_free_hibernation_slot() frees the slot directly, there is no count to put first. The slot is no longer a shadow, so the previous patch keeps it out of the swap cache. The count field stays 0 as well, so code that reads the count without checking the type sees an unused slot instead of one at SWP_TB_COUNT_MAX, and a wrong put is caught by the existing underflow check. Suggested-by: Kairui Song Link: https://lore.kernel.org/linux-mm/abp7aDgYLrxF3Me8@KASONG-MC4/ Signed-off-by: Youngjun Park Acked-by: Kairui Song --- mm/swap_table.h | 13 +++++++++++++ mm/swapfile.c | 13 +++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/mm/swap_table.h b/mm/swap_table.h index e6613e62f8d0..b916a6493521 100644 --- a/mm/swap_table.h +++ b/mm/swap_table.h @@ -30,6 +30,7 @@ struct swap_memcg_table { * PFN: |SWAP_COUNT|Z|------ PFN -------|10| - Cached slot * Pointer: |----------- Pointer ----------|100| - (Unused) * Bad: |------------- 1 -------------|1000| - Bad slot + * Hibern: | 0 |------- 1 -------|10000| - Hibernation slot * * COUNT is `SWP_TB_COUNT_BITS` long, Z is the `SWP_TB_ZERO_FLAG` bit, * and together they form the `SWP_TB_FLAGS_BITS` wide flags field. @@ -54,6 +55,10 @@ struct swap_memcg_table { * aligned pointers. * * - Bad: Swap slot is reserved, protects swap header or holes on swap dev= ices. + * + * - Hibern: Swap slot is reserved by hibernation for the suspend image, a= nd + * must never enter the swap cache. The count field is kept 0 so it never + * reads as a slot in use. */ =20 /* NULL Entry, all 0 */ @@ -81,6 +86,9 @@ struct swap_memcg_table { /* Bad slot: ends with 0b1000 and rests of bits are all 1 */ #define SWP_TB_BAD ((~0UL) << 3) =20 +/* Hibernation slot: ends with 0b10000, no count, rests of bits are all 1 = */ +#define SWP_TB_HIB (((~0UL) << 4) & ~SWP_TB_COUNT_MASK) + /* Macro for shadow offset calculation */ #define SWAP_COUNT_SHIFT SWP_TB_FLAGS_BITS =20 @@ -166,6 +174,11 @@ static inline bool swp_tb_is_bad(unsigned long swp_tb) return swp_tb =3D=3D SWP_TB_BAD; } =20 +static inline bool swp_tb_is_hibernation(unsigned long swp_tb) +{ + return swp_tb =3D=3D SWP_TB_HIB; +} + static inline bool swp_tb_is_countable(unsigned long swp_tb) { return (swp_tb_is_shadow(swp_tb) || swp_tb_is_folio(swp_tb) || diff --git a/mm/swapfile.c b/mm/swapfile.c index f5dfc7e59191..a337387f7431 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -928,7 +928,7 @@ static bool __swap_cluster_alloc_entries(struct swap_in= fo_struct *si, * upon folio unmap. * * Else, it's a exclusive order 0 allocation for hibernation. - * The slot starts with count =3D=3D 1 and never increases. + * The slot carries no swap count and is freed by offset. */ if (likely(folio)) { order =3D folio_order(folio); @@ -940,8 +940,8 @@ static bool __swap_cluster_alloc_entries(struct swap_in= fo_struct *si, order =3D 0; nr_pages =3D 1; swap_cluster_assert_empty(ci, ci_off, 1, false); - /* Fake shadow placeholder with no flag, hibernation does not use the ze= romap */ - __swap_table_set(ci, ci_off, __swp_tb_mk_count(shadow_to_swp_tb(NULL, 0)= , 1)); + /* Exclusively owned by hibernation, must never enter the swap cache */ + __swap_table_set(ci, ci_off, SWP_TB_HIB); } else { /* Allocation without folio is only possible with hibernation */ WARN_ON_ONCE(1); @@ -1929,9 +1929,11 @@ void __swap_cluster_free_entries(struct swap_info_st= ruct *si, old_tb =3D __swap_table_get(ci, ci_off); /* * Freeing is done after release of the last swap count - * ref, or after swap cache is dropped + * ref, or after swap cache is dropped. A hibernation slot + * has no count and is freed directly by its owner. */ - VM_WARN_ON(!swp_tb_is_shadow(old_tb) || __swp_tb_get_count(old_tb) > 1); + VM_WARN_ON(!swp_tb_is_hibernation(old_tb) && + (!swp_tb_is_shadow(old_tb) || __swp_tb_get_count(old_tb) > 1)); =20 /* Resetting the slot to NULL also clears the inline flags. */ __swap_table_set(ci, ci_off, null_to_swp_tb()); @@ -2201,7 +2203,6 @@ void swap_free_hibernation_slot(swp_entry_t entry) pgoff_t offset =3D swp_offset(entry); =20 ci =3D swap_cluster_lock(si, offset); - __swap_cluster_put_entry(ci, offset % SWAPFILE_CLUSTER); /* * A slot with a folio in the swap cache is freed when the folio * leaves the cache, the same rule swap_put_entries_cluster() follows. --=20 2.48.1 From nobody Tue Sep 29 06:08:34 2026 Received: from lgeamrelo03.lge.com (lgeamrelo03.lge.com [156.147.51.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ED151514F8 for ; Tue, 11 Aug 2026 13:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.51.102 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454543; cv=none; b=LZWCoYsf1O1dLOzF2bf7Ytd9QI6K4U3o2ZHDkIRCVA6bSVeOXYtxicXr+2AEYxiJhXwJXg3pWaJh0cGXBUrI3oaupuVd+fCxSfNnStLKdMW8uX69QjlcJvwM8HQzIXNoPtyeOrKe6UedwCptc36qbcNBHSFCcpYjyIS4iFJ6b1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786454543; c=relaxed/simple; bh=yohiKZKKDpu7AbaW+E9jTU4BavVrN04gTK6htM1XTs8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SG/WaaVITc9EkQg8MRkuwFx0rQVU4ZvNUP/9S8s34Z29k7bA42j8VI0XyxKzhQjv7pwa2jf8tNaKltF8TY5xgIjZASql+yiuKYcaxzTTH/SA8TYh2CHiTi/FzFYqGTpRjwOTgRegZUztvM2pSNbre2AdgwIX3Yzq/Gq+k71biLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.51.102 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330.lge.net) (10.177.112.156) by 156.147.51.102 with ESMTP; 11 Aug 2026 22:22:14 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com From: Youngjun Park To: Andrew Morton Cc: Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Jianyue Wu , her0gyugyu@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Youngjun Park Subject: [PATCH v3 4/4] mm, swap: drop the swap cache guard and reclaim in swap_free_hibernation_slot() Date: Tue, 11 Aug 2026 22:22:09 +0900 Message-Id: <20260811132209.2862708-5-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260811132209.2862708-1-youngjun.park@lge.com> References: <20260811132209.2862708-1-youngjun.park@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both are there for a folio that readahead might have put on the slot. A hibernation entry is not a shadow and has no swap count, so the swap cache turns it away and no such folio can exist. Signed-off-by: Youngjun Park Acked-by: Kairui Song --- mm/swapfile.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index a337387f7431..4fba1770ce61 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2203,18 +2203,8 @@ void swap_free_hibernation_slot(swp_entry_t entry) pgoff_t offset =3D swp_offset(entry); =20 ci =3D swap_cluster_lock(si, offset); - /* - * A slot with a folio in the swap cache is freed when the folio - * leaves the cache, the same rule swap_put_entries_cluster() follows. - * Readahead can put a folio here, and freeing the slot now would - * leave that folio with no entry behind it. - */ - if (!swp_tb_is_folio(__swap_table_get(ci, offset % SWAPFILE_CLUSTER))) - __swap_cluster_free_entries(si, ci, offset % SWAPFILE_CLUSTER, 1); + __swap_cluster_free_entries(si, ci, offset % SWAPFILE_CLUSTER, 1); swap_cluster_unlock(ci); - - /* In theory readahead might add it to the swap cache by accident */ - __try_to_reclaim_swap(si, offset, TTRS_ANYWAY); } =20 static int __find_hibernation_swap_type(dev_t device, sector_t offset) --=20 2.48.1