From patchwork Wed Oct 11 18:04: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: 13417701 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 3E336CDB473 for ; Wed, 11 Oct 2023 18:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235036AbjJKSEt (ORCPT ); Wed, 11 Oct 2023 14:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235114AbjJKSEr (ORCPT ); Wed, 11 Oct 2023 14:04:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 183ACE4 for ; Wed, 11 Oct 2023 11:04:41 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA593C433C8; Wed, 11 Oct 2023 18:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047480; bh=G0yQWZxbaPZgGvKiTKi5gu33DUd32/Mmbpnih8GhBVc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=u35DBldpoYr4szxMdUI1iuporYJryq5k7umDB8+MIZzRIGhlcxEcxi8RR4B/Ee/Da 6c3/LsLGFeMZjkusfdWaG8CZyDqToJ9YWziWk//vbRdLal6xsdAoz4QPMAmtW6/pdc 78Q9lg5K5iq86HlmnRQgo0TkVA07fKoCn98xf4c9NeMYuK1JIn1LY8U4bbwo7HArVf tYawFzwLHa7TSbP9n4qxhzpuiOiomMJpfTzbkTMmO/JmYCNxn0ahOyF3CsB0NLVw6X 2Kz68mIbMAK/Ab83PbZc4rZf/rSM7eJO43eaRsf7/eOzJB7RVwqOPP+UwMq5qVkAwa 4M6tXx0n3J+TQ== Date: Wed, 11 Oct 2023 11:04:40 -0700 Subject: [PATCH 1/7] xfs: create a helper to convert rtextents to rtblocks From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721195.1773611.10348820944256520547.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Create a helper to convert a realtime extent to a realtime block. Later on we'll change the helper to use bit shifts when possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.h | 16 ++++++++++++++++ fs/xfs/scrub/rtbitmap.c | 4 ++-- fs/xfs/scrub/rtsummary.c | 4 ++-- fs/xfs/xfs_bmap_util.c | 9 +++++---- fs/xfs/xfs_fsmap.c | 6 +++--- fs/xfs/xfs_super.c | 3 ++- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 5e2afb7fea0e7..099ea8902aaaf 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -6,6 +6,22 @@ #ifndef __XFS_RTBITMAP_H__ #define __XFS_RTBITMAP_H__ +static inline xfs_rtblock_t +xfs_rtx_to_rtb( + struct xfs_mount *mp, + xfs_rtxnum_t rtx) +{ + return rtx * mp->m_sb.sb_rextsize; +} + +static inline xfs_extlen_t +xfs_rtxlen_to_extlen( + struct xfs_mount *mp, + xfs_rtxlen_t rtxlen) +{ + return rtxlen * mp->m_sb.sb_rextsize; +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c index fe871ce224c89..01bc5119d612c 100644 --- a/fs/xfs/scrub/rtbitmap.c +++ b/fs/xfs/scrub/rtbitmap.c @@ -62,8 +62,8 @@ xchk_rtbitmap_rec( xfs_rtxnum_t startblock; xfs_filblks_t blockcount; - startblock = rec->ar_startext * mp->m_sb.sb_rextsize; - blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize; + startblock = xfs_rtx_to_rtb(mp, rec->ar_startext); + blockcount = xfs_rtx_to_rtb(mp, rec->ar_extcount); if (!xfs_verify_rtbext(mp, startblock, blockcount)) xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0); diff --git a/fs/xfs/scrub/rtsummary.c b/fs/xfs/scrub/rtsummary.c index c03f6e0074d4d..a329470bade8d 100644 --- a/fs/xfs/scrub/rtsummary.c +++ b/fs/xfs/scrub/rtsummary.c @@ -146,8 +146,8 @@ xchk_rtsum_record_free( lenlog = XFS_RTBLOCKLOG(rec->ar_extcount); offs = XFS_SUMOFFS(mp, lenlog, rbmoff); - rtbno = rec->ar_startext * mp->m_sb.sb_rextsize; - rtlen = rec->ar_extcount * mp->m_sb.sb_rextsize; + rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext); + rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount); if (!xfs_verify_rtbext(mp, rtbno, rtlen)) { xchk_ino_xref_set_corrupt(sc, mp->m_rbmip->i_ino); diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 285e9cafe29ef..cd4136b2b39c4 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -29,6 +29,7 @@ #include "xfs_iomap.h" #include "xfs_reflink.h" #include "xfs_swapext.h" +#include "xfs_rtbitmap.h" /* Kernel only BMAP related definitions and functions */ @@ -126,7 +127,7 @@ xfs_bmap_rtalloc( * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't * adjust the starting point to match it. */ - if (ralen * mp->m_sb.sb_rextsize >= XFS_MAX_BMBT_EXTLEN) + if (xfs_rtxlen_to_extlen(mp, ralen) >= XFS_MAX_BMBT_EXTLEN) ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize; /* @@ -148,7 +149,7 @@ xfs_bmap_rtalloc( error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx); if (error) return error; - ap->blkno = rtx * mp->m_sb.sb_rextsize; + ap->blkno = xfs_rtx_to_rtb(mp, rtx); } else { ap->blkno = 0; } @@ -171,8 +172,8 @@ xfs_bmap_rtalloc( return error; if (rtx != NULLRTEXTNO) { - ap->blkno = rtx * mp->m_sb.sb_rextsize; - ap->length = ralen * mp->m_sb.sb_rextsize; + ap->blkno = xfs_rtx_to_rtb(mp, rtx); + ap->length = xfs_rtxlen_to_extlen(mp, ralen); ap->ip->i_nblocks += ap->length; xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); if (ap->wasdel) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 8982c5d6cbd06..1a187bc9da3de 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -483,11 +483,11 @@ xfs_getfsmap_rtdev_rtbitmap_helper( xfs_rtblock_t rtbno; xfs_daddr_t rec_daddr, len_daddr; - rtbno = rec->ar_startext * mp->m_sb.sb_rextsize; + rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext); rec_daddr = XFS_FSB_TO_BB(mp, rtbno); irec.rm_startblock = rtbno; - rtbno = rec->ar_extcount * mp->m_sb.sb_rextsize; + rtbno = xfs_rtx_to_rtb(mp, rec->ar_extcount); len_daddr = XFS_FSB_TO_BB(mp, rtbno); irec.rm_blockcount = rtbno; @@ -514,7 +514,7 @@ xfs_getfsmap_rtdev_rtbitmap( uint64_t eofs; int error; - eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize); + eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents)); if (keys[0].fmr_physical >= eofs) return 0; start_rtb = XFS_BB_TO_FSBT(mp, diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index e352c78059e7f..f19117f76b9f4 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -44,6 +44,7 @@ #include "xfs_dahash_test.h" #include "xfs_swapext_item.h" #include "xfs_parent.h" +#include "xfs_rtbitmap.h" #include "scrub/stats.h" #include "scrub/rcbag_btree.h" @@ -893,7 +894,7 @@ xfs_fs_statfs( statp->f_blocks = sbp->sb_rblocks; freertx = percpu_counter_sum_positive(&mp->m_frextents); - statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize; + statp->f_bavail = statp->f_bfree = xfs_rtx_to_rtb(mp, freertx); } return 0; From patchwork Wed Oct 11 18:04: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: 13417702 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 0C5FCCDB470 for ; Wed, 11 Oct 2023 18:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232891AbjJKSFA (ORCPT ); Wed, 11 Oct 2023 14:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235022AbjJKSE6 (ORCPT ); Wed, 11 Oct 2023 14:04:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7E12BA for ; Wed, 11 Oct 2023 11:04:56 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AC5FC433C8; Wed, 11 Oct 2023 18:04:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047496; bh=NgQ9Q/ebYRPTuw2IhlGgJfaSbKmPfqTwGyDrsOWZFac=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZDKF1vMcfVMR37oP435n50dhF8EN3vMKu1ukby+i6Z7wNj07YAtHgIdqu0r6LbE5M udY27HcJzgimW37SngclKq21cFdBfzPh1DxiYwHEuC9PG0BD3UG6G2t5kmTBhyLNc7 XXT1l7Aua0W2UzIY6O3yXmS0GQZyhN8AV3hzF5nQL5VFAxOhbpGLJ7DPH1TG96yLhH uJSGBqaoKz82LIKMha8hS9EME5HZ6x2KgGP5cLoNPfxfAZJYCkH0r8ng2uaMx/L3aB w2zvLKvWPLApZtwxyvN9F1Kfys/AErG0kTsK77LQ9pYwYmazx0u1kXmVwDC8Jq1p0p FSyGDQcKPNlZw== Date: Wed, 11 Oct 2023 11:04:55 -0700 Subject: [PATCH 2/7] xfs: create a helper to compute leftovers of realtime extents From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721209.1773611.10988808692731283385.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Create a helper to compute the misalignment between a file extent (xfs_extlen_t) and a realtime extent. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 4 ++-- fs/xfs/libxfs/xfs_rtbitmap.h | 9 +++++++++ fs/xfs/libxfs/xfs_trans_inode.c | 1 + fs/xfs/scrub/inode.c | 3 ++- fs/xfs/scrub/inode_repair.c | 3 ++- fs/xfs/xfs_bmap_util.c | 2 +- fs/xfs/xfs_inode_item.c | 3 ++- fs/xfs/xfs_ioctl.c | 5 +++-- 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index fd083a3c554e0..82dc95944374e 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3038,7 +3038,7 @@ xfs_bmap_extsize_align( * If realtime, and the result isn't a multiple of the realtime * extent size we need to remove blocks until it is. */ - if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) { + if (rt && (temp = xfs_extlen_to_rtxmod(mp, align_alen))) { /* * We're not covering the original request, or * we won't be able to once we fix the length. @@ -3065,7 +3065,7 @@ xfs_bmap_extsize_align( else { align_alen -= orig_off - align_off; align_off = orig_off; - align_alen -= align_alen % mp->m_sb.sb_rextsize; + align_alen -= xfs_extlen_to_rtxmod(mp, align_alen); } /* * Result doesn't cover the request, fail it. diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index 099ea8902aaaf..b6a4c46bddc0a 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -22,6 +22,15 @@ xfs_rtxlen_to_extlen( return rtxlen * mp->m_sb.sb_rextsize; } +/* Compute the misalignment between an extent length and a realtime extent .*/ +static inline unsigned int +xfs_extlen_to_rtxmod( + struct xfs_mount *mp, + xfs_extlen_t len) +{ + return len % mp->m_sb.sb_rextsize; +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/fs/xfs/libxfs/xfs_trans_inode.c b/fs/xfs/libxfs/xfs_trans_inode.c index 3e07e7c6a5d53..29f1aa290ce6d 100644 --- a/fs/xfs/libxfs/xfs_trans_inode.c +++ b/fs/xfs/libxfs/xfs_trans_inode.c @@ -14,6 +14,7 @@ #include "xfs_trans.h" #include "xfs_trans_priv.h" #include "xfs_inode_item.h" +#include "xfs_rtbitmap.h" #include diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c index 3cb75c559a32f..e8da1ae3c5c01 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -20,6 +20,7 @@ #include "xfs_reflink.h" #include "xfs_rmap.h" #include "xfs_bmap_util.h" +#include "xfs_rtbitmap.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/btree.h" @@ -254,7 +255,7 @@ xchk_inode_extsize( */ if ((flags & XFS_DIFLAG_RTINHERIT) && (flags & XFS_DIFLAG_EXTSZINHERIT) && - value % sc->mp->m_sb.sb_rextsize > 0) + xfs_extlen_to_rtxmod(sc->mp, value) > 0) xchk_ino_set_warning(sc, ino); } diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index 6787abbc6d6ff..7f1f7cec822a2 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -36,6 +36,7 @@ #include "xfs_attr_leaf.h" #include "xfs_log_priv.h" #include "xfs_symlink_remote.h" +#include "xfs_rtbitmap.h" #include "scrub/xfs_scrub.h" #include "scrub/scrub.h" #include "scrub/common.h" @@ -1599,7 +1600,7 @@ xrep_inode_extsize( /* Fix misaligned extent size hints on a directory. */ if ((sc->ip->i_diflags & XFS_DIFLAG_RTINHERIT) && (sc->ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) && - sc->ip->i_extsize % sc->mp->m_sb.sb_rextsize > 0) { + xfs_extlen_to_rtxmod(sc->mp, sc->ip->i_extsize) > 0) { sc->ip->i_extsize = 0; sc->ip->i_diflags &= ~XFS_DIFLAG_EXTSZINHERIT; } diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index cd4136b2b39c4..0590d55cd88f6 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -98,7 +98,7 @@ xfs_bmap_rtalloc( if (error) return error; ASSERT(ap->length); - ASSERT(ap->length % mp->m_sb.sb_rextsize == 0); + ASSERT(xfs_extlen_to_rtxmod(mp, ap->length) == 0); /* * If we shifted the file offset downward to satisfy an extent size diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c index 127b2410eb206..3183d0b03e0bc 100644 --- a/fs/xfs/xfs_inode_item.c +++ b/fs/xfs/xfs_inode_item.c @@ -19,6 +19,7 @@ #include "xfs_log.h" #include "xfs_log_priv.h" #include "xfs_error.h" +#include "xfs_rtbitmap.h" #include @@ -107,7 +108,7 @@ xfs_inode_item_precommit( */ if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) && (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) && - (ip->i_extsize % ip->i_mount->m_sb.sb_rextsize) > 0) { + xfs_extlen_to_rtxmod(ip->i_mount, ip->i_extsize) > 0) { ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE | XFS_DIFLAG_EXTSZINHERIT); ip->i_extsize = 0; diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index a2c7508527f8c..cbfa8500e2354 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -41,6 +41,7 @@ #include "xfs_xattr.h" #include "xfs_xchgrange.h" #include "xfs_file.h" +#include "xfs_rtbitmap.h" #include #include @@ -1017,7 +1018,7 @@ xfs_fill_fsxattr( * later. */ if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) && - ip->i_extsize % mp->m_sb.sb_rextsize > 0) { + xfs_extlen_to_rtxmod(mp, ip->i_extsize) > 0) { fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); fa->fsx_extsize = 0; @@ -1083,7 +1084,7 @@ xfs_ioctl_setattr_xflags( /* If realtime flag is set then must have realtime device */ if (fa->fsx_xflags & FS_XFLAG_REALTIME) { if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 || - (ip->i_extsize % mp->m_sb.sb_rextsize)) + xfs_extlen_to_rtxmod(mp, ip->i_extsize)) return -EINVAL; } From patchwork Wed Oct 11 18:05:11 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: 13417703 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 96C3FCDB473 for ; Wed, 11 Oct 2023 18:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233055AbjJKSFO (ORCPT ); Wed, 11 Oct 2023 14:05:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232952AbjJKSFN (ORCPT ); Wed, 11 Oct 2023 14:05:13 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F62F94 for ; Wed, 11 Oct 2023 11:05:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06FCBC433C7; Wed, 11 Oct 2023 18:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047512; bh=k2J1S7+PW8uAsud6zLCq0IkcArv4G8w9CB68ulsW/5E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qaiFju2FWrfdYpgNMeXadP+/vvNPvC+1n+1vCThGlXXpCnZ8CKgD6RDSb8DnITzgQ +KeHqU36YtzbmZh1+m4NxyHdnUIK4bu2BxJirD52AsmqwtMsI+e4O+sR2SQwf57GpS Fw5A3lZx+XFaNxbTM6m2URrsgweiw9Vc+/Ll+fX5Zo1qIHUHGdLE3sOYnYERgwH+m2 l0kTOPh5MbQumDRNzixjMSJgZ2fQ3MW5o/haTTpvLlpkScu5cYBBUGdmWo8XUyZPFe oEg/6yO/Ss8oArqKjXvnE8dAaQPdhoclpeUfosE9tz+CFOWsauejqjVY9q6qbPw1rh Qyyd0t8b+T5hw== Date: Wed, 11 Oct 2023 11:05:11 -0700 Subject: [PATCH 3/7] xfs: create a helper to compute leftovers of realtime extents From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721225.1773611.3934306904978045115.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Create a helper to compute the realtime extent (xfs_rtxlen_t) from an extent length (xfs_extlen_t) value. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.h | 8 ++++++++ fs/xfs/libxfs/xfs_trans_resv.c | 3 ++- fs/xfs/xfs_bmap_util.c | 11 ++++------- fs/xfs/xfs_trans.c | 5 +++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index b6a4c46bddc0a..e2a36fc157c4c 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -31,6 +31,14 @@ xfs_extlen_to_rtxmod( return len % mp->m_sb.sb_rextsize; } +static inline xfs_rtxlen_t +xfs_extlen_to_rtxlen( + struct xfs_mount *mp, + xfs_extlen_t len) +{ + return len / mp->m_sb.sb_rextsize; +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index 328c569c20a35..9c3dbcbe05358 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -22,6 +22,7 @@ #include "xfs_attr_item.h" #include "xfs_log.h" #include "xfs_da_format.h" +#include "xfs_rtbitmap.h" #define _ALLOC true #define _FREE false @@ -223,7 +224,7 @@ xfs_rtalloc_block_count( unsigned int blksz = XFS_FSB_TO_B(mp, 1); unsigned int rtbmp_bytes; - rtbmp_bytes = (XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize) / NBBY; + rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY; return (howmany(rtbmp_bytes, blksz) + 1) * num_ops; } diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 0590d55cd88f6..c246f25aaad55 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -91,7 +91,7 @@ xfs_bmap_rtalloc( align = xfs_get_extsz_hint(ap->ip); retry: - prod = align / mp->m_sb.sb_rextsize; + prod = xfs_extlen_to_rtxlen(mp, align); error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, align, 1, ap->eof, 0, ap->conv, &ap->offset, &ap->length); @@ -118,17 +118,14 @@ xfs_bmap_rtalloc( prod = 1; /* * Set ralen to be the actual requested length in rtextents. - */ - ralen = ap->length / mp->m_sb.sb_rextsize; - /* + * * If the old value was close enough to XFS_BMBT_MAX_EXTLEN that * we rounded up to it, cut it back so it's valid again. * Note that if it's a really large request (bigger than * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't * adjust the starting point to match it. */ - if (xfs_rtxlen_to_extlen(mp, ralen) >= XFS_MAX_BMBT_EXTLEN) - ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize; + ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN)); /* * Lock out modifications to both the RT bitmap and summary inodes @@ -165,7 +162,7 @@ xfs_bmap_rtalloc( do_div(ap->blkno, mp->m_sb.sb_rextsize); rtx = ap->blkno; ap->length = ralen; - raminlen = max_t(xfs_extlen_t, 1, minlen / mp->m_sb.sb_rextsize); + raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen)); error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length, &ralen, ap->wasdel, prod, &rtx); if (error) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index ea045af01f5e8..22aa2111b6cab 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -24,6 +24,7 @@ #include "xfs_dquot_item.h" #include "xfs_dquot.h" #include "xfs_icache.h" +#include "xfs_rtbitmap.h" struct kmem_cache *xfs_trans_cache; @@ -1252,7 +1253,7 @@ xfs_trans_alloc_inode( retry: error = xfs_trans_alloc(mp, resv, dblocks, - rblocks / mp->m_sb.sb_rextsize, + xfs_extlen_to_rtxlen(mp, rblocks), force ? XFS_TRANS_RESERVE : 0, &tp); if (error) return error; @@ -1298,7 +1299,7 @@ xfs_trans_reserve_more_inode( bool force_quota) { struct xfs_mount *mp = ip->i_mount; - unsigned int rtx = rblocks / mp->m_sb.sb_rextsize; + unsigned int rtx = xfs_extlen_to_rtxlen(mp, rblocks); int error; ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); From patchwork Wed Oct 11 18:05:27 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: 13417704 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 3703ECDB470 for ; Wed, 11 Oct 2023 18:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234976AbjJKSFc (ORCPT ); Wed, 11 Oct 2023 14:05:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235033AbjJKSF3 (ORCPT ); Wed, 11 Oct 2023 14:05:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20403CA for ; Wed, 11 Oct 2023 11:05:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EA9FC433C7; Wed, 11 Oct 2023 18:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047527; bh=gWLBKDAhhyCzRO9pvit4aHSyErvbYacnXgMqF5ldz6k=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DIQSYeoXXFVJVkgHn8gD33MbX7bxJ+VL85O2LPJPZ3qKWudCO9X1FJBrHGS55SJCB fipDwPjWcCHQ4nsNvJ7NN2ay/EL4CTr7HbDA6a3W8C+snzOStfpDhZmbp48BT/UAN2 CkSMbWpPGv59qHMhsIuWNBxNowKleno9cFYowKXiN5uvE7ZPx2uqzwWEW+HoGbzox/ j5v7L34udNJxEcfB67e6Y9gt2JS+MxdOSmoCdqm5BvnKEO3gEA0JHJWlmfJf8blkb9 8e8+ixq7Iqd8Iz8Fu4H5CX2kPf3rtPfcFpDh3rPTyZ8cvkFOfGYvz9c5MCPRjI9SPE 7cd6XxV5LhEIQ== Date: Wed, 11 Oct 2023 11:05:27 -0700 Subject: [PATCH 4/7] xfs: create helpers to convert rt block numbers to rt extent numbers From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721239.1773611.10087575278257926892.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Create helpers to do unit conversions of rt block numbers to rt extent numbers. There are two variations -- the suffix "t" denotes the one that returns only the truncated extent number; the other one also returns the misalignment. Convert all the div_u64_rem users; we'll do the do_div users in the next patch. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 7 +++---- fs/xfs/libxfs/xfs_rtbitmap.c | 4 ++-- fs/xfs/libxfs/xfs_rtbitmap.h | 17 +++++++++++++++++ fs/xfs/libxfs/xfs_swapext.c | 7 ++++--- fs/xfs/xfs_rtalloc.c | 8 ++++---- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 82dc95944374e..463174af94333 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5336,7 +5336,6 @@ __xfs_bunmapi( int tmp_logflags; /* partial logging flags */ int wasdel; /* was a delayed alloc extent */ int whichfork; /* data or attribute fork */ - xfs_fsblock_t sum; xfs_filblks_t len = *rlen; /* length to unmap in file */ xfs_fileoff_t end; struct xfs_iext_cursor icur; @@ -5433,8 +5432,7 @@ __xfs_bunmapi( if (!isrt || (flags & XFS_BMAPI_REMAP)) goto delete; - sum = del.br_startblock + del.br_blockcount; - div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, del.br_startblock + del.br_blockcount, &mod); if (mod) { /* * Realtime extent not lined up at the end. @@ -5481,7 +5479,8 @@ __xfs_bunmapi( goto error0; goto nodelete; } - div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod); + + xfs_rtb_to_rtx(mp, del.br_startblock, &mod); if (mod) { xfs_extlen_t off = mp->m_sb.sb_rextsize - mod; diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c index ce14436811319..de54386cf52f3 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.c +++ b/fs/xfs/libxfs/xfs_rtbitmap.c @@ -1031,13 +1031,13 @@ xfs_rtfree_blocks( ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN); - len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod); + len = xfs_rtb_to_rtx(mp, rtlen, &mod); if (mod) { ASSERT(mod == 0); return -EIO; } - start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod); + start = xfs_rtb_to_rtx(mp, rtbno, &mod); if (mod) { ASSERT(mod == 0); return -EIO; diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index e2a36fc157c4c..bdd4858a794c2 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -39,6 +39,23 @@ xfs_extlen_to_rtxlen( return len / mp->m_sb.sb_rextsize; } +static inline xfs_rtxnum_t +xfs_rtb_to_rtx( + struct xfs_mount *mp, + xfs_rtblock_t rtbno, + xfs_extlen_t *mod) +{ + return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, mod); +} + +static inline xfs_rtxnum_t +xfs_rtb_to_rtxt( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return div_u64(rtbno, mp->m_sb.sb_rextsize); +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/fs/xfs/libxfs/xfs_swapext.c b/fs/xfs/libxfs/xfs_swapext.c index b1d66e0cfac91..6107ec7d8d568 100644 --- a/fs/xfs/libxfs/xfs_swapext.c +++ b/fs/xfs/libxfs/xfs_swapext.c @@ -30,6 +30,7 @@ #include "xfs_dir2_priv.h" #include "xfs_dir2.h" #include "xfs_symlink_remote.h" +#include "xfs_rtbitmap.h" struct kmem_cache *xfs_swapext_intent_cache; @@ -202,19 +203,19 @@ xfs_swapext_check_rt_extents( irec2.br_blockcount); /* Both mappings must be aligned to the realtime extent size. */ - div_u64_rem(irec1.br_startoff, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, irec1.br_startoff, &mod); if (mod) { ASSERT(mod == 0); return -EINVAL; } - div_u64_rem(irec2.br_startoff, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, irec1.br_startoff, &mod); if (mod) { ASSERT(mod == 0); return -EINVAL; } - div_u64_rem(irec1.br_blockcount, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, irec1.br_blockcount, &mod); if (mod) { ASSERT(mod == 0); return -EINVAL; diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 4bb776911a4fb..d3a5112f21156 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1496,16 +1496,16 @@ xfs_rtfile_want_conversion( struct xfs_bmbt_irec *irec) { xfs_fileoff_t rext_next; - uint32_t modoff, modcnt; + xfs_extlen_t modoff, modcnt; if (irec->br_state != XFS_EXT_UNWRITTEN) return false; - div_u64_rem(irec->br_startoff, mp->m_sb.sb_rextsize, &modoff); + xfs_rtb_to_rtx(mp, irec->br_startoff, &modoff); if (modoff == 0) { - uint64_t rexts = div_u64_rem(irec->br_blockcount, - mp->m_sb.sb_rextsize, &modcnt); + xfs_rtbxlen_t rexts; + rexts = xfs_rtb_to_rtx(mp, irec->br_blockcount, &modcnt); if (rexts > 0) { /* * Unwritten mapping starts at an rt extent boundary From patchwork Wed Oct 11 18:05:42 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: 13417705 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 747E2CDB470 for ; Wed, 11 Oct 2023 18:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234887AbjJKSFr (ORCPT ); Wed, 11 Oct 2023 14:05:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235049AbjJKSFq (ORCPT ); Wed, 11 Oct 2023 14:05:46 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5482B93 for ; Wed, 11 Oct 2023 11:05:44 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E8AAC433C8; Wed, 11 Oct 2023 18:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047543; bh=wn7y1rE2HpAkRzhNVQmhbUQJcog2OgfSTHV2Gq38DJE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rXOmGic9RKnELpRuXCzgkRSgHt5KpicRvqoChYtwYgI0VdBDP/m4kwd3vD5bqIh20 DXgi96oEyr1e4Y1HMZYwvwVlk17JquKkgGbwW59ODyXhjPwQ3rvPbztnhPM4VnB8YM vsHsV7X3P/vjRtTn8ZQwg5Zs75JPVmyLGcAZ1wjnB5RZalO1NMo5i196SMS4VFU2Ze fIIqZsUXl/I74nA7PRnH5tj1npH24FIThzK56LUcFHAGQp/2nYKRMMgFvzCpArHwIk 8FkxabHzU4+qT3d32/Sx/kmyhHYOWBQajQrzWUouhXonhAiuU65EZMt4TVu67aDKKc X20v5doOWWw1Q== Date: Wed, 11 Oct 2023 11:05:42 -0700 Subject: [PATCH 5/7] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721255.1773611.7719978115841778913.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Convert these calls to use the helpers, and clean up all these places where the same variable can have different units depending on where it is in the function. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 8 ++------ fs/xfs/scrub/rtbitmap.c | 14 +++++--------- fs/xfs/xfs_bmap_util.c | 10 ++++------ fs/xfs/xfs_fsmap.c | 8 ++++---- fs/xfs/xfs_rtalloc.c | 3 +-- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 463174af94333..d322fd5116179 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4883,12 +4883,8 @@ xfs_bmap_del_extent_delay( ASSERT(got->br_startoff <= del->br_startoff); ASSERT(got_endoff >= del_endoff); - if (isrt) { - uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount); - - do_div(rtexts, mp->m_sb.sb_rextsize); - xfs_mod_frextents(mp, rtexts); - } + if (isrt) + xfs_mod_frextents(mp, xfs_rtb_to_rtxt(mp, del->br_blockcount)); /* * Update the inode delalloc counter now and wait to update the diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c index 01bc5119d612c..a785fb5f317dd 100644 --- a/fs/xfs/scrub/rtbitmap.c +++ b/fs/xfs/scrub/rtbitmap.c @@ -140,26 +140,22 @@ xchk_rtbitmap( void xchk_xref_is_used_rt_space( struct xfs_scrub *sc, - xfs_rtblock_t fsbno, + xfs_rtblock_t rtbno, xfs_extlen_t len) { xfs_rtxnum_t startext; xfs_rtxnum_t endext; - xfs_rtxlen_t extcount; bool is_free; int error; if (xchk_skip_xref(sc->sm)) return; - startext = fsbno; - endext = fsbno + len - 1; - do_div(startext, sc->mp->m_sb.sb_rextsize); - do_div(endext, sc->mp->m_sb.sb_rextsize); - extcount = endext - startext + 1; + startext = xfs_rtb_to_rtxt(sc->mp, rtbno); + endext = xfs_rtb_to_rtxt(sc->mp, rtbno + len - 1); xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP); - error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount, - &is_free); + error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, + endext - startext + 1, &is_free); if (!xchk_should_check_xref(sc, &error, NULL)) goto out_unlock; if (is_free) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index c246f25aaad55..8f1e16e49dab2 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -157,14 +157,12 @@ xfs_bmap_rtalloc( * Realtime allocation, done through xfs_rtallocate_extent. */ if (ignore_locality) - ap->blkno = 0; + rtx = 0; else - do_div(ap->blkno, mp->m_sb.sb_rextsize); - rtx = ap->blkno; - ap->length = ralen; + rtx = xfs_rtb_to_rtxt(mp, ap->blkno); raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen)); - error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length, - &ralen, ap->wasdel, prod, &rtx); + error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen, + ap->wasdel, prod, &rtx); if (error) return error; diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 1a187bc9da3de..32aefaf7d6684 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -512,6 +512,7 @@ xfs_getfsmap_rtdev_rtbitmap( xfs_rtblock_t start_rtb; xfs_rtblock_t end_rtb; uint64_t eofs; + xfs_extlen_t mod; int error; eofs = XFS_FSB_TO_BB(mp, xfs_rtx_to_rtb(mp, mp->m_sb.sb_rextents)); @@ -539,10 +540,9 @@ xfs_getfsmap_rtdev_rtbitmap( * Set up query parameters to return free rtextents covering the range * we want. */ - alow.ar_startext = start_rtb; - ahigh.ar_startext = end_rtb; - do_div(alow.ar_startext, mp->m_sb.sb_rextsize); - if (do_div(ahigh.ar_startext, mp->m_sb.sb_rextsize)) + alow.ar_startext = xfs_rtb_to_rtxt(mp, start_rtb); + ahigh.ar_startext = xfs_rtb_to_rtx(mp, end_rtb, &mod); + if (mod) ahigh.ar_startext++; error = xfs_rtalloc_query_range(mp, tp, &alow, &ahigh, xfs_getfsmap_rtdev_rtbitmap_helper, info); diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index d3a5112f21156..8db8f957a683b 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1056,8 +1056,7 @@ xfs_growfs_rt( nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize * nsbp->sb_rextsize; nsbp->sb_rblocks = min(nrblocks, nrblocks_step); - nsbp->sb_rextents = nsbp->sb_rblocks; - do_div(nsbp->sb_rextents, nsbp->sb_rextsize); + nsbp->sb_rextents = xfs_rtb_to_rtxt(nmp, nsbp->sb_rblocks); ASSERT(nsbp->sb_rextents != 0); nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents); nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1; From patchwork Wed Oct 11 18:05:58 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: 13417706 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 66FD0CDB475 for ; Wed, 11 Oct 2023 18:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234700AbjJKSGB (ORCPT ); Wed, 11 Oct 2023 14:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346207AbjJKSGA (ORCPT ); Wed, 11 Oct 2023 14:06:00 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A84A94 for ; Wed, 11 Oct 2023 11:05:59 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE29CC433C7; Wed, 11 Oct 2023 18:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047559; bh=UJD/AnAy5k43DrNyqfYi8yNVnFGlcXcIOABov2HOYME=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jkCZXMCHmNNPVFtvV+xrzr6g4wcO7X4t4h9uTC7GAVFExARz8UVK7An6c/6aNhf6g TYyRNscHzELjy4oiJDq1Uzg6YX3X9CxIGhi93P5DtV86dBpSV+7ZJLWP0uPkaIicjL VXLymcTYAzbdZq+yd+eHHVSAWkAFVZ6E2ewuH7YCEWSGX1r4+QNt1huQYzIcvkXXQV Zh/V6wFq9ck4y9O9jy3XaYobIo0ZZ6JFXsCVSP2KCOOQcfCw95+bFysUdBQ2MSkO36 JQ/bXSDU5yRjKXSHZh11CGwRK2nvCY5XYcV044MzmMOfq4ujYMfY6vTj7PKLcPEb72 +IfaY98DfCAIA== Date: Wed, 11 Oct 2023 11:05:58 -0700 Subject: [PATCH 6/7] xfs: create rt extent rounding helpers for realtime extent blocks From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721269.1773611.8447535257561725790.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Create a pair of functions to round rtblock numbers up or down to the nearest rt extent. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.h | 18 ++++++++++++++++++ fs/xfs/xfs_bmap_util.c | 8 +++----- fs/xfs/xfs_rtalloc.c | 4 ++-- fs/xfs/xfs_xchgrange.c | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index bdd4858a794c2..bc51d3bfc7c45 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -56,6 +56,24 @@ xfs_rtb_to_rtxt( return div_u64(rtbno, mp->m_sb.sb_rextsize); } +/* Round this rtblock up to the nearest rt extent size. */ +static inline xfs_rtblock_t +xfs_rtb_roundup_rtx( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return roundup_64(rtbno, mp->m_sb.sb_rextsize); +} + +/* Round this rtblock down to the nearest rt extent size. */ +static inline xfs_rtblock_t +xfs_rtb_rounddown_rtx( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return rounddown_64(rtbno, mp->m_sb.sb_rextsize); +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 8f1e16e49dab2..b17332b84812e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -685,7 +685,7 @@ xfs_can_free_eofblocks( */ end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) - end_fsb = roundup_64(end_fsb, mp->m_sb.sb_rextsize); + end_fsb = xfs_rtb_roundup_rtx(mp, end_fsb); last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); if (last_fsb <= end_fsb) return false; @@ -984,10 +984,8 @@ xfs_free_file_space( /* We can only free complete realtime extents. */ if (xfs_inode_has_bigrtextents(ip)) { - startoffset_fsb = roundup_64(startoffset_fsb, - mp->m_sb.sb_rextsize); - endoffset_fsb = rounddown_64(endoffset_fsb, - mp->m_sb.sb_rextsize); + startoffset_fsb = xfs_rtb_roundup_rtx(mp, startoffset_fsb); + endoffset_fsb = xfs_rtb_rounddown_rtx(mp, endoffset_fsb); } /* diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 8db8f957a683b..e62ca51b995ba 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1633,8 +1633,8 @@ xfs_rtfile_convert_unwritten( if (mp->m_sb.sb_rextsize == 1) return 0; - off = rounddown_64(XFS_B_TO_FSBT(mp, pos), mp->m_sb.sb_rextsize); - endoff = roundup_64(XFS_B_TO_FSB(mp, pos + len), mp->m_sb.sb_rextsize); + off = xfs_rtb_rounddown_rtx(mp, XFS_B_TO_FSBT(mp, pos)); + endoff = xfs_rtb_roundup_rtx(mp, XFS_B_TO_FSB(mp, pos + len)); trace_xfs_rtfile_convert_unwritten(ip, pos, len); diff --git a/fs/xfs/xfs_xchgrange.c b/fs/xfs/xfs_xchgrange.c index befa915089ce6..a4a352e027c97 100644 --- a/fs/xfs/xfs_xchgrange.c +++ b/fs/xfs/xfs_xchgrange.c @@ -28,6 +28,7 @@ #include "xfs_icache.h" #include "xfs_log.h" #include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include /* @@ -1236,8 +1237,7 @@ xfs_xchg_range( * offsets and length in @fxr are safe to round up. */ if (XFS_IS_REALTIME_INODE(ip2)) - req.blockcount = roundup_64(req.blockcount, - mp->m_sb.sb_rextsize); + req.blockcount = xfs_rtb_roundup_rtx(mp, req.blockcount); error = xfs_xchg_range_estimate(&req); if (error) From patchwork Wed Oct 11 18:06:14 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: 13417707 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 89D04CDB475 for ; Wed, 11 Oct 2023 18:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234947AbjJKSGT (ORCPT ); Wed, 11 Oct 2023 14:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346207AbjJKSGQ (ORCPT ); Wed, 11 Oct 2023 14:06:16 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3789DBA for ; Wed, 11 Oct 2023 11:06:15 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2EC2C433C7; Wed, 11 Oct 2023 18:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697047574; bh=y7dvVRHDVzVRzNJopYewqTjTimsXb9+XOvx95jY7NRk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lNRhampNz4EX7IuPMvsr6K0ots4LAP/WVxWJZyjjbPVo8kE6ztNw0/y81WrunttfY Juiwl4kA/QNL0JXgB/wFAeHuGfz+Lx4NiG8P2neHQmDhjfNKmeCorW2EtPJZNntPrT T2+QZiGSSsJeXEbIt8HZaFAtloGqjbLCPeFiJlBoVzG+0tFkk3FfkuJt3UIhDrIH65 9hgtPwP/LHYJbtZ7N8tHdRp8jocAnFuvVWdXVrxFtLVYo4t8O+0f10mpgtS58UfJHN 37OHxGrYslyQO6S2E6ELZ8hTAgtBJFiVHG6kGhVZ+Pi0/N2AbLX1Oe2A2kDphMqvXi 2Ny1TXskSWqBQ== Date: Wed, 11 Oct 2023 11:06:14 -0700 Subject: [PATCH 7/7] xfs: use shifting and masking when converting rt extents, if possible From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, osandov@osandov.com, hch@lst.de Message-ID: <169704721284.1773611.1915589661676489.stgit@frogsfrogsfrogs> In-Reply-To: <169704721170.1773611.12311239321983752854.stgit@frogsfrogsfrogs> References: <169704721170.1773611.12311239321983752854.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 Avoid the costs of integer division (32-bit and 64-bit) if the realtime extent size is a power of two. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtbitmap.h | 20 ++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_linux.h | 12 ++++++++++++ fs/xfs/xfs_mount.h | 2 ++ fs/xfs/xfs_rtalloc.c | 1 + fs/xfs/xfs_trans.c | 4 ++++ 6 files changed, 41 insertions(+) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index bc51d3bfc7c45..9dd791181ca2b 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -11,6 +11,9 @@ xfs_rtx_to_rtb( struct xfs_mount *mp, xfs_rtxnum_t rtx) { + if (mp->m_rtxblklog >= 0) + return rtx << mp->m_rtxblklog; + return rtx * mp->m_sb.sb_rextsize; } @@ -19,6 +22,9 @@ xfs_rtxlen_to_extlen( struct xfs_mount *mp, xfs_rtxlen_t rtxlen) { + if (mp->m_rtxblklog >= 0) + return rtxlen << mp->m_rtxblklog; + return rtxlen * mp->m_sb.sb_rextsize; } @@ -28,6 +34,9 @@ xfs_extlen_to_rtxmod( struct xfs_mount *mp, xfs_extlen_t len) { + if (mp->m_rtxblklog >= 0) + return len & mp->m_rtxblkmask; + return len % mp->m_sb.sb_rextsize; } @@ -36,6 +45,9 @@ xfs_extlen_to_rtxlen( struct xfs_mount *mp, xfs_extlen_t len) { + if (mp->m_rtxblklog >= 0) + return len >> mp->m_rtxblklog; + return len / mp->m_sb.sb_rextsize; } @@ -45,6 +57,11 @@ xfs_rtb_to_rtx( xfs_rtblock_t rtbno, xfs_extlen_t *mod) { + if (mp->m_rtxblklog >= 0) { + *mod = rtbno & mp->m_rtxblkmask; + return rtbno >> mp->m_rtxblklog; + } + return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, mod); } @@ -53,6 +70,9 @@ xfs_rtb_to_rtxt( struct xfs_mount *mp, xfs_rtblock_t rtbno) { + if (mp->m_rtxblklog >= 0) + return rtbno >> mp->m_rtxblklog; + return div_u64(rtbno, mp->m_sb.sb_rextsize); } diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 5fb142b8e3d92..db04378f287a6 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -1011,6 +1011,8 @@ xfs_sb_mount_common( mp->m_blockmask = sbp->sb_blocksize - 1; mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG; mp->m_blockwmask = mp->m_blockwsize - 1; + mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize); + mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize); mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1); mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0); diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index dfde4021905b7..953466922ddf7 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -203,6 +203,18 @@ static inline bool isaligned_64(uint64_t x, uint32_t y) return do_div(x, y) == 0; } +/* If @b is a power of 2, return log2(b). Else return -1. */ +static inline int8_t log2_if_power2(unsigned long b) +{ + return is_power_of_2(b) ? ilog2(b) : -1; +} + +/* If @b is a power of 2, return a mask of the lower bits, else return zero. */ +static inline unsigned long long mask64_if_power2(unsigned long b) +{ + return is_power_of_2(b) ? b - 1 : 0; +} + int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count, char *data, enum req_op op); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index f42679a6569ff..3c5b0327164bc 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -120,6 +120,7 @@ typedef struct xfs_mount { uint8_t m_blkbb_log; /* blocklog - BBSHIFT */ uint8_t m_agno_log; /* log #ag's */ uint8_t m_sectbb_log; /* sectlog - BBSHIFT */ + int8_t m_rtxblklog; /* log2 of rextsize, if possible */ uint m_blockmask; /* sb_blocksize-1 */ uint m_blockwsize; /* sb_blocksize in words */ uint m_blockwmask; /* blockwsize-1 */ @@ -153,6 +154,7 @@ typedef struct xfs_mount { uint64_t m_features; /* active filesystem features */ uint64_t m_low_space[XFS_LOWSP_MAX]; uint64_t m_low_rtexts[XFS_LOWSP_MAX]; + uint64_t m_rtxblkmask; /* rt extent block mask */ struct xfs_ino_geometry m_ino_geo; /* inode geometry */ struct xfs_trans_resv m_resv; /* precomputed res values */ /* low free space thresholds */ diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index e62ca51b995ba..dc4874776c2cb 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1052,6 +1052,7 @@ xfs_growfs_rt( * Calculate new sb and mount fields for this round. */ nsbp->sb_rextsize = in->extsize; + nmp->m_rtxblklog = -1; /* don't use shift or masking */ nsbp->sb_rbmblocks = bmbno + 1; nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize * nsbp->sb_rextsize; diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 22aa2111b6cab..35161074c4e7d 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -712,6 +712,10 @@ xfs_trans_unreserve_and_mod_sb( mp->m_sb.sb_agcount += tp->t_agcount_delta; mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta; mp->m_sb.sb_rextsize += tp->t_rextsize_delta; + if (tp->t_rextsize_delta) { + mp->m_rtxblklog = log2_if_power2(mp->m_sb.sb_rextsize); + mp->m_rtxblkmask = mask64_if_power2(mp->m_sb.sb_rextsize); + } mp->m_sb.sb_rbmblocks += tp->t_rbmblocks_delta; mp->m_sb.sb_rblocks += tp->t_rblocks_delta; mp->m_sb.sb_rextents += tp->t_rextents_delta;