From patchwork Thu Oct 19 00:00:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C830CDB47E for ; Thu, 19 Oct 2023 00:01:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbjJSABC (ORCPT ); Wed, 18 Oct 2023 20:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbjJSABB (ORCPT ); Wed, 18 Oct 2023 20:01:01 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78483106 for ; Wed, 18 Oct 2023 17:00:56 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0895FC433C7; Thu, 19 Oct 2023 00:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673656; bh=6idJ4WrdB1xtiyJwpNBG2xEol1TKvOM0q6VT4oBWlDg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=sjiBgBA2HJWuaPSAIheF4QXKMyG+ERdFh4+ksq3QGeXzZRNqjCL4e7KjX4zkjE0GM fYw5ixOlWVXu7TWSxZZ+Gioy+qjA6MzwbYpr6RqyXE+XBL9wsfkZonv98I/vdKWNFY eMnUf9EgQq0hy46O1V4dhoYJmH/2e1gYDDm2QwWChlBViRZLVV7onxhHpsJg4K9iSc ZGjKGIfy795c+VdKUl5eQ6bFQ7LZAeb11vnVr+jPpyY3oce9lv6RIsfH5ybQpl1eq2 QJBUfYBUCyksT92uMdoxWJ/tf0Bltu+nJX03MLdd1KHwekYMnYtIAD/za9YEPvohKX YCyoxPkh3Szag== Subject: [PATCH 1/9] xfs: consolidate realtime allocation arguments From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:00:55 -0700 Message-ID: <169767365557.4127997.9370055131320052124.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Dave Chinner Consolidate the arguments passed around the rt allocator into a struct xfs_rtalloc_arg similar to how the btree allocator arguments are consolidated in a struct xfs_alloc_arg.... Signed-off-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.c | 366 +++++++++++++++++++++--------------------- fs/xfs/libxfs/xfs_rtbitmap.h | 46 +++-- fs/xfs/scrub/rtsummary.c | 6 + fs/xfs/xfs_rtalloc.c | 333 ++++++++++++++++++++------------------ 4 files changed, 386 insertions(+), 365 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 4221f539615f..07841969ada9 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -53,17 +53,17 @@ const struct xfs_buf_ops xfs_rtbuf_ops = { */ int xfs_rtbuf_get( - xfs_mount_t *mp, /* file system mount structure */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_fileoff_t block, /* block number in bitmap or summary */ - int issum, /* is summary not bitmap */ - struct xfs_buf **bpp) /* output: buffer for the block */ + struct xfs_rtalloc_args *args, + xfs_fileoff_t block, /* block number in bitmap or summary */ + int issum, /* is summary not bitmap */ + struct xfs_buf **bpp) /* output: buffer for the block */ { - struct xfs_buf *bp; /* block buffer, result */ - xfs_inode_t *ip; /* bitmap or summary inode */ - xfs_bmbt_irec_t map; - int nmap = 1; - int error; /* error value */ + struct xfs_mount *mp = args->mp; + struct xfs_buf *bp; /* block buffer, result */ + struct xfs_inode *ip; /* bitmap or summary inode */ + struct xfs_bmbt_irec map; + int nmap = 1; + int error; ip = issum ? mp->m_rsumip : mp->m_rbmip; @@ -75,13 +75,13 @@ xfs_rtbuf_get( return -EFSCORRUPTED; ASSERT(map.br_startblock != NULLFSBLOCK); - error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, + error = xfs_trans_read_buf(mp, args->tp, mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, map.br_startblock), mp->m_bsize, 0, &bp, &xfs_rtbuf_ops); if (error) return error; - xfs_trans_buf_set_type(tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF + xfs_trans_buf_set_type(args->tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF : XFS_BLFT_RTBITMAP_BUF); *bpp = bp; return 0; @@ -93,30 +93,30 @@ xfs_rtbuf_get( */ int xfs_rtfind_back( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext to look at */ - xfs_rtxnum_t limit, /* last rtext to look at */ - xfs_rtxnum_t *rtx) /* out: start rtext found */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext to look at */ + xfs_rtxnum_t limit, /* last rtext to look at */ + xfs_rtxnum_t *rtx) /* out: start rtext found */ { - int bit; /* bit number in the word */ - xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ - int error; /* error value */ - xfs_rtxnum_t firstbit; /* first useful bit in the word */ - xfs_rtxnum_t i; /* current bit number rel. to start */ - xfs_rtxnum_t len; /* length of inspected area */ - xfs_rtword_t mask; /* mask of relevant bits for value */ - xfs_rtword_t want; /* mask for "good" values */ - xfs_rtword_t wdiff; /* difference from wanted value */ - xfs_rtword_t incore; - unsigned int word; /* word number in the buffer */ + struct xfs_mount *mp = args->mp; + int bit; /* bit number in the word */ + xfs_fileoff_t block; /* bitmap block number */ + struct xfs_buf *bp; /* buf for the block */ + int error; /* error value */ + xfs_rtxnum_t firstbit; /* first useful bit in the word */ + xfs_rtxnum_t i; /* current bit number rel. to start */ + xfs_rtxnum_t len; /* length of inspected area */ + xfs_rtword_t mask; /* mask of relevant bits for value */ + xfs_rtword_t want; /* mask for "good" values */ + xfs_rtword_t wdiff; /* difference from wanted value */ + xfs_rtword_t incore; + unsigned int word; /* word number in the buffer */ /* * Compute and read in starting bitmap block for starting block. */ block = xfs_rtx_to_rbmblock(mp, start); - error = xfs_rtbuf_get(mp, tp, block, 0, &bp); + error = xfs_rtbuf_get(args, block, 0, &bp); if (error) { return error; } @@ -153,7 +153,7 @@ xfs_rtfind_back( /* * Different. Mark where we are and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i = bit - XFS_RTHIBIT(wdiff); *rtx = start - i + 1; return 0; @@ -167,8 +167,8 @@ xfs_rtfind_back( /* * If done with this block, get the previous one. */ - xfs_trans_brelse(tp, bp); - error = xfs_rtbuf_get(mp, tp, --block, 0, &bp); + xfs_trans_brelse(args->tp, bp); + error = xfs_rtbuf_get(args, --block, 0, &bp); if (error) { return error; } @@ -194,7 +194,7 @@ xfs_rtfind_back( /* * Different, mark where we are and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff); *rtx = start - i + 1; return 0; @@ -208,8 +208,8 @@ xfs_rtfind_back( /* * If done with this block, get the previous one. */ - xfs_trans_brelse(tp, bp); - error = xfs_rtbuf_get(mp, tp, --block, 0, &bp); + xfs_trans_brelse(args->tp, bp); + error = xfs_rtbuf_get(args, --block, 0, &bp); if (error) { return error; } @@ -236,7 +236,7 @@ xfs_rtfind_back( /* * Different, mark where we are and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff); *rtx = start - i + 1; return 0; @@ -246,7 +246,7 @@ xfs_rtfind_back( /* * No match, return that we scanned the whole area. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); *rtx = start - i + 1; return 0; } @@ -257,30 +257,30 @@ xfs_rtfind_back( */ int xfs_rtfind_forw( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext to look at */ - xfs_rtxnum_t limit, /* last rtext to look at */ - xfs_rtxnum_t *rtx) /* out: start rtext found */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext to look at */ + xfs_rtxnum_t limit, /* last rtext to look at */ + xfs_rtxnum_t *rtx) /* out: start rtext found */ { - int bit; /* bit number in the word */ - xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ - int error; /* error value */ - xfs_rtxnum_t i; /* current bit number rel. to start */ - xfs_rtxnum_t lastbit; /* last useful bit in the word */ - xfs_rtxnum_t len; /* length of inspected area */ - xfs_rtword_t mask; /* mask of relevant bits for value */ - xfs_rtword_t want; /* mask for "good" values */ - xfs_rtword_t wdiff; /* difference from wanted value */ - xfs_rtword_t incore; - unsigned int word; /* word number in the buffer */ + struct xfs_mount *mp = args->mp; + int bit; /* bit number in the word */ + xfs_fileoff_t block; /* bitmap block number */ + struct xfs_buf *bp; /* buf for the block */ + int error; + xfs_rtxnum_t i; /* current bit number rel. to start */ + xfs_rtxnum_t lastbit;/* last useful bit in the word */ + xfs_rtxnum_t len; /* length of inspected area */ + xfs_rtword_t mask; /* mask of relevant bits for value */ + xfs_rtword_t want; /* mask for "good" values */ + xfs_rtword_t wdiff; /* difference from wanted value */ + xfs_rtword_t incore; + unsigned int word; /* word number in the buffer */ /* * Compute and read in starting bitmap block for starting block. */ block = xfs_rtx_to_rbmblock(mp, start); - error = xfs_rtbuf_get(mp, tp, block, 0, &bp); + error = xfs_rtbuf_get(args, block, 0, &bp); if (error) { return error; } @@ -316,7 +316,7 @@ xfs_rtfind_forw( /* * Different. Mark where we are and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i = XFS_RTLOBIT(wdiff) - bit; *rtx = start + i - 1; return 0; @@ -330,8 +330,8 @@ xfs_rtfind_forw( /* * If done with this block, get the previous one. */ - xfs_trans_brelse(tp, bp); - error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); + xfs_trans_brelse(args->tp, bp); + error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; } @@ -357,7 +357,7 @@ xfs_rtfind_forw( /* * Different, mark where we are and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *rtx = start + i - 1; return 0; @@ -371,8 +371,8 @@ xfs_rtfind_forw( /* * If done with this block, get the next one. */ - xfs_trans_brelse(tp, bp); - error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); + xfs_trans_brelse(args->tp, bp); + error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; } @@ -397,7 +397,7 @@ xfs_rtfind_forw( /* * Different, mark where we are and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *rtx = start + i - 1; return 0; @@ -407,7 +407,7 @@ xfs_rtfind_forw( /* * No match, return that we scanned the whole area. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); *rtx = start + i - 1; return 0; } @@ -438,20 +438,20 @@ xfs_trans_log_rtsummary( */ int xfs_rtmodify_summary_int( - xfs_mount_t *mp, /* file system mount structure */ - xfs_trans_t *tp, /* transaction pointer */ - int log, /* log2 of extent size */ - xfs_fileoff_t bbno, /* bitmap block number */ - int delta, /* change to make to summary info */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - xfs_suminfo_t *sum) /* out: summary info for this block */ + struct xfs_rtalloc_args *args, + int log, /* log2 of extent size */ + xfs_fileoff_t bbno, /* bitmap block number */ + int delta, /* change to make to summary info */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + xfs_suminfo_t *sum) /* out: summary info for this block */ { - struct xfs_buf *bp; /* buffer for the summary block */ - int error; /* error value */ - xfs_fileoff_t sb; /* summary fsblock */ - xfs_rtsumoff_t so; /* index into the summary file */ - unsigned int infoword; + struct xfs_mount *mp = args->mp; + struct xfs_buf *bp; /* buffer for the summary block */ + int error; + xfs_fileoff_t sb; /* summary fsblock */ + xfs_rtsumoff_t so; /* index into the summary file */ + unsigned int infoword; /* * Compute entry number in the summary file. @@ -474,8 +474,8 @@ xfs_rtmodify_summary_int( * If there was an old one, get rid of it first. */ if (*rbpp) - xfs_trans_brelse(tp, *rbpp); - error = xfs_rtbuf_get(mp, tp, sb, 1, &bp); + xfs_trans_brelse(args->tp, *rbpp); + error = xfs_rtbuf_get(args, sb, 1, &bp); if (error) { return error; } @@ -498,7 +498,7 @@ xfs_rtmodify_summary_int( if (val != 0 && log < mp->m_rsum_cache[bbno]) mp->m_rsum_cache[bbno] = log; } - xfs_trans_log_rtsummary(tp, bp, infoword); + xfs_trans_log_rtsummary(args->tp, bp, infoword); if (sum) *sum = val; } else if (sum) { @@ -509,16 +509,14 @@ xfs_rtmodify_summary_int( int xfs_rtmodify_summary( - xfs_mount_t *mp, /* file system mount structure */ - xfs_trans_t *tp, /* transaction pointer */ - int log, /* log2 of extent size */ - xfs_fileoff_t bbno, /* bitmap block number */ - int delta, /* change to make to summary info */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb) /* in/out: summary block number */ + struct xfs_rtalloc_args *args, + int log, /* log2 of extent size */ + xfs_fileoff_t bbno, /* bitmap block number */ + int delta, /* change to make to summary info */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb) /* in/out: summary block number */ { - return xfs_rtmodify_summary_int(mp, tp, log, bbno, - delta, rbpp, rsb, NULL); + return xfs_rtmodify_summary_int(args, log, bbno, delta, rbpp, rsb, NULL); } /* Log rtbitmap block from the word @from to the byte before @next. */ @@ -543,22 +541,22 @@ xfs_trans_log_rtbitmap( */ int xfs_rtmodify_range( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext to modify */ - xfs_rtxlen_t len, /* length of extent to modify */ - int val) /* 1 for free, 0 for allocated */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext to modify */ + xfs_rtxlen_t len, /* length of extent to modify */ + int val) /* 1 for free, 0 for allocated */ { - int bit; /* bit number in the word */ - xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ - int error; /* error value */ - int i; /* current bit number rel. to start */ - int lastbit; /* last useful bit in word */ - xfs_rtword_t mask; /* mask o frelevant bits for value */ - xfs_rtword_t incore; - unsigned int firstword; /* first word used in the buffer */ - unsigned int word; /* word number in the buffer */ + struct xfs_mount *mp = args->mp; + int bit; /* bit number in the word */ + xfs_fileoff_t block; /* bitmap block number */ + struct xfs_buf *bp; /* buf for the block */ + int error; + int i; /* current bit number rel. to start */ + int lastbit; /* last useful bit in word */ + xfs_rtword_t mask; /* mask of relevant bits for value */ + xfs_rtword_t incore; + unsigned int firstword; /* first word used in the buffer */ + unsigned int word; /* word number in the buffer */ /* * Compute starting bitmap block number. @@ -567,7 +565,7 @@ xfs_rtmodify_range( /* * Read the bitmap block, and point to its data. */ - error = xfs_rtbuf_get(mp, tp, block, 0, &bp); + error = xfs_rtbuf_get(args, block, 0, &bp); if (error) { return error; } @@ -610,8 +608,9 @@ xfs_rtmodify_range( * Log the changed part of this block. * Get the next one. */ - xfs_trans_log_rtbitmap(tp, bp, firstword, word); - error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); + xfs_trans_log_rtbitmap(args->tp, bp, firstword, + word); + error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; } @@ -643,11 +642,11 @@ xfs_rtmodify_range( * Log the changed part of this block. * Get the next one. */ - xfs_trans_log_rtbitmap(tp, bp, firstword, word); - error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); - if (error) { + xfs_trans_log_rtbitmap(args->tp, bp, firstword, + word); + error = xfs_rtbuf_get(args, ++block, 0, &bp); + if (error) return error; - } firstword = word = 0; } @@ -676,7 +675,7 @@ xfs_rtmodify_range( * Log any remaining changed bytes. */ if (word > firstword) - xfs_trans_log_rtbitmap(tp, bp, firstword, word); + xfs_trans_log_rtbitmap(args->tp, bp, firstword, word); return 0; } @@ -686,23 +685,23 @@ xfs_rtmodify_range( */ int xfs_rtfree_range( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext to free */ - xfs_rtxlen_t len, /* length to free */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb) /* in/out: summary block number */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext to free */ + xfs_rtxlen_t len, /* length to free */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb) /* in/out: summary block number */ { - xfs_rtxnum_t end; /* end of the freed extent */ - int error; /* error value */ - xfs_rtxnum_t postblock; /* first rtext freed > end */ - xfs_rtxnum_t preblock; /* first rtext freed < start */ + struct xfs_mount *mp = args->mp; + xfs_rtxnum_t end; /* end of the freed extent */ + int error; /* error value */ + xfs_rtxnum_t postblock; /* first rtext freed > end */ + xfs_rtxnum_t preblock; /* first rtext freed < start */ end = start + len - 1; /* * Modify the bitmap to mark this extent freed. */ - error = xfs_rtmodify_range(mp, tp, start, len, 1); + error = xfs_rtmodify_range(args, start, len, 1); if (error) { return error; } @@ -711,14 +710,14 @@ xfs_rtfree_range( * We need to find the beginning and end of the extent so we can * properly update the summary. */ - error = xfs_rtfind_back(mp, tp, start, 0, &preblock); + error = xfs_rtfind_back(args, start, 0, &preblock); if (error) { return error; } /* * Find the next allocated block (end of allocated extent). */ - error = xfs_rtfind_forw(mp, tp, end, mp->m_sb.sb_rextents - 1, + error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1, &postblock); if (error) return error; @@ -727,7 +726,7 @@ xfs_rtfree_range( * old extent, add summary data for them to be allocated. */ if (preblock < start) { - error = xfs_rtmodify_summary(mp, tp, + error = xfs_rtmodify_summary(args, XFS_RTBLOCKLOG(start - preblock), xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb); if (error) { @@ -739,7 +738,7 @@ xfs_rtfree_range( * old extent, add summary data for them to be allocated. */ if (postblock > end) { - error = xfs_rtmodify_summary(mp, tp, + error = xfs_rtmodify_summary(args, XFS_RTBLOCKLOG(postblock - end), xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb); if (error) { @@ -750,7 +749,7 @@ xfs_rtfree_range( * Increment the summary information corresponding to the entire * (new) free extent. */ - error = xfs_rtmodify_summary(mp, tp, + error = xfs_rtmodify_summary(args, XFS_RTBLOCKLOG(postblock + 1 - preblock), xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb); return error; @@ -762,24 +761,24 @@ xfs_rtfree_range( */ int xfs_rtcheck_range( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext number of extent */ - xfs_rtxlen_t len, /* length of extent */ - int val, /* 1 for free, 0 for allocated */ - xfs_rtxnum_t *new, /* out: first rtext not matching */ - int *stat) /* out: 1 for matches, 0 for not */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext number of extent */ + xfs_rtxlen_t len, /* length of extent */ + int val, /* 1 for free, 0 for allocated */ + xfs_rtxnum_t *new, /* out: first rtext not matching */ + int *stat) /* out: 1 for matches, 0 for not */ { - int bit; /* bit number in the word */ - xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ - int error; /* error value */ - xfs_rtxnum_t i; /* current bit number rel. to start */ - xfs_rtxnum_t lastbit; /* last useful bit in word */ - xfs_rtword_t mask; /* mask of relevant bits for value */ - xfs_rtword_t wdiff; /* difference from wanted value */ - xfs_rtword_t incore; - unsigned int word; /* word number in the buffer */ + struct xfs_mount *mp = args->mp; + int bit; /* bit number in the word */ + xfs_fileoff_t block; /* bitmap block number */ + struct xfs_buf *bp; /* buf for the block */ + int error; + xfs_rtxnum_t i; /* current bit number rel. to start */ + xfs_rtxnum_t lastbit; /* last useful bit in word */ + xfs_rtword_t mask; /* mask of relevant bits for value */ + xfs_rtword_t wdiff; /* difference from wanted value */ + xfs_rtword_t incore; + unsigned int word; /* word number in the buffer */ /* * Compute starting bitmap block number @@ -788,7 +787,7 @@ xfs_rtcheck_range( /* * Read the bitmap block. */ - error = xfs_rtbuf_get(mp, tp, block, 0, &bp); + error = xfs_rtbuf_get(args, block, 0, &bp); if (error) { return error; } @@ -823,7 +822,7 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i = XFS_RTLOBIT(wdiff) - bit; *new = start + i; *stat = 0; @@ -838,8 +837,8 @@ xfs_rtcheck_range( /* * If done with this block, get the next one. */ - xfs_trans_brelse(tp, bp); - error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); + xfs_trans_brelse(args->tp, bp); + error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; } @@ -865,7 +864,7 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *new = start + i; *stat = 0; @@ -880,8 +879,8 @@ xfs_rtcheck_range( /* * If done with this block, get the next one. */ - xfs_trans_brelse(tp, bp); - error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp); + xfs_trans_brelse(args->tp, bp); + error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; } @@ -906,7 +905,7 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *new = start + i; *stat = 0; @@ -917,7 +916,7 @@ xfs_rtcheck_range( /* * Successful, return. */ - xfs_trans_brelse(tp, bp); + xfs_trans_brelse(args->tp, bp); *new = start + i; *stat = 1; return 0; @@ -927,54 +926,55 @@ xfs_rtcheck_range( /* * Check that the given extent (block range) is allocated already. */ -STATIC int /* error */ +STATIC int xfs_rtcheck_alloc_range( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext number of extent */ - xfs_rtxlen_t len) /* length of extent */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext number of extent */ + xfs_rtxlen_t len) /* length of extent */ { - xfs_rtxnum_t new; /* dummy for xfs_rtcheck_range */ - int stat; - int error; + xfs_rtxnum_t new; /* dummy for xfs_rtcheck_range */ + int stat; + int error; - error = xfs_rtcheck_range(mp, tp, start, len, 0, &new, &stat); + error = xfs_rtcheck_range(args, start, len, 0, &new, &stat); if (error) return error; ASSERT(stat); return 0; } #else -#define xfs_rtcheck_alloc_range(m,t,b,l) (0) +#define xfs_rtcheck_alloc_range(a,b,l) (0) #endif /* * Free an extent in the realtime subvolume. Length is expressed in * realtime extents, as is the block number. */ -int /* error */ +int xfs_rtfree_extent( - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext number to free */ - xfs_rtxlen_t len) /* length of extent freed */ + struct xfs_trans *tp, /* transaction pointer */ + xfs_rtxnum_t start, /* starting rtext number to free */ + xfs_rtxlen_t len) /* length of extent freed */ { - int error; /* error value */ - xfs_mount_t *mp; /* file system mount structure */ - xfs_fsblock_t sb; /* summary file block number */ - struct xfs_buf *sumbp = NULL; /* summary file block buffer */ - - mp = tp->t_mountp; + struct xfs_mount *mp = tp->t_mountp; + struct xfs_rtalloc_args args = { + .mp = mp, + .tp = tp, + }; + int error; + xfs_fsblock_t sb; /* summary file block number */ + struct xfs_buf *sumbp = NULL; /* summary file block buffer */ ASSERT(mp->m_rbmip->i_itemp != NULL); ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL)); - error = xfs_rtcheck_alloc_range(mp, tp, start, len); + error = xfs_rtcheck_alloc_range(&args, start, len); if (error) return error; /* * Free the range of realtime blocks. */ - error = xfs_rtfree_range(mp, tp, start, len, &sumbp, &sb); + error = xfs_rtfree_range(&args, start, len, &sumbp, &sb); if (error) { return error; } @@ -1039,6 +1039,10 @@ xfs_rtalloc_query_range( xfs_rtalloc_query_range_fn fn, void *priv) { + struct xfs_rtalloc_args args = { + .mp = mp, + .tp = tp, + }; struct xfs_rtalloc_rec rec; xfs_rtxnum_t rtstart; xfs_rtxnum_t rtend; @@ -1058,13 +1062,13 @@ xfs_rtalloc_query_range( rtstart = low_rec->ar_startext; while (rtstart <= high_key) { /* Is the first block free? */ - error = xfs_rtcheck_range(mp, tp, rtstart, 1, 1, &rtend, + error = xfs_rtcheck_range(&args, rtstart, 1, 1, &rtend, &is_free); if (error) break; /* How long does the extent go for? */ - error = xfs_rtfind_forw(mp, tp, rtstart, high_key, &rtend); + error = xfs_rtfind_forw(&args, rtstart, high_key, &rtend); if (error) break; @@ -1109,11 +1113,15 @@ xfs_rtalloc_extent_is_free( xfs_rtxlen_t len, bool *is_free) { + struct xfs_rtalloc_args args = { + .mp = mp, + .tp = tp, + }; xfs_rtxnum_t end; int matches; int error; - error = xfs_rtcheck_range(mp, tp, start, len, 1, &end, &matches); + error = xfs_rtcheck_range(&args, start, len, 1, &end, &matches); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index fdfa98e0ee52..c46f9235315f 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -281,29 +281,29 @@ typedef int (*xfs_rtalloc_query_range_fn)( void *priv); #ifdef CONFIG_XFS_RT -int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp, - xfs_fileoff_t block, int issum, struct xfs_buf **bpp); -int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp, - xfs_rtxnum_t start, xfs_rtxlen_t len, int val, - xfs_rtxnum_t *new, int *stat); -int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp, - xfs_rtxnum_t start, xfs_rtxnum_t limit, - xfs_rtxnum_t *rtblock); -int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp, - xfs_rtxnum_t start, xfs_rtxnum_t limit, - xfs_rtxnum_t *rtblock); -int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp, - xfs_rtxnum_t start, xfs_rtxlen_t len, int val); -int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp, - int log, xfs_fileoff_t bbno, int delta, - struct xfs_buf **rbpp, xfs_fileoff_t *rsb, - xfs_suminfo_t *sum); -int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log, - xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, - xfs_fileoff_t *rsb); -int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp, - xfs_rtxnum_t start, xfs_rtxlen_t len, - struct xfs_buf **rbpp, xfs_fileoff_t *rsb); +struct xfs_rtalloc_args { + struct xfs_mount *mp; + struct xfs_trans *tp; +}; + +int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block, + int issum, struct xfs_buf **bpp); +int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, + xfs_rtxlen_t len, int val, xfs_rtxnum_t *new, int *stat); +int xfs_rtfind_back(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, + xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock); +int xfs_rtfind_forw(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, + xfs_rtxnum_t limit, xfs_rtxnum_t *rtblock); +int xfs_rtmodify_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, + xfs_rtxlen_t len, int val); +int xfs_rtmodify_summary_int(struct xfs_rtalloc_args *args, int log, + xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, + xfs_fileoff_t *rsb, xfs_suminfo_t *sum); +int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log, + xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, + xfs_fileoff_t *rsb); +int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, + xfs_rtxlen_t len, struct xfs_buf **rbpp, xfs_fileoff_t *rsb); int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, const struct xfs_rtalloc_rec *low_rec, const struct xfs_rtalloc_rec *high_rec, diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c index e9eac5354f19..10e83196301c 100644 --- a/fs/xfs/scrub/rtsummary.c +++ b/fs/xfs/scrub/rtsummary.c @@ -188,6 +188,10 @@ STATIC int xchk_rtsum_compare( struct xfs_scrub *sc) { + struct xfs_rtalloc_args args = { + .mp = sc->mp, + .tp = sc->tp, + }; struct xfs_mount *mp = sc->mp; struct xfs_buf *bp; struct xfs_bmbt_irec map; @@ -217,7 +221,7 @@ xchk_rtsum_compare( } /* Read a block's worth of ondisk rtsummary file. */ - error = xfs_rtbuf_get(mp, sc->tp, off, 1, &bp); + error = xfs_rtbuf_get(&args, off, 1, &bp); if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, off, &error)) return error; diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 3be6bda2fd92..73d3280fbe36 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -29,35 +29,34 @@ */ static int xfs_rtget_summary( - xfs_mount_t *mp, /* file system mount structure */ - xfs_trans_t *tp, /* transaction pointer */ - int log, /* log2 of extent size */ - xfs_fileoff_t bbno, /* bitmap block number */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - xfs_suminfo_t *sum) /* out: summary info for this block */ + struct xfs_rtalloc_args *args, + int log, /* log2 of extent size */ + xfs_fileoff_t bbno, /* bitmap block number */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + xfs_suminfo_t *sum) /* out: summary info for this block */ { - return xfs_rtmodify_summary_int(mp, tp, log, bbno, 0, rbpp, rsb, sum); + return xfs_rtmodify_summary_int(args, log, bbno, 0, rbpp, rsb, sum); } /* * Return whether there are any free extents in the size range given * by low and high, for the bitmap block bbno. */ -STATIC int /* error */ +STATIC int xfs_rtany_summary( - xfs_mount_t *mp, /* file system mount structure */ - xfs_trans_t *tp, /* transaction pointer */ - int low, /* low log2 extent size */ - int high, /* high log2 extent size */ - xfs_fileoff_t bbno, /* bitmap block number */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - int *stat) /* out: any good extents here? */ + struct xfs_rtalloc_args *args, + int low, /* low log2 extent size */ + int high, /* high log2 extent size */ + xfs_fileoff_t bbno, /* bitmap block number */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + int *stat) /* out: any good extents here? */ { - int error; /* error value */ - int log; /* loop counter, log2 of ext. size */ - xfs_suminfo_t sum; /* summary data */ + struct xfs_mount *mp = args->mp; + int error; + int log; /* loop counter, log2 of ext. size */ + xfs_suminfo_t sum; /* summary data */ /* There are no extents at levels < m_rsum_cache[bbno]. */ if (mp->m_rsum_cache && low < mp->m_rsum_cache[bbno]) @@ -70,7 +69,7 @@ xfs_rtany_summary( /* * Get one summary datum. */ - error = xfs_rtget_summary(mp, tp, log, bbno, rbpp, rsb, &sum); + error = xfs_rtget_summary(args, log, bbno, rbpp, rsb, &sum); if (error) { return error; } @@ -98,35 +97,34 @@ xfs_rtany_summary( * Copy and transform the summary file, given the old and new * parameters in the mount structures. */ -STATIC int /* error */ +STATIC int xfs_rtcopy_summary( - xfs_mount_t *omp, /* old file system mount point */ - xfs_mount_t *nmp, /* new file system mount point */ - xfs_trans_t *tp) /* transaction pointer */ + struct xfs_rtalloc_args *oargs, + struct xfs_rtalloc_args *nargs) { - xfs_fileoff_t bbno; /* bitmap block number */ - struct xfs_buf *bp; /* summary buffer */ - int error; /* error return value */ - int log; /* summary level number (log length) */ - xfs_suminfo_t sum; /* summary data */ - xfs_fileoff_t sumbno; /* summary block number */ + xfs_fileoff_t bbno; /* bitmap block number */ + struct xfs_buf *bp; /* summary buffer */ + int error; + int log; /* summary level number (log length) */ + xfs_suminfo_t sum; /* summary data */ + xfs_fileoff_t sumbno; /* summary block number */ bp = NULL; - for (log = omp->m_rsumlevels - 1; log >= 0; log--) { - for (bbno = omp->m_sb.sb_rbmblocks - 1; + for (log = oargs->mp->m_rsumlevels - 1; log >= 0; log--) { + for (bbno = oargs->mp->m_sb.sb_rbmblocks - 1; (xfs_srtblock_t)bbno >= 0; bbno--) { - error = xfs_rtget_summary(omp, tp, log, bbno, &bp, + error = xfs_rtget_summary(oargs, log, bbno, &bp, &sumbno, &sum); if (error) return error; if (sum == 0) continue; - error = xfs_rtmodify_summary(omp, tp, log, bbno, -sum, + error = xfs_rtmodify_summary(oargs, log, bbno, -sum, &bp, &sumbno); if (error) return error; - error = xfs_rtmodify_summary(nmp, tp, log, bbno, sum, + error = xfs_rtmodify_summary(nargs, log, bbno, sum, &bp, &sumbno); if (error) return error; @@ -139,19 +137,19 @@ xfs_rtcopy_summary( * Mark an extent specified by start and len allocated. * Updates all the summary information as well as the bitmap. */ -STATIC int /* error */ +STATIC int xfs_rtallocate_range( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* start rtext to allocate */ - xfs_rtxlen_t len, /* length to allocate */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb) /* in/out: summary block number */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* start rtext to allocate */ + xfs_rtxlen_t len, /* length to allocate */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb) /* in/out: summary block number */ { - xfs_rtxnum_t end; /* end of the allocated rtext */ - int error; /* error value */ - xfs_rtxnum_t postblock = 0; /* first rtext allocated > end */ - xfs_rtxnum_t preblock = 0; /* first rtext allocated < start */ + struct xfs_mount *mp = args->mp; + xfs_rtxnum_t end; /* end of the allocated rtext */ + int error; + xfs_rtxnum_t postblock = 0; /* first rtext allocated > end */ + xfs_rtxnum_t preblock = 0; /* first rtext allocated < start */ end = start + len - 1; /* @@ -159,14 +157,14 @@ xfs_rtallocate_range( * We need to find the beginning and end of the extent so we can * properly update the summary. */ - error = xfs_rtfind_back(mp, tp, start, 0, &preblock); + error = xfs_rtfind_back(args, start, 0, &preblock); if (error) { return error; } /* * Find the next allocated block (end of free extent). */ - error = xfs_rtfind_forw(mp, tp, end, mp->m_sb.sb_rextents - 1, + error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1, &postblock); if (error) { return error; @@ -175,7 +173,7 @@ xfs_rtallocate_range( * Decrement the summary information corresponding to the entire * (old) free extent. */ - error = xfs_rtmodify_summary(mp, tp, + error = xfs_rtmodify_summary(args, XFS_RTBLOCKLOG(postblock + 1 - preblock), xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb); if (error) { @@ -186,7 +184,7 @@ xfs_rtallocate_range( * old extent, add summary data for them to be free. */ if (preblock < start) { - error = xfs_rtmodify_summary(mp, tp, + error = xfs_rtmodify_summary(args, XFS_RTBLOCKLOG(start - preblock), xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb); if (error) { @@ -198,7 +196,7 @@ xfs_rtallocate_range( * old extent, add summary data for them to be free. */ if (postblock > end) { - error = xfs_rtmodify_summary(mp, tp, + error = xfs_rtmodify_summary(args, XFS_RTBLOCKLOG(postblock - end), xfs_rtx_to_rbmblock(mp, end + 1), 1, rbpp, rsb); if (error) { @@ -208,7 +206,7 @@ xfs_rtallocate_range( /* * Modify the bitmap to mark this extent allocated. */ - error = xfs_rtmodify_range(mp, tp, start, len, 0); + error = xfs_rtmodify_range(args, start, len, 0); return error; } @@ -235,27 +233,27 @@ xfs_rtallocate_clamp_len( * the length, if given. Returns error; returns starting block in *rtx. * The lengths are all in rtextents. */ -STATIC int /* error */ +STATIC int xfs_rtallocate_extent_block( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_fileoff_t bbno, /* bitmap block number */ - xfs_rtxlen_t minlen, /* minimum length to allocate */ - xfs_rtxlen_t maxlen, /* maximum length to allocate */ - xfs_rtxlen_t *len, /* out: actual length allocated */ - xfs_rtxnum_t *nextp, /* out: next rtext to try */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - xfs_rtxlen_t prod, /* extent product factor */ - xfs_rtxnum_t *rtx) /* out: start rtext allocated */ + struct xfs_rtalloc_args *args, + xfs_fileoff_t bbno, /* bitmap block number */ + xfs_rtxlen_t minlen, /* minimum length to allocate */ + xfs_rtxlen_t maxlen, /* maximum length to allocate */ + xfs_rtxlen_t *len, /* out: actual length allocated */ + xfs_rtxnum_t *nextp, /* out: next rtext to try */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + xfs_rtxlen_t prod, /* extent product factor */ + xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { - xfs_rtxnum_t besti; /* best rtext found so far */ - xfs_rtxnum_t bestlen; /* best length found so far */ - xfs_rtxnum_t end; /* last rtext in chunk */ - int error; /* error value */ - xfs_rtxnum_t i; /* current rtext trying */ - xfs_rtxnum_t next; /* next rtext to try */ - int stat; /* status from internal calls */ + struct xfs_mount *mp = args->mp; + xfs_rtxnum_t besti; /* best rtext found so far */ + xfs_rtxnum_t bestlen;/* best length found so far */ + xfs_rtxnum_t end; /* last rtext in chunk */ + int error; + xfs_rtxnum_t i; /* current rtext trying */ + xfs_rtxnum_t next; /* next rtext to try */ + int stat; /* status from internal calls */ /* * Loop over all the extents starting in this bitmap block, @@ -272,7 +270,7 @@ xfs_rtallocate_extent_block( * See if there's a free extent of maxlen starting at i. * If it's not so then next will contain the first non-free. */ - error = xfs_rtcheck_range(mp, tp, i, maxlen, 1, &next, &stat); + error = xfs_rtcheck_range(args, i, maxlen, 1, &next, &stat); if (error) { return error; } @@ -280,7 +278,7 @@ xfs_rtallocate_extent_block( /* * i for maxlen is all free, allocate and return that. */ - error = xfs_rtallocate_range(mp, tp, i, maxlen, rbpp, + error = xfs_rtallocate_range(args, i, maxlen, rbpp, rsb); if (error) { return error; @@ -308,7 +306,7 @@ xfs_rtallocate_extent_block( * If not done yet, find the start of the next free space. */ if (next < end) { - error = xfs_rtfind_forw(mp, tp, next, end, &i); + error = xfs_rtfind_forw(args, next, end, &i); if (error) { return error; } @@ -333,7 +331,7 @@ xfs_rtallocate_extent_block( /* * Allocate besti for bestlen & return that. */ - error = xfs_rtallocate_range(mp, tp, besti, bestlen, rbpp, rsb); + error = xfs_rtallocate_range(args, besti, bestlen, rbpp, rsb); if (error) { return error; } @@ -355,30 +353,29 @@ xfs_rtallocate_extent_block( * Returns error; returns starting block in *rtx. * The lengths are all in rtextents. */ -STATIC int /* error */ +STATIC int xfs_rtallocate_extent_exact( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext number to allocate */ - xfs_rtxlen_t minlen, /* minimum length to allocate */ - xfs_rtxlen_t maxlen, /* maximum length to allocate */ - xfs_rtxlen_t *len, /* out: actual length allocated */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - xfs_rtxlen_t prod, /* extent product factor */ - xfs_rtxnum_t *rtx) /* out: start rtext allocated */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext number to allocate */ + xfs_rtxlen_t minlen, /* minimum length to allocate */ + xfs_rtxlen_t maxlen, /* maximum length to allocate */ + xfs_rtxlen_t *len, /* out: actual length allocated */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + xfs_rtxlen_t prod, /* extent product factor */ + xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { - int error; /* error value */ - xfs_rtxlen_t i; /* extent length trimmed due to prod */ - int isfree; /* extent is free */ - xfs_rtxnum_t next; /* next rtext to try (dummy) */ + int error; + xfs_rtxlen_t i; /* extent length trimmed due to prod */ + int isfree; /* extent is free */ + xfs_rtxnum_t next; /* next rtext to try (dummy) */ ASSERT(minlen % prod == 0); ASSERT(maxlen % prod == 0); /* * Check if the range in question (for maxlen) is free. */ - error = xfs_rtcheck_range(mp, tp, start, maxlen, 1, &next, &isfree); + error = xfs_rtcheck_range(args, start, maxlen, 1, &next, &isfree); if (error) { return error; } @@ -386,7 +383,7 @@ xfs_rtallocate_extent_exact( /* * If it is, allocate it and return success. */ - error = xfs_rtallocate_range(mp, tp, start, maxlen, rbpp, rsb); + error = xfs_rtallocate_range(args, start, maxlen, rbpp, rsb); if (error) { return error; } @@ -421,7 +418,7 @@ xfs_rtallocate_extent_exact( /* * Allocate what we can and return it. */ - error = xfs_rtallocate_range(mp, tp, start, maxlen, rbpp, rsb); + error = xfs_rtallocate_range(args, start, maxlen, rbpp, rsb); if (error) { return error; } @@ -435,27 +432,27 @@ xfs_rtallocate_extent_exact( * to start as possible. If we don't get maxlen then use prod to trim * the length, if given. The lengths are all in rtextents. */ -STATIC int /* error */ +STATIC int xfs_rtallocate_extent_near( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext number to allocate */ - xfs_rtxlen_t minlen, /* minimum length to allocate */ - xfs_rtxlen_t maxlen, /* maximum length to allocate */ - xfs_rtxlen_t *len, /* out: actual length allocated */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - xfs_rtxlen_t prod, /* extent product factor */ - xfs_rtxnum_t *rtx) /* out: start rtext allocated */ + struct xfs_rtalloc_args *args, + xfs_rtxnum_t start, /* starting rtext number to allocate */ + xfs_rtxlen_t minlen, /* minimum length to allocate */ + xfs_rtxlen_t maxlen, /* maximum length to allocate */ + xfs_rtxlen_t *len, /* out: actual length allocated */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + xfs_rtxlen_t prod, /* extent product factor */ + xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { - int any; /* any useful extents from summary */ - xfs_fileoff_t bbno; /* bitmap block number */ - int error; /* error value */ - int i; /* bitmap block offset (loop control) */ - int j; /* secondary loop control */ - int log2len; /* log2 of minlen */ - xfs_rtxnum_t n; /* next rtext to try */ - xfs_rtxnum_t r; /* result rtext */ + struct xfs_mount *mp = args->mp; + int any; /* any useful extents from summary */ + xfs_fileoff_t bbno; /* bitmap block number */ + int error; + int i; /* bitmap block offset (loop control) */ + int j; /* secondary loop control */ + int log2len; /* log2 of minlen */ + xfs_rtxnum_t n; /* next rtext to try */ + xfs_rtxnum_t r; /* result rtext */ ASSERT(minlen % prod == 0); ASSERT(maxlen % prod == 0); @@ -477,8 +474,8 @@ xfs_rtallocate_extent_near( /* * Try the exact allocation first. */ - error = xfs_rtallocate_extent_exact(mp, tp, start, minlen, maxlen, len, - rbpp, rsb, prod, &r); + error = xfs_rtallocate_extent_exact(args, start, minlen, maxlen, len, + rbpp, rsb, prod, &r); if (error) { return error; } @@ -501,7 +498,7 @@ xfs_rtallocate_extent_near( * Get summary information of extents of all useful levels * starting in this bitmap block. */ - error = xfs_rtany_summary(mp, tp, log2len, mp->m_rsumlevels - 1, + error = xfs_rtany_summary(args, log2len, mp->m_rsumlevels - 1, bbno + i, rbpp, rsb, &any); if (error) { return error; @@ -519,7 +516,7 @@ xfs_rtallocate_extent_near( * Try to allocate an extent starting in * this block. */ - error = xfs_rtallocate_extent_block(mp, tp, + error = xfs_rtallocate_extent_block(args, bbno + i, minlen, maxlen, len, &n, rbpp, rsb, prod, &r); if (error) { @@ -548,7 +545,7 @@ xfs_rtallocate_extent_near( * Grab the summary information for * this bitmap block. */ - error = xfs_rtany_summary(mp, tp, + error = xfs_rtany_summary(args, log2len, mp->m_rsumlevels - 1, bbno + j, rbpp, rsb, &any); if (error) { @@ -564,8 +561,8 @@ xfs_rtallocate_extent_near( */ if (any) continue; - error = xfs_rtallocate_extent_block(mp, - tp, bbno + j, minlen, maxlen, + error = xfs_rtallocate_extent_block(args, + bbno + j, minlen, maxlen, len, &n, rbpp, rsb, prod, &r); if (error) { return error; @@ -586,7 +583,7 @@ xfs_rtallocate_extent_near( * Try to allocate from the summary block * that we found. */ - error = xfs_rtallocate_extent_block(mp, tp, + error = xfs_rtallocate_extent_block(args, bbno + i, minlen, maxlen, len, &n, rbpp, rsb, prod, &r); if (error) { @@ -640,24 +637,24 @@ xfs_rtallocate_extent_near( * specified. If we don't get maxlen then use prod to trim * the length, if given. The lengths are all in rtextents. */ -STATIC int /* error */ +STATIC int xfs_rtallocate_extent_size( - xfs_mount_t *mp, /* file system mount point */ - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxlen_t minlen, /* minimum length to allocate */ - xfs_rtxlen_t maxlen, /* maximum length to allocate */ - xfs_rtxlen_t *len, /* out: actual length allocated */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ - xfs_rtxlen_t prod, /* extent product factor */ - xfs_rtxnum_t *rtx) /* out: start rtext allocated */ + struct xfs_rtalloc_args *args, + xfs_rtxlen_t minlen, /* minimum length to allocate */ + xfs_rtxlen_t maxlen, /* maximum length to allocate */ + xfs_rtxlen_t *len, /* out: actual length allocated */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ + xfs_rtxlen_t prod, /* extent product factor */ + xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { - int error; /* error value */ - xfs_fileoff_t i; /* bitmap block number */ - int l; /* level number (loop control) */ - xfs_rtxnum_t n; /* next rtext to be tried */ - xfs_rtxnum_t r; /* result rtext number */ - xfs_suminfo_t sum; /* summary information for extents */ + struct xfs_mount *mp = args->mp; + int error; + xfs_fileoff_t i; /* bitmap block number */ + int l; /* level number (loop control) */ + xfs_rtxnum_t n; /* next rtext to be tried */ + xfs_rtxnum_t r; /* result rtext number */ + xfs_suminfo_t sum; /* summary information for extents */ ASSERT(minlen % prod == 0); ASSERT(maxlen % prod == 0); @@ -678,7 +675,7 @@ xfs_rtallocate_extent_size( /* * Get the summary for this level/block. */ - error = xfs_rtget_summary(mp, tp, l, i, rbpp, rsb, + error = xfs_rtget_summary(args, l, i, rbpp, rsb, &sum); if (error) { return error; @@ -691,7 +688,7 @@ xfs_rtallocate_extent_size( /* * Try allocating the extent. */ - error = xfs_rtallocate_extent_block(mp, tp, i, maxlen, + error = xfs_rtallocate_extent_block(args, i, maxlen, maxlen, len, &n, rbpp, rsb, prod, &r); if (error) { return error; @@ -737,7 +734,7 @@ xfs_rtallocate_extent_size( /* * Get the summary information for this level/block. */ - error = xfs_rtget_summary(mp, tp, l, i, rbpp, rsb, + error = xfs_rtget_summary(args, l, i, rbpp, rsb, &sum); if (error) { return error; @@ -752,7 +749,7 @@ xfs_rtallocate_extent_size( * minlen/maxlen are in the possible range for * this summary level. */ - error = xfs_rtallocate_extent_block(mp, tp, i, + error = xfs_rtallocate_extent_block(args, i, XFS_RTMAX(minlen, 1 << l), XFS_RTMIN(maxlen, (1 << (l + 1)) - 1), len, &n, rbpp, rsb, prod, &r); @@ -1044,6 +1041,12 @@ xfs_growfs_rt( ((sbp->sb_rextents & ((1 << mp->m_blkbit_log) - 1)) != 0); bmbno < nrbmblocks; bmbno++) { + struct xfs_rtalloc_args args = { + .mp = mp, + }; + struct xfs_rtalloc_args nargs = { + .mp = nmp, + }; struct xfs_trans *tp; xfs_rfsblock_t nrblocks_step; @@ -1072,6 +1075,9 @@ xfs_growfs_rt( &tp); if (error) break; + args.tp = tp; + nargs.tp = tp; + /* * Lock out other callers by grabbing the bitmap inode lock. */ @@ -1105,7 +1111,7 @@ xfs_growfs_rt( */ if (sbp->sb_rbmblocks != nsbp->sb_rbmblocks || mp->m_rsumlevels != nmp->m_rsumlevels) { - error = xfs_rtcopy_summary(mp, nmp, tp); + error = xfs_rtcopy_summary(&args, &nargs); if (error) goto error_cancel; } @@ -1131,7 +1137,7 @@ xfs_growfs_rt( * Free new extent. */ bp = NULL; - error = xfs_rtfree_range(nmp, tp, sbp->sb_rextents, + error = xfs_rtfree_range(&nargs, sbp->sb_rextents, nsbp->sb_rextents - sbp->sb_rextents, &bp, &sumbno); if (error) { error_cancel: @@ -1190,24 +1196,27 @@ xfs_growfs_rt( * parameters. The length units are all in realtime extents, as is the * result block number. */ -int /* error */ +int xfs_rtallocate_extent( - xfs_trans_t *tp, /* transaction pointer */ - xfs_rtxnum_t start, /* starting rtext number to allocate */ - xfs_rtxlen_t minlen, /* minimum length to allocate */ - xfs_rtxlen_t maxlen, /* maximum length to allocate */ - xfs_rtxlen_t *len, /* out: actual length allocated */ - int wasdel, /* was a delayed allocation extent */ - xfs_rtxlen_t prod, /* extent product factor */ - xfs_rtxnum_t *rtblock) /* out: start rtext allocated */ + struct xfs_trans *tp, + xfs_rtxnum_t start, /* starting rtext number to allocate */ + xfs_rtxlen_t minlen, /* minimum length to allocate */ + xfs_rtxlen_t maxlen, /* maximum length to allocate */ + xfs_rtxlen_t *len, /* out: actual length allocated */ + int wasdel, /* was a delayed allocation extent */ + xfs_rtxlen_t prod, /* extent product factor */ + xfs_rtxnum_t *rtblock) /* out: start rtext allocated */ { - xfs_mount_t *mp = tp->t_mountp; - int error; /* error value */ - xfs_rtxnum_t r; /* result allocated rtext */ - xfs_fileoff_t sb; /* summary file block number */ - struct xfs_buf *sumbp; /* summary file block buffer */ + struct xfs_rtalloc_args args = { + .mp = tp->t_mountp, + .tp = tp, + }; + int error; + xfs_rtxnum_t r; /* result allocated rtext */ + xfs_fileoff_t sb; /* summary file block number */ + struct xfs_buf *sumbp; /* summary file block buffer */ - ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL)); + ASSERT(xfs_isilocked(args.mp->m_rbmip, XFS_ILOCK_EXCL)); ASSERT(minlen > 0 && minlen <= maxlen); /* @@ -1229,11 +1238,11 @@ xfs_rtallocate_extent( retry: sumbp = NULL; if (start == 0) { - error = xfs_rtallocate_extent_size(mp, tp, minlen, maxlen, len, - &sumbp, &sb, prod, &r); + error = xfs_rtallocate_extent_size(&args, minlen, + maxlen, len, &sumbp, &sb, prod, &r); } else { - error = xfs_rtallocate_extent_near(mp, tp, start, minlen, maxlen, - len, &sumbp, &sb, prod, &r); + error = xfs_rtallocate_extent_near(&args, start, minlen, + maxlen, len, &sumbp, &sb, prod, &r); } if (error) From patchwork Thu Oct 19 00:01:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B5D7CDB482 for ; Thu, 19 Oct 2023 00:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjJSABI (ORCPT ); Wed, 18 Oct 2023 20:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbjJSABH (ORCPT ); Wed, 18 Oct 2023 20:01:07 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50577106 for ; Wed, 18 Oct 2023 17:01:02 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0A02C433C7; Thu, 19 Oct 2023 00:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673661; bh=qnnUNV15RAK4iOg09bSBwtcI79wgJFgDwJyHru3jx38=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Vo4+foFLhADgp+ySmhco8Oqn7RwqopdQf0tVA83w+MRTQOUv3aeYTuidBg31AdEs1 EyvN3/qspiAqrJLXtf2O32dSQuizKjc0TASiG/WCJzX4xTy2LU8mFWAzxRv/8N21Ro fAh9qzpNWnHIE2YOap6mxU3gNkutnhPm6z6A/Z5J5ep9kiic5Mat9lkQewJhxc+aF5 P9JQnlPWEVXULIPlwHrU/tvlk6TpRo7uS1MFJM8fGnOPjfkK9G+F54afohxemi6Rg6 7dAWyIKw5/T24WVpcCAzROhNhkpZYiawOPrQ99IumVEZVDqS2F1sOX2LYk7M5efUDP P6DuwxHtAi/+Q== Subject: [PATCH 2/9] xfs: cache last bitmap block in realtime allocator From: "Darrick J. Wong" To: djwong@kernel.org Cc: Omar Sandoval , Christoph Hellwig , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:01 -0700 Message-ID: <169767366125.4127997.17316218399531807389.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval Profiling a workload on a highly fragmented realtime device showed a ton of CPU cycles being spent in xfs_trans_read_buf() called by xfs_rtbuf_get(). Further tracing showed that much of that was repeated calls to xfs_rtbuf_get() for the same block of the realtime bitmap. These come from xfs_rtallocate_extent_block(): as it walks through ranges of free bits in the bitmap, each call to xfs_rtcheck_range() and xfs_rtfind_{forw,back}() gets the same bitmap block. If the bitmap block is very fragmented, then this is _a lot_ of buffer lookups. The realtime allocator already passes around a cache of the last used realtime summary block to avoid repeated reads (the parameters rbpp and rsb). We can do the same for the realtime bitmap. This replaces rbpp and rsb with a struct xfs_rtbuf_cache, which caches the most recently used block for both the realtime bitmap and summary. xfs_rtbuf_get() now handles the caching instead of the callers, which requires plumbing xfs_rtbuf_cache to more functions but also makes sure we don't miss anything. Signed-off-by: Omar Sandoval Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.c | 147 ++++++++++++++++++++++-------------------- fs/xfs/libxfs/xfs_rtbitmap.h | 17 +++-- fs/xfs/scrub/rtsummary.c | 4 + fs/xfs/xfs_rtalloc.c | 111 +++++++++++++------------------- 4 files changed, 135 insertions(+), 144 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 07841969ada9..5a2d5eaaba57 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -47,6 +47,23 @@ const struct xfs_buf_ops xfs_rtbuf_ops = { .verify_write = xfs_rtbuf_verify_write, }; +/* Release cached rt bitmap and summary buffers. */ +void +xfs_rtbuf_cache_relse( + struct xfs_rtalloc_args *args) +{ + if (args->rbmbp) { + xfs_trans_brelse(args->tp, args->rbmbp); + args->rbmbp = NULL; + args->rbmoff = NULLFILEOFF; + } + if (args->sumbp) { + xfs_trans_brelse(args->tp, args->sumbp); + args->sumbp = NULL; + args->sumoff = NULLFILEOFF; + } +} + /* * Get a buffer for the bitmap or summary file block specified. * The buffer is returned read and locked. @@ -59,13 +76,42 @@ xfs_rtbuf_get( struct xfs_buf **bpp) /* output: buffer for the block */ { struct xfs_mount *mp = args->mp; + struct xfs_buf **cbpp; /* cached block buffer */ + xfs_fileoff_t *coffp; /* cached block number */ struct xfs_buf *bp; /* block buffer, result */ struct xfs_inode *ip; /* bitmap or summary inode */ struct xfs_bmbt_irec map; + enum xfs_blft type; int nmap = 1; int error; - ip = issum ? mp->m_rsumip : mp->m_rbmip; + if (issum) { + cbpp = &args->sumbp; + coffp = &args->sumoff; + ip = mp->m_rsumip; + type = XFS_BLFT_RTSUMMARY_BUF; + } else { + cbpp = &args->rbmbp; + coffp = &args->rbmoff; + ip = mp->m_rbmip; + type = XFS_BLFT_RTBITMAP_BUF; + } + + /* + * If we have a cached buffer, and the block number matches, use that. + */ + if (*cbpp && *coffp == block) { + *bpp = *cbpp; + return 0; + } + /* + * Otherwise we have to have to get the buffer. If there was an old + * one, get rid of it first. + */ + if (*cbpp) { + xfs_trans_brelse(args->tp, *cbpp); + *cbpp = NULL; + } error = xfs_bmapi_read(ip, block, 1, &map, &nmap, 0); if (error) @@ -81,9 +127,9 @@ xfs_rtbuf_get( if (error) return error; - xfs_trans_buf_set_type(args->tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF - : XFS_BLFT_RTBITMAP_BUF); - *bpp = bp; + xfs_trans_buf_set_type(args->tp, bp, type); + *cbpp = *bpp = bp; + *coffp = block; return 0; } @@ -153,7 +199,6 @@ xfs_rtfind_back( /* * Different. Mark where we are and return. */ - xfs_trans_brelse(args->tp, bp); i = bit - XFS_RTHIBIT(wdiff); *rtx = start - i + 1; return 0; @@ -167,7 +212,6 @@ xfs_rtfind_back( /* * If done with this block, get the previous one. */ - xfs_trans_brelse(args->tp, bp); error = xfs_rtbuf_get(args, --block, 0, &bp); if (error) { return error; @@ -194,7 +238,6 @@ xfs_rtfind_back( /* * Different, mark where we are and return. */ - xfs_trans_brelse(args->tp, bp); i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff); *rtx = start - i + 1; return 0; @@ -208,7 +251,6 @@ xfs_rtfind_back( /* * If done with this block, get the previous one. */ - xfs_trans_brelse(args->tp, bp); error = xfs_rtbuf_get(args, --block, 0, &bp); if (error) { return error; @@ -236,7 +278,6 @@ xfs_rtfind_back( /* * Different, mark where we are and return. */ - xfs_trans_brelse(args->tp, bp); i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff); *rtx = start - i + 1; return 0; @@ -246,7 +287,6 @@ xfs_rtfind_back( /* * No match, return that we scanned the whole area. */ - xfs_trans_brelse(args->tp, bp); *rtx = start - i + 1; return 0; } @@ -316,7 +356,6 @@ xfs_rtfind_forw( /* * Different. Mark where we are and return. */ - xfs_trans_brelse(args->tp, bp); i = XFS_RTLOBIT(wdiff) - bit; *rtx = start + i - 1; return 0; @@ -330,7 +369,6 @@ xfs_rtfind_forw( /* * If done with this block, get the previous one. */ - xfs_trans_brelse(args->tp, bp); error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; @@ -357,7 +395,6 @@ xfs_rtfind_forw( /* * Different, mark where we are and return. */ - xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *rtx = start + i - 1; return 0; @@ -371,7 +408,6 @@ xfs_rtfind_forw( /* * If done with this block, get the next one. */ - xfs_trans_brelse(args->tp, bp); error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; @@ -397,7 +433,6 @@ xfs_rtfind_forw( /* * Different, mark where we are and return. */ - xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *rtx = start + i - 1; return 0; @@ -407,7 +442,6 @@ xfs_rtfind_forw( /* * No match, return that we scanned the whole area. */ - xfs_trans_brelse(args->tp, bp); *rtx = start + i - 1; return 0; } @@ -442,8 +476,6 @@ xfs_rtmodify_summary_int( int log, /* log2 of extent size */ xfs_fileoff_t bbno, /* bitmap block number */ int delta, /* change to make to summary info */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ { struct xfs_mount *mp = args->mp; @@ -461,30 +493,11 @@ xfs_rtmodify_summary_int( * Compute the block number in the summary file. */ sb = xfs_rtsumoffs_to_block(mp, so); - /* - * If we have an old buffer, and the block number matches, use that. - */ - if (*rbpp && *rsb == sb) - bp = *rbpp; - /* - * Otherwise we have to get the buffer. - */ - else { - /* - * If there was an old one, get rid of it first. - */ - if (*rbpp) - xfs_trans_brelse(args->tp, *rbpp); - error = xfs_rtbuf_get(args, sb, 1, &bp); - if (error) { - return error; - } - /* - * Remember this buffer and block for the next call. - */ - *rbpp = bp; - *rsb = sb; - } + + error = xfs_rtbuf_get(args, sb, 1, &bp); + if (error) + return error; + /* * Point to the summary information, modify/log it, and/or copy it out. */ @@ -512,11 +525,9 @@ xfs_rtmodify_summary( struct xfs_rtalloc_args *args, int log, /* log2 of extent size */ xfs_fileoff_t bbno, /* bitmap block number */ - int delta, /* change to make to summary info */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb) /* in/out: summary block number */ + int delta) /* in/out: summary block number */ { - return xfs_rtmodify_summary_int(args, log, bbno, delta, rbpp, rsb, NULL); + return xfs_rtmodify_summary_int(args, log, bbno, delta, NULL); } /* Log rtbitmap block from the word @from to the byte before @next. */ @@ -687,9 +698,7 @@ int xfs_rtfree_range( struct xfs_rtalloc_args *args, xfs_rtxnum_t start, /* starting rtext to free */ - xfs_rtxlen_t len, /* length to free */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb) /* in/out: summary block number */ + xfs_rtxlen_t len) /* in/out: summary block number */ { struct xfs_mount *mp = args->mp; xfs_rtxnum_t end; /* end of the freed extent */ @@ -718,7 +727,7 @@ xfs_rtfree_range( * Find the next allocated block (end of allocated extent). */ error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1, - &postblock); + &postblock); if (error) return error; /* @@ -727,8 +736,8 @@ xfs_rtfree_range( */ if (preblock < start) { error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(start - preblock), - xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb); + XFS_RTBLOCKLOG(start - preblock), + xfs_rtx_to_rbmblock(mp, preblock), -1); if (error) { return error; } @@ -739,8 +748,8 @@ xfs_rtfree_range( */ if (postblock > end) { error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(postblock - end), - xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb); + XFS_RTBLOCKLOG(postblock - end), + xfs_rtx_to_rbmblock(mp, end + 1), -1); if (error) { return error; } @@ -749,10 +758,9 @@ xfs_rtfree_range( * Increment the summary information corresponding to the entire * (new) free extent. */ - error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(postblock + 1 - preblock), - xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb); - return error; + return xfs_rtmodify_summary(args, + XFS_RTBLOCKLOG(postblock + 1 - preblock), + xfs_rtx_to_rbmblock(mp, preblock), 1); } /* @@ -822,7 +830,6 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - xfs_trans_brelse(args->tp, bp); i = XFS_RTLOBIT(wdiff) - bit; *new = start + i; *stat = 0; @@ -837,7 +844,6 @@ xfs_rtcheck_range( /* * If done with this block, get the next one. */ - xfs_trans_brelse(args->tp, bp); error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; @@ -864,7 +870,6 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *new = start + i; *stat = 0; @@ -879,7 +884,6 @@ xfs_rtcheck_range( /* * If done with this block, get the next one. */ - xfs_trans_brelse(args->tp, bp); error = xfs_rtbuf_get(args, ++block, 0, &bp); if (error) { return error; @@ -905,7 +909,6 @@ xfs_rtcheck_range( /* * Different, compute first wrong bit and return. */ - xfs_trans_brelse(args->tp, bp); i += XFS_RTLOBIT(wdiff); *new = start + i; *stat = 0; @@ -916,7 +919,6 @@ xfs_rtcheck_range( /* * Successful, return. */ - xfs_trans_brelse(args->tp, bp); *new = start + i; *stat = 1; return 0; @@ -961,8 +963,6 @@ xfs_rtfree_extent( .tp = tp, }; int error; - xfs_fsblock_t sb; /* summary file block number */ - struct xfs_buf *sumbp = NULL; /* summary file block buffer */ ASSERT(mp->m_rbmip->i_itemp != NULL); ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL)); @@ -974,10 +974,10 @@ xfs_rtfree_extent( /* * Free the range of realtime blocks. */ - error = xfs_rtfree_range(&args, start, len, &sumbp, &sb); - if (error) { - return error; - } + error = xfs_rtfree_range(&args, start, len); + if (error) + goto out; + /* * Mark more blocks free in the superblock. */ @@ -993,7 +993,10 @@ xfs_rtfree_extent( *(uint64_t *)&VFS_I(mp->m_rbmip)->i_atime = 0; xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE); } - return 0; + error = 0; +out: + xfs_rtbuf_cache_relse(&args); + return error; } /* @@ -1084,6 +1087,7 @@ xfs_rtalloc_query_range( rtstart = rtend + 1; } + xfs_rtbuf_cache_relse(&args); return error; } @@ -1122,6 +1126,7 @@ xfs_rtalloc_extent_is_free( int error; error = xfs_rtcheck_range(&args, start, len, 1, &end, &matches); + xfs_rtbuf_cache_relse(&args); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index c46f9235315f..7f959f9472c6 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -284,8 +284,16 @@ typedef int (*xfs_rtalloc_query_range_fn)( struct xfs_rtalloc_args { struct xfs_mount *mp; struct xfs_trans *tp; + + struct xfs_buf *rbmbp; /* bitmap block buffer */ + struct xfs_buf *sumbp; /* summary block buffer */ + + xfs_fileoff_t rbmoff; /* bitmap block number */ + xfs_fileoff_t sumoff; /* summary block number */ }; +void xfs_rtbuf_cache_relse(struct xfs_rtalloc_args *args); + int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block, int issum, struct xfs_buf **bpp); int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, @@ -297,13 +305,11 @@ int xfs_rtfind_forw(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, int xfs_rtmodify_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, xfs_rtxlen_t len, int val); int xfs_rtmodify_summary_int(struct xfs_rtalloc_args *args, int log, - xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, - xfs_fileoff_t *rsb, xfs_suminfo_t *sum); + xfs_fileoff_t bbno, int delta, xfs_suminfo_t *sum); int xfs_rtmodify_summary(struct xfs_rtalloc_args *args, int log, - xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, - xfs_fileoff_t *rsb); + xfs_fileoff_t bbno, int delta); int xfs_rtfree_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, - xfs_rtxlen_t len, struct xfs_buf **rbpp, xfs_fileoff_t *rsb); + xfs_rtxlen_t len); int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, const struct xfs_rtalloc_rec *low_rec, const struct xfs_rtalloc_rec *high_rec, @@ -343,6 +349,7 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, # define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS) # define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS) # define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS) +# define xfs_rtbuf_cache_relse(a) (0) # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) static inline xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c index 10e83196301c..ec17385fe4b0 100644 --- a/fs/xfs/scrub/rtsummary.c +++ b/fs/xfs/scrub/rtsummary.c @@ -228,7 +228,7 @@ xchk_rtsum_compare( /* Read a block's worth of computed rtsummary file. */ error = xfsum_copyout(sc, sumoff, sc->buf, mp->m_blockwsize); if (error) { - xfs_trans_brelse(sc->tp, bp); + xfs_rtbuf_cache_relse(&args); return error; } @@ -237,7 +237,7 @@ xchk_rtsum_compare( mp->m_blockwsize << XFS_WORDLOG) != 0) xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off); - xfs_trans_brelse(sc->tp, bp); + xfs_rtbuf_cache_relse(&args); sumoff += mp->m_blockwsize; } diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 73d3280fbe36..d5b6be45755f 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -32,11 +32,9 @@ xfs_rtget_summary( struct xfs_rtalloc_args *args, int log, /* log2 of extent size */ xfs_fileoff_t bbno, /* bitmap block number */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ { - return xfs_rtmodify_summary_int(args, log, bbno, 0, rbpp, rsb, sum); + return xfs_rtmodify_summary_int(args, log, bbno, 0, sum); } /* @@ -49,8 +47,6 @@ xfs_rtany_summary( int low, /* low log2 extent size */ int high, /* high log2 extent size */ xfs_fileoff_t bbno, /* bitmap block number */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ int *stat) /* out: any good extents here? */ { struct xfs_mount *mp = args->mp; @@ -69,7 +65,7 @@ xfs_rtany_summary( /* * Get one summary datum. */ - error = xfs_rtget_summary(args, log, bbno, rbpp, rsb, &sum); + error = xfs_rtget_summary(args, log, bbno, &sum); if (error) { return error; } @@ -103,34 +99,31 @@ xfs_rtcopy_summary( struct xfs_rtalloc_args *nargs) { xfs_fileoff_t bbno; /* bitmap block number */ - struct xfs_buf *bp; /* summary buffer */ int error; int log; /* summary level number (log length) */ xfs_suminfo_t sum; /* summary data */ - xfs_fileoff_t sumbno; /* summary block number */ - bp = NULL; for (log = oargs->mp->m_rsumlevels - 1; log >= 0; log--) { for (bbno = oargs->mp->m_sb.sb_rbmblocks - 1; (xfs_srtblock_t)bbno >= 0; bbno--) { - error = xfs_rtget_summary(oargs, log, bbno, &bp, - &sumbno, &sum); + error = xfs_rtget_summary(oargs, log, bbno, &sum); if (error) - return error; + goto out; if (sum == 0) continue; - error = xfs_rtmodify_summary(oargs, log, bbno, -sum, - &bp, &sumbno); + error = xfs_rtmodify_summary(oargs, log, bbno, -sum); if (error) - return error; - error = xfs_rtmodify_summary(nargs, log, bbno, sum, - &bp, &sumbno); + goto out; + error = xfs_rtmodify_summary(nargs, log, bbno, sum); if (error) - return error; + goto out; ASSERT(sum > 0); } } + error = 0; +out: + xfs_rtbuf_cache_relse(oargs); return 0; } /* @@ -141,9 +134,7 @@ STATIC int xfs_rtallocate_range( struct xfs_rtalloc_args *args, xfs_rtxnum_t start, /* start rtext to allocate */ - xfs_rtxlen_t len, /* length to allocate */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb) /* in/out: summary block number */ + xfs_rtxlen_t len) /* in/out: summary block number */ { struct xfs_mount *mp = args->mp; xfs_rtxnum_t end; /* end of the allocated rtext */ @@ -165,7 +156,7 @@ xfs_rtallocate_range( * Find the next allocated block (end of free extent). */ error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1, - &postblock); + &postblock); if (error) { return error; } @@ -174,8 +165,8 @@ xfs_rtallocate_range( * (old) free extent. */ error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(postblock + 1 - preblock), - xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb); + XFS_RTBLOCKLOG(postblock + 1 - preblock), + xfs_rtx_to_rbmblock(mp, preblock), -1); if (error) { return error; } @@ -185,8 +176,8 @@ xfs_rtallocate_range( */ if (preblock < start) { error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(start - preblock), - xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb); + XFS_RTBLOCKLOG(start - preblock), + xfs_rtx_to_rbmblock(mp, preblock), 1); if (error) { return error; } @@ -197,8 +188,8 @@ xfs_rtallocate_range( */ if (postblock > end) { error = xfs_rtmodify_summary(args, - XFS_RTBLOCKLOG(postblock - end), - xfs_rtx_to_rbmblock(mp, end + 1), 1, rbpp, rsb); + XFS_RTBLOCKLOG(postblock - end), + xfs_rtx_to_rbmblock(mp, end + 1), 1); if (error) { return error; } @@ -241,8 +232,6 @@ xfs_rtallocate_extent_block( xfs_rtxlen_t maxlen, /* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ xfs_rtxnum_t *nextp, /* out: next rtext to try */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { @@ -278,8 +267,7 @@ xfs_rtallocate_extent_block( /* * i for maxlen is all free, allocate and return that. */ - error = xfs_rtallocate_range(args, i, maxlen, rbpp, - rsb); + error = xfs_rtallocate_range(args, i, maxlen); if (error) { return error; } @@ -331,7 +319,7 @@ xfs_rtallocate_extent_block( /* * Allocate besti for bestlen & return that. */ - error = xfs_rtallocate_range(args, besti, bestlen, rbpp, rsb); + error = xfs_rtallocate_range(args, besti, bestlen); if (error) { return error; } @@ -360,8 +348,6 @@ xfs_rtallocate_extent_exact( xfs_rtxlen_t minlen, /* minimum length to allocate */ xfs_rtxlen_t maxlen, /* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { @@ -383,7 +369,7 @@ xfs_rtallocate_extent_exact( /* * If it is, allocate it and return success. */ - error = xfs_rtallocate_range(args, start, maxlen, rbpp, rsb); + error = xfs_rtallocate_range(args, start, maxlen); if (error) { return error; } @@ -418,7 +404,7 @@ xfs_rtallocate_extent_exact( /* * Allocate what we can and return it. */ - error = xfs_rtallocate_range(args, start, maxlen, rbpp, rsb); + error = xfs_rtallocate_range(args, start, maxlen); if (error) { return error; } @@ -439,8 +425,6 @@ xfs_rtallocate_extent_near( xfs_rtxlen_t minlen, /* minimum length to allocate */ xfs_rtxlen_t maxlen, /* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { @@ -475,7 +459,7 @@ xfs_rtallocate_extent_near( * Try the exact allocation first. */ error = xfs_rtallocate_extent_exact(args, start, minlen, maxlen, len, - rbpp, rsb, prod, &r); + prod, &r); if (error) { return error; } @@ -499,7 +483,7 @@ xfs_rtallocate_extent_near( * starting in this bitmap block. */ error = xfs_rtany_summary(args, log2len, mp->m_rsumlevels - 1, - bbno + i, rbpp, rsb, &any); + bbno + i, &any); if (error) { return error; } @@ -517,8 +501,8 @@ xfs_rtallocate_extent_near( * this block. */ error = xfs_rtallocate_extent_block(args, - bbno + i, minlen, maxlen, len, &n, rbpp, - rsb, prod, &r); + bbno + i, minlen, maxlen, len, + &n, prod, &r); if (error) { return error; } @@ -546,8 +530,9 @@ xfs_rtallocate_extent_near( * this bitmap block. */ error = xfs_rtany_summary(args, - log2len, mp->m_rsumlevels - 1, - bbno + j, rbpp, rsb, &any); + log2len, + mp->m_rsumlevels - 1, + bbno + j, &any); if (error) { return error; } @@ -562,8 +547,9 @@ xfs_rtallocate_extent_near( if (any) continue; error = xfs_rtallocate_extent_block(args, - bbno + j, minlen, maxlen, - len, &n, rbpp, rsb, prod, &r); + bbno + j, minlen, + maxlen, len, &n, prod, + &r); if (error) { return error; } @@ -584,8 +570,8 @@ xfs_rtallocate_extent_near( * that we found. */ error = xfs_rtallocate_extent_block(args, - bbno + i, minlen, maxlen, len, &n, rbpp, - rsb, prod, &r); + bbno + i, minlen, maxlen, len, + &n, prod, &r); if (error) { return error; } @@ -643,8 +629,6 @@ xfs_rtallocate_extent_size( xfs_rtxlen_t minlen, /* minimum length to allocate */ xfs_rtxlen_t maxlen, /* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ - struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { @@ -675,8 +659,7 @@ xfs_rtallocate_extent_size( /* * Get the summary for this level/block. */ - error = xfs_rtget_summary(args, l, i, rbpp, rsb, - &sum); + error = xfs_rtget_summary(args, l, i, &sum); if (error) { return error; } @@ -689,7 +672,7 @@ xfs_rtallocate_extent_size( * Try allocating the extent. */ error = xfs_rtallocate_extent_block(args, i, maxlen, - maxlen, len, &n, rbpp, rsb, prod, &r); + maxlen, len, &n, prod, &r); if (error) { return error; } @@ -734,8 +717,7 @@ xfs_rtallocate_extent_size( /* * Get the summary information for this level/block. */ - error = xfs_rtget_summary(args, l, i, rbpp, rsb, - &sum); + error = xfs_rtget_summary(args, l, i, &sum); if (error) { return error; } @@ -752,7 +734,7 @@ xfs_rtallocate_extent_size( error = xfs_rtallocate_extent_block(args, i, XFS_RTMAX(minlen, 1 << l), XFS_RTMIN(maxlen, (1 << (l + 1)) - 1), - len, &n, rbpp, rsb, prod, &r); + len, &n, prod, &r); if (error) { return error; } @@ -941,7 +923,6 @@ xfs_growfs_rt( xfs_extlen_t rbmblocks; /* current number of rt bitmap blocks */ xfs_extlen_t rsumblocks; /* current number of rt summary blks */ xfs_sb_t *sbp; /* old superblock */ - xfs_fileoff_t sumbno; /* summary block number */ uint8_t *rsum_cache; /* old summary cache */ sbp = &mp->m_sb; @@ -1136,9 +1117,9 @@ xfs_growfs_rt( /* * Free new extent. */ - bp = NULL; error = xfs_rtfree_range(&nargs, sbp->sb_rextents, - nsbp->sb_rextents - sbp->sb_rextents, &bp, &sumbno); + nsbp->sb_rextents - sbp->sb_rextents); + xfs_rtbuf_cache_relse(&nargs); if (error) { error_cancel: xfs_trans_cancel(tp); @@ -1211,10 +1192,8 @@ xfs_rtallocate_extent( .mp = tp->t_mountp, .tp = tp, }; - int error; + int error; /* error value */ xfs_rtxnum_t r; /* result allocated rtext */ - xfs_fileoff_t sb; /* summary file block number */ - struct xfs_buf *sumbp; /* summary file block buffer */ ASSERT(xfs_isilocked(args.mp->m_rbmip, XFS_ILOCK_EXCL)); ASSERT(minlen > 0 && minlen <= maxlen); @@ -1236,15 +1215,15 @@ xfs_rtallocate_extent( } retry: - sumbp = NULL; if (start == 0) { error = xfs_rtallocate_extent_size(&args, minlen, - maxlen, len, &sumbp, &sb, prod, &r); + maxlen, len, prod, &r); } else { error = xfs_rtallocate_extent_near(&args, start, minlen, - maxlen, len, &sumbp, &sb, prod, &r); + maxlen, len, prod, &r); } + xfs_rtbuf_cache_relse(&args); if (error) return error; From patchwork Thu Oct 19 00:01:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BD40CDB47E for ; Thu, 19 Oct 2023 00:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231544AbjJSABN (ORCPT ); Wed, 18 Oct 2023 20:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjJSABM (ORCPT ); Wed, 18 Oct 2023 20:01:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEE4CFA for ; Wed, 18 Oct 2023 17:01:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F9CAC433C8; Thu, 19 Oct 2023 00:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673667; bh=gGhhJciu4HmbN5HHGTumUXG0+Mi7tSuyiXJgBQP31IQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jS1+Ye3V6xQAQ9vVeftmwp2jcdal8RK3xxBfyhfDATw1pScRGM17fR4L7BLjW3S0d tGyHRo/WjUWK5LRJi0DJ2c9L9nQ7zboMZKPKGCxMnNIO4Rbn6CYVIHhNu6Ra2kc95q KsGVHxSqqPsOn2Aoh4xVXPGD7Q5DABBndsfwFSgN1wzlYK3FDaJoSCxdxgj2XGftOo j+l8Wg1+PA56bOmWypWSk12TutFHE6KvBatO3eHQ+3klqr06pAB/n0sD+cJUxTJNVw H/otoMsPsL+W1s3c4xG2YAN0cruOvgkwEVZ4o+4OVAHGjfwpwYKENcxMDs9eeqdCRP R3CsXwa+2+PQA== Subject: [PATCH 3/9] xfs: simplify xfs_rtbuf_get calling conventions From: "Darrick J. Wong" To: djwong@kernel.org Cc: osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:06 -0700 Message-ID: <169767366685.4127997.4431733556908746478.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Now that xfs_rtalloc_args holds references to the last-read bitmap and summary blocks, we don't need to pass the buffer pointer out of xfs_rtbuf_get. Callers no longer have to xfs_trans_brelse on their own, though they are required to call xfs_rtbuf_cache_relse before the xfs_rtalloc_args goes out of scope. While we're at it, create some trivial helpers so that we don't have to remember if "0" means "bitmap" and "1" means "summary". Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.c | 115 ++++++++++++++++++------------------------ fs/xfs/libxfs/xfs_rtbitmap.h | 22 +++++++- fs/xfs/scrub/rtsummary.c | 5 +- 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 5a2d5eaaba57..9867a6f8f56e 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -72,8 +72,7 @@ int xfs_rtbuf_get( struct xfs_rtalloc_args *args, xfs_fileoff_t block, /* block number in bitmap or summary */ - int issum, /* is summary not bitmap */ - struct xfs_buf **bpp) /* output: buffer for the block */ + int issum) /* is summary not bitmap */ { struct xfs_mount *mp = args->mp; struct xfs_buf **cbpp; /* cached block buffer */ @@ -100,10 +99,9 @@ xfs_rtbuf_get( /* * If we have a cached buffer, and the block number matches, use that. */ - if (*cbpp && *coffp == block) { - *bpp = *cbpp; + if (*cbpp && *coffp == block) return 0; - } + /* * Otherwise we have to have to get the buffer. If there was an old * one, get rid of it first. @@ -128,7 +126,7 @@ xfs_rtbuf_get( return error; xfs_trans_buf_set_type(args->tp, bp, type); - *cbpp = *bpp = bp; + *cbpp = bp; *coffp = block; return 0; } @@ -147,7 +145,6 @@ xfs_rtfind_back( struct xfs_mount *mp = args->mp; int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ int error; /* error value */ xfs_rtxnum_t firstbit; /* first useful bit in the word */ xfs_rtxnum_t i; /* current bit number rel. to start */ @@ -162,10 +159,9 @@ xfs_rtfind_back( * Compute and read in starting bitmap block for starting block. */ block = xfs_rtx_to_rbmblock(mp, start); - error = xfs_rtbuf_get(args, block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, block); + if (error) return error; - } /* * Get the first word's index & point to it. @@ -177,7 +173,7 @@ xfs_rtfind_back( * Compute match value, based on the bit at start: if 1 (free) * then all-ones, else all-zeroes. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0; /* * If the starting position is not word-aligned, deal with the @@ -212,10 +208,9 @@ xfs_rtfind_back( /* * If done with this block, get the previous one. */ - error = xfs_rtbuf_get(args, --block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, --block); + if (error) return error; - } word = mp->m_blockwsize - 1; } @@ -233,7 +228,7 @@ xfs_rtfind_back( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = incore ^ want)) { /* * Different, mark where we are and return. @@ -251,10 +246,9 @@ xfs_rtfind_back( /* * If done with this block, get the previous one. */ - error = xfs_rtbuf_get(args, --block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, --block); + if (error) return error; - } word = mp->m_blockwsize - 1; } @@ -273,7 +267,7 @@ xfs_rtfind_back( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = (incore ^ want) & mask)) { /* * Different, mark where we are and return. @@ -305,7 +299,6 @@ xfs_rtfind_forw( struct xfs_mount *mp = args->mp; int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ int error; xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t lastbit;/* last useful bit in the word */ @@ -320,10 +313,9 @@ xfs_rtfind_forw( * Compute and read in starting bitmap block for starting block. */ block = xfs_rtx_to_rbmblock(mp, start); - error = xfs_rtbuf_get(args, block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, block); + if (error) return error; - } /* * Get the first word's index & point to it. @@ -335,7 +327,7 @@ xfs_rtfind_forw( * Compute match value, based on the bit at start: if 1 (free) * then all-ones, else all-zeroes. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0; /* * If the starting position is not word-aligned, deal with the @@ -369,10 +361,9 @@ xfs_rtfind_forw( /* * If done with this block, get the previous one. */ - error = xfs_rtbuf_get(args, ++block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, ++block); + if (error) return error; - } word = 0; } @@ -390,7 +381,7 @@ xfs_rtfind_forw( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = incore ^ want)) { /* * Different, mark where we are and return. @@ -408,10 +399,9 @@ xfs_rtfind_forw( /* * If done with this block, get the next one. */ - error = xfs_rtbuf_get(args, ++block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, ++block); + if (error) return error; - } word = 0; } @@ -428,7 +418,7 @@ xfs_rtfind_forw( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = (incore ^ want) & mask)) { /* * Different, mark where we are and return. @@ -479,7 +469,6 @@ xfs_rtmodify_summary_int( xfs_suminfo_t *sum) /* out: summary info for this block */ { struct xfs_mount *mp = args->mp; - struct xfs_buf *bp; /* buffer for the summary block */ int error; xfs_fileoff_t sb; /* summary fsblock */ xfs_rtsumoff_t so; /* index into the summary file */ @@ -494,7 +483,7 @@ xfs_rtmodify_summary_int( */ sb = xfs_rtsumoffs_to_block(mp, so); - error = xfs_rtbuf_get(args, sb, 1, &bp); + error = xfs_rtsummary_read_buf(args, sb); if (error) return error; @@ -503,7 +492,8 @@ xfs_rtmodify_summary_int( */ infoword = xfs_rtsumoffs_to_infoword(mp, so); if (delta) { - xfs_suminfo_t val = xfs_suminfo_add(bp, infoword, delta); + xfs_suminfo_t val = xfs_suminfo_add(args->sumbp, infoword, + delta); if (mp->m_rsum_cache) { if (val == 0 && log == mp->m_rsum_cache[bbno]) @@ -511,11 +501,11 @@ xfs_rtmodify_summary_int( if (val != 0 && log < mp->m_rsum_cache[bbno]) mp->m_rsum_cache[bbno] = log; } - xfs_trans_log_rtsummary(args->tp, bp, infoword); + xfs_trans_log_rtsummary(args->tp, args->sumbp, infoword); if (sum) *sum = val; } else if (sum) { - *sum = xfs_suminfo_get(bp, infoword); + *sum = xfs_suminfo_get(args->sumbp, infoword); } return 0; } @@ -560,7 +550,6 @@ xfs_rtmodify_range( struct xfs_mount *mp = args->mp; int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ int error; int i; /* current bit number rel. to start */ int lastbit; /* last useful bit in word */ @@ -576,10 +565,9 @@ xfs_rtmodify_range( /* * Read the bitmap block, and point to its data. */ - error = xfs_rtbuf_get(args, block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, block); + if (error) return error; - } /* * Compute the starting word's address, and starting bit. @@ -603,12 +591,12 @@ xfs_rtmodify_range( /* * Set/clear the active bits. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if (val) incore |= mask; else incore &= ~mask; - xfs_rtbitmap_setword(bp, word, incore); + xfs_rtbitmap_setword(args->rbmbp, word, incore); i = lastbit - bit; /* * Go on to the next block if that's where the next word is @@ -619,12 +607,11 @@ xfs_rtmodify_range( * Log the changed part of this block. * Get the next one. */ - xfs_trans_log_rtbitmap(args->tp, bp, firstword, + xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word); - error = xfs_rtbuf_get(args, ++block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, ++block); + if (error) return error; - } firstword = word = 0; } @@ -642,7 +629,7 @@ xfs_rtmodify_range( /* * Set the word value correctly. */ - xfs_rtbitmap_setword(bp, word, val); + xfs_rtbitmap_setword(args->rbmbp, word, val); i += XFS_NBWORD; /* * Go on to the next block if that's where the next word is @@ -653,9 +640,9 @@ xfs_rtmodify_range( * Log the changed part of this block. * Get the next one. */ - xfs_trans_log_rtbitmap(args->tp, bp, firstword, + xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word); - error = xfs_rtbuf_get(args, ++block, 0, &bp); + error = xfs_rtbitmap_read_buf(args, ++block); if (error) return error; @@ -674,19 +661,19 @@ xfs_rtmodify_range( /* * Set/clear the active bits. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if (val) incore |= mask; else incore &= ~mask; - xfs_rtbitmap_setword(bp, word, incore); + xfs_rtbitmap_setword(args->rbmbp, word, incore); word++; } /* * Log any remaining changed bytes. */ if (word > firstword) - xfs_trans_log_rtbitmap(args->tp, bp, firstword, word); + xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word); return 0; } @@ -779,7 +766,6 @@ xfs_rtcheck_range( struct xfs_mount *mp = args->mp; int bit; /* bit number in the word */ xfs_fileoff_t block; /* bitmap block number */ - struct xfs_buf *bp; /* buf for the block */ int error; xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t lastbit; /* last useful bit in word */ @@ -795,10 +781,9 @@ xfs_rtcheck_range( /* * Read the bitmap block. */ - error = xfs_rtbuf_get(args, block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, block); + if (error) return error; - } /* * Compute the starting word's address, and starting bit. @@ -825,7 +810,7 @@ xfs_rtcheck_range( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = (incore ^ val) & mask)) { /* * Different, compute first wrong bit and return. @@ -844,10 +829,9 @@ xfs_rtcheck_range( /* * If done with this block, get the next one. */ - error = xfs_rtbuf_get(args, ++block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, ++block); + if (error) return error; - } word = 0; } @@ -865,7 +849,7 @@ xfs_rtcheck_range( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = incore ^ val)) { /* * Different, compute first wrong bit and return. @@ -884,10 +868,9 @@ xfs_rtcheck_range( /* * If done with this block, get the next one. */ - error = xfs_rtbuf_get(args, ++block, 0, &bp); - if (error) { + error = xfs_rtbitmap_read_buf(args, ++block); + if (error) return error; - } word = 0; } @@ -904,7 +887,7 @@ xfs_rtcheck_range( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(bp, word); + incore = xfs_rtbitmap_getword(args->rbmbp, word); if ((wdiff = (incore ^ val) & mask)) { /* * Different, compute first wrong bit and return. diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 7f959f9472c6..9516bc333828 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -295,7 +295,24 @@ struct xfs_rtalloc_args { void xfs_rtbuf_cache_relse(struct xfs_rtalloc_args *args); int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block, - int issum, struct xfs_buf **bpp); + int issum); + +static inline int +xfs_rtbitmap_read_buf( + struct xfs_rtalloc_args *args, + xfs_fileoff_t block) +{ + return xfs_rtbuf_get(args, block, 0); +} + +static inline int +xfs_rtsummary_read_buf( + struct xfs_rtalloc_args *args, + xfs_fileoff_t block) +{ + return xfs_rtbuf_get(args, block, 1); +} + int xfs_rtcheck_range(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, xfs_rtxlen_t len, int val, xfs_rtxnum_t *new, int *stat); int xfs_rtfind_back(struct xfs_rtalloc_args *args, xfs_rtxnum_t start, @@ -348,7 +365,8 @@ unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, # define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS) # define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS) # define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS) -# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS) +# define xfs_rtbitmap_read_buf(a,b) (-ENOSYS) +# define xfs_rtsummary_read_buf(a,b) (-ENOSYS) # define xfs_rtbuf_cache_relse(a) (0) # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) static inline xfs_filblks_t diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c index ec17385fe4b0..cc5ae050dfb2 100644 --- a/fs/xfs/scrub/rtsummary.c +++ b/fs/xfs/scrub/rtsummary.c @@ -193,7 +193,6 @@ xchk_rtsum_compare( .tp = sc->tp, }; struct xfs_mount *mp = sc->mp; - struct xfs_buf *bp; struct xfs_bmbt_irec map; xfs_fileoff_t off; xchk_rtsumoff_t sumoff = 0; @@ -221,7 +220,7 @@ xchk_rtsum_compare( } /* Read a block's worth of ondisk rtsummary file. */ - error = xfs_rtbuf_get(&args, off, 1, &bp); + error = xfs_rtsummary_read_buf(&args, off); if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, off, &error)) return error; @@ -232,7 +231,7 @@ xchk_rtsum_compare( return error; } - ondisk_info = xfs_rsumblock_infoptr(bp, 0); + ondisk_info = xfs_rsumblock_infoptr(args.sumbp, 0); if (memcmp(ondisk_info, sc->buf, mp->m_blockwsize << XFS_WORDLOG) != 0) xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off); From patchwork Thu Oct 19 00:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CF3BCDB483 for ; Thu, 19 Oct 2023 00:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229891AbjJSABQ (ORCPT ); Wed, 18 Oct 2023 20:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjJSABP (ORCPT ); Wed, 18 Oct 2023 20:01:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D7AFA for ; Wed, 18 Oct 2023 17:01:13 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DCE8C433C7; Thu, 19 Oct 2023 00:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673673; bh=48HvR6kjejywLx1Wmn0Q+hNJlBuq2EvO18KtNBBOpUM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=pp6KvU6mWxPbmx4HU6sk2f9qRvWr/7XlNZ1WCfMTgB8wJzatfuZfSZ9EsLbmqMSM4 YifoXs1YFyRwB9sK6nQMC1cefbC8R9wJvqTrrMnfuqmqtrkflZUfEZC1RhyjOMevc4 4+r2jLd5YyhLSnXjBe2Gy5vEs1jJrcH+eJTIgSWp0HmiPlBijA1S7IEXNV80y21giV m9dgTFBvkAyso7hdT6a0mFoqGt87FEyjqS8De2G8cdin+R/sLqxc7eiOTCjwNQEHXh 4HPvsxeg314MiXIUltTLNIWC6qLvzOnGrYvjtj8yWFbHB7UaPIBLs3aU9wNJxDqhDK zPbLzalLEFLaA== Subject: [PATCH 4/9] xfs: simplify rt bitmap/summary block accessor functions From: "Darrick J. Wong" To: djwong@kernel.org Cc: osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:12 -0700 Message-ID: <169767367256.4127997.17671935176137544426.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Simplify the calling convention of these functions since the xfs_rtalloc_args structure contains the parameters we need. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.c | 61 ++++++++++++++++++++---------------------- fs/xfs/libxfs/xfs_rtbitmap.h | 46 ++++++++++++++++---------------- fs/xfs/scrub/rtsummary.c | 2 + 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 9867a6f8f56e..9f806af4f720 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -173,7 +173,7 @@ xfs_rtfind_back( * Compute match value, based on the bit at start: if 1 (free) * then all-ones, else all-zeroes. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0; /* * If the starting position is not word-aligned, deal with the @@ -228,7 +228,7 @@ xfs_rtfind_back( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = incore ^ want)) { /* * Different, mark where we are and return. @@ -267,7 +267,7 @@ xfs_rtfind_back( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = (incore ^ want) & mask)) { /* * Different, mark where we are and return. @@ -327,7 +327,7 @@ xfs_rtfind_forw( * Compute match value, based on the bit at start: if 1 (free) * then all-ones, else all-zeroes. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0; /* * If the starting position is not word-aligned, deal with the @@ -381,7 +381,7 @@ xfs_rtfind_forw( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = incore ^ want)) { /* * Different, mark where we are and return. @@ -418,7 +418,7 @@ xfs_rtfind_forw( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = (incore ^ want) & mask)) { /* * Different, mark where we are and return. @@ -439,16 +439,16 @@ xfs_rtfind_forw( /* Log rtsummary counter at @infoword. */ static inline void xfs_trans_log_rtsummary( - struct xfs_trans *tp, - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int infoword) { + struct xfs_buf *bp = args->sumbp; size_t first, last; - first = (void *)xfs_rsumblock_infoptr(bp, infoword) - bp->b_addr; + first = (void *)xfs_rsumblock_infoptr(args, infoword) - bp->b_addr; last = first + sizeof(xfs_suminfo_t) - 1; - xfs_trans_log_buf(tp, bp, first, last); + xfs_trans_log_buf(args->tp, bp, first, last); } /* @@ -492,8 +492,7 @@ xfs_rtmodify_summary_int( */ infoword = xfs_rtsumoffs_to_infoword(mp, so); if (delta) { - xfs_suminfo_t val = xfs_suminfo_add(args->sumbp, infoword, - delta); + xfs_suminfo_t val = xfs_suminfo_add(args, infoword, delta); if (mp->m_rsum_cache) { if (val == 0 && log == mp->m_rsum_cache[bbno]) @@ -501,11 +500,11 @@ xfs_rtmodify_summary_int( if (val != 0 && log < mp->m_rsum_cache[bbno]) mp->m_rsum_cache[bbno] = log; } - xfs_trans_log_rtsummary(args->tp, args->sumbp, infoword); + xfs_trans_log_rtsummary(args, infoword); if (sum) *sum = val; } else if (sum) { - *sum = xfs_suminfo_get(args->sumbp, infoword); + *sum = xfs_suminfo_get(args, infoword); } return 0; } @@ -523,17 +522,17 @@ xfs_rtmodify_summary( /* Log rtbitmap block from the word @from to the byte before @next. */ static inline void xfs_trans_log_rtbitmap( - struct xfs_trans *tp, - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int from, unsigned int next) { + struct xfs_buf *bp = args->rbmbp; size_t first, last; - first = (void *)xfs_rbmblock_wordptr(bp, from) - bp->b_addr; - last = ((void *)xfs_rbmblock_wordptr(bp, next) - 1) - bp->b_addr; + first = (void *)xfs_rbmblock_wordptr(args, from) - bp->b_addr; + last = ((void *)xfs_rbmblock_wordptr(args, next) - 1) - bp->b_addr; - xfs_trans_log_buf(tp, bp, first, last); + xfs_trans_log_buf(args->tp, bp, first, last); } /* @@ -591,12 +590,12 @@ xfs_rtmodify_range( /* * Set/clear the active bits. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if (val) incore |= mask; else incore &= ~mask; - xfs_rtbitmap_setword(args->rbmbp, word, incore); + xfs_rtbitmap_setword(args, word, incore); i = lastbit - bit; /* * Go on to the next block if that's where the next word is @@ -607,8 +606,7 @@ xfs_rtmodify_range( * Log the changed part of this block. * Get the next one. */ - xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, - word); + xfs_trans_log_rtbitmap(args, firstword, word); error = xfs_rtbitmap_read_buf(args, ++block); if (error) return error; @@ -629,7 +627,7 @@ xfs_rtmodify_range( /* * Set the word value correctly. */ - xfs_rtbitmap_setword(args->rbmbp, word, val); + xfs_rtbitmap_setword(args, word, val); i += XFS_NBWORD; /* * Go on to the next block if that's where the next word is @@ -640,8 +638,7 @@ xfs_rtmodify_range( * Log the changed part of this block. * Get the next one. */ - xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, - word); + xfs_trans_log_rtbitmap(args, firstword, word); error = xfs_rtbitmap_read_buf(args, ++block); if (error) return error; @@ -661,19 +658,19 @@ xfs_rtmodify_range( /* * Set/clear the active bits. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if (val) incore |= mask; else incore &= ~mask; - xfs_rtbitmap_setword(args->rbmbp, word, incore); + xfs_rtbitmap_setword(args, word, incore); word++; } /* * Log any remaining changed bytes. */ if (word > firstword) - xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word); + xfs_trans_log_rtbitmap(args, firstword, word); return 0; } @@ -810,7 +807,7 @@ xfs_rtcheck_range( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = (incore ^ val) & mask)) { /* * Different, compute first wrong bit and return. @@ -849,7 +846,7 @@ xfs_rtcheck_range( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = incore ^ val)) { /* * Different, compute first wrong bit and return. @@ -887,7 +884,7 @@ xfs_rtcheck_range( /* * Compute difference between actual and desired value. */ - incore = xfs_rtbitmap_getword(args->rbmbp, word); + incore = xfs_rtbitmap_getword(args, word); if ((wdiff = (incore ^ val) & mask)) { /* * Different, compute first wrong bit and return. diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 9516bc333828..c0637057d69c 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -6,6 +6,17 @@ #ifndef __XFS_RTBITMAP_H__ #define __XFS_RTBITMAP_H__ +struct xfs_rtalloc_args { + struct xfs_mount *mp; + struct xfs_trans *tp; + + struct xfs_buf *rbmbp; /* bitmap block buffer */ + struct xfs_buf *sumbp; /* summary block buffer */ + + xfs_fileoff_t rbmoff; /* bitmap block number */ + xfs_fileoff_t sumoff; /* summary block number */ +}; + static inline xfs_rtblock_t xfs_rtx_to_rtb( struct xfs_mount *mp, @@ -161,10 +172,10 @@ xfs_rbmblock_to_rtx( /* Return a pointer to a bitmap word within a rt bitmap block. */ static inline union xfs_rtword_raw * xfs_rbmblock_wordptr( - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int index) { - union xfs_rtword_raw *words = bp->b_addr; + union xfs_rtword_raw *words = args->rbmbp->b_addr; return words + index; } @@ -172,10 +183,10 @@ xfs_rbmblock_wordptr( /* Convert an ondisk bitmap word to its incore representation. */ static inline xfs_rtword_t xfs_rtbitmap_getword( - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int index) { - union xfs_rtword_raw *word = xfs_rbmblock_wordptr(bp, index); + union xfs_rtword_raw *word = xfs_rbmblock_wordptr(args, index); return word->old; } @@ -183,11 +194,11 @@ xfs_rtbitmap_getword( /* Set an ondisk bitmap word from an incore representation. */ static inline void xfs_rtbitmap_setword( - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int index, xfs_rtword_t value) { - union xfs_rtword_raw *word = xfs_rbmblock_wordptr(bp, index); + union xfs_rtword_raw *word = xfs_rbmblock_wordptr(args, index); word->old = value; } @@ -234,10 +245,10 @@ xfs_rtsumoffs_to_infoword( /* Return a pointer to a summary info word within a rt summary block. */ static inline union xfs_suminfo_raw * xfs_rsumblock_infoptr( - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int index) { - union xfs_suminfo_raw *info = bp->b_addr; + union xfs_suminfo_raw *info = args->sumbp->b_addr; return info + index; } @@ -245,10 +256,10 @@ xfs_rsumblock_infoptr( /* Get the current value of a summary counter. */ static inline xfs_suminfo_t xfs_suminfo_get( - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int index) { - union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index); + union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(args, index); return info->old; } @@ -256,11 +267,11 @@ xfs_suminfo_get( /* Add to the current value of a summary counter and return the new value. */ static inline xfs_suminfo_t xfs_suminfo_add( - struct xfs_buf *bp, + struct xfs_rtalloc_args *args, unsigned int index, int delta) { - union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index); + union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(args, index); info->old += delta; return info->old; @@ -281,17 +292,6 @@ typedef int (*xfs_rtalloc_query_range_fn)( void *priv); #ifdef CONFIG_XFS_RT -struct xfs_rtalloc_args { - struct xfs_mount *mp; - struct xfs_trans *tp; - - struct xfs_buf *rbmbp; /* bitmap block buffer */ - struct xfs_buf *sumbp; /* summary block buffer */ - - xfs_fileoff_t rbmoff; /* bitmap block number */ - xfs_fileoff_t sumoff; /* summary block number */ -}; - void xfs_rtbuf_cache_relse(struct xfs_rtalloc_args *args); int xfs_rtbuf_get(struct xfs_rtalloc_args *args, xfs_fileoff_t block, diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c index cc5ae050dfb2..8b15c47408d0 100644 --- a/fs/xfs/scrub/rtsummary.c +++ b/fs/xfs/scrub/rtsummary.c @@ -231,7 +231,7 @@ xchk_rtsum_compare( return error; } - ondisk_info = xfs_rsumblock_infoptr(args.sumbp, 0); + ondisk_info = xfs_rsumblock_infoptr(&args, 0); if (memcmp(ondisk_info, sc->buf, mp->m_blockwsize << XFS_WORDLOG) != 0) xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off); From patchwork Thu Oct 19 00:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E339CDB47E for ; Thu, 19 Oct 2023 00:01:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbjJSABY (ORCPT ); Wed, 18 Oct 2023 20:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbjJSABV (ORCPT ); Wed, 18 Oct 2023 20:01:21 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07322113 for ; Wed, 18 Oct 2023 17:01:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DB40C433CB; Thu, 19 Oct 2023 00:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673678; bh=InkiRMpgGSXGhna/tMAkhLx1wC6Uumc62RS8+eg0DMA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=imLXwuVQ3LszqZANbAXctRjB9Yi/Gey6K9UIIV7z2V0jAHh/XLUZ+niyD36nmjo/g KRmcAjgJtp3toZkIu4GK6a7yUp6PDw6KYT8U4uhsK4Ub8oiMO4nX+i/AhVkYwdxRP0 qOell4Do0cYUW3zy0wFMqrwtLQt+ERu08hzOaYN0IDEnrdWfRETqpu67bhXXXfJA46 K5g6KeBBAvaeoCitSCgkcyyVCdNGoXviWxnBZrSqtDJz81j0etcjyIEjVHov2f4Fn9 eCQ+kSyKHebPyCgvyWw9rTsJr0A2izXAGIriePUoX/o22YYMhitE8lj1/dpH3zlDki eC9KiFrq12yUg== Subject: [PATCH 5/9] xfs: invert the realtime summary cache From: "Darrick J. Wong" To: djwong@kernel.org Cc: Omar Sandoval , Christoph Hellwig , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:18 -0700 Message-ID: <169767367822.4127997.11830982811104670142.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval In commit 355e3532132b ("xfs: cache minimum realtime summary level"), I added a cache of the minimum level of the realtime summary that has any free extents. However, it turns out that the _maximum_ level is more useful for upcoming optimizations, and basically equivalent for the existing usage. So, let's change the meaning of the cache to be the maximum level + 1, or 0 if there are no free extents. For example, if the cache contains: {0, 4} then there are no free extents starting in realtime bitmap block 0, and there are no free extents larger than or equal to 2^4 blocks starting in realtime bitmap block 1. The cache is a loose upper bound, so there may or may not be free extents smaller than 2^4 blocks in realtime bitmap block 1. Signed-off-by: Omar Sandoval Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.c | 6 +++--- fs/xfs/xfs_mount.h | 6 +++--- fs/xfs/xfs_rtalloc.c | 31 +++++++++++++++++++------------ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index 9f806af4f720..b332ab490a48 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -495,10 +495,10 @@ xfs_rtmodify_summary_int( xfs_suminfo_t val = xfs_suminfo_add(args, infoword, delta); if (mp->m_rsum_cache) { - if (val == 0 && log == mp->m_rsum_cache[bbno]) - mp->m_rsum_cache[bbno]++; - if (val != 0 && log < mp->m_rsum_cache[bbno]) + if (val == 0 && log + 1 == mp->m_rsum_cache[bbno]) mp->m_rsum_cache[bbno] = log; + if (val != 0 && log >= mp->m_rsum_cache[bbno]) + mp->m_rsum_cache[bbno] = log + 1; } xfs_trans_log_rtsummary(args, infoword); if (sum) diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index d8769dc5f6dd..9cd1d570d24d 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -101,9 +101,9 @@ typedef struct xfs_mount { /* * Optional cache of rt summary level per bitmap block with the - * invariant that m_rsum_cache[bbno] <= the minimum i for which - * rsum[i][bbno] != 0. Reads and writes are serialized by the rsumip - * inode lock. + * invariant that m_rsum_cache[bbno] > the maximum i for which + * rsum[i][bbno] != 0, or 0 if rsum[i][bbno] == 0 for all i. + * Reads and writes are serialized by the rsumip inode lock. */ uint8_t *m_rsum_cache; struct xfs_mru_cache *m_filestream; /* per-mount filestream data */ diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index d5b6be45755f..6bde64584a37 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -54,14 +54,19 @@ xfs_rtany_summary( int log; /* loop counter, log2 of ext. size */ xfs_suminfo_t sum; /* summary data */ - /* There are no extents at levels < m_rsum_cache[bbno]. */ - if (mp->m_rsum_cache && low < mp->m_rsum_cache[bbno]) - low = mp->m_rsum_cache[bbno]; + /* There are no extents at levels >= m_rsum_cache[bbno]. */ + if (mp->m_rsum_cache) { + high = min(high, mp->m_rsum_cache[bbno] - 1); + if (low > high) { + *stat = 0; + return 0; + } + } /* * Loop over logs of extent sizes. */ - for (log = low; log <= high; log++) { + for (log = high; log >= low; log--) { /* * Get one summary datum. */ @@ -82,9 +87,9 @@ xfs_rtany_summary( */ *stat = 0; out: - /* There were no extents at levels < log. */ - if (mp->m_rsum_cache && log > mp->m_rsum_cache[bbno]) - mp->m_rsum_cache[bbno] = log; + /* There were no extents at levels > log. */ + if (mp->m_rsum_cache && log + 1 < mp->m_rsum_cache[bbno]) + mp->m_rsum_cache[bbno] = log + 1; return 0; } @@ -887,12 +892,14 @@ xfs_alloc_rsum_cache( xfs_extlen_t rbmblocks) /* number of rt bitmap blocks */ { /* - * The rsum cache is initialized to all zeroes, which is trivially a - * lower bound on the minimum level with any free extents. We can - * continue without the cache if it couldn't be allocated. + * The rsum cache is initialized to the maximum value, which is + * trivially an upper bound on the maximum level with any free extents. + * We can continue without the cache if it couldn't be allocated. */ - mp->m_rsum_cache = kvzalloc(rbmblocks, GFP_KERNEL); - if (!mp->m_rsum_cache) + mp->m_rsum_cache = kvmalloc(rbmblocks, GFP_KERNEL); + if (mp->m_rsum_cache) + memset(mp->m_rsum_cache, -1, rbmblocks); + else xfs_warn(mp, "could not allocate realtime summary cache"); } From patchwork Thu Oct 19 00:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E843CDB483 for ; Thu, 19 Oct 2023 00:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231629AbjJSAB1 (ORCPT ); Wed, 18 Oct 2023 20:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232169AbjJSAB0 (ORCPT ); Wed, 18 Oct 2023 20:01:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6159115 for ; Wed, 18 Oct 2023 17:01:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E1C5C433C8; Thu, 19 Oct 2023 00:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673684; bh=qEl8dy0NWO606fpPfCIiWFIdCN8Kj5Ua3qqCpUbiNzY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=RleYVLXym/5fE0B/D0du/5PMLtLEoQbqsniOjoDNy3etTkOEpKd8qB9zQ04KdcMQM iB+VL0Yx3I1OQWDeNGj2rMEW/uzL6BhzO7au71dSyBp6IoFH/1dDjowB5C/W5KD5z4 +0JF7jq+97k762j5BvtyDfMNXy+ijU2M539X5imJIUt7L1KB2Y58a0ixGdqhRIHfKc GFOetxn9zfEKGCTk3XC9nOGJBgBewdc/zSRyHHIPI7RxFanAbC1UspacTFd8F8AGjg KsErmhuP/IevGkEGREBZcsH4Mj/XFEB7pM8sV8/ch3vzOdFZPfas7gX6PRNJWtUgOm s7o3AC92r5xgg== Subject: [PATCH 6/9] xfs: return maximum free size from xfs_rtany_summary() From: "Darrick J. Wong" To: djwong@kernel.org Cc: Omar Sandoval , Christoph Hellwig , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:23 -0700 Message-ID: <169767368381.4127997.215213369441088455.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval Instead of only returning whether there is any free space, return the maximum size, which is fast thanks to the previous commit. This will be used by two upcoming optimizations. Reviewed-by: Darrick J. Wong Signed-off-by: Omar Sandoval Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 6bde64584a37..c774a4ccdd15 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -47,7 +47,7 @@ xfs_rtany_summary( int low, /* low log2 extent size */ int high, /* high log2 extent size */ xfs_fileoff_t bbno, /* bitmap block number */ - int *stat) /* out: any good extents here? */ + int *maxlog) /* out: max log2 extent size free */ { struct xfs_mount *mp = args->mp; int error; @@ -58,7 +58,7 @@ xfs_rtany_summary( if (mp->m_rsum_cache) { high = min(high, mp->m_rsum_cache[bbno] - 1); if (low > high) { - *stat = 0; + *maxlog = -1; return 0; } } @@ -78,14 +78,14 @@ xfs_rtany_summary( * If there are any, return success. */ if (sum) { - *stat = 1; + *maxlog = log; goto out; } } /* * Found nothing, return failure. */ - *stat = 0; + *maxlog = -1; out: /* There were no extents at levels > log. */ if (mp->m_rsum_cache && log + 1 < mp->m_rsum_cache[bbno]) @@ -434,7 +434,7 @@ xfs_rtallocate_extent_near( xfs_rtxnum_t *rtx) /* out: start rtext allocated */ { struct xfs_mount *mp = args->mp; - int any; /* any useful extents from summary */ + int maxlog; /* max useful extent from summary */ xfs_fileoff_t bbno; /* bitmap block number */ int error; int i; /* bitmap block offset (loop control) */ @@ -488,7 +488,7 @@ xfs_rtallocate_extent_near( * starting in this bitmap block. */ error = xfs_rtany_summary(args, log2len, mp->m_rsumlevels - 1, - bbno + i, &any); + bbno + i, &maxlog); if (error) { return error; } @@ -496,7 +496,7 @@ xfs_rtallocate_extent_near( * If there are any useful extents starting here, try * allocating one. */ - if (any) { + if (maxlog >= 0) { /* * On the positive side of the starting location. */ @@ -537,7 +537,7 @@ xfs_rtallocate_extent_near( error = xfs_rtany_summary(args, log2len, mp->m_rsumlevels - 1, - bbno + j, &any); + bbno + j, &maxlog); if (error) { return error; } @@ -549,7 +549,7 @@ xfs_rtallocate_extent_near( * extent given, we've already tried * that allocation, don't do it again. */ - if (any) + if (maxlog >= 0) continue; error = xfs_rtallocate_extent_block(args, bbno + j, minlen, From patchwork Thu Oct 19 00:01:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A851FCDB47E for ; Thu, 19 Oct 2023 00:01:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbjJSABg (ORCPT ); Wed, 18 Oct 2023 20:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232218AbjJSABd (ORCPT ); Wed, 18 Oct 2023 20:01:33 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6615A119 for ; Wed, 18 Oct 2023 17:01:30 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06FA6C433C8; Thu, 19 Oct 2023 00:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673690; bh=6vv3xVqJpajTXx3S+iwxB0KeYu60hx+uePFok+0jkao=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XgN9+0eyv6BUJl3yoeFXJDQTLcxvoSuHI34tSSdUgCXTASNZ3O8XJf1OCnr7icSkp LCF/IRmsodzROXJSCAmktSX9bDy84vkdE1wvZ2Nlz+3irCN7mF1WiP8adA6flOGgMl TVayX+Iyg/f/8DBuHjmi6X+NUhvZEiAkmxFdWAiaQS9ZUhx+dgppWfE5KV7zMFaf6T nlQDiTFKYIDYwETynrB7/YUUtD4yVzStTcQjHH2Xb+MmAfZbz7GvG3Z0n23iqhgRYc 9ZnntyUsqhCqp9JWT7fPKoqJ9NhABQULbDpgXcqDmrIgXBBZzx7xng5qrfEAa1XnJm EzGZ87gkm201g== Subject: [PATCH 7/9] xfs: limit maxlen based on available space in xfs_rtallocate_extent_near() From: "Darrick J. Wong" To: djwong@kernel.org Cc: Omar Sandoval , Christoph Hellwig , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:29 -0700 Message-ID: <169767368947.4127997.1529811893671633810.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval xfs_rtallocate_extent_near() calls xfs_rtallocate_extent_block() with the minlen and maxlen that were passed to it. xfs_rtallocate_extent_block() then scans the bitmap block looking for a free range of size maxlen. If there is none, it has to scan the whole bitmap block before returning the largest range of at least size minlen. For a fragmented realtime device and a large allocation request, it's almost certain that this will have to search the whole bitmap block, leading to high CPU usage. However, the realtime summary tells us the maximum size available in the bitmap block. We can limit the search in xfs_rtallocate_extent_block() to that size and often stop before scanning the whole bitmap block. Signed-off-by: Omar Sandoval Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index c774a4ccdd15..3aa9634a9e76 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -497,6 +497,9 @@ xfs_rtallocate_extent_near( * allocating one. */ if (maxlog >= 0) { + xfs_extlen_t maxavail = + min_t(xfs_rtblock_t, maxlen, + (1ULL << (maxlog + 1)) - 1); /* * On the positive side of the starting location. */ @@ -506,7 +509,7 @@ xfs_rtallocate_extent_near( * this block. */ error = xfs_rtallocate_extent_block(args, - bbno + i, minlen, maxlen, len, + bbno + i, minlen, maxavail, len, &n, prod, &r); if (error) { return error; @@ -553,7 +556,7 @@ xfs_rtallocate_extent_near( continue; error = xfs_rtallocate_extent_block(args, bbno + j, minlen, - maxlen, len, &n, prod, + maxavail, len, &n, prod, &r); if (error) { return error; @@ -575,7 +578,7 @@ xfs_rtallocate_extent_near( * that we found. */ error = xfs_rtallocate_extent_block(args, - bbno + i, minlen, maxlen, len, + bbno + i, minlen, maxavail, len, &n, prod, &r); if (error) { return error; From patchwork Thu Oct 19 00:01:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82F40CDB47E for ; Thu, 19 Oct 2023 00:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232200AbjJSABj (ORCPT ); Wed, 18 Oct 2023 20:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232194AbjJSABh (ORCPT ); Wed, 18 Oct 2023 20:01:37 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09023FA for ; Wed, 18 Oct 2023 17:01:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B617C433C7; Thu, 19 Oct 2023 00:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673695; bh=W8UQs7cQ0fsWF8IaOh4icITPUxohx6TMKUZSGhMjdw4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=iSIGqgORtDbVucY43/WzbnC/Z+TADnMxjIbmX1cL/GyReW0DggpJG7vBXc6eavgrz q3z2hk6CMaiy+PamudRt4A6Cmx396uu8JgL525cgOQiEbhf+8XfTIX55sbSEjaNadU KHgXPPCE+JJVHpt22gfjJ+GTroviLfod84PhsUJl6+A52BJT9Dv8Mh6TTzrJprqyC0 7CxhvqPoA4wFOjWzDAu8ejkrIbKaZZPKD2f5APMVR7XaMI3ajh5ltlOUWpCvzeDJAy 2LHRwon5Ca5/7J/is7NSsrzHF3FBN1gDnakqfJ/soOa9jNBZ/lEhYM8MQzNZcH/8uU aa7ss6RfvBHYA== Subject: [PATCH 8/9] xfs: don't try redundant allocations in xfs_rtallocate_extent_near() From: "Darrick J. Wong" To: djwong@kernel.org Cc: Omar Sandoval , Christoph Hellwig , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:35 -0700 Message-ID: <169767369521.4127997.2310069452742899094.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval xfs_rtallocate_extent_near() tries to find a free extent as close to a target bitmap block given by bbno as possible, which may be before or after bbno. Searching backwards has a complication: the realtime summary accounts for free space _starting_ in a bitmap block, but not straddling or ending in a bitmap block. So, when the negative search finds a free extent in the realtime summary, in order to end up closer to the target, it looks for the end of the free extent. For example, if bbno - 2 has a free extent, then it will check bbno - 1, then bbno - 2. But then if bbno - 3 has a free extent, it will check bbno - 1 again, then bbno - 2 again, and then bbno - 3. This results in a quadratic loop, which is completely pointless since the repeated checks won't find anything new. Fix it by remembering where we last checked up to and continue from there. This also obviates the need for a check of the realtime summary. Signed-off-by: Omar Sandoval Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 54 ++++++-------------------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 3aa9634a9e76..b743da885ed6 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -477,6 +477,7 @@ xfs_rtallocate_extent_near( } bbno = xfs_rtx_to_rbmblock(mp, start); i = 0; + j = -1; ASSERT(minlen != 0); log2len = xfs_highbit32(minlen); /* @@ -527,33 +528,13 @@ xfs_rtallocate_extent_near( */ else { /* i < 0 */ /* - * Loop backwards through the bitmap blocks from - * the starting point-1 up to where we are now. - * There should be an extent which ends in this - * bitmap block and is long enough. + * Loop backwards through the bitmap blocks + * from where we last checked down to where we + * are now. There should be an extent which + * ends in this bitmap block and is long + * enough. */ - for (j = -1; j > i; j--) { - /* - * Grab the summary information for - * this bitmap block. - */ - error = xfs_rtany_summary(args, - log2len, - mp->m_rsumlevels - 1, - bbno + j, &maxlog); - if (error) { - return error; - } - /* - * If there's no extent given in the - * summary that means the extent we - * found must carry over from an - * earlier block. If there is an - * extent given, we've already tried - * that allocation, don't do it again. - */ - if (maxlog >= 0) - continue; + for (; j >= i; j--) { error = xfs_rtallocate_extent_block(args, bbno + j, minlen, maxavail, len, &n, prod, @@ -569,27 +550,6 @@ xfs_rtallocate_extent_near( return 0; } } - /* - * There weren't intervening bitmap blocks - * with a long enough extent, or the - * allocation didn't work for some reason - * (i.e. it's a little * too short). - * Try to allocate from the summary block - * that we found. - */ - error = xfs_rtallocate_extent_block(args, - bbno + i, minlen, maxavail, len, - &n, prod, &r); - if (error) { - return error; - } - /* - * If it works, return the extent. - */ - if (r != NULLRTEXTNO) { - *rtx = r; - return 0; - } } } /* From patchwork Thu Oct 19 00:01:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13428153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59668CDB47E for ; Thu, 19 Oct 2023 00:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbjJSABo (ORCPT ); Wed, 18 Oct 2023 20:01:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232078AbjJSABn (ORCPT ); Wed, 18 Oct 2023 20:01:43 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAE2A113 for ; Wed, 18 Oct 2023 17:01:41 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56123C433C9; Thu, 19 Oct 2023 00:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697673701; bh=3GZ7RxLbYG6GfPXLdRRlbnjzLxzhE1OoyJaGgc+3fS8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=EfDyH6OANsSqqyCM+YI70K1dJRHgAcsUjC3aQsb98vvBQbpfs2oTko623njinlHv4 8DqBmpIyljNqu7BwPkG5e14qdINoCkliQKZbI+cVM8pZMjIsednBtIlS0TTAvtvXi9 OMY5jDKgR09ohKWwk5+ozWIEg5yUAZ1TcIFMpOvae5Na5dQB64migBEmQMihwTS/8J bjdIeEw2BUFmDAGX3918eHkiexYqrSM0HEQEm1W86cnWEIDkYPbao/botyBWnKquB8 WnsiSnTgLm40lFUglVutbXjtrxGg+NpOrrNMT1ypXj//O1gj54uhGboYQb0OwjE6cK zy0+OFjDBLTZQ== Subject: [PATCH 9/9] xfs: don't look for end of extent further than necessary in xfs_rtallocate_extent_near() From: "Darrick J. Wong" To: djwong@kernel.org Cc: Omar Sandoval , Christoph Hellwig , osandov@fb.com, linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Date: Wed, 18 Oct 2023 17:01:40 -0700 Message-ID: <169767370083.4127997.6969768755256045688.stgit@frogsfrogsfrogs> In-Reply-To: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> References: <169767364977.4127997.1556211251650244714.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval As explained in the previous commit, xfs_rtallocate_extent_near() looks for the end of a free extent when searching backwards from the target bitmap block. Since the previous commit, it searches from the last bitmap block it checked to the bitmap block containing the start of the extent. This may still be more than necessary, since the free extent may not be that long. We know the maximum size of the free extent from the realtime summary. Use that to compute how many bitmap blocks we actually need to check. Reviewed-by: Darrick J. Wong Signed-off-by: Omar Sandoval Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index b743da885ed6..ba66442910b1 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -527,13 +527,30 @@ xfs_rtallocate_extent_near( * On the negative side of the starting location. */ else { /* i < 0 */ + int maxblocks; + /* - * Loop backwards through the bitmap blocks - * from where we last checked down to where we - * are now. There should be an extent which - * ends in this bitmap block and is long - * enough. + * Loop backwards to find the end of the extent + * we found in the realtime summary. + * + * maxblocks is the maximum possible number of + * bitmap blocks from the start of the extent + * to the end of the extent. */ + if (maxlog == 0) + maxblocks = 0; + else if (maxlog < mp->m_blkbit_log) + maxblocks = 1; + else + maxblocks = 2 << (maxlog - mp->m_blkbit_log); + + /* + * We need to check bbno + i + maxblocks down to + * bbno + i. We already checked bbno down to + * bbno + j + 1, so we don't need to check those + * again. + */ + j = min(i + maxblocks, j); for (; j >= i; j--) { error = xfs_rtallocate_extent_block(args, bbno + j, minlen,