Commit 6aaa58c9 authored by Jack Wang's avatar Jack Wang Committed by Shaohua Li

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 5a409b4f, the fixes should go to
4.18+

Fixes: 5a409b4f ("MD: fix lock contention for flush bios")
Signed-off-by: default avatarJack Wang <jinpu.wang@profitbricks.com>
Reviewed-by: default avatarXiao Ni <xni@redhat.com>
Signed-off-by: default avatarShaohua Li <shli@fb.com>
parent ea89238c
...@@ -5904,14 +5904,6 @@ static void __md_stop(struct mddev *mddev) ...@@ -5904,14 +5904,6 @@ static void __md_stop(struct mddev *mddev)
mddev->to_remove = &md_redundancy_group; mddev->to_remove = &md_redundancy_group;
module_put(pers->owner); module_put(pers->owner);
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
}
void md_stop(struct mddev *mddev)
{
/* stop the array and free an attached data structures.
* This is called from dm-raid
*/
__md_stop(mddev);
if (mddev->flush_bio_pool) { if (mddev->flush_bio_pool) {
mempool_destroy(mddev->flush_bio_pool); mempool_destroy(mddev->flush_bio_pool);
mddev->flush_bio_pool = NULL; mddev->flush_bio_pool = NULL;
...@@ -5920,6 +5912,14 @@ void md_stop(struct mddev *mddev) ...@@ -5920,6 +5912,14 @@ void md_stop(struct mddev *mddev)
mempool_destroy(mddev->flush_pool); mempool_destroy(mddev->flush_pool);
mddev->flush_pool = NULL; mddev->flush_pool = NULL;
} }
}
void md_stop(struct mddev *mddev)
{
/* stop the array and free an attached data structures.
* This is called from dm-raid
*/
__md_stop(mddev);
bioset_exit(&mddev->bio_set); bioset_exit(&mddev->bio_set);
bioset_exit(&mddev->sync_set); bioset_exit(&mddev->sync_set);
} }
......
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