diff options
author | Jack Wang <jinpu.wang@profitbricks.com> | 2018-10-19 10:21:31 -0400 |
---|---|---|
committer | Shaohua Li <shli@fb.com> | 2018-10-22 12:12:38 -0400 |
commit | 6aaa58c994277647f8b05ffef3b9b225a2d08f36 (patch) | |
tree | 8eff51ce7443e040d881ae13965423c52d85e633 | |
parent | ea89238c0a7b346bc90552e0244e87edf3311920 (diff) |
md: fix memleak for mempool
I noticed kmemleak report memory leak when run create/stop
md in a loop, backtrace:
[<000000001ca975e7>] mempool_create_node+0x86/0xd0
[<0000000095576bcd>] md_run+0x1057/0x1410 [md_mod]
[<000000007b45c5fc>] do_md_run+0x15/0x130 [md_mod]
[<000000001ede9ec0>] md_ioctl+0x1f49/0x25d0 [md_mod]
[<000000004142cacf>] blkdev_ioctl+0x680/0xd00
The root cause is we alloc mddev->flush_pool and
mddev->flush_bio_pool in md_run, but from do_md_stop
will not call into md_stop but __md_stop, move the
mempool_destroy to __md_stop fixes the problem for me.
The bug was introduced in 5a409b4f56d5, the fixes should go to
4.18+
Fixes: 5a409b4f56d5 ("MD: fix lock contention for flush bios")
Signed-off-by: Jack Wang <jinpu.wang@profitbricks.com>
Reviewed-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Shaohua Li <shli@fb.com>
-rw-r--r-- | drivers/md/md.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index 390f410e51dd..1fa7f1b1d98a 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -5904,14 +5904,6 @@ static void __md_stop(struct mddev *mddev) | |||
5904 | mddev->to_remove = &md_redundancy_group; | 5904 | mddev->to_remove = &md_redundancy_group; |
5905 | module_put(pers->owner); | 5905 | module_put(pers->owner); |
5906 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); | 5906 | clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
5907 | } | ||
5908 | |||
5909 | void md_stop(struct mddev *mddev) | ||
5910 | { | ||
5911 | /* stop the array and free an attached data structures. | ||
5912 | * This is called from dm-raid | ||
5913 | */ | ||
5914 | __md_stop(mddev); | ||
5915 | if (mddev->flush_bio_pool) { | 5907 | if (mddev->flush_bio_pool) { |
5916 | mempool_destroy(mddev->flush_bio_pool); | 5908 | mempool_destroy(mddev->flush_bio_pool); |
5917 | mddev->flush_bio_pool = NULL; | 5909 | mddev->flush_bio_pool = NULL; |
@@ -5920,6 +5912,14 @@ void md_stop(struct mddev *mddev) | |||
5920 | mempool_destroy(mddev->flush_pool); | 5912 | mempool_destroy(mddev->flush_pool); |
5921 | mddev->flush_pool = NULL; | 5913 | mddev->flush_pool = NULL; |
5922 | } | 5914 | } |
5915 | } | ||
5916 | |||
5917 | void md_stop(struct mddev *mddev) | ||
5918 | { | ||
5919 | /* stop the array and free an attached data structures. | ||
5920 | * This is called from dm-raid | ||
5921 | */ | ||
5922 | __md_stop(mddev); | ||
5923 | bioset_exit(&mddev->bio_set); | 5923 | bioset_exit(&mddev->bio_set); |
5924 | bioset_exit(&mddev->sync_set); | 5924 | bioset_exit(&mddev->sync_set); |
5925 | } | 5925 | } |