]> git.hungrycats.org Git - linux/commitdiff
zygo: btrfs: use a stable rolling average (1000 sec, 1000 refs, 0.75 decay, with...
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Tue, 25 Feb 2020 18:14:19 +0000 (13:14 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 6 Mar 2021 14:44:27 +0000 (09:44 -0500)
zygo: btrfs: use a stable rolling average (300 sec, 0.75 decay, with noisy debug)

zygo: btrfs: what does the _kernel_ think the delayed ref runtime is?

zygo: btrfs: slow down the swings

zygo: btrfs: proper rolling average

zygo: btrfs: weight older data more

zygo: btrfs: less noisy rolling average
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
zygo: btrfs: average over 300 sec

zygo: btrfs: slow down average calculations (1000 seconds or 1000 delayed refs)
(cherry picked from commit d26a857e08612d7dce8fa665bcce6fe6c0598e5e)
(cherry picked from commit 052469e5fd52d6353dd25f6efe2f4f8c37b81bdc)
(cherry picked from commit a30caddd802bd79f7c45756de36d8a9616b92d99)

fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c

index 40ec3393d2a1732a9f3bb7d267a1de3982f59524..9a3e7adfd9bc9e8e60605a6e72d3eb82c55fac5e 100644 (file)
@@ -640,6 +640,8 @@ struct btrfs_fs_info {
        u64 generation;
        u64 last_trans_committed;
        u64 avg_delayed_ref_runtime;
+       u64 avg_delayed_ref_count;
+       u64 avg_delayed_ref_time;
 
        /*
         * this is updated to the current trans every time a full commit
index c2576c5fe62ed07e95450ef83946810d495eef33..981234032a34329452e7e07c2778033be54d3257 100644 (file)
@@ -2830,6 +2830,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
        fs_info->tree_mod_log = RB_ROOT;
        fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
        fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */
+       fs_info->avg_delayed_ref_count = 64;
+       fs_info->avg_delayed_ref_time = NSEC_PER_SEC;
        /* readahead state */
        INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
        spin_lock_init(&fs_info->reada_lock);
index 78ad31a59e59e0755f678e181c9ffe3c5d3319f2..b5f24bb879713af9be0a440908c2d4e3489ae5d4 100644 (file)
@@ -2063,15 +2063,28 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
        if (actual_count > 0) {
                u64 runtime = ktime_to_ns(ktime_sub(ktime_get(), start));
                u64 avg;
+               u64 time = 0;
+               u64 count = 0;
 
                /*
                 * We weigh the current average higher than our current runtime
                 * to avoid large swings in the average.
                 */
                spin_lock(&delayed_refs->lock);
-               avg = fs_info->avg_delayed_ref_runtime * 3 + runtime;
-               fs_info->avg_delayed_ref_runtime = avg >> 2;    /* div by 4 */
+               fs_info->avg_delayed_ref_count += actual_count;
+               fs_info->avg_delayed_ref_time += runtime;
+               avg = fs_info->avg_delayed_ref_time / fs_info->avg_delayed_ref_count;
+               if (fs_info->avg_delayed_ref_time >= NSEC_PER_SEC * 1000 && fs_info->avg_delayed_ref_count > 1000) {
+                       fs_info->avg_delayed_ref_time = fs_info->avg_delayed_ref_time * 3 / 4;
+                       fs_info->avg_delayed_ref_count = fs_info->avg_delayed_ref_count * 3 / 4;
+                       time = fs_info->avg_delayed_ref_time;
+                       count = fs_info->avg_delayed_ref_count;
+               }
+               fs_info->avg_delayed_ref_runtime = avg;
                spin_unlock(&delayed_refs->lock);
+               if (time || count) {
+                       printk(KERN_ERR "avg_delayed_ref_runtime = %llu, time = %llu, count = %llu\n", avg, time, count);
+               }
        }
        return 0;
 }