From: Gao Xiang <hsiangkao@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
Dave Chinner <dchinner@redhat.com>,
Eric Sandeen <sandeen@sandeen.net>
Subject: Re: [RFC PATCH] xfs_repair: fix rebuilding btree node block less than minrecs
Date: Tue, 9 Jun 2020 22:35:20 +0800 [thread overview]
Message-ID: <20200609143520.GA22145@xiangao.remote.csb> (raw)
In-Reply-To: <20200609114053.31924-1-hsiangkao@redhat.com>
On Tue, Jun 09, 2020 at 07:40:53PM +0800, Gao Xiang wrote:
> In production, we found that sometimes xfs_repair phase 5
> rebuilds freespace node block with pointers less than minrecs
> and if we trigger xfs_repair again it would report such
> the following message:
>
> bad btree nrecs (39, min=40, max=80) in btbno block 0/7882
>
> The background is that xfs_repair starts to rebuild AGFL
> after the freespace btree is settled in phase 5 so we may
> need to leave necessary room in advance for each btree
> leaves in order to avoid freespace btree split and then
> result in AGFL rebuild fails. The old mathematics uses
> ceil(num_extents / maxrecs) to decide the number of node
> blocks. That would be fine without leaving extra space
> since minrecs = maxrecs / 2 but if some slack was decreased
> from maxrecs, the result would be larger than what is
> expected and cause num_recs_pb less than minrecs, i.e:
>
> num_extents = 79, adj_maxrecs = 80 - 2 (slack) = 78
>
> so we'd get
>
> num_blocks = ceil(79 / 78) = 2,
> num_recs_pb = 79 / 2 = 39, which is less than
> minrecs = 80 / 2 = 40
>
> OTOH, btree bulk loading code behaves in a different way.
> As in xfs_btree_bload_level_geometry it wrote
>
> num_blocks = floor(num_extents / maxrecs)
>
> which will never go below minrecs. And when it goes
> above maxrecs, just increment num_blocks and recalculate
> so we can get the reasonable results.
>
> In the long term, btree bulk loader will replace the current
> repair code as well as to resolve AGFL dependency issue.
> But we may still want to look for a backportable solution
> for stable versions. Hence, use the same logic to avoid the
> freespace btree minrecs underflow for now.
>
> Cc: "Darrick J. Wong" <darrick.wong@oracle.com>
> Cc: Dave Chinner <dchinner@redhat.com>
> Cc: Eric Sandeen <sandeen@sandeen.net>
> Fixes: 9851fd79bfb1 ("repair: AGFL rebuild fails if btree split required")
> Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
> ---
> not heavy tested yet..
>
> repair/phase5.c | 101 +++++++++++++++++++++---------------------------
> 1 file changed, 45 insertions(+), 56 deletions(-)
>
> diff --git a/repair/phase5.c b/repair/phase5.c
> index abae8a08..997804a5 100644
> --- a/repair/phase5.c
> +++ b/repair/phase5.c
> @@ -348,11 +348,29 @@ finish_cursor(bt_status_t *curs)
> * failure at runtime. Hence leave a couple of records slack space in
> * each block to allow immediate modification of the tree without
> * requiring splits to be done.
> - *
> - * XXX(hch): any reason we don't just look at mp->m_alloc_mxr?
> */
> -#define XR_ALLOC_BLOCK_MAXRECS(mp, level) \
> - (libxfs_allocbt_maxrecs((mp), (mp)->m_sb.sb_blocksize, (level) == 0) - 2)
> +static void
> +compute_level_geometry(xfs_mount_t *mp, bt_stat_level_t *lptr,
> + uint64_t nr_this_level, bool leaf)
> +{
> + unsigned int maxrecs = mp->m_alloc_mxr[!leaf];
> + int slack = leaf ? 2 : 0;
> + unsigned int desired_npb;
> +
> + desired_npb = max(mp->m_alloc_mnr[!leaf], maxrecs - slack);
> + lptr->num_recs_tot = nr_this_level;
> + lptr->num_blocks = max(1ULL, nr_this_level / desired_npb);
> +
> + lptr->num_recs_pb = nr_this_level / lptr->num_blocks;
> + lptr->modulo = nr_this_level % lptr->num_blocks;
> + if (lptr->num_recs_pb > maxrecs || (lptr->num_recs_pb == maxrecs &&
> + lptr->modulo)) {
> + lptr->num_blocks++;
> +
> + lptr->num_recs_pb = nr_this_level / lptr->num_blocks;
> + lptr->modulo = nr_this_level % lptr->num_blocks;
> + }
> +}
side note: alternatively, maybe we could also adjust (by decreasing)
num_blocks and recalculate for the original approach.
Although for both ways we could not make 2 extra leaves
room for the above 79 of 80 case...
next prev parent reply other threads:[~2020-06-09 14:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-09 11:40 [RFC PATCH] xfs_repair: fix rebuilding btree node block less than minrecs Gao Xiang
2020-06-09 14:35 ` Gao Xiang [this message]
2020-06-09 20:14 ` Darrick J. Wong
2020-06-09 22:12 ` Darrick J. Wong
2020-06-10 1:04 ` Gao Xiang
2020-06-10 3:58 ` [RFC PATCH v2] xfs_repair: fix rebuilding btree " Gao Xiang
2020-06-10 5:26 ` [RFC PATCH v3] " Gao Xiang
2020-06-16 16:11 ` Darrick J. Wong
2020-06-16 17:26 ` Gao Xiang
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=20200609143520.GA22145@xiangao.remote.csb \
--to=hsiangkao@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=dchinner@redhat.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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