btrfs: add new flushing states for the delayed refs rsv
authorJosef Bacik <josef@toxicpanda.com>
Mon, 3 Dec 2018 15:20:35 +0000 (10:20 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Dec 2018 13:51:47 +0000 (14:51 +0100)
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>
fs/btrfs/ctree.h
fs/btrfs/extent-tree.c
include/trace/events/btrfs.h

index ab9d9ed20e0cf67fb59acc01feb1eb51a7405360..d07a23f15e22732252ea792bff4dcd025b605a3c 100644 (file)
@@ -2765,10 +2765,12 @@ enum btrfs_reserve_flush_enum {
 enum btrfs_flush_state {
        FLUSH_DELAYED_ITEMS_NR  =       1,
        FLUSH_DELAYED_ITEMS     =       2,
-       FLUSH_DELALLOC          =       3,
-       FLUSH_DELALLOC_WAIT     =       4,
-       ALLOC_CHUNK             =       5,
-       COMMIT_TRANS            =       6,
+       FLUSH_DELAYED_REFS_NR   =       3,
+       FLUSH_DELAYED_REFS      =       4,
+       FLUSH_DELALLOC          =       5,
+       FLUSH_DELALLOC_WAIT     =       6,
+       ALLOC_CHUNK             =       7,
+       COMMIT_TRANS            =       8,
 };
 
 int btrfs_alloc_data_chunk_ondemand(struct btrfs_inode *inode, u64 bytes);
index e2f6dbed0c631aefc173b4c8a2b31016b97cabb3..1b10c2fe7c7d805520e935479660bde3f8747236 100644 (file)
@@ -4938,6 +4938,20 @@ static void flush_space(struct btrfs_fs_info *fs_info,
                shrink_delalloc(fs_info, num_bytes * 2, num_bytes,
                                state == FLUSH_DELALLOC_WAIT);
                break;
+       case FLUSH_DELAYED_REFS_NR:
+       case FLUSH_DELAYED_REFS:
+               trans = btrfs_join_transaction(root);
+               if (IS_ERR(trans)) {
+                       ret = PTR_ERR(trans);
+                       break;
+               }
+               if (state == FLUSH_DELAYED_REFS_NR)
+                       nr = calc_reclaim_items_nr(fs_info, num_bytes);
+               else
+                       nr = 0;
+               btrfs_run_delayed_refs(trans, nr);
+               btrfs_end_transaction(trans);
+               break;
        case ALLOC_CHUNK:
                trans = btrfs_join_transaction(root);
                if (IS_ERR(trans)) {
index 4b8400f7d4fab7951235ce0757532dba0c7e6f3f..2887503e4d128fd3ab9caaea8f55cfc16bf07006 100644 (file)
@@ -1048,6 +1048,8 @@ TRACE_EVENT(btrfs_trigger_flush,
                { FLUSH_DELAYED_ITEMS,          "FLUSH_DELAYED_ITEMS"},         \
                { FLUSH_DELALLOC,               "FLUSH_DELALLOC"},              \
                { FLUSH_DELALLOC_WAIT,          "FLUSH_DELALLOC_WAIT"},         \
+               { FLUSH_DELAYED_REFS_NR,        "FLUSH_DELAYED_REFS_NR"},       \
+               { FLUSH_DELAYED_REFS,           "FLUSH_ELAYED_REFS"},           \
                { ALLOC_CHUNK,                  "ALLOC_CHUNK"},                 \
                { COMMIT_TRANS,                 "COMMIT_TRANS"})