Skip to content

Commit 413df72

Browse files
josefbacikkdave
authored andcommitted
btrfs: add new flushing states for the delayed refs rsv
A nice thing we gain with the delayed refs rsv is the ability to flush the delayed refs on demand to deal with enospc pressure. Add states to flush delayed refs on demand, and this will allow us to remove a lot of ad-hoc work around checking to see if we should commit the transaction to run our delayed refs. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 4c8edbc commit 413df72

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

fs/btrfs/ctree.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,10 +2765,12 @@ enum btrfs_reserve_flush_enum {
27652765
enum btrfs_flush_state {
27662766
FLUSH_DELAYED_ITEMS_NR = 1,
27672767
FLUSH_DELAYED_ITEMS = 2,
2768-
FLUSH_DELALLOC = 3,
2769-
FLUSH_DELALLOC_WAIT = 4,
2770-
ALLOC_CHUNK = 5,
2771-
COMMIT_TRANS = 6,
2768+
FLUSH_DELAYED_REFS_NR = 3,
2769+
FLUSH_DELAYED_REFS = 4,
2770+
FLUSH_DELALLOC = 5,
2771+
FLUSH_DELALLOC_WAIT = 6,
2772+
ALLOC_CHUNK = 7,
2773+
COMMIT_TRANS = 8,
27722774
};
27732775

27742776
int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes);

fs/btrfs/extent-tree.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4938,6 +4938,20 @@ static void flush_space(struct btrfs_fs_info *fs_info,
49384938
shrink_delalloc(fs_info, num_bytes * 2, num_bytes,
49394939
state == FLUSH_DELALLOC_WAIT);
49404940
break;
4941+
case FLUSH_DELAYED_REFS_NR:
4942+
case FLUSH_DELAYED_REFS:
4943+
trans = btrfs_join_transaction(root);
4944+
if (IS_ERR(trans)) {
4945+
ret = PTR_ERR(trans);
4946+
break;
4947+
}
4948+
if (state == FLUSH_DELAYED_REFS_NR)
4949+
nr = calc_reclaim_items_nr(fs_info, num_bytes);
4950+
else
4951+
nr = 0;
4952+
btrfs_run_delayed_refs(trans, nr);
4953+
btrfs_end_transaction(trans);
4954+
break;
49414955
case ALLOC_CHUNK:
49424956
trans = btrfs_join_transaction(root);
49434957
if (IS_ERR(trans)) {

include/trace/events/btrfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,8 @@ TRACE_EVENT(btrfs_trigger_flush,
10481048
{ FLUSH_DELAYED_ITEMS, "FLUSH_DELAYED_ITEMS"}, \
10491049
{ FLUSH_DELALLOC, "FLUSH_DELALLOC"}, \
10501050
{ FLUSH_DELALLOC_WAIT, "FLUSH_DELALLOC_WAIT"}, \
1051+
{ FLUSH_DELAYED_REFS_NR, "FLUSH_DELAYED_REFS_NR"}, \
1052+
{ FLUSH_DELAYED_REFS, "FLUSH_ELAYED_REFS"}, \
10511053
{ ALLOC_CHUNK, "ALLOC_CHUNK"}, \
10521054
{ COMMIT_TRANS, "COMMIT_TRANS"})
10531055

0 commit comments

Comments
 (0)