]> www.infradead.org Git - users/jedix/linux-maple.git/commit
Btrfs: rewrite btrfs_trim_block_group()
authorLi Zefan <lizf@cn.fujitsu.com>
Thu, 29 Dec 2011 06:47:27 +0000 (14:47 +0800)
committerGuru Anbalagane <guru.anbalagane@oracle.com>
Fri, 27 Jan 2012 01:20:50 +0000 (17:20 -0800)
commit33a073a5a22cca4d790fee67750bfd10373917fd
treecb83a31b8979bcf3e8ec15df6c1e1202871d2abc
parent9ec6aca633d955fc4c2336aec3a68c30055481c5
Btrfs: rewrite btrfs_trim_block_group()

There are various bugs in block group trimming:

- It may trim from offset smaller than user-specified offset.
- It may trim beyond user-specified range.
- It may leak free space for extents smaller than specified minlen.
- It may truncate the last trimmed extent thus leak free space.
- With mixed extents+bitmaps, some extents may not be trimmed.
- With mixed extents+bitmaps, some bitmaps may not be trimmed (even
none will be trimmed). Even for those trimmed, not all the free space
in the bitmaps will be trimmed.

I rewrite btrfs_trim_block_group() and break it into two functions.
One is to trim extents only, and the other is to trim bitmaps only.

Before patching:

# fstrim -v /mnt/
/mnt/: 1496465408 bytes were trimmed

After patching:

# fstrim -v /mnt/
/mnt/: 2193768448 bytes were trimmed

And this matches the total free space:

# btrfs fi df /mnt
Data: total=3.58GB, used=1.79GB
System, DUP: total=8.00MB, used=4.00KB
System: total=4.00MB, used=0.00
Metadata, DUP: total=205.12MB, used=97.14MB
Metadata: total=8.00MB, used=0.00

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
(cherry picked from commit 7fe1e641502616220437079258506196bc4d8cbf)
fs/btrfs/free-space-cache.c