Re: [PATCH v4 2/3] mm, swap: give hibernation swap slots their own swap table entry type

From: Nhat Pham

Date: Wed Nov 04 2026 - 11:40:50 EST


On Tue, Nov 3, 2026 at 9:25 AM Kairui Song via B4 Relay
<devnull+kasong.tencent.com@xxxxxxxxxx> wrote:
>
> From: Youngjun Park <youngjun.park@xxxxxxx>
>
> 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 <kasong@xxxxxxxxxxx>
> Link: https://lore.kernel.org/linux-mm/abp7aDgYLrxF3Me8@KASONG-MC4/
> Signed-off-by: Youngjun Park <youngjun.park@xxxxxxx>
> Acked-by: Kairui Song <kasong@xxxxxxxxxxx>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> [kasong@xxxxxxxxxxx: renamed the layout entry to HIB and reworded its doc]

Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>