diff mbox series

[06/13] btrfs: add a mode for delayed ref time based throttling

Message ID 20200313212330.149024-7-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Throttle delayed refs based on time | expand

Commit Message

Josef Bacik March 13, 2020, 9:23 p.m. UTC
Currently we only use btrfs_should_throttle_delayed_refs in the case
where we want to pre-emptively stop what we're doing and throttle
delayed refs in some way.  However we're going to use this function for
all transaction ending, so add a flag so we can toggle between the
maximum theoretical runtime and our "maybe we should start flushing"
runtime.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/delayed-ref.c | 9 +++++----
 fs/btrfs/delayed-ref.h | 3 ++-
 fs/btrfs/inode.c       | 3 ++-
 fs/btrfs/transaction.c | 2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index e28565dc4288..6e9fa03be87d 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -50,7 +50,8 @@  bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info)
 	return ret;
 }
 
-bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans)
+bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans,
+					bool for_throttle)
 {
 	u64 num_entries =
 		atomic_read(&trans->transaction->delayed_refs.num_entries);
@@ -62,9 +63,9 @@  bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans)
 	val = num_entries * avg_runtime;
 	if (val >= NSEC_PER_SEC)
 		return true;
-	if (val >= NSEC_PER_SEC / 2)
-		return true;
-	return false;
+	if (!for_throttle)
+		return false;
+	return (val >= NSEC_PER_SEC / 2);
 }
 
 /**
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index 9a07480b497b..c0ae440434af 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -371,7 +371,8 @@  int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
 void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info,
 				       struct btrfs_block_rsv *src,
 				       u64 num_bytes);
-bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans);
+bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans,
+					bool for_throttle);
 bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info);
 
 /*
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d3e75e04a0a0..ad0f0961a711 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4349,7 +4349,8 @@  int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
 				break;
 			}
 			if (be_nice) {
-				if (btrfs_should_throttle_delayed_refs(trans) ||
+				if (btrfs_should_throttle_delayed_refs(trans,
+								       true) ||
 				    btrfs_check_space_for_delayed_refs(fs_info))
 					should_throttle = true;
 			}
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index f6eecb402f5b..b0d82e1a6a6e 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -865,7 +865,7 @@  int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
 	    cur_trans->delayed_refs.flushing)
 		return 1;
 
-	if (btrfs_should_throttle_delayed_refs(trans) ||
+	if (btrfs_should_throttle_delayed_refs(trans, true) ||
 	    btrfs_check_space_for_delayed_refs(fs_info))
 		return 1;