From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 D203143CE6A for ; Tue, 11 Aug 2026 16:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786466929; cv=none; b=htqq+fyujha9E01EGvvam4P+sIaYaZMJldy5zd+SiZ5UyDDowMg2B6MX8qrYZpOZjmt6St0bUWILgx+UYxT8xsEKQhyQ1CcvetenauGpA3VdBFxEc+pzQevcmQtsy9eMWzhQlrJj2aeTUmguiljOv2MqjlB+yQCyqcbTPg3AINE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786466929; c=relaxed/simple; bh=Ux8bB5A4zyRNyvoAkTWQyQ1SQnUO5keMIMNixXOe8+s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ihE+r8SjZcZimoVtTndNlN6esti1O0KdenkimbzFioNetkDLcnk1386rMg8WQq87VyWyU8V2HafzZyFpDRhLgsIwRH2hMV5s/vxEgj3WmQPyjfIXHNvP8axABhHEG8Pa7iP11/IJ7eI3hIw+lXb+lhKSLQM1I66RWsy+CidILcs= 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=r5hD8iih; arc=none smtp.client-ip=209.85.210.178 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="r5hD8iih" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-8484f229529so66273b3a.2 for ; Tue, 11 Aug 2026 09:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786466926; x=1787071726; 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=OLBaiJQvXFC//um24aVUsRphyaJvRKwYbCegxqDVEAo=; b=r5hD8iihnVqEPeVrQG2KrGja/D9LVh21DesLEpwXXK/pZnpnFWFfYwFfLqesTezx8c P5vgMIwYA06Ufwq/NaRWmQoLHmqwlKEM/Stka7Y4rf7eUdII+tf6piAzHJYusUG4Sbwx d0oa5pLkvG9xiDJtOd/+hM6K3Pwf+4ISgmHoZ4IDCsg4y3yAXcB+0hUyKu8igblxUrVp 87zc5K5Q/N9tuY93AgFp9GhZHWZ2eRtdF1h/7Hw9iey1PesPc3N7hxwrAQcabC1t0AUm y4oL8I3wtYCagjpDM65a9smq38sxNKzQl2VkEn5d7+aRwl79c6e9NPxYhprfSRRgUd24 9GNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786466926; x=1787071726; 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=OLBaiJQvXFC//um24aVUsRphyaJvRKwYbCegxqDVEAo=; b=mWWvKOtd1yaBnYgNLRrtVrqy9SaQwH5z04DrNs7OVjljtoWJ6yTdyu8QrmS11/0m2J wcpYGK1r+oinBn6KRwDUT9FH1uCIoOoGg/ZHAB9GqpwdX26R2oYsWURQ+Kz4V5Kgptlz nQI0mL5QnYquOlMGHhYm8a4SQO7BVILvzju7T1R/raGh8GE5AXdzKvWCf8XYR/7vQEyI sTkmd/RmDHpqXgckSQgK2vMRItPPyi4nxrPdaTmRtUbWoK00HDOFUxLai8QEkWg3muZC mqKNczg/IbRWSr2bZeZvJMuWHgMFwkIHJ4Z0NZvLHB9loD/JGEC9MRIEWR0+KRGiO1vb 7Fzw== X-Forwarded-Encrypted: i=1; AHgh+Rr+8uf3CvcbOgCBn7gUq7iep2H3hVVJARAsrww0pM15uJ7Rq9P9bW0rXJL1b8AvSqQiz1pvREil1PIUAKg=@vger.kernel.org X-Gm-Message-State: AOJu0YxeG/AmGMeXOKLwBFWAHmmPC7HPXdHoZkrmjZK45KWOmNUuftYW 8boYaFFoeX09kUCNfVTNXhKCKlleKWh/ExxwlZSWtsvOOsPV4V9QqOem X-Gm-Gg: AR+sD10rgf9IRBoXyiW3IdQeOK+VAqcG44GCkd5YToT+ZA7MsFTcPu3+uar8h0cfmHv MfrNZYQK8WBuIY1hm3ZW+2VfOE9ehM3PVY7Zz72SDnrxcA5axJcY6iV+kgs5B6SSUBsSZdBOe8H 4QihjDrZoO90tYBUgyP17gaOdjmXJNPnFT6/R6AleoKBNZT/OLO6DZm58HNT4KyAbRSEyqgQr7m ICCgFK3s44aOPy4CJsd2qQnqKvyIbwZqd9ENt0yFsi0QfaL3Xc2N8o4l5aO6EzoSl0YV9AOSxJM WQ3KzTgYE1CUg5vzkyiD9v230p7JMMjAScocXZ9nOv14z67quN1CDJ3X6rm3wWVhH3WIKa2X5xD M6vlbBKBRjfjibVTG5h3RrNrkszFKgjKULRaNWoQQUePoaCd9Oiyh4dnfGcmJD3DUeZBToIib3C 3I4gGKGtKN63l1cZmwv434RKDy7cllXChYU2ppKEynZzS/bxypgRTeFotfQs2/IbG97knW9vXqn qNBJYOZKBJdgM7Vg3E87Rps/A== X-Received: by 2002:a05:6a00:400c:b0:84f:7001:7a7f with SMTP id d2e1a72fcca58-84fa88a3b2fmr5152732b3a.36.1786466925897; Tue, 11 Aug 2026 09:48:45 -0700 (PDT) Received: from KASONG-MC4 ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cbed8ea1ecesm1283681a12.31.2026.08.11.09.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 09:48:45 -0700 (PDT) Date: Wed, 12 Aug 2026 00:48: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 v3 3/4] mm, swap: give hibernation swap slots their own swap table entry type Message-ID: References: <20260811132209.2862708-1-youngjun.park@lge.com> <20260811132209.2862708-4-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: <20260811132209.2862708-4-youngjun.park@lge.com> On Tue, Aug 11, 2026 at 10:22:08PM +0800, Youngjun Park wrote: > 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 > --- > 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 Hibern is a odd name, but I don't have better idea for this... Maybe just HIB, match the macro name? > * > * 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 devices. > + * > + * - Hibern: Swap slot is reserved by hibernation for the suspend image, and > + * must never enter the swap cache. The count field is kept 0 so it never > + * reads as a slot in use. Not sure if the comment is a bit misleading. The slot is treated as in use by allocator since it is not a NULL slot, kind of like a special pin, just like swap cache pin, which also has a count == 0, until folio_dup_swap is called. We can never dup a hibernate slot though, which is expected. And we never add it to swap cache. > @@ -2201,7 +2203,6 @@ void swap_free_hibernation_slot(swp_entry_t entry) > pgoff_t offset = swp_offset(entry); > > ci = swap_cluster_lock(si, offset); > - __swap_cluster_put_entry(ci, offset % SWAPFILE_CLUSTER); Nice! We can free it directly now. > /* > * 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. > -- > 2.48.1 > Just two trivial nit picks on doc, feel free to ignore, code looks good to me, Thanks! Acked-by: Kairui Song