Skip to contentSkip to conversation

dm thin: fix a memory leak when passing discard bio down

PATCH In review Dennis Yang 2 participants 2 messages Apr 18, 2017 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm thin: fix a memory leak when passing discard bio down

dm-thin does not free the discard_parent bio after all chained sub bios finished. The following kmemleak report could be observed after pool with discard_passdown option processes discard bios in linux v4.11-rc7. To fix this, we drop the discard_parent bio reference when its endio (passdown_endio) called.

unreferenced object 0xffff8803d6b29700 (size 256):
comm "kworker/u8:0", pid 30349, jiffies 4379504020 (age 143002.776s) hex dump (first 32 bytes):

    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    01 00 00 00 00 00 00 f0 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<ffffffff81a5efd9>] kmemleak_alloc+0x49/0xa0
    [<ffffffff8114ec34>] kmem_cache_alloc+0xb4/0x100
    [<ffffffff8110eec0>] mempool_alloc_slab+0x10/0x20
    [<ffffffff8110efa5>] mempool_alloc+0x55/0x150
    [<ffffffff81374939>] bio_alloc_bioset+0xb9/0x260
    [<ffffffffa018fd20>] process_prepared_discard_passdown_pt1+0x40/0x1c0 [dm_thin_pool]
    [<ffffffffa018b409>] break_up_discard_bio+0x1a9/0x200 [dm_thin_pool]
    [<ffffffffa018b484>] process_discard_cell_passdown+0x24/0x40 [dm_thin_pool]
    [<ffffffffa018b24d>] process_discard_bio+0xdd/0xf0 [dm_thin_pool]
    [<ffffffffa018ecf6>] do_worker+0xa76/0xd50 [dm_thin_pool]
    [<ffffffff81086239>] process_one_work+0x139/0x370
    [<ffffffff810867b1>] worker_thread+0x61/0x450
    [<ffffffff8108b316>] kthread+0xd6/0xf0
    [<ffffffff81a6cd1f>] ret_from_fork+0x3f/0x70
    [<ffffffffffffffff>] 0xffffffffffffffff
---
 drivers/md/dm-thin.c | 1 +
 1 file changed, 1 insertion(+)
drivers/md/dm-thin.c +1 -0
index 2b266a2..5742e5e 100644
@@ -1069,6 +1069,7 @@ static void passdown_endio(struct bio *bio)
 	 * to unmap (we ignore err).
 	 */
 	queue_passdown_pt2(bio->bi_private);
+	bio_put(bio);
 }
 
 static void process_prepared_discard_passdown_pt1(struct dm_thin_new_mapping *m)
Signature · 1 line
1.9.1
#1 lore raw

Dne 18.4.2017 v 09:27 Dennis Yang napsal(a):

Quoted 38 lines

dm-thin does not free the discard_parent bio after all chained sub bios finished. The following kmemleak report could be observed after pool with discard_passdown option processes discard bios in linux v4.11-rc7. To fix this, we drop the discard_parent bio reference when its endio (passdown_endio) called.

unreferenced object 0xffff8803d6b29700 (size 256):

   comm "kworker/u8:0", pid 30349, jiffies 4379504020 (age 143002.776s)
   hex dump (first 32 bytes):
     00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
     01 00 00 00 00 00 00 f0 00 00 00 00 00 00 00 00  ................
   backtrace:
     [<ffffffff81a5efd9>] kmemleak_alloc+0x49/0xa0
     [<ffffffff8114ec34>] kmem_cache_alloc+0xb4/0x100
     [<ffffffff8110eec0>] mempool_alloc_slab+0x10/0x20
     [<ffffffff8110efa5>] mempool_alloc+0x55/0x150
     [<ffffffff81374939>] bio_alloc_bioset+0xb9/0x260
     [<ffffffffa018fd20>] process_prepared_discard_passdown_pt1+0x40/0x1c0 [dm_thin_pool]
     [<ffffffffa018b409>] break_up_discard_bio+0x1a9/0x200 [dm_thin_pool]
     [<ffffffffa018b484>] process_discard_cell_passdown+0x24/0x40 [dm_thin_pool]
     [<ffffffffa018b24d>] process_discard_bio+0xdd/0xf0 [dm_thin_pool]
     [<ffffffffa018ecf6>] do_worker+0xa76/0xd50 [dm_thin_pool]
     [<ffffffff81086239>] process_one_work+0x139/0x370
     [<ffffffff810867b1>] worker_thread+0x61/0x450
     [<ffffffff8108b316>] kthread+0xd6/0xf0
     [<ffffffff81a6cd1f>] ret_from_fork+0x3f/0x70
     [<ffffffffffffffff>] 0xffffffffffffffff
---
  drivers/md/dm-thin.c | 1 +
  1 file changed, 1 insertion(+)
drivers/md/dm-thin.c +0 -0
index 2b266a2..5742e5e 100644

drivers/md/dm-thin.c static void passdown_endio(struct bio *bio) · line 1075

Quoted 7 lines
drivers/md/dm-thin.c +1 -0
@@ -1069,6 +1069,7 @@ static void passdown_endio(struct bio *bio)
  	 * to unmap (we ignore err).
  	 */
  	queue_passdown_pt2(bio->bi_private);
+	bio_put(bio);
  }
 
  static void process_prepared_discard_passdown_pt1(struct dm_thin_new_mapping *m)

Thanks

https://bugzilla.redhat.com/show_bug.cgi?id=1420462

Regards

Zdenek

https://bugzilla.redhat.com/show_bug.cgi?id=1420462