All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: linux-xfs@vger.kernel.org, bfoster@redhat.com, david@fromorbit.com
Subject: [PATCH 4/6] xfs: always succeed at setting the reserve pool size
Date: Sun, 27 Mar 2022 09:58:39 -0700	[thread overview]
Message-ID: <164840031922.54920.3945394555613593655.stgit@magnolia> (raw)
In-Reply-To: <164840029642.54920.17464512987764939427.stgit@magnolia>

From: Darrick J. Wong <djwong@kernel.org>

Nowadays, xfs_mod_fdblocks will always choose to fill the reserve pool
with freed blocks before adding to fdblocks.  Therefore, we can change
the behavior of xfs_reserve_blocks slightly -- setting the target size
of the pool should always succeed, since a deficiency will eventually
be made up as blocks get freed.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_fsops.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)


diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 3c6d9d6836ef..5c2bea1e12a8 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -434,11 +434,14 @@ xfs_reserve_blocks(
 	 * The code below estimates how many blocks it can request from
 	 * fdblocks to stash in the reserve pool.  This is a classic TOCTOU
 	 * race since fdblocks updates are not always coordinated via
-	 * m_sb_lock.
+	 * m_sb_lock.  Set the reserve size even if there's not enough free
+	 * space to fill it because mod_fdblocks will refill an undersized
+	 * reserve when it can.
 	 */
 	free = percpu_counter_sum(&mp->m_fdblocks) -
 						xfs_fdblocks_unavailable(mp);
 	delta = request - mp->m_resblks;
+	mp->m_resblks = request;
 	if (delta > 0 && free > 0) {
 		/*
 		 * We'll either succeed in getting space from the free block
@@ -455,10 +458,8 @@ xfs_reserve_blocks(
 		 * Update the reserve counters if blocks have been successfully
 		 * allocated.
 		 */
-		if (!error) {
-			mp->m_resblks += fdblks_delta;
+		if (!error)
 			mp->m_resblks_avail += fdblks_delta;
-		}
 	}
 out:
 	if (outval) {


  parent reply	other threads:[~2022-03-27 16:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-27 16:58 [PATCHSET v4 0/6] xfs: fix incorrect reserve pool calculations and reporting Darrick J. Wong
2022-03-27 16:58 ` [PATCH 1/6] xfs: document the XFS_ALLOC_AGFL_RESERVE constant Darrick J. Wong
2022-03-28  1:18   ` Dave Chinner
2022-04-01  5:51   ` Christoph Hellwig
2022-03-27 16:58 ` [PATCH 2/6] xfs: don't include bnobt blocks when reserving free block pool Darrick J. Wong
2022-04-06 16:39   ` Christoph Hellwig
2022-03-27 16:58 ` [PATCH 3/6] xfs: remove infinite loop " Darrick J. Wong
2022-03-28  1:20   ` Dave Chinner
2022-04-06 16:40   ` Christoph Hellwig
2022-03-27 16:58 ` Darrick J. Wong [this message]
2022-03-28  1:21   ` [PATCH 4/6] xfs: always succeed at setting the reserve pool size Dave Chinner
2022-04-06 16:40   ` Christoph Hellwig
2022-03-27 16:58 ` [PATCH 5/6] xfs: fix overfilling of reserve pool Darrick J. Wong
2022-03-28  1:22   ` Dave Chinner
2022-04-06 16:42   ` Christoph Hellwig
2022-03-27 16:58 ` [PATCH 6/6] xfs: don't report reserved bnobt space as available Darrick J. Wong
2022-04-06 16:43   ` Christoph Hellwig

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=164840031922.54920.3945394555613593655.stgit@magnolia \
    --to=djwong@kernel.org \
    --cc=bfoster@redhat.com \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.