Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 7/8] btrfs: fix may_commit_transaction to deal with no partial filling
Date: Fri, 16 Aug 2019 10:19:51 -0400	[thread overview]
Message-ID: <20190816141952.19369-8-josef@toxicpanda.com> (raw)
In-Reply-To: <20190816141952.19369-1-josef@toxicpanda.com>

Now that we aren't partially filling tickets we may have some slack
space left in the space_info.  We need to account for this in
may_commit_transaction, otherwise we may choose to not commit the
transaction despite it actually having enough space to satisfy our
ticket.

Calculate the free space we have in the space_info, if any.  Then check
to see if its >= the amount of bytes_needed after we've accounted for
the space being used by the delayed refs rsv.  If it's not subtract it
from the bytes_needed before doing the final pinned check.  If we still
don't have enough space then we are truly out of space.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/space-info.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index bd485be783b8..f79afdc04925 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -471,12 +471,19 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
 	struct btrfs_trans_handle *trans;
 	u64 bytes_needed;
 	u64 reclaim_bytes = 0;
+	u64 cur_free_bytes = 0;
 
 	trans = (struct btrfs_trans_handle *)current->journal_info;
 	if (trans)
 		return -EAGAIN;
 
 	spin_lock(&space_info->lock);
+	cur_free_bytes = btrfs_space_info_used(space_info, true);
+	if (cur_free_bytes < space_info->total_bytes)
+		cur_free_bytes = space_info->total_bytes - cur_free_bytes;
+	else
+		cur_free_bytes = 0;
+
 	if (!list_empty(&space_info->priority_tickets))
 		ticket = list_first_entry(&space_info->priority_tickets,
 					  struct reserve_ticket, list);
@@ -522,6 +529,18 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
 		goto commit;
 	bytes_needed -= reclaim_bytes;
 
+	/*
+	 * We don't partially fill tickets anymore, so we could have some free
+	 * bytes in the space_info already, just not enough to satisfy the
+	 * ticket.  If bytes_needed is already below cur_free_bytes after taking
+	 * away the delayed refs and delayed rsv's then we can commit.
+	 * Otherwise subtract our cur_free_bytes from bytes_needed before we
+	 * check pinned.
+	 */
+	if (bytes_needed <= cur_free_bytes)
+		goto commit;
+	bytes_needed -= cur_free_bytes;
+
 	if (__percpu_counter_compare(&space_info->total_bytes_pinned,
 				   bytes_needed,
 				   BTRFS_TOTAL_BYTES_PINNED_BATCH) < 0)
-- 
2.21.0


  parent reply	other threads:[~2019-08-16 14:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 14:19 [PATCH 0/8][v2] Rework reserve ticket handling Josef Bacik
2019-08-16 14:19 ` [PATCH 1/8] btrfs: do not allow reservations if we have pending tickets Josef Bacik
2019-08-19 12:54   ` Nikolay Borisov
2019-08-19 12:57     ` Josef Bacik
2019-08-16 14:19 ` [PATCH 2/8] btrfs: roll tracepoint into btrfs_space_info_update helper Josef Bacik
2019-08-16 14:19 ` [PATCH 3/8] btrfs: add space reservation tracepoint for reserved bytes Josef Bacik
2019-08-16 14:19 ` [PATCH 4/8] btrfs: rework btrfs_space_info_add_old_bytes Josef Bacik
2019-08-16 14:19 ` [PATCH 5/8] btrfs: refactor the ticket wakeup code Josef Bacik
2019-08-19 13:58   ` Nikolay Borisov
2019-08-16 14:19 ` [PATCH 6/8] btrfs: rework wake_all_tickets Josef Bacik
2019-08-19 14:49   ` Nikolay Borisov
2019-08-19 15:06     ` Josef Bacik
2019-08-20  7:51       ` Nikolay Borisov
2019-08-16 14:19 ` Josef Bacik [this message]
2019-08-20  8:20   ` [PATCH 7/8] btrfs: fix may_commit_transaction to deal with no partial filling Nikolay Borisov
2019-08-16 14:19 ` [PATCH 8/8] btrfs: remove orig_bytes from reserve_ticket Josef Bacik
2019-08-20  8:28   ` Nikolay Borisov
2019-08-21 14:07     ` 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=20190816141952.19369-8-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