btrfs: close the gap between inode_should_defrag() and autodefrag extent size threshold
authorQu Wenruo <wqu@suse.com>
Sun, 13 Feb 2022 07:42:33 +0000 (15:42 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 15 Feb 2022 15:51:18 +0000 (16:51 +0100)
commit13b2f7ab699a5a707d85ddf61e3582cb30ad6aaa
tree766de6e9b17e559890618e6e14245dc3b89a0189
parentdb360c49d476fe29815a76623b4bf37676d75e5a
btrfs: close the gap between inode_should_defrag() and autodefrag extent size threshold

There is a big gap between inode_should_defrag() and autodefrag extent
size threshold.

For inode_should_defrag() it has a flexiable @small_write value. For
compressed extent is 16K, and for non-compressed extent it's 64K.

However for autodefrag extent size threshold, it's always fixed to the
default value (256K).

This means, the following write sequence will trigger autodefrag to
defrag ranges which didn't cause autodefrag:

 pwrite 0 8k
 sync
 pwrite 8k 128K
 sync

The later 128K write will also be considered as a defrag target (if
other conditions are met). While only that 8K write is really
triggering autodefrag.

Such behavior can cause extra IO for autodefrag.

This patch will close the gap, by copying the @small_write value into
inode_defrag, so that later autodefrag can use the same @small_write
value which triggered autodefrag.

With the existing transid value, this allows autodefrag really to scan
the ranges which triggered autodefrag.

Although this behavior change is mostly reducing the extent_thresh value
for autodefrag, I believe in the future we should allow users to specify
the autodefrag extent threshold through mount options, but that's an
other problem to consider in the future.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/file.c
fs/btrfs/inode.c