From: Nigel Croxon <ncroxon@redhat.com>
To: song@kernel.org, yukuai@kernel.org, linux-raid@vger.kernel.org
Subject: [PATCH] md/md-bitmap: bitmap pages leaked after recovery
Date: Fri, 7 Aug 2026 14:55:29 -0400 [thread overview]
Message-ID: <e86f6b88-ea4f-425a-880d-a3622f3f458a@redhat.com> (raw)
The bitmap pages leaked after recovery if successful writes occur
concurrently during array degradation/recovery.
We performed write I/Os to an MD RAID1 array while it was in a degraded
state or actively undergoing recovery. Even after the array recovery
successfully reached 100%, the disk status returned to normal ([UU]),
and all I/Os completely stopped, the number of bitmap pages
(bitmap: n/N pages in /proc/mdstat) never dropped back to 0, resulting
in a persistent memory leak of bitmap pages.
Bitmap pages remain permanently allocated in the kernel memory even after
the array has fully returned to a healthy state, leading to a kernel
memory leak.
When a disk is re-added and recovery starts, MD_RECOVERY_RUNNING is set
in mddev->recovery. The else if condition evaluates to false for normal
concurrent writes during recovery. NEEDED_MASK is never applied to these
blocks.
Fixes: 4f0e7d0e03b7
md/md-bitmap: remove the last parameter for bimtap_ops->endwrite()
This is becauses removing success caused bitmap_endwrite()
to treat mddev->degraded as a blanket trigger for NEEDED_MASK.
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
---
drivers/md/md-bitmap.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 1d4a050dab3a..b8be0d079780 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1756,7 +1756,14 @@ static void bitmap_end_write(struct mddev *mddev,
sector_t offset,
sysfs_notify_dirent_safe(
bitmap->sysfs_can_clear);
}
- } else if (!NEEDED(*bmc)) {
+ /*
+ * Do not set NEEDED_MASK if recovery is actively running.
+ * Writes completing during recovery/resync are already covered by
+ * the recovery thread and setting NEEDED_MASK will cause orphaned
+ * bitmap flags and memory leaks after recovery finishes.
+ */
+ } else if (!test_bit(MD_RECOVERY_RUNNING,
+ &bitmap->mddev->recovery) && !NEEDED(*bmc)) {
*bmc |= NEEDED_MASK;
}
--
2.47.3
next reply other threads:[~2026-08-07 18:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 18:55 Nigel Croxon [this message]
2026-08-19 12:47 ` [PATCH] md/md-bitmap: bitmap pages leaked after recovery Nigel Croxon
2026-08-24 15:41 ` yu kuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e86f6b88-ea4f-425a-880d-a3622f3f458a@redhat.com \
--to=ncroxon@redhat.com \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=yukuai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox