Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
@ 2026-11-26 12:08 Tejun Heo
  2026-11-26 12:17 ` Tejun Heo
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Tejun Heo @ 2026-11-26 12:08 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin,
	Muchun Song, David Hildenbrand, Qi Zheng, Lorenzo Stoakes,
	Matthew Wilcox (Oracle), Jan Kara, Alexander Viro,
	Christian Brauner, Jens Axboe, Christoph Hellwig, Greg Thelen,
	Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel, linux-kernel

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@kernel.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
This was first posted in a private thread and is resent here for the lists,
rebased onto the current mainline. The only other change is the added
Reviewed-by tags.

This is on top of v7.4-rc4-388 (25faec9ce61c). In a test with a filesystem
on a loop device backed by a file on another filesystem, writers to both in
a v1 memcg and the backing filesystem frozen and thawed in a loop, the
unpatched kernel deadlocks within seconds. With the patch, a stuck freeze
gets through in 15 to 18 seconds.

 fs/super.c               |    7 +++++
 include/linux/fs/super.h |    1 
 mm/filemap.c             |   22 +++++++++++++++--
 mm/internal.h            |    1 
 mm/vmscan.c              |   58 ++++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 83 insertions(+), 6 deletions(-)

--- a/fs/super.c
+++ b/fs/super.c
@@ -48,6 +48,9 @@ static int thaw_super_locked(struct supe
 static LIST_HEAD(super_blocks);
 static DEFINE_SPINLOCK(sb_lock);
 
+/* nr of superblocks that freeze_super() is in the middle of freezing */
+atomic_t sb_nr_freezing;
+
 static char *sb_writers_name[SB_FREEZE_LEVELS] = {
 	"sb_writers",
 	"sb_pagefaults",
@@ -2235,6 +2238,7 @@ retry:
 		return 0;
 	}
 
+	atomic_inc(&sb_nr_freezing);
 	sb->s_writers.frozen = SB_FREEZE_WRITE;
 	/* Release s_umount to preserve sb_start_write -> s_umount ordering */
 	super_unlock_excl(sb);
@@ -2249,6 +2253,7 @@ retry:
 	ret = sync_filesystem(sb);
 	if (ret) {
 		sb->s_writers.frozen = SB_UNFROZEN;
+		atomic_dec(&sb_nr_freezing);
 		sb_freeze_unlock(sb, SB_FREEZE_PAGEFAULT);
 		wake_up_var(&sb->s_writers.frozen);
 		deactivate_locked_super(sb);
@@ -2265,6 +2270,7 @@ retry:
 			printk(KERN_ERR
 				"VFS:Filesystem freeze failed\n");
 			sb->s_writers.frozen = SB_UNFROZEN;
+			atomic_dec(&sb_nr_freezing);
 			sb_freeze_unlock(sb, SB_FREEZE_FS);
 			wake_up_var(&sb->s_writers.frozen);
 			deactivate_locked_super(sb);
@@ -2278,6 +2284,7 @@ retry:
 	WARN_ON_ONCE(freeze_inc(sb, who) > 1);
 	sb->s_writers.freeze_owner = freeze_owner;
 	sb->s_writers.frozen = SB_FREEZE_COMPLETE;
+	atomic_dec(&sb_nr_freezing);
 	wake_up_var(&sb->s_writers.frozen);
 	lockdep_sb_freeze_release(sb);
 	super_unlock_excl(sb);
--- a/include/linux/fs/super.h
+++ b/include/linux/fs/super.h
@@ -234,6 +234,7 @@ int freeze_super(struct super_block *sup
 		 const void *freeze_owner);
 int thaw_super(struct super_block *super, enum freeze_holder who,
 	       const void *freeze_owner);
+extern atomic_t sb_nr_freezing;
 
 int sb_init_dio_done_wq(struct super_block *sb);
 
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1245,8 +1245,8 @@ static inline bool folio_trylock_flag(st
 	return true;
 }
 
-static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,
-		int state, enum behavior behavior)
+static inline int folio_wait_bit_common_timeout(struct folio *folio, int bit_nr, int state,
+		enum behavior behavior, long timeout)
 {
 	wait_queue_head_t *q = folio_waitqueue(folio);
 	int unfairness = sysctl_page_lock_unfairness;
@@ -1324,7 +1324,9 @@ repeat:
 			if (signal_pending_state(state, current))
 				break;
 
-			io_schedule();
+			timeout = io_schedule_timeout(timeout);
+			if (!timeout)
+				break;
 			continue;
 		}
 
@@ -1393,6 +1395,13 @@ repeat:
 	return wait->flags & WQ_FLAG_WOKEN ? 0 : -EINTR;
 }
 
+static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, int state,
+		enum behavior behavior)
+{
+	return folio_wait_bit_common_timeout(folio, bit_nr, state, behavior,
+					     MAX_SCHEDULE_TIMEOUT);
+}
+
 #ifdef CONFIG_MIGRATION
 /**
  * softleaf_entry_wait_on_locked - Wait for a migration entry or
@@ -1490,6 +1499,13 @@ int folio_wait_bit_killable(struct folio
 }
 EXPORT_SYMBOL(folio_wait_bit_killable);
 
+/* wait up to @timeout jiffies for @bit_nr to clear, true if it cleared */
+bool folio_wait_bit_timeout(struct folio *folio, int bit_nr, long timeout)
+{
+	return !folio_wait_bit_common_timeout(folio, bit_nr, TASK_UNINTERRUPTIBLE, SHARED,
+					      timeout);
+}
+
 /**
  * folio_put_wait_locked - Drop a reference and wait for it to be unlocked
  * @folio: The folio to wait for.
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1276,6 +1276,7 @@ struct migration_target_control {
  */
 ssize_t splice_folio_into_pipe(struct pipe_inode_info *pipe,
 			       struct folio *folio, loff_t fpos, size_t size);
+bool folio_wait_bit_timeout(struct folio *folio, int bit_nr, long timeout);
 
 static inline bool vma_is_single_threaded_private(struct vm_area_struct *vma)
 {
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1157,6 +1157,55 @@ static bool may_enter_fs(struct folio *f
 }
 
 /*
+ * Legacy memcg reclaim has no dirty throttling and waits for writeback in
+ * shrink_folio_list() instead. That wait can deadlock against a filesystem
+ * freeze:
+ *
+ * 1. A task holds freeze protection on filesystem B, e.g. in write(), enters
+ *    reclaim and waits for writeback of a folio whose I/O ends up as a write to
+ *    B, e.g. through 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 write to B waits for the freeze.
+ *
+ * Reclaim can't tell which filesystem a writeback depends on. As a crude
+ * workaround, memcg_wait_writeback() times out and, if any filesystem is being
+ * frozen at that point, sets memcg_wb_wait_skip. While it is set, legacy memcg
+ * reclaim neither waits for nor throttles on writeback, so that the task a
+ * freeze may be waiting for isn't held up in reclaim and can drop its freeze
+ * protection. This can cause premature memcg OOM kills.
+ */
+static bool memcg_wb_wait_skip;
+
+/*
+ * Test memcg_wb_wait_skip. It takes effect only while a filesystem is being
+ * frozen and is cleared here once none is. A freeze that starts before it is
+ * cleared inherits the skip.
+ */
+static bool memcg_skip_wb_wait(void)
+{
+	if (!READ_ONCE(memcg_wb_wait_skip))
+		return false;
+	if (atomic_read(&sb_nr_freezing))
+		return true;
+	WRITE_ONCE(memcg_wb_wait_skip, false);
+	return false;
+}
+
+/* wait for writeback of @folio, see memcg_wb_wait_skip for the timeout */
+static void memcg_wait_writeback(struct folio *folio)
+{
+	while (!folio_wait_bit_timeout(folio, PG_writeback, 15 * HZ)) {
+		if (atomic_read(&sb_nr_freezing)) {
+			WRITE_ONCE(memcg_wb_wait_skip, true);
+			pr_warn("memcg1 writeback wait timed out during fs freeze, skipping waits, may OOM early\n");
+			return;
+		}
+	}
+}
+
+/*
  * shrink_folio_list() returns the number of reclaimed pages
  */
 static unsigned int shrink_folio_list(struct list_head *folio_list,
@@ -1277,7 +1326,9 @@ retry:
 		 *    reclaim flag set. memcg does not have any dirty folio
 		 *    throttling so we could easily OOM just because too many
 		 *    folios are in writeback and there is nothing else to
-		 *    reclaim. Wait for the writeback to complete.
+		 *    reclaim. Wait for the writeback to complete. If
+		 *    memcg_wait_writeback() gives up, such folios are treated
+		 *    as in case 2 until no filesystem is being frozen.
 		 *
 		 * In cases 1) and 2) we activate the folios to get them out of
 		 * the way while we continue scanning for clean folios on the
@@ -1300,6 +1351,7 @@ retry:
 
 			/* Case 2 above */
 			} else if (writeback_throttling_sane(sc) ||
+			    memcg_skip_wb_wait() ||
 			    !folio_test_reclaim(folio) ||
 			    !may_enter_fs(folio, sc->gfp_mask) ||
 			    (mapping &&
@@ -1325,7 +1377,7 @@ retry:
 			/* Case 3 above */
 			} else {
 				folio_unlock(folio);
-				folio_wait_writeback(folio);
+				memcg_wait_writeback(folio);
 				/* then go back and try same folio again */
 				list_add_tail(&folio->lru, folio_list);
 				continue;
@@ -2086,7 +2138,7 @@ static void handle_reclaim_writeback(uns
 		 * enough for cgroupv1 writeback throttling to work
 		 * on a large system.
 		 */
-		if (!writeback_throttling_sane(sc))
+		if (!writeback_throttling_sane(sc) && !memcg_skip_wb_wait())
 			reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK);
 	}
 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
  2026-11-26 12:08 [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze Tejun Heo
@ 2026-11-26 12:17 ` Tejun Heo
  2026-11-27  2:02   ` Andrew Morton
  2026-11-26 13:29 ` Jan Kara
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Tejun Heo @ 2026-11-26 12:17 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin,
	Muchun Song, David Hildenbrand, Qi Zheng, Lorenzo Stoakes,
	Matthew Wilcox (Oracle), Jan Kara, Alexander Viro,
	Christian Brauner, Jens Axboe, Christoph Hellwig, Greg Thelen,
	Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel, linux-kernel

Hello, Andrew.

Your follow-up, "mm/vmscan: scope freeze writeback skip to the reclaim
target", applies on top of this patch and tests fine here.

Thanks.

--
tejun


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
  2026-11-26 12:08 [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze Tejun Heo
  2026-11-26 12:17 ` Tejun Heo
@ 2026-11-26 13:29 ` Jan Kara
  2026-11-26 15:22 ` Shakeel Butt
  2026-11-27  9:25 ` Michal Hocko
  3 siblings, 0 replies; 7+ messages in thread
From: Jan Kara @ 2026-11-26 13:29 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Shakeel Butt,
	Roman Gushchin, Muchun Song, David Hildenbrand, Qi Zheng,
	Lorenzo Stoakes, Matthew Wilcox (Oracle), Jan Kara,
	Alexander Viro, Christian Brauner, Jens Axboe, Christoph Hellwig,
	Greg Thelen, Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel,
	linux-kernel

On Thu 26-11-26 02:08:56, 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@kernel.org>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
> Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org>

Yeah, it's ugly but it should fix the deadlock. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
> This was first posted in a private thread and is resent here for the lists,
> rebased onto the current mainline. The only other change is the added
> Reviewed-by tags.
> 
> This is on top of v7.4-rc4-388 (25faec9ce61c). In a test with a filesystem
> on a loop device backed by a file on another filesystem, writers to both in
> a v1 memcg and the backing filesystem frozen and thawed in a loop, the
> unpatched kernel deadlocks within seconds. With the patch, a stuck freeze
> gets through in 15 to 18 seconds.
> 
>  fs/super.c               |    7 +++++
>  include/linux/fs/super.h |    1 
>  mm/filemap.c             |   22 +++++++++++++++--
>  mm/internal.h            |    1 
>  mm/vmscan.c              |   58 ++++++++++++++++++++++++++++++++++++++++++++---
>  5 files changed, 83 insertions(+), 6 deletions(-)
> 
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -48,6 +48,9 @@ static int thaw_super_locked(struct supe
>  static LIST_HEAD(super_blocks);
>  static DEFINE_SPINLOCK(sb_lock);
>  
> +/* nr of superblocks that freeze_super() is in the middle of freezing */
> +atomic_t sb_nr_freezing;
> +
>  static char *sb_writers_name[SB_FREEZE_LEVELS] = {
>  	"sb_writers",
>  	"sb_pagefaults",
> @@ -2235,6 +2238,7 @@ retry:
>  		return 0;
>  	}
>  
> +	atomic_inc(&sb_nr_freezing);
>  	sb->s_writers.frozen = SB_FREEZE_WRITE;
>  	/* Release s_umount to preserve sb_start_write -> s_umount ordering */
>  	super_unlock_excl(sb);
> @@ -2249,6 +2253,7 @@ retry:
>  	ret = sync_filesystem(sb);
>  	if (ret) {
>  		sb->s_writers.frozen = SB_UNFROZEN;
> +		atomic_dec(&sb_nr_freezing);
>  		sb_freeze_unlock(sb, SB_FREEZE_PAGEFAULT);
>  		wake_up_var(&sb->s_writers.frozen);
>  		deactivate_locked_super(sb);
> @@ -2265,6 +2270,7 @@ retry:
>  			printk(KERN_ERR
>  				"VFS:Filesystem freeze failed\n");
>  			sb->s_writers.frozen = SB_UNFROZEN;
> +			atomic_dec(&sb_nr_freezing);
>  			sb_freeze_unlock(sb, SB_FREEZE_FS);
>  			wake_up_var(&sb->s_writers.frozen);
>  			deactivate_locked_super(sb);
> @@ -2278,6 +2284,7 @@ retry:
>  	WARN_ON_ONCE(freeze_inc(sb, who) > 1);
>  	sb->s_writers.freeze_owner = freeze_owner;
>  	sb->s_writers.frozen = SB_FREEZE_COMPLETE;
> +	atomic_dec(&sb_nr_freezing);
>  	wake_up_var(&sb->s_writers.frozen);
>  	lockdep_sb_freeze_release(sb);
>  	super_unlock_excl(sb);
> --- a/include/linux/fs/super.h
> +++ b/include/linux/fs/super.h
> @@ -234,6 +234,7 @@ int freeze_super(struct super_block *sup
>  		 const void *freeze_owner);
>  int thaw_super(struct super_block *super, enum freeze_holder who,
>  	       const void *freeze_owner);
> +extern atomic_t sb_nr_freezing;
>  
>  int sb_init_dio_done_wq(struct super_block *sb);
>  
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1245,8 +1245,8 @@ static inline bool folio_trylock_flag(st
>  	return true;
>  }
>  
> -static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,
> -		int state, enum behavior behavior)
> +static inline int folio_wait_bit_common_timeout(struct folio *folio, int bit_nr, int state,
> +		enum behavior behavior, long timeout)
>  {
>  	wait_queue_head_t *q = folio_waitqueue(folio);
>  	int unfairness = sysctl_page_lock_unfairness;
> @@ -1324,7 +1324,9 @@ repeat:
>  			if (signal_pending_state(state, current))
>  				break;
>  
> -			io_schedule();
> +			timeout = io_schedule_timeout(timeout);
> +			if (!timeout)
> +				break;
>  			continue;
>  		}
>  
> @@ -1393,6 +1395,13 @@ repeat:
>  	return wait->flags & WQ_FLAG_WOKEN ? 0 : -EINTR;
>  }
>  
> +static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, int state,
> +		enum behavior behavior)
> +{
> +	return folio_wait_bit_common_timeout(folio, bit_nr, state, behavior,
> +					     MAX_SCHEDULE_TIMEOUT);
> +}
> +
>  #ifdef CONFIG_MIGRATION
>  /**
>   * softleaf_entry_wait_on_locked - Wait for a migration entry or
> @@ -1490,6 +1499,13 @@ int folio_wait_bit_killable(struct folio
>  }
>  EXPORT_SYMBOL(folio_wait_bit_killable);
>  
> +/* wait up to @timeout jiffies for @bit_nr to clear, true if it cleared */
> +bool folio_wait_bit_timeout(struct folio *folio, int bit_nr, long timeout)
> +{
> +	return !folio_wait_bit_common_timeout(folio, bit_nr, TASK_UNINTERRUPTIBLE, SHARED,
> +					      timeout);
> +}
> +
>  /**
>   * folio_put_wait_locked - Drop a reference and wait for it to be unlocked
>   * @folio: The folio to wait for.
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1276,6 +1276,7 @@ struct migration_target_control {
>   */
>  ssize_t splice_folio_into_pipe(struct pipe_inode_info *pipe,
>  			       struct folio *folio, loff_t fpos, size_t size);
> +bool folio_wait_bit_timeout(struct folio *folio, int bit_nr, long timeout);
>  
>  static inline bool vma_is_single_threaded_private(struct vm_area_struct *vma)
>  {
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1157,6 +1157,55 @@ static bool may_enter_fs(struct folio *f
>  }
>  
>  /*
> + * Legacy memcg reclaim has no dirty throttling and waits for writeback in
> + * shrink_folio_list() instead. That wait can deadlock against a filesystem
> + * freeze:
> + *
> + * 1. A task holds freeze protection on filesystem B, e.g. in write(), enters
> + *    reclaim and waits for writeback of a folio whose I/O ends up as a write to
> + *    B, e.g. through 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 write to B waits for the freeze.
> + *
> + * Reclaim can't tell which filesystem a writeback depends on. As a crude
> + * workaround, memcg_wait_writeback() times out and, if any filesystem is being
> + * frozen at that point, sets memcg_wb_wait_skip. While it is set, legacy memcg
> + * reclaim neither waits for nor throttles on writeback, so that the task a
> + * freeze may be waiting for isn't held up in reclaim and can drop its freeze
> + * protection. This can cause premature memcg OOM kills.
> + */
> +static bool memcg_wb_wait_skip;
> +
> +/*
> + * Test memcg_wb_wait_skip. It takes effect only while a filesystem is being
> + * frozen and is cleared here once none is. A freeze that starts before it is
> + * cleared inherits the skip.
> + */
> +static bool memcg_skip_wb_wait(void)
> +{
> +	if (!READ_ONCE(memcg_wb_wait_skip))
> +		return false;
> +	if (atomic_read(&sb_nr_freezing))
> +		return true;
> +	WRITE_ONCE(memcg_wb_wait_skip, false);
> +	return false;
> +}
> +
> +/* wait for writeback of @folio, see memcg_wb_wait_skip for the timeout */
> +static void memcg_wait_writeback(struct folio *folio)
> +{
> +	while (!folio_wait_bit_timeout(folio, PG_writeback, 15 * HZ)) {
> +		if (atomic_read(&sb_nr_freezing)) {
> +			WRITE_ONCE(memcg_wb_wait_skip, true);
> +			pr_warn("memcg1 writeback wait timed out during fs freeze, skipping waits, may OOM early\n");
> +			return;
> +		}
> +	}
> +}
> +
> +/*
>   * shrink_folio_list() returns the number of reclaimed pages
>   */
>  static unsigned int shrink_folio_list(struct list_head *folio_list,
> @@ -1277,7 +1326,9 @@ retry:
>  		 *    reclaim flag set. memcg does not have any dirty folio
>  		 *    throttling so we could easily OOM just because too many
>  		 *    folios are in writeback and there is nothing else to
> -		 *    reclaim. Wait for the writeback to complete.
> +		 *    reclaim. Wait for the writeback to complete. If
> +		 *    memcg_wait_writeback() gives up, such folios are treated
> +		 *    as in case 2 until no filesystem is being frozen.
>  		 *
>  		 * In cases 1) and 2) we activate the folios to get them out of
>  		 * the way while we continue scanning for clean folios on the
> @@ -1300,6 +1351,7 @@ retry:
>  
>  			/* Case 2 above */
>  			} else if (writeback_throttling_sane(sc) ||
> +			    memcg_skip_wb_wait() ||
>  			    !folio_test_reclaim(folio) ||
>  			    !may_enter_fs(folio, sc->gfp_mask) ||
>  			    (mapping &&
> @@ -1325,7 +1377,7 @@ retry:
>  			/* Case 3 above */
>  			} else {
>  				folio_unlock(folio);
> -				folio_wait_writeback(folio);
> +				memcg_wait_writeback(folio);
>  				/* then go back and try same folio again */
>  				list_add_tail(&folio->lru, folio_list);
>  				continue;
> @@ -2086,7 +2138,7 @@ static void handle_reclaim_writeback(uns
>  		 * enough for cgroupv1 writeback throttling to work
>  		 * on a large system.
>  		 */
> -		if (!writeback_throttling_sane(sc))
> +		if (!writeback_throttling_sane(sc) && !memcg_skip_wb_wait())
>  			reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK);
>  	}
>  
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
  2026-11-26 12:08 [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze Tejun Heo
  2026-11-26 12:17 ` Tejun Heo
  2026-11-26 13:29 ` Jan Kara
@ 2026-11-26 15:22 ` Shakeel Butt
  2026-11-27  9:25 ` Michal Hocko
  3 siblings, 0 replies; 7+ messages in thread
From: Shakeel Butt @ 2026-11-26 15:22 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Muchun Song, David Hildenbrand, Qi Zheng, Lorenzo Stoakes,
	Matthew Wilcox (Oracle), Jan Kara, Alexander Viro,
	Christian Brauner, Jens Axboe, Christoph Hellwig, Greg Thelen,
	Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel, linux-kernel

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@kernel.org>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
> Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org>

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
  2026-11-26 12:17 ` Tejun Heo
@ 2026-11-27  2:02   ` Andrew Morton
  2026-11-27  9:26     ` Michal Hocko
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2026-11-27  2:02 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Johannes Weiner, Michal Hocko, Shakeel Butt, Roman Gushchin,
	Muchun Song, David Hildenbrand, Qi Zheng, Lorenzo Stoakes,
	Matthew Wilcox (Oracle), Jan Kara, Alexander Viro,
	Christian Brauner, Jens Axboe, Christoph Hellwig, Greg Thelen,
	Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel, linux-kernel

On Thu, 26 Nov 2026 02:17:38 -1000 Tejun Heo <tj@kernel.org> wrote:

> Hello, Andrew.
> 
> Your follow-up, "mm/vmscan: scope freeze writeback skip to the reclaim
> target", applies on top of this patch and tests fine here.

Cool, thanks.  I'd forgotten about that ;) It was a hastily slop-coded
"maybe you'd like to include something like this in your patch" thing.

Can people please take a look and suggest whether it should be a
standalone patch, or just fold it into this patch, "mm/vmscan: Fix
legacy memcg reclaim deadlock against filesystem freeze"?


(That's mem_cgroup's fifth bool - maybe scrunch them all into an
atomic_t and do atomic bitops on it?)

(I am told that moving wb_wait_skip to just after oom_group would avoid
increasing sizeof(mem_cgroup), but that puts wb_wait_skip into the
read-mostly section. wdyt?) 


From: Andrew Morton <akpm@linux-foundation.org>
Subject: mm/vmscan: scope freeze writeback skip to the reclaim target
Date: Tue, 17 Nov 2026 14:04:43 -0800

The freeze workaround sets memcg_wb_wait_skip globally when a memcg's
writeback wait times out.  While any superblock freeze is pending, this
makes reclaimers in unrelated memcgs bypass their writeback waits and can
drive an otherwise recoverable cgroup to OOM.

Store the flag in the reclaim target memcg instead.  Use
sc->target_mem_cgroup, not the folio's memcg: reclaim against a parent
limit scans descendants.  This also keeps the skip across successive
try_to_free_mem_cgroup_pages() calls in try_charge_memcg(), each of which
creates a new scan_control.  Reclaim against a different target must first
time out on its own writeback.

Reclaimers sharing the target can still OOM early during a freeze.

Reclaimers of the same target can run concurrently, without a lock
protecting this flag.  Keep READ_ONCE() and WRITE_ONCE() for its lockless
loads and stores.  The flag does not publish any other data.  As with the
global flag, a clear racing with a new timeout may cost another 15-second
wait; the timeout path can set the flag again.

Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Tejun Heo <tj@kernel.org>

 include/linux/memcontrol.h |    2 +
 mm/vmscan.c                |   52 ++++++++++++++++++++---------------
 2 files changed, 33 insertions(+), 21 deletions(-)

--- a/include/linux/memcontrol.h~mm-vmscan-scope-freeze-writeback-skip-to-the-reclaim-target
+++ a/include/linux/memcontrol.h
@@ -248,6 +248,8 @@ struct mem_cgroup {
 	struct list_head memory_peaks;
 	struct list_head swap_peaks;
 	spinlock_t	 peaks_lock;
+	/* Legacy writeback wait timed out during a filesystem freeze. */
+	bool wb_wait_skip;
 
 	/* memory.events and memory.events.local */
 	struct cgroup_file events_file;
--- a/mm/vmscan.c~mm-vmscan-scope-freeze-writeback-skip-to-the-reclaim-target
+++ a/mm/vmscan.c
@@ -1171,39 +1171,49 @@ static bool may_enter_fs(struct folio *f
  *
  * Reclaim can't tell which filesystem a writeback depends on. As a crude
  * workaround, memcg_wait_writeback() times out and, if any filesystem is being
- * frozen at that point, sets memcg_wb_wait_skip. While it is set, legacy memcg
- * reclaim neither waits for nor throttles on writeback, so that the task a
- * freeze may be waiting for isn't held up in reclaim and can drop its freeze
- * protection. This can cause premature memcg OOM kills.
+ * frozen at that point, sets a skip flag on the reclaim target memcg. While
+ * it is set, reclaim against that target neither waits for nor throttles on
+ * writeback, so that the task a freeze may be waiting for isn't held up in
+ * reclaim and can drop its freeze protection. This can cause premature memcg
+ * OOM kills in that reclaim target.
  */
-static bool memcg_wb_wait_skip;
-
-/*
- * Test memcg_wb_wait_skip. It takes effect only while a filesystem is being
- * frozen and is cleared here once none is. A freeze that starts before it is
- * cleared inherits the skip.
- */
-static bool memcg_skip_wb_wait(void)
+#ifdef CONFIG_MEMCG
+/* Retain the skip across separate reclaim attempts against the same limit. */
+static bool memcg_skip_wb_wait(struct scan_control *sc)
 {
-	if (!READ_ONCE(memcg_wb_wait_skip))
+	struct mem_cgroup *memcg = sc->target_mem_cgroup;
+
+	if (!memcg || !READ_ONCE(memcg->wb_wait_skip))
 		return false;
 	if (atomic_read(&sb_nr_freezing))
 		return true;
-	WRITE_ONCE(memcg_wb_wait_skip, false);
+	WRITE_ONCE(memcg->wb_wait_skip, false);
 	return false;
 }
 
-/* wait for writeback of @folio, see memcg_wb_wait_skip for the timeout */
-static void memcg_wait_writeback(struct folio *folio)
+/* Wait for writeback, unless a freeze stalls this reclaim target. */
+static void memcg_wait_writeback(struct folio *folio, struct scan_control *sc)
 {
 	while (!folio_wait_bit_timeout(folio, PG_writeback, 15 * HZ)) {
 		if (atomic_read(&sb_nr_freezing)) {
-			WRITE_ONCE(memcg_wb_wait_skip, true);
-			pr_warn("memcg1 writeback wait timed out during fs freeze, skipping waits, may OOM early\n");
+			WRITE_ONCE(sc->target_mem_cgroup->wb_wait_skip, true);
+			pr_warn("memcg writeback wait timed out during fs freeze; "
+				"skipping waits for reclaim target, may OOM early\n");
 			return;
 		}
 	}
 }
+#else
+static bool memcg_skip_wb_wait(struct scan_control *sc)
+{
+	return false;
+}
+
+static void memcg_wait_writeback(struct folio *folio, struct scan_control *sc)
+{
+	folio_wait_writeback(folio);
+}
+#endif
 
 /*
  * shrink_folio_list() returns the number of reclaimed pages
@@ -1351,7 +1361,7 @@ retry:
 
 			/* Case 2 above */
 			} else if (writeback_throttling_sane(sc) ||
-			    memcg_skip_wb_wait() ||
+			    memcg_skip_wb_wait(sc) ||
 			    !folio_test_reclaim(folio) ||
 			    !may_enter_fs(folio, sc->gfp_mask) ||
 			    (mapping &&
@@ -1377,7 +1387,7 @@ retry:
 			/* Case 3 above */
 			} else {
 				folio_unlock(folio);
-				memcg_wait_writeback(folio);
+				memcg_wait_writeback(folio, sc);
 				/* then go back and try same folio again */
 				list_add_tail(&folio->lru, folio_list);
 				continue;
@@ -2138,7 +2148,7 @@ static void handle_reclaim_writeback(uns
 		 * enough for cgroupv1 writeback throttling to work
 		 * on a large system.
 		 */
-		if (!writeback_throttling_sane(sc) && !memcg_skip_wb_wait())
+		if (!writeback_throttling_sane(sc) && !memcg_skip_wb_wait(sc))
 			reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK);
 	}
 
_



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
  2026-11-26 12:08 [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze Tejun Heo
                   ` (2 preceding siblings ...)
  2026-11-26 15:22 ` Shakeel Butt
@ 2026-11-27  9:25 ` Michal Hocko
  3 siblings, 0 replies; 7+ messages in thread
From: Michal Hocko @ 2026-11-27  9:25 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Andrew Morton, Johannes Weiner, Shakeel Butt, Roman Gushchin,
	Muchun Song, David Hildenbrand, Qi Zheng, Lorenzo Stoakes,
	Matthew Wilcox (Oracle), Jan Kara, Alexander Viro,
	Christian Brauner, Jens Axboe, Christoph Hellwig, Greg Thelen,
	Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel, linux-kernel

On Thu 26-11-26 02:08:56, 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@kernel.org>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Reviewed-by: Johannes Weiner <hannes@cmpxchg.org>
> Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org>

Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!

> ---
> This was first posted in a private thread and is resent here for the lists,
> rebased onto the current mainline. The only other change is the added
> Reviewed-by tags.
> 
> This is on top of v7.4-rc4-388 (25faec9ce61c). In a test with a filesystem
> on a loop device backed by a file on another filesystem, writers to both in
> a v1 memcg and the backing filesystem frozen and thawed in a loop, the
> unpatched kernel deadlocks within seconds. With the patch, a stuck freeze
> gets through in 15 to 18 seconds.
> 
>  fs/super.c               |    7 +++++
>  include/linux/fs/super.h |    1 
>  mm/filemap.c             |   22 +++++++++++++++--
>  mm/internal.h            |    1 
>  mm/vmscan.c              |   58 ++++++++++++++++++++++++++++++++++++++++++++---
>  5 files changed, 83 insertions(+), 6 deletions(-)
> 
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -48,6 +48,9 @@ static int thaw_super_locked(struct supe
>  static LIST_HEAD(super_blocks);
>  static DEFINE_SPINLOCK(sb_lock);
>  
> +/* nr of superblocks that freeze_super() is in the middle of freezing */
> +atomic_t sb_nr_freezing;
> +
>  static char *sb_writers_name[SB_FREEZE_LEVELS] = {
>  	"sb_writers",
>  	"sb_pagefaults",
> @@ -2235,6 +2238,7 @@ retry:
>  		return 0;
>  	}
>  
> +	atomic_inc(&sb_nr_freezing);
>  	sb->s_writers.frozen = SB_FREEZE_WRITE;
>  	/* Release s_umount to preserve sb_start_write -> s_umount ordering */
>  	super_unlock_excl(sb);
> @@ -2249,6 +2253,7 @@ retry:
>  	ret = sync_filesystem(sb);
>  	if (ret) {
>  		sb->s_writers.frozen = SB_UNFROZEN;
> +		atomic_dec(&sb_nr_freezing);
>  		sb_freeze_unlock(sb, SB_FREEZE_PAGEFAULT);
>  		wake_up_var(&sb->s_writers.frozen);
>  		deactivate_locked_super(sb);
> @@ -2265,6 +2270,7 @@ retry:
>  			printk(KERN_ERR
>  				"VFS:Filesystem freeze failed\n");
>  			sb->s_writers.frozen = SB_UNFROZEN;
> +			atomic_dec(&sb_nr_freezing);
>  			sb_freeze_unlock(sb, SB_FREEZE_FS);
>  			wake_up_var(&sb->s_writers.frozen);
>  			deactivate_locked_super(sb);
> @@ -2278,6 +2284,7 @@ retry:
>  	WARN_ON_ONCE(freeze_inc(sb, who) > 1);
>  	sb->s_writers.freeze_owner = freeze_owner;
>  	sb->s_writers.frozen = SB_FREEZE_COMPLETE;
> +	atomic_dec(&sb_nr_freezing);
>  	wake_up_var(&sb->s_writers.frozen);
>  	lockdep_sb_freeze_release(sb);
>  	super_unlock_excl(sb);
> --- a/include/linux/fs/super.h
> +++ b/include/linux/fs/super.h
> @@ -234,6 +234,7 @@ int freeze_super(struct super_block *sup
>  		 const void *freeze_owner);
>  int thaw_super(struct super_block *super, enum freeze_holder who,
>  	       const void *freeze_owner);
> +extern atomic_t sb_nr_freezing;
>  
>  int sb_init_dio_done_wq(struct super_block *sb);
>  
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -1245,8 +1245,8 @@ static inline bool folio_trylock_flag(st
>  	return true;
>  }
>  
> -static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,
> -		int state, enum behavior behavior)
> +static inline int folio_wait_bit_common_timeout(struct folio *folio, int bit_nr, int state,
> +		enum behavior behavior, long timeout)
>  {
>  	wait_queue_head_t *q = folio_waitqueue(folio);
>  	int unfairness = sysctl_page_lock_unfairness;
> @@ -1324,7 +1324,9 @@ repeat:
>  			if (signal_pending_state(state, current))
>  				break;
>  
> -			io_schedule();
> +			timeout = io_schedule_timeout(timeout);
> +			if (!timeout)
> +				break;
>  			continue;
>  		}
>  
> @@ -1393,6 +1395,13 @@ repeat:
>  	return wait->flags & WQ_FLAG_WOKEN ? 0 : -EINTR;
>  }
>  
> +static inline int folio_wait_bit_common(struct folio *folio, int bit_nr, int state,
> +		enum behavior behavior)
> +{
> +	return folio_wait_bit_common_timeout(folio, bit_nr, state, behavior,
> +					     MAX_SCHEDULE_TIMEOUT);
> +}
> +
>  #ifdef CONFIG_MIGRATION
>  /**
>   * softleaf_entry_wait_on_locked - Wait for a migration entry or
> @@ -1490,6 +1499,13 @@ int folio_wait_bit_killable(struct folio
>  }
>  EXPORT_SYMBOL(folio_wait_bit_killable);
>  
> +/* wait up to @timeout jiffies for @bit_nr to clear, true if it cleared */
> +bool folio_wait_bit_timeout(struct folio *folio, int bit_nr, long timeout)
> +{
> +	return !folio_wait_bit_common_timeout(folio, bit_nr, TASK_UNINTERRUPTIBLE, SHARED,
> +					      timeout);
> +}
> +
>  /**
>   * folio_put_wait_locked - Drop a reference and wait for it to be unlocked
>   * @folio: The folio to wait for.
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1276,6 +1276,7 @@ struct migration_target_control {
>   */
>  ssize_t splice_folio_into_pipe(struct pipe_inode_info *pipe,
>  			       struct folio *folio, loff_t fpos, size_t size);
> +bool folio_wait_bit_timeout(struct folio *folio, int bit_nr, long timeout);
>  
>  static inline bool vma_is_single_threaded_private(struct vm_area_struct *vma)
>  {
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1157,6 +1157,55 @@ static bool may_enter_fs(struct folio *f
>  }
>  
>  /*
> + * Legacy memcg reclaim has no dirty throttling and waits for writeback in
> + * shrink_folio_list() instead. That wait can deadlock against a filesystem
> + * freeze:
> + *
> + * 1. A task holds freeze protection on filesystem B, e.g. in write(), enters
> + *    reclaim and waits for writeback of a folio whose I/O ends up as a write to
> + *    B, e.g. through 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 write to B waits for the freeze.
> + *
> + * Reclaim can't tell which filesystem a writeback depends on. As a crude
> + * workaround, memcg_wait_writeback() times out and, if any filesystem is being
> + * frozen at that point, sets memcg_wb_wait_skip. While it is set, legacy memcg
> + * reclaim neither waits for nor throttles on writeback, so that the task a
> + * freeze may be waiting for isn't held up in reclaim and can drop its freeze
> + * protection. This can cause premature memcg OOM kills.
> + */
> +static bool memcg_wb_wait_skip;
> +
> +/*
> + * Test memcg_wb_wait_skip. It takes effect only while a filesystem is being
> + * frozen and is cleared here once none is. A freeze that starts before it is
> + * cleared inherits the skip.
> + */
> +static bool memcg_skip_wb_wait(void)
> +{
> +	if (!READ_ONCE(memcg_wb_wait_skip))
> +		return false;
> +	if (atomic_read(&sb_nr_freezing))
> +		return true;
> +	WRITE_ONCE(memcg_wb_wait_skip, false);
> +	return false;
> +}
> +
> +/* wait for writeback of @folio, see memcg_wb_wait_skip for the timeout */
> +static void memcg_wait_writeback(struct folio *folio)
> +{
> +	while (!folio_wait_bit_timeout(folio, PG_writeback, 15 * HZ)) {
> +		if (atomic_read(&sb_nr_freezing)) {
> +			WRITE_ONCE(memcg_wb_wait_skip, true);
> +			pr_warn("memcg1 writeback wait timed out during fs freeze, skipping waits, may OOM early\n");
> +			return;
> +		}
> +	}
> +}
> +
> +/*
>   * shrink_folio_list() returns the number of reclaimed pages
>   */
>  static unsigned int shrink_folio_list(struct list_head *folio_list,
> @@ -1277,7 +1326,9 @@ retry:
>  		 *    reclaim flag set. memcg does not have any dirty folio
>  		 *    throttling so we could easily OOM just because too many
>  		 *    folios are in writeback and there is nothing else to
> -		 *    reclaim. Wait for the writeback to complete.
> +		 *    reclaim. Wait for the writeback to complete. If
> +		 *    memcg_wait_writeback() gives up, such folios are treated
> +		 *    as in case 2 until no filesystem is being frozen.
>  		 *
>  		 * In cases 1) and 2) we activate the folios to get them out of
>  		 * the way while we continue scanning for clean folios on the
> @@ -1300,6 +1351,7 @@ retry:
>  
>  			/* Case 2 above */
>  			} else if (writeback_throttling_sane(sc) ||
> +			    memcg_skip_wb_wait() ||
>  			    !folio_test_reclaim(folio) ||
>  			    !may_enter_fs(folio, sc->gfp_mask) ||
>  			    (mapping &&
> @@ -1325,7 +1377,7 @@ retry:
>  			/* Case 3 above */
>  			} else {
>  				folio_unlock(folio);
> -				folio_wait_writeback(folio);
> +				memcg_wait_writeback(folio);
>  				/* then go back and try same folio again */
>  				list_add_tail(&folio->lru, folio_list);
>  				continue;
> @@ -2086,7 +2138,7 @@ static void handle_reclaim_writeback(uns
>  		 * enough for cgroupv1 writeback throttling to work
>  		 * on a large system.
>  		 */
> -		if (!writeback_throttling_sane(sc))
> +		if (!writeback_throttling_sane(sc) && !memcg_skip_wb_wait())
>  			reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK);
>  	}
>  

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze
  2026-11-27  2:02   ` Andrew Morton
@ 2026-11-27  9:26     ` Michal Hocko
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Hocko @ 2026-11-27  9:26 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Tejun Heo, Johannes Weiner, Shakeel Butt, Roman Gushchin,
	Muchun Song, David Hildenbrand, Qi Zheng, Lorenzo Stoakes,
	Matthew Wilcox (Oracle), Jan Kara, Alexander Viro,
	Christian Brauner, Jens Axboe, Christoph Hellwig, Greg Thelen,
	Greg KH, Ming Lei, linux-mm, cgroups, linux-fsdevel, linux-kernel

On Thu 26-11-26 18:02:28, Andrew Morton wrote:
> On Thu, 26 Nov 2026 02:17:38 -1000 Tejun Heo <tj@kernel.org> wrote:
> 
> > Hello, Andrew.
> > 
> > Your follow-up, "mm/vmscan: scope freeze writeback skip to the reclaim
> > target", applies on top of this patch and tests fine here.
> 
> Cool, thanks.  I'd forgotten about that ;) It was a hastily slop-coded
> "maybe you'd like to include something like this in your patch" thing.
> 
> Can people please take a look and suggest whether it should be a
> standalone patch, or just fold it into this patch, "mm/vmscan: Fix
> legacy memcg reclaim deadlock against filesystem freeze"?

standalone patch. And quite honestly I am not convinced we need this.
Let's see what other memcg maintainers think but I would keep the global
thing as this is a global situation.

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-27  9:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 12:08 [PATCH RESEND] mm/vmscan: Fix legacy memcg reclaim deadlock against filesystem freeze Tejun Heo
2026-11-26 12:17 ` Tejun Heo
2026-11-27  2:02   ` Andrew Morton
2026-11-27  9:26     ` Michal Hocko
2026-11-26 13:29 ` Jan Kara
2026-11-26 15:22 ` Shakeel Butt
2026-11-27  9:25 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox