OSDN Git Service

btrfs: autodefrag: only scan one inode once
authorQu Wenruo <wqu@suse.com>
Tue, 22 Feb 2022 17:20:59 +0000 (18:20 +0100)
committerDavid Sterba <dsterba@suse.com>
Wed, 23 Feb 2022 16:55:01 +0000 (17:55 +0100)
commit26fbac2517fcad34fa3f950151fd4c0240fb2935
tree55111ce5c59cf94c95b57dd1398526cc2a56c079
parent199257a78bb01341c3ba6e85bdcf3a2e6e452c6d
btrfs: autodefrag: only scan one inode once

Although we have btrfs_requeue_inode_defrag(), for autodefrag we are
still just exhausting all inode_defrag items in the tree.

This means, it doesn't make much difference to requeue an inode_defrag,
other than scan the inode from the beginning till its end.

Change the behaviour to always scan from offset 0 of an inode, and till
the end.

By this we get the following benefit:

- Straight-forward code

- No more re-queue related check

- Fewer members in inode_defrag

We still keep the same btrfs_get_fs_root() and btrfs_iget() check for
each loop, and added extra should_auto_defrag() check per-loop.

Note: the patch needs to be backported and is intentionally written
to minimize the diff size, code will be cleaned up later.

CC: stable@vger.kernel.org # 5.16
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c