From patchwork Thu Jun 13 20:27:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13697451 Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C23A2F50 for ; Thu, 13 Jun 2024 20:35:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.212.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310911; cv=pass; b=Eh8otyRy/0AOZ8OiyVKAUzaE4+ysIVPkBHkmEEP6omcoQDLl/tgO8VxT+Tgz1Xs3nYNCvexYG9mgeFNdiXVI7/5kRC7R9b5I/NRNKOLASdCtG9sBjq3M3bhh3aLZCK5kD0ETcJi8SKf8AzrsDYsMIE/aKpkF11eGXKrkoGXt7dI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310911; c=relaxed/simple; bh=kgQYnBrCdFlJPQrtHghs5FV9jeOUmrC41FJ6dOK2GAU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=J3Go8UBDOkpKfgvO5WZJpyQz2ut4qzMHmeatydlHzeqyyK28cHm1ZGZ+bRu+NybROURy+MnYE/jAfh4WCYs56IrnDvbCXUoCmwff1O9XMWFCZPnwzYcry32qsX70X7R+z/z3broTRQyL/LL1RGNOHe9LXvqfL6qMRreJMihOlGw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=jY6y+7iR; arc=pass smtp.client-ip=23.83.212.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="jY6y+7iR" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id A95D8943416 for ; Thu, 13 Jun 2024 20:27:37 +0000 (UTC) Received: from pdx1-sub0-mail-a231.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9BD8A94336C for ; Thu, 13 Jun 2024 20:27:36 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1718310456; a=rsa-sha256; cv=none; b=mkNpErKHpa1D9HGP4PW/6DBfaPFIFfQoG5dOXqmAn4qTPzWQAmxI2VaboKvHA1f2ZSTnmw jTf9P2mC9aHER5rRobcPO5SvRFgS4KpkSLAv5jOta7dK/xpknIkqogkmicqnjVDNKQRD4i 6SDZeax59OV5O/OEEUDPoVegvBqXG/xpUk+0DGwvwTl91UeRwvhTItZitEYnfLMm7nmGzW X70SewaioMW+k9fv0Oyj8ip7pOUcMe6Tmcb82ByQqrNoclnuOeUlAbPL5dufVI34ohnxPw 6lcASgOSrL8Y1L0eMLM/U+tPi6RQ/bAYRUpogLxrZjWjaNVLJ9vfkmfZJbDrlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1718310456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1iSCtRGrKFJDNMmzLAtrQCKn5WonABpNq9YSs++ns8w=; b=pbVfKSjoqE2bVD5Pn69d4ahg+x+UXd8tRTMsznFeE9lRhMUqnT04LW/IF90ipD63Kpn+Tm sQgFwb9tVZOaVMnscbiGzX36Bi5LjtPYEx3JgmFOM1pk8yho5YSHqzUONIMzoWviCLPLsE OQw6omyTJotkWftKEHA4geUiCOKC+T6aAUu0oD0g8To1KiW4Z+uvEu/+lhnNXnRAD2Vlza myU0W8nF6G5/HlRbkodozQO4yrryxb8AlGY0OXBHmnp4HHv9uGlX9QlNbPXImp4+JTo9qY 8CCG1irSGq475K08KfJxhpyPlxwY/EsQKKlmBKONcjUlJGRR0uYdJoxSJizeAA== ARC-Authentication-Results: i=1; rspamd-79677bdb95-kt8wt; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Trade-Grain: 71b4e99938561c5f_1718310457630_367315211 X-MC-Loop-Signature: 1718310457629:4223977573 X-MC-Ingress-Time: 1718310457629 Received: from pdx1-sub0-mail-a231.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.110.173.217 (trex/6.9.2); Thu, 13 Jun 2024 20:27:37 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a231.dreamhost.com (Postfix) with ESMTPSA id 4W0Yqr2vs5z1y for ; Thu, 13 Jun 2024 13:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1718310456; bh=1iSCtRGrKFJDNMmzLAtrQCKn5WonABpNq9YSs++ns8w=; h=Date:From:To:Cc:Subject:Content-Type; b=jY6y+7iR9wSvTbZn7xqUy/wEJfrO9RhC2WG9v0puqW22MS5zcFTTLiU6MbpEXpgqE 3p80As4RfjzqVUrBNQlGeozlXVRVdmoJSd1dWNmTifgRcRFveY/7LIacfNkd6uo6ea FIHPTm1KpfXovJ0mflyri0ADrVp6dLsJrpNkv6vKKCCZYfa+JRnM6NkqAvCyB9H1zK WbIgPh6luZ3kPCV4WM/jTMYCw7xvU6qOGcTy60hhBcBIwvbh+KvLC3tvwOGCNHnBtR 3iQU7R59mWvQ/VDiq7uz0mMMJFEgpIdbYqe4x8A5M4n32DR2Uvk1COXEIKXfnAiCzn H7A/e7aStmBYQ== Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e006b by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 13 Jun 2024 13:27:26 -0700 Date: Thu, 13 Jun 2024 13:27:26 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Gao Xiang , linux-xfs@vger.kernel.org Subject: [RFC PATCH 1/4] xfs: resurrect the AGFL reservation Message-ID: <0dfbe8d00d2be53999b20e336641ba3d60306ffa.1718232004.git.kjlx@templeofstupid.com> References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Transactions that perform multiple allocations may inadvertently run out of space after the first allocation selects an AG that appears to have enough available space. The problem occurs when the allocation in the transaction splits freespace b-trees but the second allocation does not have enough available space to refill the AGFL. This results in an aborted transaction and a filesystem shutdown. In this author's case, it's frequently encountered in the xfs_bmap_extents_to_btree path on a write to an AG that's almost reached its limits. The AGFL reservation allows us to save some blocks to refill the AGFL to its minimum level in an Nth allocation, and to prevent allocations from proceeding when there's not enough reserved space to accommodate the refill. This patch just brings back the reservation and does the plumbing. The policy decisions about which allocations to allow will be in a subsequent patch. This implementation includes space for the bnobt and cnobt in the reserve. This was done largely because the AGFL reserve stubs appeared to already be doing it this way. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_ag.h | 2 ++ fs/xfs/libxfs/xfs_ag_resv.c | 54 ++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_ag_resv.h | 4 +++ fs/xfs/libxfs/xfs_alloc.c | 43 +++++++++++++++++++++++- fs/xfs/libxfs/xfs_alloc.h | 3 +- fs/xfs/libxfs/xfs_alloc_btree.c | 59 +++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_alloc_btree.h | 5 +++ fs/xfs/libxfs/xfs_rmap_btree.c | 5 +++ fs/xfs/scrub/fscounters.c | 1 + 9 files changed, 161 insertions(+), 15 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h index 35de09a2516c..40bff82f2b7e 100644 --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -62,6 +62,8 @@ struct xfs_perag { struct xfs_ag_resv pag_meta_resv; /* Blocks reserved for the reverse mapping btree. */ struct xfs_ag_resv pag_rmapbt_resv; + /* Blocks reserved for the AGFL. */ + struct xfs_ag_resv pag_agfl_resv; /* for rcu-safe freeing */ struct rcu_head rcu_head; diff --git a/fs/xfs/libxfs/xfs_ag_resv.c b/fs/xfs/libxfs/xfs_ag_resv.c index 216423df939e..db1d416f6ac8 100644 --- a/fs/xfs/libxfs/xfs_ag_resv.c +++ b/fs/xfs/libxfs/xfs_ag_resv.c @@ -17,6 +17,7 @@ #include "xfs_trans.h" #include "xfs_rmap_btree.h" #include "xfs_btree.h" +#include "xfs_alloc_btree.h" #include "xfs_refcount_btree.h" #include "xfs_ialloc_btree.h" #include "xfs_ag.h" @@ -75,12 +76,14 @@ xfs_ag_resv_critical( switch (type) { case XFS_AG_RESV_METADATA: - avail = pag->pagf_freeblks - pag->pag_rmapbt_resv.ar_reserved; + avail = pag->pagf_freeblks - pag->pag_rmapbt_resv.ar_reserved - + pag->pag_agfl_resv.ar_reserved; orig = pag->pag_meta_resv.ar_asked; break; case XFS_AG_RESV_RMAPBT: avail = pag->pagf_freeblks + pag->pagf_flcount - - pag->pag_meta_resv.ar_reserved; + pag->pag_meta_resv.ar_reserved - + pag->pag_agfl_resv.ar_reserved; orig = pag->pag_rmapbt_resv.ar_asked; break; default: @@ -107,10 +110,14 @@ xfs_ag_resv_needed( { xfs_extlen_t len; - len = pag->pag_meta_resv.ar_reserved + pag->pag_rmapbt_resv.ar_reserved; + len = pag->pag_meta_resv.ar_reserved + + pag->pag_rmapbt_resv.ar_reserved + + pag->pag_agfl_resv.ar_reserved; + switch (type) { case XFS_AG_RESV_METADATA: case XFS_AG_RESV_RMAPBT: + case XFS_AG_RESV_AGFL: len -= xfs_perag_resv(pag, type)->ar_reserved; break; case XFS_AG_RESV_NONE: @@ -144,7 +151,7 @@ __xfs_ag_resv_free( * considered "free", so whatever was reserved at mount time must be * given back at umount. */ - if (type == XFS_AG_RESV_RMAPBT) + if (type == XFS_AG_RESV_RMAPBT || type == XFS_AG_RESV_AGFL) oldresv = resv->ar_orig_reserved; else oldresv = resv->ar_reserved; @@ -161,6 +168,7 @@ xfs_ag_resv_free( { __xfs_ag_resv_free(pag, XFS_AG_RESV_RMAPBT); __xfs_ag_resv_free(pag, XFS_AG_RESV_METADATA); + __xfs_ag_resv_free(pag, XFS_AG_RESV_AGFL); } static int @@ -180,11 +188,13 @@ __xfs_ag_resv_init( switch (type) { case XFS_AG_RESV_RMAPBT: + case XFS_AG_RESV_AGFL: /* - * Space taken by the rmapbt is not subtracted from fdblocks - * because the rmapbt lives in the free space. Here we must - * subtract the entire reservation from fdblocks so that we - * always have blocks available for rmapbt expansion. + * Space taken by the rmapbt and agfl are not subtracted from + * fdblocks because they both live in the free space. Here we + * must subtract the entire reservation from fdblocks so that we + * always have blocks available for rmapbt expansion and agfl + * refilling. */ hidden_space = ask; break; @@ -299,6 +309,25 @@ xfs_ag_resv_init( has_resv = true; } + /* Create the AGFL reservation */ + if (pag->pag_agfl_resv.ar_asked == 0) { + ask = used = 0; + + error = xfs_allocbt_calc_reserves(mp, tp, pag, &ask, &used); + if (error) + goto out; + + error = xfs_alloc_agfl_calc_reserves(mp, tp, pag, &ask, &used); + if (error) + goto out; + + error = __xfs_ag_resv_init(pag, XFS_AG_RESV_AGFL, ask, used); + if (error) + goto out; + if (ask) + has_resv = true; + } + out: /* * Initialize the pagf if we have at least one active reservation on the @@ -324,7 +353,8 @@ xfs_ag_resv_init( */ if (!error && xfs_perag_resv(pag, XFS_AG_RESV_METADATA)->ar_reserved + - xfs_perag_resv(pag, XFS_AG_RESV_RMAPBT)->ar_reserved > + xfs_perag_resv(pag, XFS_AG_RESV_RMAPBT)->ar_reserved + + xfs_perag_resv(pag, XFS_AG_RESV_AGFL)->ar_reserved > pag->pagf_freeblks + pag->pagf_flcount) error = -ENOSPC; } @@ -347,7 +377,6 @@ xfs_ag_resv_alloc_extent( switch (type) { case XFS_AG_RESV_AGFL: - return; case XFS_AG_RESV_METADATA: case XFS_AG_RESV_RMAPBT: resv = xfs_perag_resv(pag, type); @@ -364,7 +393,7 @@ xfs_ag_resv_alloc_extent( len = min_t(xfs_extlen_t, args->len, resv->ar_reserved); resv->ar_reserved -= len; - if (type == XFS_AG_RESV_RMAPBT) + if (type == XFS_AG_RESV_RMAPBT || type == XFS_AG_RESV_AGFL) return; /* Allocations of reserved blocks only need on-disk sb updates... */ xfs_trans_mod_sb(args->tp, XFS_TRANS_SB_RES_FDBLOCKS, -(int64_t)len); @@ -389,7 +418,6 @@ xfs_ag_resv_free_extent( switch (type) { case XFS_AG_RESV_AGFL: - return; case XFS_AG_RESV_METADATA: case XFS_AG_RESV_RMAPBT: resv = xfs_perag_resv(pag, type); @@ -406,7 +434,7 @@ xfs_ag_resv_free_extent( leftover = min_t(xfs_extlen_t, len, resv->ar_asked - resv->ar_reserved); resv->ar_reserved += leftover; - if (type == XFS_AG_RESV_RMAPBT) + if (type == XFS_AG_RESV_RMAPBT || type == XFS_AG_RESV_AGFL) return; /* Freeing into the reserved pool only requires on-disk update... */ xfs_trans_mod_sb(tp, XFS_TRANS_SB_RES_FDBLOCKS, len); diff --git a/fs/xfs/libxfs/xfs_ag_resv.h b/fs/xfs/libxfs/xfs_ag_resv.h index ff20ed93de77..ea2c16dfb843 100644 --- a/fs/xfs/libxfs/xfs_ag_resv.h +++ b/fs/xfs/libxfs/xfs_ag_resv.h @@ -28,6 +28,8 @@ xfs_perag_resv( return &pag->pag_meta_resv; case XFS_AG_RESV_RMAPBT: return &pag->pag_rmapbt_resv; + case XFS_AG_RESV_AGFL: + return &pag->pag_agfl_resv; default: return NULL; } @@ -48,6 +50,8 @@ xfs_ag_resv_rmapbt_alloc( args.len = 1; pag = xfs_perag_get(mp, agno); + /* Transfer this reservation from the AGFL to RMAPBT */ + xfs_ag_resv_free_extent(pag, XFS_AG_RESV_AGFL, NULL, 1); xfs_ag_resv_alloc_extent(pag, XFS_AG_RESV_RMAPBT, &args); xfs_perag_put(pag); } diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 6c55a6e88eba..d70d027a8178 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -1176,12 +1176,14 @@ xfs_alloc_ag_vextent_small( /* * If we're feeding an AGFL block to something that doesn't live in the - * free space, we need to clear out the OWN_AG rmap. + * free space, we need to clear out the OWN_AG rmap and remove it from + * the AGFL reservation. */ error = xfs_rmap_free(args->tp, args->agbp, args->pag, fbno, 1, &XFS_RMAP_OINFO_AG); if (error) goto error; + xfs_ag_resv_free_extent(args->pag, XFS_AG_RESV_AGFL, args->tp, 1); *stat = 0; return 0; @@ -2778,6 +2780,43 @@ xfs_exact_minlen_extent_available( } #endif +/* + * Work out how many blocks to reserve for the AGFL as well as how many are in + * use currently. + */ +int +xfs_alloc_agfl_calc_reserves( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct xfs_perag *pag, + xfs_extlen_t *ask, + xfs_extlen_t *used) +{ + struct xfs_buf *agbp; + struct xfs_agf *agf; + xfs_extlen_t agfl_blocks; + xfs_extlen_t list_len; + int error; + + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); + if (error) + return error; + + agf = agbp->b_addr; + agfl_blocks = xfs_alloc_min_freelist(mp, NULL); + list_len = be32_to_cpu(agf->agf_flcount); + xfs_trans_brelse(tp, agbp); + + /* + * Reserve enough space to refill AGFL to minimum fullness if btrees are + * at maximum height. + */ + *ask += agfl_blocks; + *used += list_len; + + return error; +} + /* * Decide whether to use this allocation group for this allocation. * If so, fix up the btree freelist's size. @@ -2944,6 +2983,8 @@ xfs_alloc_fix_freelist( if (error) goto out_agflbp_relse; + xfs_ag_resv_alloc_extent(targs.pag, targs.resv, &targs); + /* * Put each allocated block on the list. */ diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 0b956f8b9d5a..8cbdfb62ac14 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -80,7 +80,8 @@ int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp, int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp, struct xfs_buf *agfbp, struct xfs_buf *agflbp, xfs_agblock_t bno, int btreeblk); - +int xfs_alloc_agfl_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, + struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used); /* * Compute and fill in value of m_alloc_maxlevels. */ diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btree.c index 6ef5ddd89600..9c20f85a459d 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.c +++ b/fs/xfs/libxfs/xfs_alloc_btree.c @@ -671,6 +671,65 @@ xfs_allocbt_calc_size( return xfs_btree_calc_size(mp->m_alloc_mnr, len); } +/* + * Calculate the maximum alloc btree size. This is for a single allocbt. + * Callers wishing to compute both the size of the bnobt and cnobt must double + * this result. + */ +xfs_extlen_t +xfs_allocbt_max_size( + struct xfs_mount *mp, + xfs_agblock_t agblocks) +{ + + /* Don't proceed if uninitialized. Can happen in mkfs. */ + if (mp->m_alloc_mxr[0] == 0) + return 0; + + return xfs_allocbt_calc_size(mp, agblocks); +} + +/* + * Work out how many blocks to reserve for the bnobt and the cnobt as well as + * how many blocks are in use by these trees. + */ +int +xfs_allocbt_calc_reserves( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct xfs_perag *pag, + xfs_extlen_t *ask, + xfs_extlen_t *used) +{ + struct xfs_buf *agbp; + struct xfs_agf *agf; + xfs_agblock_t agblocks; + xfs_extlen_t tree_len; + int error; + + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); + if (error) + return error; + + agf = agbp->b_addr; + agblocks = be32_to_cpu(agf->agf_length); + tree_len = be32_to_cpu(agf->agf_btreeblks); + xfs_trans_brelse(tp, agbp); + + /* + * The log is permanently allocated. The space it occupies will never be + * available for btree expansion. Pretend the space is not there. + */ + if (xfs_ag_contains_log(mp, pag->pag_agno)) + agblocks -= mp->m_sb.sb_logblocks; + + /* Reserve 1% of the AG or enough for one block per record per tree. */ + *ask += max(agblocks / 100, 2 * xfs_allocbt_max_size(mp, agblocks)); + *used += tree_len; + + return error; +} + int __init xfs_allocbt_init_cur_cache(void) { diff --git a/fs/xfs/libxfs/xfs_alloc_btree.h b/fs/xfs/libxfs/xfs_alloc_btree.h index 155b47f231ab..8334195e2462 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.h +++ b/fs/xfs/libxfs/xfs_alloc_btree.h @@ -56,6 +56,11 @@ struct xfs_btree_cur *xfs_cntbt_init_cursor(struct xfs_mount *mp, extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int); extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp, unsigned long long len); +extern xfs_extlen_t xfs_allocbt_max_size(struct xfs_mount *mp, + xfs_agblock_t agblocks); + +extern int xfs_allocbt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, + struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used); void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur, struct xfs_trans *tp, struct xfs_buf *agbp); diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c index 9e759efa81cc..49b1652f715a 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -121,6 +121,7 @@ xfs_rmapbt_free_block( struct xfs_buf *agbp = cur->bc_ag.agbp; struct xfs_agf *agf = agbp->b_addr; struct xfs_perag *pag = cur->bc_ag.pag; + struct xfs_alloc_arg args = { NULL }; xfs_agblock_t bno; int error; @@ -135,6 +136,10 @@ xfs_rmapbt_free_block( XFS_EXTENT_BUSY_SKIP_DISCARD); xfs_ag_resv_free_extent(pag, XFS_AG_RESV_RMAPBT, NULL, 1); + args.len = 1; + /* Transfer this reservation back to the AGFL. */ + xfs_ag_resv_alloc_extent(pag, XFS_AG_RESV_AGFL, &args); + return 0; } diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c index 1d3e98346933..fec4aa13052a 100644 --- a/fs/xfs/scrub/fscounters.c +++ b/fs/xfs/scrub/fscounters.c @@ -338,6 +338,7 @@ xchk_fscount_aggregate_agcounts( */ fsc->fdblocks -= pag->pag_meta_resv.ar_reserved; fsc->fdblocks -= pag->pag_rmapbt_resv.ar_orig_reserved; + fsc->fdblocks -= pag->pag_agfl_resv.ar_orig_reserved; } if (pag) From patchwork Thu Jun 13 20:27:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13697453 Received: from panther.cherry.relay.mailchannels.net (panther.cherry.relay.mailchannels.net [23.83.223.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 387B513B58A for ; Thu, 13 Jun 2024 20:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.223.141 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718311410; cv=pass; b=mhBjqTlKSMmszGv5AbhDJJIXXS/xGHcVBTTfr8CleeTRja3lsxoXRlpGAezQ5o5gTc/cpiVCMGZW5jdlERL1xJPUJ0cyF8MNYvW8D4qeMjIflJcP0CtRVQoBt1lpyBIEME0lrj4MouqC9P6PTxbCTQ+WqpHGaCoGOLC18qUJlJ0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718311410; c=relaxed/simple; bh=RpBC65bdovXusXADyGwc238tThmOsMBqeOZ0Lg60lug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L5oLtc88cxRVYZf9LzM+XAPyRoGX66gzQxHSMhzKqT5Y6oHK2//Me+SuMmAqb+FsviwQcfKxwkbsiv0gERuVZxG9iktnLKy6bwNBX1IBkxgjFqGhI966XAW9Mk9IcyIyzv+HjZLvYVgX3gYYsVI77SBXgEOxxbd9UkxQO9UobJE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=bR24r/lf; arc=pass smtp.client-ip=23.83.223.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="bR24r/lf" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id AE535901DFD for ; Thu, 13 Jun 2024 20:27:43 +0000 (UTC) Received: from pdx1-sub0-mail-a231.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 585D4903876 for ; Thu, 13 Jun 2024 20:27:43 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1718310463; a=rsa-sha256; cv=none; b=1HjiGjhantU04IE4XSoEeTTtSnP66/7cODvJzWaoUNoGZaFc2ABxIYrOcUT58MoIXbc1T/ aNAzQdeB1pXkmr7/hndcKIaa/4aAghD33a3+sQ9LX0et7JBEaiIHh/CqH5GQxe3fhkhFsI HFI8uJUAJNKDQAKqFyqRbAC0LaoRx+sIxLbg6sBek6mO1poX3Evx7UfXARJBLJ1auG9ni2 7blwYL4Q/0X1sQ6oCvspnDDzijw01Ztl9Z15niY34mIbTHwz+zDPpbhjsG0d2W6tjV1OVY Yc5AszT+gAM5spHimTnPf0yvydeJ7ol96B89+Gj9ZNufYaE0I7L43ki3BWppbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1718310463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZBs+17Ij2599xPvqLbg1BwkejzoMnVt6qu+0xtH1bYc=; b=l/Usl0GHcim6Mavu6u1rdw6uO2Zk/s5F1UigNlKOLhu5GQemwKrCvoMZgeD+UrvB/79ZtZ BsE1qIWV0Gi9UHTPr1LPbLUaW7UKHURMQ8C6TZsszD/1l+2wrUoYSvbY/i2d2K7AE+PDDW LLGtD0BtFdZese/TWjZNVgq36dazgbmHPBmdp7rJkyl5A6iawkKGhhh6xhG66d7iXK9N7Z knEriasIYOVuOUtCXLXSDMoHsK9B2NFVqFCoLi/DDf9VmWz+ctkbq09ocavrUgQiyouRHo xCdBKyCP1oVWGEdlXDkKeAaWOw67wvGFPzXA/I8M8tKcHUeYwQMjdSl9BlUpEw== ARC-Authentication-Results: i=1; rspamd-79677bdb95-kt8wt; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Wiry-Juvenile: 3dec3ad1287c27ae_1718310463606_2212892820 X-MC-Loop-Signature: 1718310463606:3050848005 X-MC-Ingress-Time: 1718310463606 Received: from pdx1-sub0-mail-a231.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.117.83.163 (trex/6.9.2); Thu, 13 Jun 2024 20:27:43 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a231.dreamhost.com (Postfix) with ESMTPSA id 4W0Yqz0pw9z58 for ; Thu, 13 Jun 2024 13:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1718310463; bh=ZBs+17Ij2599xPvqLbg1BwkejzoMnVt6qu+0xtH1bYc=; h=Date:From:To:Cc:Subject:Content-Type; b=bR24r/lf0sy8wcatMWHtgXya6xj4UuiRe6B4NWzbY4Dkz3xN/ARi9wogbNCEKWMGG a8MKHSwGeB/TXB222LCFH6tmkXcuGN7rGsifWmwum4nt+ruiU13dWH2E+8juxzyfHA zZV3pDbaLcxfKW/2fH3JztzpyaPf/2GCysg9+Tu18cQ3v2Ee+Is9cCXF17bnlIMQkW uC1Oi8YIKN9fXK6nonbcSrCAH0PMF29uLCsYOE3avf1i/8uQ9G4WBF7LdxluWz4kxl XN5Lh56qX2GHhSh2vJEhA54vwqQ7ht0hWDf4zOs4+1Uhqrb1TPflZuztJqj0K75y4D hXpYrT3roQ0tg== Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e006b by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 13 Jun 2024 13:27:34 -0700 Date: Thu, 13 Jun 2024 13:27:34 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Gao Xiang , linux-xfs@vger.kernel.org Subject: [RFC PATCH 2/4] xfs: modify xfs_alloc_min_freelist to take an increment Message-ID: <36f4ac4967812331e275b8540859a9473e38153e.1718232004.git.kjlx@templeofstupid.com> References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: xfs_alloc_min_freelist is used to determine the minimum size for the AGFL based upon the current height of the bnobt, cnobt, and rmapbt. In order to determine how much space needs to be in the AGFL reserve in order to permit a transacation that may perform multiple allocations, it is necessary to also know the minimum size of the AGFL after trees are split and the level has incremented. Let xfs_alloc_min_freelist take an increment so that callers may request the minimum AGFL size based upon current + N. This patch has no functional change. A subsequent patch will bring new users. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_alloc.c | 21 +++++++++++++-------- fs/xfs/libxfs/xfs_alloc.h | 2 +- fs/xfs/libxfs/xfs_bmap.c | 2 +- fs/xfs/libxfs/xfs_ialloc.c | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index d70d027a8178..0b15414468cf 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2325,17 +2325,22 @@ xfs_alloc_longest_free_extent( /* * Compute the minimum length of the AGFL in the given AG. If @pag is NULL, - * return the largest possible minimum length. + * return the largest possible minimum length. If @level_inc is greater than + * zero, increment the level being computed by cur + level_inc. */ unsigned int xfs_alloc_min_freelist( struct xfs_mount *mp, - struct xfs_perag *pag) + struct xfs_perag *pag, + unsigned int level_inc) { /* AG btrees have at least 1 level. */ - const unsigned int bno_level = pag ? pag->pagf_bno_level : 1; - const unsigned int cnt_level = pag ? pag->pagf_cnt_level : 1; - const unsigned int rmap_level = pag ? pag->pagf_rmap_level : 1; + const unsigned int bno_level = + pag ? pag->pagf_bno_level + level_inc : 1; + const unsigned int cnt_level = + pag ? pag->pagf_cnt_level + level_inc : 1; + const unsigned int rmap_level = + pag ? pag->pagf_rmap_level + level_inc : 1; unsigned int min_free; ASSERT(mp->m_alloc_maxlevels > 0); @@ -2803,7 +2808,7 @@ xfs_alloc_agfl_calc_reserves( return error; agf = agbp->b_addr; - agfl_blocks = xfs_alloc_min_freelist(mp, NULL); + agfl_blocks = xfs_alloc_min_freelist(mp, NULL, 0); list_len = be32_to_cpu(agf->agf_flcount); xfs_trans_brelse(tp, agbp); @@ -2861,7 +2866,7 @@ xfs_alloc_fix_freelist( goto out_agbp_relse; } - need = xfs_alloc_min_freelist(mp, pag); + need = xfs_alloc_min_freelist(mp, pag, 0); if (!xfs_alloc_space_available(args, need, alloc_flags | XFS_ALLOC_FLAG_CHECK)) goto out_agbp_relse; @@ -2885,7 +2890,7 @@ xfs_alloc_fix_freelist( xfs_agfl_reset(tp, agbp, pag); /* If there isn't enough total space or single-extent, reject it. */ - need = xfs_alloc_min_freelist(mp, pag); + need = xfs_alloc_min_freelist(mp, pag, 0); if (!xfs_alloc_space_available(args, need, alloc_flags)) goto out_agbp_relse; diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 8cbdfb62ac14..77347d69f797 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -74,7 +74,7 @@ unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp); xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag, xfs_extlen_t need, xfs_extlen_t reserved); unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp, - struct xfs_perag *pag); + struct xfs_perag *pag, unsigned int level_inc); int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp, struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk); int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp, diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index c101cf266bc4..742ec4142fb0 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3270,7 +3270,7 @@ xfs_bmap_longest_free_extent( } longest = xfs_alloc_longest_free_extent(pag, - xfs_alloc_min_freelist(pag->pag_mount, pag), + xfs_alloc_min_freelist(pag->pag_mount, pag, 0), xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE)); if (*blen < longest) *blen = longest; diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 14c81f227c5b..30690b7965af 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -3047,7 +3047,7 @@ xfs_ialloc_calc_rootino( first_bno += 1; /* ...the initial AGFL... */ - first_bno += xfs_alloc_min_freelist(mp, NULL); + first_bno += xfs_alloc_min_freelist(mp, NULL, 0); /* ...the free inode btree root... */ if (xfs_has_finobt(mp)) From patchwork Thu Jun 13 20:27:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13697450 Received: from crocodile.elm.relay.mailchannels.net (crocodile.elm.relay.mailchannels.net [23.83.212.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92550824A4 for ; Thu, 13 Jun 2024 20:27:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.212.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310482; cv=pass; b=UkEhZs3K89o0GX9cCKPL+eNaov8VUzp+rNhtRpXBbdk2CRH7IgMJcWT19/2N9E7UOQ/Cjdyok08Qutl1quA1G4P0Vli0AGffrxm652FCiz+7r5Qiwqxl1TRIaTr2igkrosk7ByRVO9SawVqNj+9FfiVluKyHildC6x3jMXIPOD4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718310482; c=relaxed/simple; bh=OIC76fgDHrWTJW3Oypu1DWfs0cQNJKRJE7Jw15MTfq8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k5uz0/hsb94LWPrbusdotljsNDKLTAqChEJJYEuZEv4umzDRD/5hyULEDplXpNxJzORKsn/Ah034DvYH08IZQdr83aordMICdMjKhMdA/3Gkmh056RXQ1lMbduoQoeZlM6f2Wgr19XY99AvHayWhwC4vmi40wOXiMn1c0L/rEkw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=YACJKUNm; arc=pass smtp.client-ip=23.83.212.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="YACJKUNm" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E4DAF424BF for ; Thu, 13 Jun 2024 20:27:57 +0000 (UTC) Received: from pdx1-sub0-mail-a231.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 835A34043D for ; Thu, 13 Jun 2024 20:27:57 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1718310477; a=rsa-sha256; cv=none; b=3cVVfylclox1y8N04h6J97YiV4QJoOKv8KGeIFg8gV4AVS0EbhOrD7vJDCgYtV0YVnM6aA j3/JlA/yTW7NdBDPsxYbdRfyfySub4s5NEDMTedIY1o0XscrwWdozF4QEH+TYswiwMiIzw ZcoE+pHX9oZBQ6vP6D3gVIStjeK+YT6NjWP3WsqRF1b0ATnjtMVPAtBzDbHW798bT9fZtO 86XCBkEi6bcKhhY+nAmFCAATHDBn3xza/Hgr0oDyBRcFryAL7zIXJHTH8SJ8Bt18FVpZem 6YE9Uy7kNPZAeyFP5YVI8azUwgDQMnZe6Y9ZL1+FZCQ4mXhK4TeKB3loQygXCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1718310477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oEtRnV6fCVboF1vhEUchMRUKfle7ghdO8uBvJiwAi4A=; b=9E5Xa/PEs6vuGa6inryi785OyeHJmdMRCinfL2f6KNY33F6SYKQhSvhi4aUaxIOP8CNaFQ O9cgrQ6LwtM3PXc/p0bwh7Alb71uiFF+IhoaAUyvsqeNLty+S1jFyzf9OcRXWdd5codgA9 +PVaVCO3AI3nHTT8MAwOm63tzuZr3j2JMxvazy3M+n10XaeGkXqwwhfQNraB9QYtQkWup8 AeHNcrsHXvBKdfmQc2G5c4bUsqE3lgKI59qP7qgul99ikHVvpq1MeSdAxDbSKARD+TO1vG iUO9fxqnyvq4J9vJyhoLCh1KafPgF5g+m21toPktXhRXalVe7yFrlZxginTF8A== ARC-Authentication-Results: i=1; rspamd-79677bdb95-mkdnm; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Cooing-Abaft: 20cb34f91f8faf37_1718310477795_1107781588 X-MC-Loop-Signature: 1718310477795:3745807984 X-MC-Ingress-Time: 1718310477795 Received: from pdx1-sub0-mail-a231.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.110.173.217 (trex/6.9.2); Thu, 13 Jun 2024 20:27:57 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a231.dreamhost.com (Postfix) with ESMTPSA id 4W0YrF25DtzHF for ; Thu, 13 Jun 2024 13:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1718310477; bh=oEtRnV6fCVboF1vhEUchMRUKfle7ghdO8uBvJiwAi4A=; h=Date:From:To:Cc:Subject:Content-Type; b=YACJKUNm5+edaVdjs5/hI7RQVlmW6mKoXeah9Hx7yELFfuwtWyRe3HLN1rTcNJw5k j08KGKVtBOZjr3Va2eDiI92knLQj3A/YBZoyVxuCGvKRH1NA+4QMu66o2ukVwD5FkL p0fxdP7XZ+tTGfmaOYt/I+INT65v82+XyxwRjVHSmX+FOCxZIYgZx1m5fZkWAqX72E o5smOFoaD94nVBv6zgP0nhL/920lIMOgdDSLZXtLm80aep4WGhho7lqcBFOOg/Z25B r4/hspce+VBd4GTeTje0iSM6BUFUY+29F7Vbl7OJK9vClo2pHgGTKSkBYe1SHe3Mzi 4loTM4Ug8dOfA== Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e006b by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 13 Jun 2024 13:27:47 -0700 Date: Thu, 13 Jun 2024 13:27:47 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Gao Xiang , linux-xfs@vger.kernel.org Subject: [RFC PATCH 3/4] xfs: let allocations tap the AGFL reserve Message-ID: References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: In the case where a transaction is making an allocation after its initial allocation, allow that transaction to tap the AGFL reserve. This is done in case a prior allocation depleted the freelists below their minimum fill and reserve space is needed to finish the transaction. This is predicated on the earlier phases of the allocation enforcing that the AGFL reserve has sufficient space for the transaction to refill the AGFL. That enforcement is in a separate commit. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_alloc.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 0b15414468cf..3fc8448e02d9 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2389,6 +2389,7 @@ xfs_alloc_space_available( int flags) { struct xfs_perag *pag = args->pag; + enum xfs_ag_resv_type resv_type = args->resv; xfs_extlen_t alloc_len, longest; xfs_extlen_t reservation; /* blocks that are still reserved */ int available; @@ -2397,7 +2398,19 @@ xfs_alloc_space_available( if (flags & XFS_ALLOC_FLAG_FREEING) return true; - reservation = xfs_ag_resv_needed(pag, args->resv); + /* + * If this allocation is a subsequent allocation in a transaction with + * multiple allocations, allow it to tap the AGFL reserve in order to + * ensure that it can refill its freelist if a prior transaction has + * depleted it. This is done to ensure that the available space checks + * below don't stop an allocation that's up against the reservation + * space limits when there is AGFL space still reserved and available. + */ + if (args->tp->t_highest_agno != NULLAGNUMBER && + args->resv == XFS_AG_RESV_NONE) { + resv_type = XFS_AG_RESV_AGFL; + } + reservation = xfs_ag_resv_needed(pag, resv_type); /* do we have enough contiguous free space for the allocation? */ alloc_len = args->minlen + (args->alignment - 1) + args->minalignslop; From patchwork Thu Jun 13 20:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krister Johansen X-Patchwork-Id: 13697452 Received: from poodle.tulip.relay.mailchannels.net (poodle.tulip.relay.mailchannels.net [23.83.218.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDEB9135A7D for ; Thu, 13 Jun 2024 20:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=23.83.218.249 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718311049; cv=pass; b=fYn9v3DKD6283+DI24d345SNlcMV5ahdUPTPJxezkQF7Y5dqozqEDqhfjkUOYJjeiREPikTjkiD6A6KMxpEmdcPuRKDr9+3BEaYHgmtMAHTX5hJavZrKHYPEX5LAMbfN/QxsbrkwcPe458WiAiE0Uqr8/09a2v6wsrPN+2fPy7w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718311049; c=relaxed/simple; bh=Tetj88LPtvkglnISn3PzT13trw4CozURsUBO076yNRQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PP4pZ4zO5vslD8ay3cKc6M8DuCd+U0ku20kmtoQB0067cpPH8LYbKXGvXVWkWmD0xDW8zzZpQsRPBXNY02wju3KuPVQ9JrQEmJeqwIjTrtbaorrI60groMhESEEVamsBXOcYBWqS2hseDnQfo0oLf7acV26NxvJGrsAwOsAsbfo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com; spf=pass smtp.mailfrom=templeofstupid.com; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b=GUS2jvIj; arc=pass smtp.client-ip=23.83.218.249 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=templeofstupid.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=templeofstupid.com header.i=@templeofstupid.com header.b="GUS2jvIj" X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 9672D8425F4 for ; Thu, 13 Jun 2024 20:28:08 +0000 (UTC) Received: from pdx1-sub0-mail-a231.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 48A63842701 for ; Thu, 13 Jun 2024 20:28:08 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1718310488; a=rsa-sha256; cv=none; b=QdGpoCrZbSgpFNprdxdcTqAxKE4Lc5W/f2ehlk+taf5v6+Cpq7G7KT06A+DrI/29MS/vhf P8ofscmLdo6f14RTn1negIizvuxaMQvUwrup3Q1FF2zDJ/niXBiZUslOh+ujwt0Ep7M4T8 TwbeFQvyQiGHXhyGujdya7srn9/rCGuSQxJznpcu+pYeZ71FnsXz6DwUdYNUcJHpGLc87y RqR5jiiomK7zRDXSeUNSGxsbzTeu3VjiOFsxqH/54zWiIrzG7WXQD05Yk2mMAdImvbRlqH eRFzdHtosYF8wzvU3Kgmj3B+jPOinyYIgJ50uAwNh40J2Z581qMVyclX1d1OPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1718310488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EOQ9i9IdUgbMinaQRggIQuygSNpYAsxs4kqFU4lVXwc=; b=sv9f8WLsu6BAYVJuccv4uH3+yo2knD+gnB0NXoi/+sT3RzK/S65HpG3HIlL3UGMAUEmXqs lWFQAaKDncOquxNJpuvtrSCKvfvhM1RmQiUsxYwBlLG99Zuo4wzCNR0d3hLE4s4Uzewm/o m6HTU3BMFOU0aLyVwmlkkOSsJsSjvp4UwgoWXDI0W7fx6yZfgLEUWSVqD/kqM/Mi09gedd vNXB8rjzNaFpEHnFftgHPJeCdapz6COklSEZldCa35MdoFJzGNNYU7RAGFkTGpRjLkilKY 6fgleVoRBLyisz094jObFUIVWRO8JJqsDQYJDUWVaJIaXVVEbbAqPOO/cbh/cA== ARC-Authentication-Results: i=1; rspamd-79677bdb95-l6xf4; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@templeofstupid.com X-Sender-Id: dreamhost|x-authsender|kjlx@templeofstupid.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|kjlx@templeofstupid.com X-MailChannels-Auth-Id: dreamhost X-Harbor-Cellar: 796ea2eb0f6ef146_1718310488505_1620179655 X-MC-Loop-Signature: 1718310488505:2549102912 X-MC-Ingress-Time: 1718310488504 Received: from pdx1-sub0-mail-a231.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.123.82.153 (trex/6.9.2); Thu, 13 Jun 2024 20:28:08 +0000 Received: from kmjvbox.templeofstupid.com (c-73-70-109-47.hsd1.ca.comcast.net [73.70.109.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kjlx@templeofstupid.com) by pdx1-sub0-mail-a231.dreamhost.com (Postfix) with ESMTPSA id 4W0YrR5LDPzHZ for ; Thu, 13 Jun 2024 13:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=templeofstupid.com; s=dreamhost; t=1718310487; bh=EOQ9i9IdUgbMinaQRggIQuygSNpYAsxs4kqFU4lVXwc=; h=Date:From:To:Cc:Subject:Content-Type; b=GUS2jvIjZBFQ0zzp16/d57fFVlRz4YnvjjnjFyi1PkX3HWLUJ+ekl2LYDzOw+M6EV t7YaNFW9qBqK0xInzBXoqk2qpmVjqpevJBmOjmpmkqviV9UvAOTGxxf66bkgNAxY2v A/qcfIcKDU9NH5UiehFrE/J/x6U5S0OOLmKbLYfZ6DXpvm69M8DITjHVkPsXynUWYD 7L2+Vd/HfO4Ikp6BoJEyUoQK6Ejl6MJ+uh4Mzxeq3gJUL/GorTvW2rnKb22P2Mzgtg NgTl5TTw3hDMXX5FL7cwp/Kw/LvTbB/JcYqx6uKUpHrvpXSeHidDEF+2Fgz+kIpLTz 3qt2415i+ebcQ== Received: from johansen (uid 1000) (envelope-from kjlx@templeofstupid.com) id e006b by kmjvbox.templeofstupid.com (DragonFly Mail Agent v0.12); Thu, 13 Jun 2024 13:27:58 -0700 Date: Thu, 13 Jun 2024 13:27:58 -0700 From: Krister Johansen To: Chandan Babu R , "Darrick J. Wong" , Dave Chinner Cc: Gao Xiang , linux-xfs@vger.kernel.org Subject: [RFC PATCH 4/4] xfs: refuse allocations without agfl refill space Message-ID: <100c327fc8c5dcd74d659aff97033783380c28e6.1718232004.git.kjlx@templeofstupid.com> References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Ensure that an allocation that may be part of a multiple-allocation transaction has enough space in the AGFL reserve to refill the AGFL in a subsequent transaction. The AGFL reserve was established to make sure that there is enough space reserved for multiple allocation transactions to use this space to refill the AGFL close to ENOSPC. Check an allocation against this reserve and refuse to let it proceed if the AGFL reserve cannot meet the needs of a subsequent allocation. Without this, the second transaction may ENOSPC if the first uses all of the AGFL blocks and the AG is close enough to the limits that it cannot refill. Signed-off-by: Krister Johansen --- fs/xfs/libxfs/xfs_alloc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 3fc8448e02d9..7b0302f7e960 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2389,11 +2389,13 @@ xfs_alloc_space_available( int flags) { struct xfs_perag *pag = args->pag; + struct xfs_ag_resv *resv; enum xfs_ag_resv_type resv_type = args->resv; xfs_extlen_t alloc_len, longest; xfs_extlen_t reservation; /* blocks that are still reserved */ int available; xfs_extlen_t agflcount; + unsigned int agfl_refill; if (flags & XFS_ALLOC_FLAG_FREEING) return true; @@ -2429,6 +2431,21 @@ xfs_alloc_space_available( if (available < (int)max(args->total, alloc_len)) return false; + /* + * If this is the first allocation in a transaction that may perform + * multiple allocations, check the AGFL reserve to see if it contains + * enough blocks to refill the AGFL if freespace b-trees split as part + * of the first allocation. This is done to ensure that subsequent + * allocations can utilize the reserve space instead of running out and + * triggering a shutdown. + */ + if (args->tp->t_highest_agno == NULLAGNUMBER && args->minleft > 0) { + agfl_refill = xfs_alloc_min_freelist(args->mp, pag, 1); + resv = xfs_perag_resv(pag, XFS_AG_RESV_AGFL); + if (resv->ar_asked > 0 && agfl_refill > resv->ar_reserved) + return false; + } + /* * Clamp maxlen to the amount of free space available for the actual * extent allocation.