Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
From: Shakeel Butt
Date: Thu Nov 26 2026 - 10:22:40 EST
On Thu, Nov 26, 2026 at 02:08:56AM -1000, Tejun Heo wrote:
> Legacy memcg reclaim has no dirty throttling, and shrink_folio_list() waits
> for a folio that is under writeback and already marked for reclaim (case 3
> in its comment). That wait can deadlock against a filesystem freeze:
>
> 1. A task in write() to filesystem B holds freeze protection on B, enters
> memcg reclaim and waits for writeback of a folio of a filesystem on a
> loop device backed by a file on B.
>
> 2. A freeze of B waits for the task to drop its freeze protection.
>
> 3. The loop worker has to take freeze protection on B to write the folio out
> and blocks behind the freeze.
>
> The same applies to any driver that writes to a file on a local filesystem
> to serve block I/O and takes freeze protection for it.
>
> Reclaim can't tell which filesystem a writeback depends on. Count the
> superblocks that are being frozen and make the wait time out after 15
> seconds. If one is being frozen at that point, warn and give up. Until none
> is, treat such folios like case 2 and skip the legacy writeback throttle, so
> that the task a freeze may be waiting for isn't held up.
>
> This trades the deadlock for premature memcg OOM kills during such a freeze.
> The wait also no longer hits the folio_wait_writeback tracepoint, and the
> hung task detector no longer reports a task stuck in it for another reason
> as the task wakes up every 15 seconds.
>
> Fixes: e62e384e9da8 ("memcg: prevent OOM with too many dirty pages")
> Reported-by: Christian Brauner <brauner@xxxxxxxxxx>
> Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
> Reviewed-by: Johannes Weiner <hannes@xxxxxxxxxxx>
> Reviewed-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
Acked-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>