From mboxrd@z Thu Jan 1 00:00:00 1970 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 38A3A4C77C7 for ; Thu, 6 Aug 2026 19:21:37 +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=1786044102; cv=none; b=S3IPDRzWLM3ttCXBgncc5LCtBv1P9ig5xdSuy00j379I0wgDouAxHFxLLba0L0V5hQsxrlvl+KgVpUtTw2tMF2CQbzrvTPwbIwc/QV5kY/VmYEdCHie4FFQc7iMoM0KmE05y1ruL+NMGFP2xJN7WwF2xkIe2bIL9Ls0vFGxHYnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786044102; c=relaxed/simple; bh=7eQQEKwziasGTzkaarw57l6DodZpQOReFsCajgppINk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=PUs/3K05cFrHcB7XEZ9hhtaeR7SF2infsqCeAyi+VConoTZJ0ccR2doJzu40NCBig3b0/ezAcsX8WZMvpLQXZ3YPg2Q0m2t0aoGt1b19L+HouYwhxJCxVMDfzITebsiKwcOQ+3NtN81WPF0pwE96KSlCXm1jLUejUMLFJkVnrck= 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; 7 Aug 2026 04:06:36 +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 , Youngjun Park , her0gyugyu@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/4] mm, swap: keep hibernation swap slots out of the swap cache Date: Fri, 7 Aug 2026 04:06:32 +0900 Message-Id: <20260806190636.446205-1-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cluster readahead walks a raw page_cluster sized window of offsets around the faulting entry. A hibernation slot looks like an ordinary swapped out slot, so __swap_cache_add_check() lets it in. Readahead reads the offset off the device into a folio and puts that folio in the swap table where the hibernation entry was. This has been possible for a long time. It only wasted a folio and a read. That changed with commit 0d6af9bcf383 ("mm, swap: use the swap table to track the swap count"). A slot with a folio in the swap cache should only be freed when the folio leaves the cache. swap_put_entries_cluster() still does that, but the conversion left swap_free_hibernation_slot() freeing the slot either way. Nothing points at the folio after that, and when reclaim drops it later, it writes to the table entry at the old offset, which someone else may own by then. Patch 1 is the fix. It puts the missing check back, so both free paths behave the same again. The rest removes the cause. Readahead should not touch these slots at all, so patch 2 gives hibernation slots their own swap table entry type, patch 3 lets only swapped out slots into the swap cache, and patch 4 drops the check and the reclaim, since no such folio can exist any more. For any of this a task has to hold hibernation slots while the system is still running. The in kernel path does not, it allocates, writes and frees the slots with everything frozen. Userspace hibernation is different. The process writing the image is not frozen, and SNAPSHOT_ALLOC_SWAP_PAGE does not check that anything is frozen. The swap device must also not be SWP_SYNCHRONOUS_IO, or swapin takes the direct path and never reaches cluster readahead. Tested with a debug patch generated by AI that counts hibernation slots through the swap cache paths. virtio-blk swap, page-cluster 3, SNAPSHOT_ALLOC_SWAP_PAGE interleaved with MADV_PAGEOUT of a shmem region so the hibernation slots land in the readahead windows. unpatched +patch 1 patches 1-4 hibernation slots allocated 2732 2732 2732 readahead landed on the slot 2731 2731 2731 admitted to the swap cache 2731 2731 0 reclaim found the folio 0 2731 - slot left unfreed 0 0 0 VM_WARN in the free path 2731 0 0 The VM_WARN is the existing assertion in __swap_cluster_free_entries(), not something the debug patch adds. Youngjun Park (4): mm, swap: don't free a hibernation slot that is in the swap cache mm, swap: give hibernation swap slots their own swap table entry type mm, swap: only allow swapped-out slots into the swap cache mm, swap: drop the swap cache guard and reclaim in swap_free_hibernation_slot() mm/swap_state.c | 9 +++++++-- mm/swap_table.h | 12 ++++++++++++ mm/swapfile.c | 16 +++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) base-commit: 0b53bff4fa05ff0d3ffbd3d3bb10fae69dfab498 -- 2.48.1