Commit a0e7744a authored by Yu Kuai's avatar Yu Kuai Committed by Song Liu

md/md-bitmap: add 'behind_writes' and 'behind_wait' into struct md_bitmap_stats

There are no functional changes, avoid dereferencing bitmap directly to
prepare inventing a new bitmap.

Also fix following checkpatch warning by using wq_has_sleeper().

WARNING: waitqueue_active without comment
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240826074452.1490072-9-yukuai1@huaweicloud.comSigned-off-by: default avatarSong Liu <song@kernel.org>
parent 10bc2ac1
...@@ -2115,6 +2115,8 @@ int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats) ...@@ -2115,6 +2115,8 @@ int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
stats->file_pages = storage->file_pages; stats->file_pages = storage->file_pages;
stats->file = storage->file; stats->file = storage->file;
stats->behind_writes = atomic_read(&bitmap->behind_writes);
stats->behind_wait = wq_has_sleeper(&bitmap->behind_wait);
stats->events_cleared = bitmap->events_cleared; stats->events_cleared = bitmap->events_cleared;
return 0; return 0;
} }
......
...@@ -236,6 +236,9 @@ struct bitmap { ...@@ -236,6 +236,9 @@ struct bitmap {
struct md_bitmap_stats { struct md_bitmap_stats {
u64 events_cleared; u64 events_cleared;
int behind_writes;
bool behind_wait;
unsigned long missing_pages; unsigned long missing_pages;
unsigned long file_pages; unsigned long file_pages;
unsigned long sync_size; unsigned long sync_size;
......
...@@ -1590,16 +1590,19 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, ...@@ -1590,16 +1590,19 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
continue; continue;
if (first_clone) { if (first_clone) {
unsigned long max_write_behind =
mddev->bitmap_info.max_write_behind;
struct md_bitmap_stats stats;
int err;
/* do behind I/O ? /* do behind I/O ?
* Not if there are too many, or cannot * Not if there are too many, or cannot
* allocate memory, or a reader on WriteMostly * allocate memory, or a reader on WriteMostly
* is waiting for behind writes to flush */ * is waiting for behind writes to flush */
if (bitmap && write_behind && err = md_bitmap_get_stats(bitmap, &stats);
(atomic_read(&bitmap->behind_writes) if (!err && write_behind && !stats.behind_wait &&
< mddev->bitmap_info.max_write_behind) && stats.behind_writes < max_write_behind)
!waitqueue_active(&bitmap->behind_wait)) {
alloc_behind_master_bio(r1_bio, bio); alloc_behind_master_bio(r1_bio, bio);
}
md_bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors, md_bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors,
test_bit(R1BIO_BehindIO, &r1_bio->state)); test_bit(R1BIO_BehindIO, &r1_bio->state));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment