Re: [PATCH] mm/swap: fix swap cache memcg accounting

From: Johannes Weiner

Date: Fri Mar 20 2026 - 10:24:51 EST


On Fri, Mar 20, 2026 at 06:05:59AM +0100, Alexandre Ghiti wrote:
> The swap readahead path was recently refactored and while doing this,
> the order between the charging of the folio in the memcg and the addition
> of the folio in the swap cache was inverted.
>
> Since the accounting of the folio is done while adding the folio to the
> swap cache and the folio is not charged in the memcg yet, the accounting
> is then done at the node level, which is wrong.
>
> Fix this by charging the folio in the memcg before adding it to the swap cache.
>
> Fixes: 2732acda82c9 ("mm, swap: use swap cache as the swap in synchronize layer")
> Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>

Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>