Skip to content
  • Filipe David Borba Manana's avatar
    Btrfs: fix memory leak of orphan block rsv · 1cb048f5
    Filipe David Borba Manana authored
    
    
    This issue is simple to reproduce and observe if kmemleak is enabled.
    Two simple ways to reproduce it:
    
    ** 1
    
    $ mkfs.btrfs -f /dev/loop0
    $ mount /dev/loop0 /mnt/btrfs
    $ btrfs balance start /mnt/btrfs
    $ umount /mnt/btrfs
    
    ** 2
    
    $ mkfs.btrfs -f /dev/loop0
    $ mount /dev/loop0 /mnt/btrfs
    $ touch /mnt/btrfs/foobar
    $ rm -f /mnt/btrfs/foobar
    $ umount /mnt/btrfs
    
    After a while, kmemleak reports the leak:
    
    $ cat /sys/kernel/debug/kmemleak
    unreferenced object 0xffff880402b13e00 (size 128):
      comm "btrfs", pid 19621, jiffies 4341648183 (age 70057.844s)
      hex dump (first 32 bytes):
        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        00 fc c6 b1 04 88 ff ff 04 00 04 00 ad 4e ad de  .............N..
      backtrace:
        [<ffffffff817275a6>] kmemleak_alloc+0x26/0x50
        [<ffffffff8117832b>] kmem_cache_alloc_trace+0xeb/0x1d0
        [<ffffffffa04db499>] btrfs_alloc_block_rsv+0x39/0x70 [btrfs]
        [<ffffffffa04f8bad>] btrfs_orphan_add+0x13d/0x1b0 [btrfs]
        [<ffffffffa04e2b13>] btrfs_remove_block_group+0x143/0x500 [btrfs]
        [<ffffffffa0518158>] btrfs_relocate_chunk.isra.63+0x618/0x790 [btrfs]
        [<ffffffffa051bc27>] btrfs_balance+0x8f7/0xe90 [btrfs]
        [<ffffffffa05240a0>] btrfs_ioctl_balance+0x250/0x550 [btrfs]
        [<ffffffffa05269ca>] btrfs_ioctl+0xdfa/0x25f0 [btrfs]
        [<ffffffff8119c936>] do_vfs_ioctl+0x96/0x570
        [<ffffffff8119cea1>] SyS_ioctl+0x91/0xb0
        [<ffffffff81750242>] system_call_fastpath+0x16/0x1b
        [<ffffffffffffffff>] 0xffffffffffffffff
    
    This affects btrfs-next, revision be8e3cd00d7293dd177e3f8a4a1645ce09ca3acb
    (Btrfs: separate out tests into their own directory).
    
    Signed-off-by: default avatarFilipe David Borba Manana <fdmanana@gmail.com>
    Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
    Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
    1cb048f5