Skip to content

Commit 08c5014

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/md-bitmap: factor behind write counters out from bitmap_{start/end}write()
behind_write is only used in raid1, prepare to refactor bitmap_{start/end}write(), there are no functional changes. Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Xiao Ni <xni@redhat.com> Link: https://lore.kernel.org/r/20250109015145.158868-2-yukuai1@huaweicloud.com Signed-off-by: Song Liu <song@kernel.org>
1 parent 4fa9161 commit 08c5014

File tree

6 files changed

+56
-40
lines changed

6 files changed

+56
-40
lines changed

drivers/md/md-bitmap.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,24 +1671,13 @@ __acquires(bitmap->lock)
16711671
}
16721672

16731673
static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
1674-
unsigned long sectors, bool behind)
1674+
unsigned long sectors)
16751675
{
16761676
struct bitmap *bitmap = mddev->bitmap;
16771677

16781678
if (!bitmap)
16791679
return 0;
16801680

1681-
if (behind) {
1682-
int bw;
1683-
atomic_inc(&bitmap->behind_writes);
1684-
bw = atomic_read(&bitmap->behind_writes);
1685-
if (bw > bitmap->behind_writes_used)
1686-
bitmap->behind_writes_used = bw;
1687-
1688-
pr_debug("inc write-behind count %d/%lu\n",
1689-
bw, bitmap->mddev->bitmap_info.max_write_behind);
1690-
}
1691-
16921681
while (sectors) {
16931682
sector_t blocks;
16941683
bitmap_counter_t *bmc;
@@ -1737,21 +1726,13 @@ static int bitmap_startwrite(struct mddev *mddev, sector_t offset,
17371726
}
17381727

17391728
static void bitmap_endwrite(struct mddev *mddev, sector_t offset,
1740-
unsigned long sectors, bool success, bool behind)
1729+
unsigned long sectors, bool success)
17411730
{
17421731
struct bitmap *bitmap = mddev->bitmap;
17431732

17441733
if (!bitmap)
17451734
return;
17461735

1747-
if (behind) {
1748-
if (atomic_dec_and_test(&bitmap->behind_writes))
1749-
wake_up(&bitmap->behind_wait);
1750-
pr_debug("dec write-behind count %d/%lu\n",
1751-
atomic_read(&bitmap->behind_writes),
1752-
bitmap->mddev->bitmap_info.max_write_behind);
1753-
}
1754-
17551736
while (sectors) {
17561737
sector_t blocks;
17571738
unsigned long flags;
@@ -2062,6 +2043,37 @@ static void md_bitmap_free(void *data)
20622043
kfree(bitmap);
20632044
}
20642045

2046+
static void bitmap_start_behind_write(struct mddev *mddev)
2047+
{
2048+
struct bitmap *bitmap = mddev->bitmap;
2049+
int bw;
2050+
2051+
if (!bitmap)
2052+
return;
2053+
2054+
atomic_inc(&bitmap->behind_writes);
2055+
bw = atomic_read(&bitmap->behind_writes);
2056+
if (bw > bitmap->behind_writes_used)
2057+
bitmap->behind_writes_used = bw;
2058+
2059+
pr_debug("inc write-behind count %d/%lu\n",
2060+
bw, bitmap->mddev->bitmap_info.max_write_behind);
2061+
}
2062+
2063+
static void bitmap_end_behind_write(struct mddev *mddev)
2064+
{
2065+
struct bitmap *bitmap = mddev->bitmap;
2066+
2067+
if (!bitmap)
2068+
return;
2069+
2070+
if (atomic_dec_and_test(&bitmap->behind_writes))
2071+
wake_up(&bitmap->behind_wait);
2072+
pr_debug("dec write-behind count %d/%lu\n",
2073+
atomic_read(&bitmap->behind_writes),
2074+
bitmap->mddev->bitmap_info.max_write_behind);
2075+
}
2076+
20652077
static void bitmap_wait_behind_writes(struct mddev *mddev)
20662078
{
20672079
struct bitmap *bitmap = mddev->bitmap;
@@ -2981,6 +2993,9 @@ static struct bitmap_operations bitmap_ops = {
29812993
.dirty_bits = bitmap_dirty_bits,
29822994
.unplug = bitmap_unplug,
29832995
.daemon_work = bitmap_daemon_work,
2996+
2997+
.start_behind_write = bitmap_start_behind_write,
2998+
.end_behind_write = bitmap_end_behind_write,
29842999
.wait_behind_writes = bitmap_wait_behind_writes,
29853000

29863001
.startwrite = bitmap_startwrite,

drivers/md/md-bitmap.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ struct bitmap_operations {
8484
unsigned long e);
8585
void (*unplug)(struct mddev *mddev, bool sync);
8686
void (*daemon_work)(struct mddev *mddev);
87+
88+
void (*start_behind_write)(struct mddev *mddev);
89+
void (*end_behind_write)(struct mddev *mddev);
8790
void (*wait_behind_writes)(struct mddev *mddev);
8891

8992
int (*startwrite)(struct mddev *mddev, sector_t offset,
90-
unsigned long sectors, bool behind);
93+
unsigned long sectors);
9194
void (*endwrite)(struct mddev *mddev, sector_t offset,
92-
unsigned long sectors, bool success, bool behind);
95+
unsigned long sectors, bool success);
9396
bool (*start_sync)(struct mddev *mddev, sector_t offset,
9497
sector_t *blocks, bool degraded);
9598
void (*end_sync)(struct mddev *mddev, sector_t offset, sector_t *blocks);

drivers/md/raid1.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,11 @@ static void close_write(struct r1bio *r1_bio)
420420
r1_bio->behind_master_bio = NULL;
421421
}
422422

423+
if (test_bit(R1BIO_BehindIO, &r1_bio->state))
424+
mddev->bitmap_ops->end_behind_write(mddev);
423425
/* clear the bitmap if all writes complete successfully */
424426
mddev->bitmap_ops->endwrite(mddev, r1_bio->sector, r1_bio->sectors,
425-
!test_bit(R1BIO_Degraded, &r1_bio->state),
426-
test_bit(R1BIO_BehindIO, &r1_bio->state));
427+
!test_bit(R1BIO_Degraded, &r1_bio->state));
427428
md_write_end(mddev);
428429
}
429430

@@ -1645,9 +1646,10 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
16451646
stats.behind_writes < max_write_behind)
16461647
alloc_behind_master_bio(r1_bio, bio);
16471648

1648-
mddev->bitmap_ops->startwrite(
1649-
mddev, r1_bio->sector, r1_bio->sectors,
1650-
test_bit(R1BIO_BehindIO, &r1_bio->state));
1649+
if (test_bit(R1BIO_BehindIO, &r1_bio->state))
1650+
mddev->bitmap_ops->start_behind_write(mddev);
1651+
mddev->bitmap_ops->startwrite(mddev, r1_bio->sector,
1652+
r1_bio->sectors);
16511653
first_clone = 0;
16521654
}
16531655

drivers/md/raid10.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ static void close_write(struct r10bio *r10_bio)
430430

431431
/* clear the bitmap if all writes complete successfully */
432432
mddev->bitmap_ops->endwrite(mddev, r10_bio->sector, r10_bio->sectors,
433-
!test_bit(R10BIO_Degraded, &r10_bio->state),
434-
false);
433+
!test_bit(R10BIO_Degraded, &r10_bio->state));
435434
md_write_end(mddev);
436435
}
437436

@@ -1519,8 +1518,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
15191518
md_account_bio(mddev, &bio);
15201519
r10_bio->master_bio = bio;
15211520
atomic_set(&r10_bio->remaining, 1);
1522-
mddev->bitmap_ops->startwrite(mddev, r10_bio->sector, r10_bio->sectors,
1523-
false);
1521+
mddev->bitmap_ops->startwrite(mddev, r10_bio->sector, r10_bio->sectors);
15241522

15251523
for (i = 0; i < conf->copies; i++) {
15261524
if (r10_bio->devs[i].bio)

drivers/md/raid5-cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ void r5c_handle_cached_data_endio(struct r5conf *conf,
315315
r5c_return_dev_pending_writes(conf, &sh->dev[i]);
316316
conf->mddev->bitmap_ops->endwrite(conf->mddev,
317317
sh->sector, RAID5_STRIPE_SECTORS(conf),
318-
!test_bit(STRIPE_DEGRADED, &sh->state),
319-
false);
318+
!test_bit(STRIPE_DEGRADED, &sh->state));
320319
}
321320
}
322321
}

drivers/md/raid5.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,7 +3564,7 @@ static void __add_stripe_bio(struct stripe_head *sh, struct bio *bi,
35643564
set_bit(STRIPE_BITMAP_PENDING, &sh->state);
35653565
spin_unlock_irq(&sh->stripe_lock);
35663566
conf->mddev->bitmap_ops->startwrite(conf->mddev, sh->sector,
3567-
RAID5_STRIPE_SECTORS(conf), false);
3567+
RAID5_STRIPE_SECTORS(conf));
35683568
spin_lock_irq(&sh->stripe_lock);
35693569
clear_bit(STRIPE_BITMAP_PENDING, &sh->state);
35703570
if (!sh->batch_head) {
@@ -3665,7 +3665,7 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
36653665
if (bitmap_end)
36663666
conf->mddev->bitmap_ops->endwrite(conf->mddev,
36673667
sh->sector, RAID5_STRIPE_SECTORS(conf),
3668-
false, false);
3668+
false);
36693669
bitmap_end = 0;
36703670
/* and fail all 'written' */
36713671
bi = sh->dev[i].written;
@@ -3712,7 +3712,7 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
37123712
if (bitmap_end)
37133713
conf->mddev->bitmap_ops->endwrite(conf->mddev,
37143714
sh->sector, RAID5_STRIPE_SECTORS(conf),
3715-
false, false);
3715+
false);
37163716
/* If we were in the middle of a write the parity block might
37173717
* still be locked - so just clear all R5_LOCKED flags
37183718
*/
@@ -4063,8 +4063,7 @@ static void handle_stripe_clean_event(struct r5conf *conf,
40634063
}
40644064
conf->mddev->bitmap_ops->endwrite(conf->mddev,
40654065
sh->sector, RAID5_STRIPE_SECTORS(conf),
4066-
!test_bit(STRIPE_DEGRADED, &sh->state),
4067-
false);
4066+
!test_bit(STRIPE_DEGRADED, &sh->state));
40684067
if (head_sh->batch_head) {
40694068
sh = list_first_entry(&sh->batch_list,
40704069
struct stripe_head,
@@ -5787,7 +5786,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
57875786
for (d = 0; d < conf->raid_disks - conf->max_degraded;
57885787
d++)
57895788
mddev->bitmap_ops->startwrite(mddev, sh->sector,
5790-
RAID5_STRIPE_SECTORS(conf), false);
5789+
RAID5_STRIPE_SECTORS(conf));
57915790
sh->bm_seq = conf->seq_flush + 1;
57925791
set_bit(STRIPE_BIT_DELAY, &sh->state);
57935792
}

0 commit comments

Comments
 (0)