Skip to content

Commit a022325

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/md-bitmap: add a new helper to unplug bitmap asynchrously
If bitmap is enabled, bitmap must update before submitting write io, this is why unplug callback must move these io to 'conf->pending_io_list' if 'current->bio_list' is not empty, which will suffer performance degradation. A new helper md_bitmap_unplug_async() is introduced to submit bitmap io in a kworker, so that submit bitmap io in raid10_unplug() doesn't require that 'current->bio_list' is empty. This patch prepare to limit the number of plugged bio. Signed-off-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7db922b commit a022325

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

drivers/md/md-bitmap.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,35 @@ void md_bitmap_unplug(struct bitmap *bitmap)
10541054
}
10551055
EXPORT_SYMBOL(md_bitmap_unplug);
10561056

1057+
struct bitmap_unplug_work {
1058+
struct work_struct work;
1059+
struct bitmap *bitmap;
1060+
struct completion *done;
1061+
};
1062+
1063+
static void md_bitmap_unplug_fn(struct work_struct *work)
1064+
{
1065+
struct bitmap_unplug_work *unplug_work =
1066+
container_of(work, struct bitmap_unplug_work, work);
1067+
1068+
md_bitmap_unplug(unplug_work->bitmap);
1069+
complete(unplug_work->done);
1070+
}
1071+
1072+
void md_bitmap_unplug_async(struct bitmap *bitmap)
1073+
{
1074+
DECLARE_COMPLETION_ONSTACK(done);
1075+
struct bitmap_unplug_work unplug_work;
1076+
1077+
INIT_WORK_ONSTACK(&unplug_work.work, md_bitmap_unplug_fn);
1078+
unplug_work.bitmap = bitmap;
1079+
unplug_work.done = &done;
1080+
1081+
queue_work(md_bitmap_wq, &unplug_work.work);
1082+
wait_for_completion(&done);
1083+
}
1084+
EXPORT_SYMBOL(md_bitmap_unplug_async);
1085+
10571086
static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
10581087
/* * bitmap_init_from_disk -- called at bitmap_create time to initialize
10591088
* the in-memory bitmap from the on-disk bitmap -- also, sets up the

drivers/md/md-bitmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void md_bitmap_sync_with_cluster(struct mddev *mddev,
264264
sector_t new_lo, sector_t new_hi);
265265

266266
void md_bitmap_unplug(struct bitmap *bitmap);
267+
void md_bitmap_unplug_async(struct bitmap *bitmap);
267268
void md_bitmap_daemon_work(struct mddev *mddev);
268269

269270
int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,

drivers/md/md.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static struct module *md_cluster_mod;
8383
static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
8484
static struct workqueue_struct *md_wq;
8585
static struct workqueue_struct *md_misc_wq;
86+
struct workqueue_struct *md_bitmap_wq;
8687

8788
static int remove_and_add_spares(struct mddev *mddev,
8889
struct md_rdev *this);
@@ -9637,6 +9638,11 @@ static int __init md_init(void)
96379638
if (!md_misc_wq)
96389639
goto err_misc_wq;
96399640

9641+
md_bitmap_wq = alloc_workqueue("md_bitmap", WQ_MEM_RECLAIM | WQ_UNBOUND,
9642+
0);
9643+
if (!md_bitmap_wq)
9644+
goto err_bitmap_wq;
9645+
96409646
ret = __register_blkdev(MD_MAJOR, "md", md_probe);
96419647
if (ret < 0)
96429648
goto err_md;
@@ -9655,6 +9661,8 @@ static int __init md_init(void)
96559661
err_mdp:
96569662
unregister_blkdev(MD_MAJOR, "md");
96579663
err_md:
9664+
destroy_workqueue(md_bitmap_wq);
9665+
err_bitmap_wq:
96589666
destroy_workqueue(md_misc_wq);
96599667
err_misc_wq:
96609668
destroy_workqueue(md_wq);
@@ -9951,6 +9959,7 @@ static __exit void md_exit(void)
99519959
spin_unlock(&all_mddevs_lock);
99529960

99539961
destroy_workqueue(md_misc_wq);
9962+
destroy_workqueue(md_bitmap_wq);
99549963
destroy_workqueue(md_wq);
99559964
}
99569965

drivers/md/md.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ struct mdu_array_info_s;
852852
struct mdu_disk_info_s;
853853

854854
extern int mdp_major;
855+
extern struct workqueue_struct *md_bitmap_wq;
855856
void md_autostart_arrays(int part);
856857
int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info);
857858
int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info);

0 commit comments

Comments
 (0)