1 |
From aa44e19c98556484f3ea6ba663bea61954a89f48 Mon Sep 17 00:00:00 2001 |
2 |
From: Jack Wang <jinpu.wang@profitbricks.com> |
3 |
Date: Fri, 19 Oct 2018 16:21:31 +0200 |
4 |
Subject: [PATCH 089/145] md: fix memleak for mempool |
5 |
|
6 |
[ Upstream commit 6aaa58c994277647f8b05ffef3b9b225a2d08f36 ] |
7 |
|
8 |
I noticed kmemleak report memory leak when run create/stop |
9 |
md in a loop, backtrace: |
10 |
[<000000001ca975e7>] mempool_create_node+0x86/0xd0 |
11 |
[<0000000095576bcd>] md_run+0x1057/0x1410 [md_mod] |
12 |
[<000000007b45c5fc>] do_md_run+0x15/0x130 [md_mod] |
13 |
[<000000001ede9ec0>] md_ioctl+0x1f49/0x25d0 [md_mod] |
14 |
[<000000004142cacf>] blkdev_ioctl+0x680/0xd00 |
15 |
|
16 |
The root cause is we alloc mddev->flush_pool and |
17 |
mddev->flush_bio_pool in md_run, but from do_md_stop |
18 |
will not call into md_stop but __md_stop, move the |
19 |
mempool_destroy to __md_stop fixes the problem for me. |
20 |
|
21 |
The bug was introduced in 5a409b4f56d5, the fixes should go to |
22 |
4.18+ |
23 |
|
24 |
Fixes: 5a409b4f56d5 ("MD: fix lock contention for flush bios") |
25 |
Signed-off-by: Jack Wang <jinpu.wang@profitbricks.com> |
26 |
Reviewed-by: Xiao Ni <xni@redhat.com> |
27 |
Signed-off-by: Shaohua Li <shli@fb.com> |
28 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
29 |
--- |
30 |
drivers/md/md.c | 16 ++++++++-------- |
31 |
1 file changed, 8 insertions(+), 8 deletions(-) |
32 |
|
33 |
diff --git a/drivers/md/md.c b/drivers/md/md.c |
34 |
index 06f68f19b5f3..8668793262d0 100644 |
35 |
--- a/drivers/md/md.c |
36 |
+++ b/drivers/md/md.c |
37 |
@@ -5906,14 +5906,6 @@ static void __md_stop(struct mddev *mddev) |
38 |
mddev->to_remove = &md_redundancy_group; |
39 |
module_put(pers->owner); |
40 |
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); |
41 |
-} |
42 |
- |
43 |
-void md_stop(struct mddev *mddev) |
44 |
-{ |
45 |
- /* stop the array and free an attached data structures. |
46 |
- * This is called from dm-raid |
47 |
- */ |
48 |
- __md_stop(mddev); |
49 |
if (mddev->flush_bio_pool) { |
50 |
mempool_destroy(mddev->flush_bio_pool); |
51 |
mddev->flush_bio_pool = NULL; |
52 |
@@ -5922,6 +5914,14 @@ void md_stop(struct mddev *mddev) |
53 |
mempool_destroy(mddev->flush_pool); |
54 |
mddev->flush_pool = NULL; |
55 |
} |
56 |
+} |
57 |
+ |
58 |
+void md_stop(struct mddev *mddev) |
59 |
+{ |
60 |
+ /* stop the array and free an attached data structures. |
61 |
+ * This is called from dm-raid |
62 |
+ */ |
63 |
+ __md_stop(mddev); |
64 |
bioset_exit(&mddev->bio_set); |
65 |
bioset_exit(&mddev->sync_set); |
66 |
} |
67 |
-- |
68 |
2.19.1 |
69 |
|