linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 06/10] btrfs: update may_commit_transaction to use the delayed refs rsv
Date: Mon,  3 Dec 2018 10:20:34 -0500	[thread overview]
Message-ID: <20181203152038.21388-7-josef@toxicpanda.com> (raw)
In-Reply-To: <20181203152038.21388-1-josef@toxicpanda.com>

Any space used in the delayed_refs_rsv will be freed up by a transaction
commit, so instead of just counting the pinned space we also need to
account for any space in the delayed_refs_rsv when deciding if it will
make a different to commit the transaction to satisfy our space
reservation.  If we have enough bytes to satisfy our reservation ticket
then we are good to go, otherwise subtract out what space we would gain
back by committing the transaction and compare that against the pinned
space to make our decision.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index aa0a638d0263..63ff9d832867 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4843,8 +4843,10 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
 {
 	struct reserve_ticket *ticket = NULL;
 	struct btrfs_block_rsv *delayed_rsv = &fs_info->delayed_block_rsv;
+	struct btrfs_block_rsv *delayed_refs_rsv = &fs_info->delayed_refs_rsv;
 	struct btrfs_trans_handle *trans;
-	u64 bytes;
+	u64 bytes_needed;
+	u64 reclaim_bytes = 0;
 
 	trans = (struct btrfs_trans_handle *)current->journal_info;
 	if (trans)
@@ -4857,15 +4859,15 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
 	else if (!list_empty(&space_info->tickets))
 		ticket = list_first_entry(&space_info->tickets,
 					  struct reserve_ticket, list);
-	bytes = (ticket) ? ticket->bytes : 0;
+	bytes_needed = (ticket) ? ticket->bytes : 0;
 	spin_unlock(&space_info->lock);
 
-	if (!bytes)
+	if (!bytes_needed)
 		return 0;
 
 	/* See if there is enough pinned space to make this reservation */
 	if (__percpu_counter_compare(&space_info->total_bytes_pinned,
-				   bytes,
+				   bytes_needed,
 				   BTRFS_TOTAL_BYTES_PINNED_BATCH) >= 0)
 		goto commit;
 
@@ -4877,14 +4879,18 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
 		return -ENOSPC;
 
 	spin_lock(&delayed_rsv->lock);
-	if (delayed_rsv->size > bytes)
-		bytes = 0;
-	else
-		bytes -= delayed_rsv->size;
+	reclaim_bytes += delayed_rsv->reserved;
 	spin_unlock(&delayed_rsv->lock);
 
+	spin_lock(&delayed_refs_rsv->lock);
+	reclaim_bytes += delayed_refs_rsv->reserved;
+	spin_unlock(&delayed_refs_rsv->lock);
+	if (reclaim_bytes >= bytes_needed)
+		goto commit;
+	bytes_needed -= reclaim_bytes;
+
 	if (__percpu_counter_compare(&space_info->total_bytes_pinned,
-				   bytes,
+				   bytes_needed,
 				   BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0) {
 		return -ENOSPC;
 	}
-- 
2.14.3


  parent reply	other threads:[~2018-12-03 15:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-03 15:20 [PATCH 00/10][V2] Delayed refs rsv Josef Bacik
2018-12-03 15:20 ` [PATCH 01/10] btrfs: add btrfs_delete_ref_head helper Josef Bacik
2018-12-06 12:32   ` Nikolay Borisov
2018-12-03 15:20 ` [PATCH 02/10] btrfs: add cleanup_ref_head_accounting helper Josef Bacik
2018-12-06 12:38   ` Nikolay Borisov
2018-12-03 15:20 ` [PATCH 03/10] btrfs: cleanup extent_op handling Josef Bacik
2018-12-03 15:20 ` [PATCH 04/10] btrfs: only track ref_heads in delayed_ref_updates Josef Bacik
2018-12-07 13:01   ` Nikolay Borisov
2018-12-13 16:36     ` David Sterba
2018-12-03 15:20 ` [PATCH 05/10] btrfs: introduce delayed_refs_rsv Josef Bacik
2018-12-07 14:45   ` Nikolay Borisov
2018-12-13 16:49     ` David Sterba
2018-12-03 15:20 ` Josef Bacik [this message]
2018-12-06 12:51   ` [PATCH 06/10] btrfs: update may_commit_transaction to use the delayed refs rsv Nikolay Borisov
2018-12-03 15:20 ` [PATCH 07/10] btrfs: add new flushing states for " Josef Bacik
2018-12-03 15:20 ` [PATCH 08/10] btrfs: rework btrfs_check_space_for_delayed_refs Josef Bacik
2018-12-06 16:52   ` Nikolay Borisov
2018-12-06 17:54     ` David Sterba
2018-12-07  7:09       ` Nikolay Borisov
2018-12-07  9:57         ` Nikolay Borisov
2018-12-13 16:44         ` David Sterba
2019-01-14  6:28   ` Qu Wenruo
2018-12-03 15:20 ` [PATCH 09/10] btrfs: don't run delayed refs in the end transaction logic Josef Bacik
2018-12-06 16:43   ` Nikolay Borisov
2018-12-03 15:20 ` [PATCH 10/10] btrfs: fix truncate throttling Josef Bacik
2018-12-06 15:56 ` [PATCH 00/10][V2] Delayed refs rsv David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181203152038.21388-7-josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).