Skip to content

Commit c444c42

Browse files
Jack Wangsmb49
authored andcommitted
md: fix memleak for mempool
BugLink: http://bugs.launchpad.net/bugs/1810820 [ Upstream commit 6aaa58c ] 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 5a409b4, the fixes should go to 4.18+ Fixes: 5a409b4 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
1 parent 7ab91be commit c444c42

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/md/md.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5909,14 +5909,6 @@ static void __md_stop(struct mddev *mddev)
59095909
mddev->to_remove = &md_redundancy_group;
59105910
module_put(pers->owner);
59115911
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5912-
}
5913-
5914-
void md_stop(struct mddev *mddev)
5915-
{
5916-
/* stop the array and free an attached data structures.
5917-
* This is called from dm-raid
5918-
*/
5919-
__md_stop(mddev);
59205912
if (mddev->flush_bio_pool) {
59215913
mempool_destroy(mddev->flush_bio_pool);
59225914
mddev->flush_bio_pool = NULL;
@@ -5925,6 +5917,14 @@ void md_stop(struct mddev *mddev)
59255917
mempool_destroy(mddev->flush_pool);
59265918
mddev->flush_pool = NULL;
59275919
}
5920+
}
5921+
5922+
void md_stop(struct mddev *mddev)
5923+
{
5924+
/* stop the array and free an attached data structures.
5925+
* This is called from dm-raid
5926+
*/
5927+
__md_stop(mddev);
59285928
bioset_exit(&mddev->bio_set);
59295929
bioset_exit(&mddev->sync_set);
59305930
}

0 commit comments

Comments
 (0)