Commit 7693e1350b06 for kernel
commit 7693e1350b06191143724da742559fb47211348e
Author: Christian Brauner <brauner@kernel.org>
Date: Sat Nov 14 22:40:28 2026 +0100
memcg: make MEMCG select BLK_CGROUP
Memcg reclaim only relies on writeback throttling if
writeback_throttling_sane() does. Since commit 97c9341f7271 ("mm:
vmscan: disable memcg direct reclaim stalling if cgroup writeback
support is in use") that's the case if the memory controller is on the
default hierarchy and CONFIG_CGROUP_WRITEBACK is set. Otherwise
shrink_folio_list() sleeps in folio_wait_writeback() for a folio that
is under writeback and already marked for reclaim if the allocation may
enter the filesystem.
CONFIG_CGROUP_WRITEBACK is enabled whenever CONFIG_MEMCG and
CONFIG_BLK_CGROUP are. So with CONFIG_MEMCG=y and CONFIG_BLK_CGROUP=n
memcg reclaim on cgroup v2 waits for writeback just like it does on
cgroup v1.
That wait can deadlock against freezing a filesystem. Loop takes freeze
protection on the backing filesystem for its writes. A task in the
middle of a write() to the backing filesystem holds freeze protection
as well.
If that task enters memcg reclaim it can end up waiting for writeback of
a folio that belongs to a filesystem on the loop device. If a freeze of
the backing filesystem is pending the loop worker blocks when it tries
to write that folio out. And the freeze waits for the task in reclaim to
drop its freeze protection. The same applies to other drivers that serve
block I/O by writing to a file on a local filesystem and take freeze
protection for it, e.g., the scsi target's fileio backend.
Make CONFIG_MEMCG select CONFIG_BLK_CGROUP if CONFIG_BLOCK is set. Then
CONFIG_CGROUP_WRITEBACK is always enabled together with memcg and memcg
reclaim on cgroup v2 doesn't sleep in folio_wait_writeback() anymore.
a
Without CONFIG_BLOCK there are no block devices that could deadlock
like this.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Tejun Heo <tj@kernel.org>
diff --git a/init/Kconfig b/init/Kconfig
index 8583d9f06c52..720914cc8bf5 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1088,6 +1088,7 @@ config MEMCG
select EVENTFD
select SLAB_OBJ_EXT
select VM_EVENT_COUNTERS
+ select BLK_CGROUP if BLOCK
help
Provides control over the memory footprint of tasks in a cgroup.