Re: [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy
From: Muchun Song
Date: Sat Dec 05 2026 - 21:58:10 EST
> On Dec 5, 2026, at 01:39, Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
>
> From: Chris Mason <mason@xxxxxxxxxx>
>
> memcg_destroy_list_lru() tears down lru->xa by erasing its entries,
> and relies on the XArray to free each node once its last entry is
> gone. That is not how an XArray is torn down. A node can exist
> without entries, and nothing frees that one; it also keeps the count
> of its parent up, so the parent and everything above it stay
> allocated as well. The API has xa_destroy() for this: free the
> entries, then call it to free the nodes.
>
> Empty nodes come from a store that gave up partway. xas_create()
> builds the path to a new index one level at a time, and links each
> node into the tree before it allocates the next. If that allocation
> fails, the linked node stays. This is by design: once xas_nomem()
> has refilled the cache, the retry descends into the node and
> completes the path, and later stores reuse it too. But if the retry
> cannot allocate either, the store returns -ENOMEM and the node stays
> empty. __memcg_list_lru_alloc() gets there with GFP_NOWAIT when the
> page cache allocates a node under memory pressure.
>
> The leak is small, a few nodes per list_lru, and shows at umount.
>
> Fix it by calling xa_destroy() once the entries are freed.
>
> Fixes: bbca91cca9a9 ("mm: list_lru: replace linear array with xarray")
> Cc: Dave Chinner <david@xxxxxxxxxxxxx>
> Cc: Kairui Song <kasong@xxxxxxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxxxxx>
> Cc: Muchun Song <muchun.song@xxxxxxxxx>
> Cc: Qi Zheng <qi.zheng@xxxxxxxxx>
> Cc: Roman Gushchin <roman.gushchin@xxxxxxxxx>
> Cc: Shakeel Butt <shakeel.butt@xxxxxxxxx>
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
Acked-by: Muchun Song (ByteDance) <muchun.song@xxxxxxxxx>
Thanks.