Btrfs: honor extent thresh during defragmentation
authorLi Zefan <lizf@cn.fujitsu.com>
Fri, 2 Sep 2011 07:57:07 +0000 (15:57 +0800)
committerDavid Sterba <dsterba@suse.cz>
Thu, 20 Oct 2011 16:10:39 +0000 (18:10 +0200)
We won't defrag an extent, if it's bigger than the threshold we
specified and there's no small extent before it, but actually
the code doesn't work this way.

There are three bugs:

- When should_defrag_range() decides we should keep on defragmenting
  an extent, last_len is not incremented. (old bug)

- The length that passes to should_defrag_range() is not the length
  we're going to defrag. (new bug)

- We always defrag 256K bytes data, and a big extent can be part of
  this range. (new bug)

For a file with 4 extents:

        | 4K | 4K | 256K | 256K |

The result of defrag with (the default) 256K extent thresh should be:

        | 264K | 256K |

but with those bugs, we'll get:

        | 520K |

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>

No differences found