From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 0F2863264C4 for ; Sat, 8 Aug 2026 13:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786195602; cv=none; b=e0rkGg5v0fB2VJuMXP4ekzhyd1TXtcGCHWx+Bu5x0ousoyMGy2DKnzupQ7Umwf+puKQb/eEAWZCNGL9nsLmFpeE3rXgqL9krfAbvjLFIpyuapBBVOeTQoUgruSdgnxJnarfvWwf4zypugQsjucSwWaSrrgNY1q2KxxQEsxOJb7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786195602; c=relaxed/simple; bh=+SaURdHkNseR4dBaWayfGFnYzgcaoXOxr9GAclU0EvE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SggtkBQprkxTZz2bxuxtEUz5JRGwGas9SCZarS4a2T8qVQpVthU+sLf/kUQ+VKduNNvUzOyovwZNXNW3OWJiWvSBcM4EIZZNY5vIeX8ziAw24DIkLT1ErS+D/NfLt4vxeoI803r90GM0h/fSRZsjuoUAMANielntfpN9c3KpPOg= 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=I1UdKS4p; arc=none smtp.client-ip=209.85.216.44 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="I1UdKS4p" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so462894a91.3 for ; Sat, 08 Aug 2026 06:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786195600; x=1786800400; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=t9E1a2kLGvFYXzBwJKT2QHl92Z0jFI3rJy3UAWTsihA=; b=I1UdKS4pzc28SeuTj+uagFiYqV2vU50jtQrwVKVMjNimYJdrFE9O41/UlnmW6RhnSm f2hKgz7U0OFpNhiHO44aM8N1n8RZp6OsygGygkz6ITL78dvoogxf0IZFY4vX0yJNtRYU B3ji7y94kbUHMkYA6MP4NWvYyHOFvueYnaO3ZVmYeetHi80IkJEZuAdfIwrqgoGGg9X8 x1B1YP+rg/xJHkRYHiO4QxlCPwwVnfk0eExyzu9N3tBHJecgMYBxefUTGj0mvXpvET9U nD2L8za2aP79eoOF4vS44314+5D6f/OjPOg3uh2pyTcKr1Tt8ha3Cwv5bUh9C1nWceVu N8gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786195600; x=1786800400; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=t9E1a2kLGvFYXzBwJKT2QHl92Z0jFI3rJy3UAWTsihA=; b=npEcjydxoZioZIoTelGPsUG1kyfDH9fylFspzfKYcCgyExrg+0QeuQt1XHE+6bcBrC oL+1qDA8UKNoGwb01SztR+RsqSIjE8rDTTOYNFY0mmxfGRQtyF1cguMBw2n4RJN+GngC 40QzQs56dOuPaDMrf4Kl5ejOiMh8/V8aQzzZjDgnKPPXSA7Mv0cnzqPoxk6i3K0mUun7 seHZ0RuLF9HDdsjwHcZ1cVZLLrmtwij2GR89lwaPKR0hKTTnj0KiCDyJZlVZ5Zqt8mds YOunpVhbhdrcEKBBhL/4GocrIMht7MzZfpWDbkCCufLkmCaDyeE2IWg+292mXZFy6ayU f75g== X-Forwarded-Encrypted: i=1; AHgh+RofS+JhA4kabdKyAEFGOPlEws+3PiruEX5uSm3RxyHmGHGYNEhC7vwITvhOFQsQ8jq7XljY0Y9F/sfk+DY=@vger.kernel.org X-Gm-Message-State: AOJu0YzNlayQ113nUwCwvR08xDh4gHqIaQ8ZXTdyr0XxwnzVKAexKejP Bl5bNB1npqedSrO2tzOi25LXpHSMmrQywDszYv3FLbVNiGc3KvZquHMI X-Gm-Gg: AR+sD116Hxpqg0JoJ/V5LLA2VI06WaQsfMPKAJIEa0vIydQ9ENSqvREigo8vBIgv2OB 8TV4hNBr+HijZ6NLNVEDmryNTOFsU3RPGqU6ks4ErgIvWd5H7AscAq/6809yNTDiPkOpnzgoVfm 4c5EXGeD4b6pBxCKhA+enB3HUlBHrV2YZNUFGos20pNMW8Y4sigRcu1DPa+8QaL8p1Jgcqo/+Vi HLZR/wGBK+obsQ+WN5Z0iIiVpOlhnobeTd/Ir/qAsLECi3Q36SfapH5Xqie/nuqkU8nlRywmBqA Q+LljqF5RkPwQQxf52u863DVj9G2kOa+p5gwXvTh5wmiHzwi6n39Ryl1APv/CcY5ZZIEpOSextd fjkBNVmBgFg3a8kVrfSKTJrqbWFc+n0P8BALOD1eMzyYz/v26L6yBmtKeDNzd2b3WQDWSGcJcRT maEznSDVkxsD0pxhK8uVp/wEbWRqCRe/afOeHns+W28o8HKrUmnpNU+DP7I30dvfEFYBdXt7Wel jegD20uyawfKoSnySmLYMCGu/S9vcJZ8aua X-Received: by 2002:a17:90b:4d84:b0:381:5bd6:eb19 with SMTP id 98e67ed59e1d1-3903c5dfd9amr28471631a91.18.1786195600291; Sat, 08 Aug 2026 06:26:40 -0700 (PDT) Received: from KASONG-MC4 ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-390b370b145sm2711263a91.2.2026.08.08.06.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 06:26:39 -0700 (PDT) Date: Sat, 8 Aug 2026 21:26:34 +0800 From: Kairui Song To: Youngjun Park Cc: Andrew Morton , 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 Subject: Re: [PATCH 1/4] mm, swap: don't free a hibernation slot that is in the swap cache Message-ID: References: <20260806190636.446205-1-youngjun.park@lge.com> <20260806190636.446205-2-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sat, Aug 08, 2026 at 08:09:44PM +0800, Kairui Song wrote: > On Fri, Aug 07, 2026 at 04:06:33AM +0800, Youngjun Park wrote: > > 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") > > Signed-off-by: Youngjun Park > > --- > > mm/swapfile.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > Hi Youngjun, > > Thanks a lot for looking into the hibernation issue, I've been thinking > about using a exclusive type for it, glad to see actual code for it :) > > And this patch looks good to me, nice catch! > > Acked-by: Kairui Song Oh and I think we need to Cc stable?