From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 69A2F37F002 for ; Sat, 8 Aug 2026 12:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786190994; cv=none; b=PSJNl+FsMTiznE38/Ns3SoL2FP/bjh1MQ1rSBS1YPnm/l+uOUxVFO/M1q1kAfb8PBp0ILi1T/0w58yUuohiUUeDwFqJFUUte2TmbdNzkxhoU2OBGyTjinGA14H/C/DzKWKt4irkpSAvk7+KSURxAu3s0WeLT6d9IQy0cY5XyPQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786190994; c=relaxed/simple; bh=wmUUbNKvaRF3/45ycCdLXb6Zm1F130Pu0BKDezml6rE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PoFKn4Y780TFnK3ZEqh7D4zxSXY3AwGQKQX5lO/UqaKkpN5/xqzL8Ff/Z7pRK3DmzDTDvoOchk1Oorh4xYu7QJcRjoE4o0zl9RzqgKHtCinmtTBR9SRyPs4U4WI3mybHpgNJSAb1XlfqKkjHsD9sI5iJ8zbA5t6WL+180C78MpM= 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=XctAhPne; arc=none smtp.client-ip=209.85.210.174 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="XctAhPne" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-84e84a6c4bfso355361b3a.1 for ; Sat, 08 Aug 2026 05:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786190991; x=1786795791; 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=gtdtzXvGEBVmzPjM10Nks6+mSpQf5NRA60Z5gDD36Zk=; b=XctAhPneCZ/gPOZ/XCdFRUT+1vcg8ryLeaKYvcw0nWrydH8RqjGPPKNzoYP7kFE18Y nb5oK4wNwQGeI77jJuWiXcM/zrs1DMvLkfG/hzO2p2qm+/OipDVvXycqM1YWN/GxsKQB aj4rSP2NbIiEWp4IJMTcmmAdvT7nLo4ZhgZ3fmNEqsQVI+r6bueLNquC8Swgki6AA8Ux DwTyF+33SCDiHV/jeoe0umrofxZ9LygImpQQx15OSbV6yoLnjA91bbRJObBYss3cNZzV DBUcXaiYH4nNXEN3EiVWAqKHzk13gnJuXPMQ2OJAxPKjMuVYNsOyV6290T/3iAOJslHY 3H7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786190991; x=1786795791; 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=gtdtzXvGEBVmzPjM10Nks6+mSpQf5NRA60Z5gDD36Zk=; b=hMzNofOlu9/gL2f5O7aAhP2kFjRer6x4TEngInxnlYn6bLVSz/VRelfsLECDYmyB4C 8qPvk0i22i+6ZeNSOWOyyA8lFCTBeR+y+hpU1s8z4tnIkfVrDCrrDpdddXGUDCQvhcUk rNTwobT/FPhPar5zhAO5kRzFnGK+R301NM721qOv1ySgC6tsXj1g1zgv+feWTl5adQ6u HvU5gA32Bd8fCrpZ9jXtCpojn2EgG9buJNoOMmz0CZA7AZkdtVRDWcOR16OAozYMGSDI 0wFo+zeRuzPH64xghO/xY6jq8E/sUPj4VE6e3CdETp+G+xilVtCw8hVqZPyQVuEc4map aIIg== X-Forwarded-Encrypted: i=1; AHgh+RoBbcWXwSn+oiIEHasgxv4oJIeEX1LUJMzNwcgFMTxtnelOlINpOj9aRy3Vq+l0HZGLP/SMSocdc5pEdBs=@vger.kernel.org X-Gm-Message-State: AOJu0YwpHIG/Jp6vu52HAJXu4MgkekNsbv1TAoOZ7EfZUw/OS0XEmmLL 20VHFsF+btvwl0Bs6Hpw/6N9Pg0Y0a6Yyvh70b/yqi9Bl1xQIvedanEs X-Gm-Gg: AR+sD13lFJiHcHvIl1t6GXQ1rfRmMnBe0FXqjiyZJN2WwU1PlvFJsNrXyoRFcU6d81E ZbzVVREP8C3FGXI3Zy6Mnsx4FqvfH4hBgcRV3x//RbBUPbX2688SWynnPTNx7NkQVK6FJ3Pis1w FKbhXF5iFgq5KKX1CPLwDVmjAF9N2zIDTb19o1iazsrRSx6zvQeqZzss/UI1CAG/Mz7iWbJk88K bHeVVDquurT5lmjED1na0PC+SsAxYU8WzqC18EcxF3hL4Ssj1cv90ib2mo5mMqSzo1U7Z74AK3C e9QURAVN7qVA1LS9WaOfsdiu3X9N4LO5II4+ETteh2UJr99VeKtziVNFCknIyVzXwGvvsWbcge0 rXkOrYl+KRzgiM8rhSrZiot9eAytMFuD2xxQuMyyvY6kWI4HQSyhVnGDt7nZ939r5G0LfMKhgnQ tVYNreQV0we+4exYFsIsBGe+US/Pv3cfDwTK+oUG4scBMNzyVZF04Re15M8sd8aWx5HIy2kaYR7 4rM3mTmoAS989vBS7HnsGjb X-Received: by 2002:a05:6a00:c0ce:20b0:84f:72f7:de58 with SMTP id d2e1a72fcca58-84f72f7e7cemr1924485b3a.17.1786190990918; Sat, 08 Aug 2026 05:09:50 -0700 (PDT) Received: from KASONG-MC4 ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f5a589592sm2097842b3a.51.2026.08.08.05.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2026 05:09:50 -0700 (PDT) Date: Sat, 8 Aug 2026 20:09:44 +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: <20260806190636.446205-2-youngjun.park@lge.com> 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