[RFC PATCH 1/4] block: do not issue background swap bios as root
From: Alexandre Ghiti
Date: Mon Sep 28 2026 - 04:21:35 EST
bio_issue_as_root_blkg() issues every REQ_SWAP bio as root, bypassing
the cgroup IO controllers, because reclaim cannot stall indefinitely on
swap writes. Some swap writes are not urgent though: zswap writeback is
best effort.
Such a bio cannot simply drop REQ_SWAP: dm-crypt and dm-thin rely on it
for limit_swap_bios, which caps in-flight swap bios to avoid a memory
deadlock, see commit a666e5c05e7c ("dm: fix deadlock when swapping to
encrypted device").
So let REQ_BACKGROUND, which already marks IO that is not urgent, opt a
swap bio out of being issued as root. No swap bio sets it today, so
nothing changes until a caller does.
Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
---
block/blk-cgroup.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index e67c69839129..02009cb45495 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -242,10 +242,16 @@ void blkg_conf_close_bdev(struct blkg_conf_ctx *ctx)
* the bio and attach the appropriate blkg to the bio. Then we call this helper
* and if it is true run with the root blkg for that queue and then do any
* backcharging to the originating cgroup once the io is complete.
+ *
+ * A REQ_SWAP bio is issued as root because reclaim waits on it, unless it is
+ * also REQ_BACKGROUND, which marks it as not urgent.
*/
static inline bool bio_issue_as_root_blkg(struct bio *bio)
{
- return (bio->bi_opf & (REQ_META | REQ_SWAP)) != 0;
+ blk_opf_t opf = bio->bi_opf;
+
+ return (opf & REQ_META) ||
+ (opf & (REQ_SWAP | REQ_BACKGROUND)) == REQ_SWAP;
}
/**
--
2.53.0-Meta