Re: [PATCH] mm, swap: avoid leaving unused extend table after alloc race
From: Breno Leitao
Date: Wed May 13 2026 - 09:04:14 EST
On Wed, May 13, 2026 at 05:21:11PM +0800, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> Allocating an extend table requires dropping the ci lock first.
> While the lock is dropped, a concurrent put can decrease the slot's
> swap count to a value that is no longer maxed out, so the extend
> table is no longer required. The current allocation path still
> attach the new extend table to the cluster anyway, leaving it unused.
>
> It's not really leaked, the next maxed out count on the same cluster
> reuses the table, and frees it properly. Swapoff will also clean it up.
>
> The worst case is one unused page pinned per cluster until the next
> maxed-out allocation or swapoff. To eliminate the waste, re-check
> under the ci lock that the extend table is still needed before
> publishing it, and free the local allocation otherwise. The added
> overhead is ignorable.
>
> Fixes: 0d6af9bcf383 ("mm, swap: use the swap table to track the swap count")
> Reported-by: Breno Leitao <leitao@xxxxxxxxxx>
> Closes: https://lore.kernel.org/linux-mm/agG6Dp0umhs6O1SY@xxxxxxxxx/
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Tested-by: Breno Leitao <leitao@xxxxxxxxxx>
Thanks for the fix,
--breno