[PATCH v4 01/25] md/md-llbitmap: clear flush state after daemon flush

From: Yu Kuai

Date: Sat Aug 01 2026 - 13:27:14 EST


From: Yu Kuai <yukuai@xxxxxxx>

llbitmap_flush() sets LLPageFlush on each bitmap page before it queues the
daemon worker. The flag tells md_llbitmap_daemon_fn() to ignore the normal
barrier_idle expiry check and clean the page immediately.

The daemon only tested LLPageFlush. Once a page had been flushed explicitly,
the flag stayed set, so later dirty bits on that page also bypassed
barrier_idle and were cleaned the next time the daemon ran. That can make a
new write look clean much earlier than the configured idle window.

Consume LLPageFlush in md_llbitmap_daemon_fn() with test_and_clear_bit() and
use the returned value for the current expiry check. The explicit flush still
forces the current daemon pass, while later writes on the same page wait for
barrier_idle again.

This can be reproduced through normal sysfs operations:

1. Create a small RAID1 with --bitmap=lockless and --assume-clean.
2. Set llbitmap/daemon_sleep=1 and llbitmap/barrier_idle=10.
3. Toggle md/array_state from active to readonly and back to active to call
llbitmap_flush() without destroying the in-memory bitmap.
4. Write one sector and read llbitmap/bits immediately, after 2 seconds,
and after 12 seconds.

On the bad kernel the dirty bit is already clean after 2 seconds. With this
change it remains dirty until the barrier_idle window expires.

Signed-off-by: Yu Kuai <yukuai@xxxxxxx>
---
drivers/md/md-llbitmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md-llbitmap.c b/drivers/md/md-llbitmap.c
index 5a4e2abaa757..131582724e7e 100644
--- a/drivers/md/md-llbitmap.c
+++ b/drivers/md/md-llbitmap.c
@@ -1066,14 +1066,14 @@ static void md_llbitmap_daemon_fn(struct work_struct *work)

for (idx = 0; idx < llbitmap->nr_pages; idx++) {
struct llbitmap_page_ctl *pctl = llbitmap->pctl[idx];
+ bool flush = test_and_clear_bit(LLPageFlush, &pctl->flags);

if (idx > 0) {
start = end + 1;
end = min(end + PAGE_SIZE, llbitmap->chunks - 1);
}

- if (!test_bit(LLPageFlush, &pctl->flags) &&
- time_before(jiffies, pctl->expire)) {
+ if (!flush && time_before(jiffies, pctl->expire)) {
restart = true;
continue;
}
--
2.51.0