From patchwork Fri Dec 30 22:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085640 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 80F77C4332F for ; Sat, 31 Dec 2022 02:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236219AbiLaCWE (ORCPT ); Fri, 30 Dec 2022 21:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236224AbiLaCWC (ORCPT ); Fri, 30 Dec 2022 21:22:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A6DA19C12 for ; Fri, 30 Dec 2022 18:22:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 24AC661C31 for ; Sat, 31 Dec 2022 02:22:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F6C9C433D2; Sat, 31 Dec 2022 02:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453320; bh=nyKqIR4xQ0u9byPhB7wUPV3dA2lftW+AqkrF02lvLhg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=M2k/m6IiswzkyfT/vPeclTnPWfoW2s37KaeMeGyfX8y+y2PL7b3abNz3TN4EukfXm rUYYudvBgjUTo5Kf5bY3nIQe38yfToSuM1peKwfDuM7Ajb5+wSgc2wKhN6IIvkUFxw +3aey46wz0+vQhJqjbmEQ2OQmVZw9pI1TSWYKMszpduy53LjrThc2EqKQfdP2zPw6g tHAx0p09DUgmdHZQP0/857/xCxYls5Eis6ehqO7fuJoffb8quQMzDHiwiWEOOw9GEN OgyJLmYzEhMVV+RcJcv4hmr2KjOUy4UpGlDZjibmqzyvP7AhA1Vtzu6DAoW9WtjzWJ Z+bNCAPx6aAXw== Subject: [PATCH 01/10] xfs: create a helper to convert rtextents to rtblocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:28 -0800 Message-ID: <167243876829.727509.12593553022316443491.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 --- libxfs/xfs_rtbitmap.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 5e2afb7fea0..099ea8902aa 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/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. */ From patchwork Fri Dec 30 22:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085641 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 2727CC4332F for ; Sat, 31 Dec 2022 02:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236211AbiLaCWV (ORCPT ); Fri, 30 Dec 2022 21:22:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236217AbiLaCWU (ORCPT ); Fri, 30 Dec 2022 21:22:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC9561A833 for ; Fri, 30 Dec 2022 18:22:18 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 65277B81E0A for ; Sat, 31 Dec 2022 02:22:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10158C433D2; Sat, 31 Dec 2022 02:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453336; bh=u3MNaCQd66e07cqc9QhEL31yHRDcbkEaLgjh0JHD+tk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Qv/9WMdB7Xs53LEB8oucjyopajufwGYAhxhe8XxQXxcI0Mh8BsTT4T+J5N8k9ffN+ Lu2r3jdKH5hi/AluUcpec7el5ybNnnqPGIBdGtH7S+YRDdDAM3SZnK3V/7ZKpVNj9v Y9fAT3s6HzgWiQtHeakMtW4zj3IvrzhGefuT29r7UEm9bfh76A6NX47z79cJGPNU3J uKXlSa24u/1heX1HxpkUBKU1xt8r2HmG5rXUs4PRTcbBWQbuPCzmFmnB4+zGiRO5eE qKhV0Z4IbyP6CD3T7/+WyYP2rBkzahUuB6u9hMJmziDOGBFzzx9U3+YtIgUAC0VrC8 Qfln19uaUo1uQ== Subject: [PATCH 02/10] xfs: create a helper to compute leftovers of realtime extents From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:28 -0800 Message-ID: <167243876841.727509.4018694486761266328.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 --- libxfs/xfs_bmap.c | 4 ++-- libxfs/xfs_rtbitmap.h | 9 +++++++++ libxfs/xfs_trans_inode.c | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 25b89d5ee13..025298db1e8 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -3052,7 +3052,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. @@ -3079,7 +3079,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/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 099ea8902aa..b6a4c46bddc 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/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/libxfs/xfs_trans_inode.c b/libxfs/xfs_trans_inode.c index 6fc7a65d517..e2d5d3efaab 100644 --- a/libxfs/xfs_trans_inode.c +++ b/libxfs/xfs_trans_inode.c @@ -12,6 +12,7 @@ #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_trans.h" +#include "xfs_rtbitmap.h" /* @@ -149,7 +150,7 @@ xfs_trans_log_inode( */ 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; From patchwork Fri Dec 30 22:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085642 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 BCD7BC4332F for ; Sat, 31 Dec 2022 02:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236217AbiLaCWe (ORCPT ); Fri, 30 Dec 2022 21:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236216AbiLaCWd (ORCPT ); Fri, 30 Dec 2022 21:22:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC9B519C12 for ; Fri, 30 Dec 2022 18:22:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5335361C77 for ; Sat, 31 Dec 2022 02:22:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEEBBC433EF; Sat, 31 Dec 2022 02:22:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453351; bh=VdCpNsLQfwQwAOpdjNdrU6w8GGuls+JZyid9v0ramyU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=WbdaAtbys4YAGWjiGO3idlN8mClmRoKplYQMNh7kYayAkpG7akNuz3D0lNr+cX1ZG w72sMR6bFGKh+qBoCDvnhIlCQsJR3zX6IM+BrjVau/adF2I9O4VxFpTkLtHPWE0qvH RL1W8kpwOrURKHynWkxMm78Afq98EaZKNbPIrkmlLawAtR0MZ4F3YehrG7pDeFLoiL 0C3B+hj+sI5ljurhUYdGPGuNzJWYZOrQfgUgboO12FFW5cS0DTOz5CxWLRDT+Gyw+r WV0wnwD0lxk6OIuQ8lcgrqEhjUI+ryAVPmbNQj4N/a/5WtiyJ9d633As2OJ5C+wVUy alKkwqnWB+1IA== Subject: [PATCH 03/10] xfs: create a helper to compute leftovers of realtime extents From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:28 -0800 Message-ID: <167243876855.727509.16014981401064876176.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 --- libxfs/xfs_rtbitmap.h | 8 ++++++++ libxfs/xfs_trans_resv.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index b6a4c46bddc..e2a36fc157c 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/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/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c index 2835d7754a8..be486ed42c3 100644 --- a/libxfs/xfs_trans_resv.c +++ b/libxfs/xfs_trans_resv.c @@ -18,6 +18,7 @@ #include "xfs_trans.h" #include "xfs_trans_space.h" #include "xfs_quota_defs.h" +#include "xfs_rtbitmap.h" #define _ALLOC true #define _FREE false @@ -219,7 +220,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; } From patchwork Fri Dec 30 22:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085643 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 3DA2CC4332F for ; Sat, 31 Dec 2022 02:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236218AbiLaCWt (ORCPT ); Fri, 30 Dec 2022 21:22:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236216AbiLaCWt (ORCPT ); Fri, 30 Dec 2022 21:22:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D6D519C12 for ; Fri, 30 Dec 2022 18:22:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CED4761C43 for ; Sat, 31 Dec 2022 02:22:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37AA0C433EF; Sat, 31 Dec 2022 02:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453367; bh=MiuHvsC/tBqxyPKHtP1pAHm4pCl3IpB2W1oOEpp1FKA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KjXfKGT7IF1iTbLqgRhItOJpxTG3cjpwVLvCGU+/I4eIYrzQlTJeea0EdM86wkk4w uRIDe8KTMPY4YVKynkn3lZ2iCycijjyQ4IpmM08JcpIXOJqXSAiyaaTVp1XLN2y19K yqjT3Km6Dc7YA4RMGpWqKX+BljTbjFVlO8jMCo8VUG1iaO7H1RnqHmrGtnS+3WkEGq CwXQEdNDROV6Yua6Kk+xVMos8rXmBS25NWbeRBOb5pud4fKzT+Y43Ml8rR70N7Tlhl urZaSe22WAC+kJNFIr2bWCkMuFjV2Vze8L6Kh30piTfLGpOkPfXY+0N39z9AvudP+B /3nwKf9pqtmIA== Subject: [PATCH 04/10] libfrog: move 64-bit division wrappers to libfrog From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:28 -0800 Message-ID: <167243876868.727509.14947013529888847664.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 We want to keep the rtgroup unit conversion functions as static inlines, so share the div64 functions via libfrog instead of libxfs_priv.h. Signed-off-by: Darrick J. Wong --- libfrog/Makefile | 1 + libfrog/div64.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/libxfs_priv.h | 61 +------------------------------------------- 3 files changed, 71 insertions(+), 60 deletions(-) create mode 100644 libfrog/div64.h diff --git a/libfrog/Makefile b/libfrog/Makefile index 66d2afe56fe..04aecf1abf1 100644 --- a/libfrog/Makefile +++ b/libfrog/Makefile @@ -40,6 +40,7 @@ crc32c.h \ crc32cselftest.h \ crc32defs.h \ crc32table.h \ +div64.h \ file_exchange.h \ fsgeom.h \ logging.h \ diff --git a/libfrog/div64.h b/libfrog/div64.h new file mode 100644 index 00000000000..265487916fc --- /dev/null +++ b/libfrog/div64.h @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2005 Silicon Graphics, Inc. + * All Rights Reserved. + */ +#ifndef LIBFROG_DIV64_H_ +#define LIBFROG_DIV64_H_ + +static inline int __do_div(unsigned long long *n, unsigned base) +{ + int __res; + __res = (int)(((unsigned long) *n) % (unsigned) base); + *n = ((unsigned long) *n) / (unsigned) base; + return __res; +} + +#define do_div(n,base) (__do_div((unsigned long long *)&(n), (base))) +#define do_mod(a, b) ((a) % (b)) +#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) + +/** + * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 32bit divisor + * @remainder: pointer to unsigned 32bit remainder + * + * Return: sets ``*remainder``, then returns dividend / divisor + * + * This is commonly provided by 32bit archs to provide an optimized 64bit + * divide. + */ +static inline uint64_t +div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) +{ + *remainder = dividend % divisor; + return dividend / divisor; +} + +/** + * div_u64 - unsigned 64bit divide with 32bit divisor + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 32bit divisor + * + * This is the most common 64bit divide and should be used if possible, + * as many 32bit archs can optimize this variant better than a full 64bit + * divide. + */ +static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor) +{ + uint32_t remainder; + return div_u64_rem(dividend, divisor, &remainder); +} + +/** + * div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 64bit divisor + * @remainder: pointer to unsigned 64bit remainder + * + * Return: sets ``*remainder``, then returns dividend / divisor + */ +static inline uint64_t +div64_u64_rem(uint64_t dividend, uint64_t divisor, uint64_t *remainder) +{ + *remainder = dividend % divisor; + return dividend / divisor; +} + +#endif /* LIBFROG_DIV64_H_ */ diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 4cb996a3f3f..49441ac787f 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -50,6 +50,7 @@ #include "bitops.h" #include "kmem.h" #include "libfrog/radix-tree.h" +#include "libfrog/div64.h" #include "atomic.h" #include "spinlock.h" #include "linux-err.h" @@ -257,66 +258,6 @@ static inline bool __must_check __must_check_overflow(bool overflow) __builtin_add_overflow(__a, __b, __d); \ })) -static inline int __do_div(unsigned long long *n, unsigned base) -{ - int __res; - __res = (int)(((unsigned long) *n) % (unsigned) base); - *n = ((unsigned long) *n) / (unsigned) base; - return __res; -} - -#define do_div(n,base) (__do_div((unsigned long long *)&(n), (base))) -#define do_mod(a, b) ((a) % (b)) -#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) - -/** - * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder - * @dividend: unsigned 64bit dividend - * @divisor: unsigned 32bit divisor - * @remainder: pointer to unsigned 32bit remainder - * - * Return: sets ``*remainder``, then returns dividend / divisor - * - * This is commonly provided by 32bit archs to provide an optimized 64bit - * divide. - */ -static inline uint64_t -div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) -{ - *remainder = dividend % divisor; - return dividend / divisor; -} - -/** - * div_u64 - unsigned 64bit divide with 32bit divisor - * @dividend: unsigned 64bit dividend - * @divisor: unsigned 32bit divisor - * - * This is the most common 64bit divide and should be used if possible, - * as many 32bit archs can optimize this variant better than a full 64bit - * divide. - */ -static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor) -{ - uint32_t remainder; - return div_u64_rem(dividend, divisor, &remainder); -} - -/** - * div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder - * @dividend: unsigned 64bit dividend - * @divisor: unsigned 64bit divisor - * @remainder: pointer to unsigned 64bit remainder - * - * Return: sets ``*remainder``, then returns dividend / divisor - */ -static inline uint64_t -div64_u64_rem(uint64_t dividend, uint64_t divisor, uint64_t *remainder) -{ - *remainder = dividend % divisor; - return dividend / divisor; -} - #define min_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) #define max_t(type,x,y) \ From patchwork Fri Dec 30 22:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085644 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 8D9E6C4332F for ; Sat, 31 Dec 2022 02:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236220AbiLaCXI (ORCPT ); Fri, 30 Dec 2022 21:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236216AbiLaCXH (ORCPT ); Fri, 30 Dec 2022 21:23:07 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 104CB19C12 for ; Fri, 30 Dec 2022 18:23:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 81D34CE1A95 for ; Sat, 31 Dec 2022 02:23:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C672BC433D2; Sat, 31 Dec 2022 02:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453382; bh=S6ctwEH7xSaFsi45TnKQonX8jDlQbZATy9XhNJscNic=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=lJ8CGmj/LZfgG0vTBLtD7uLq6tF/4k4c7dA2GKEl/mzSZ6652PkrBeg3Zu0w2BREE DdHoU+ii4x3YHK0kfHfBtEIfhHSqZpeDtpD5joyNqXs/ZK3wh+5WKIsK8hlIrrIhP/ rcBGch/Zd/XJvr0dRBUBHUneXvRJvSagfu2L0hdg9erSrhyrrgtreOKJNNGki8RXXN R5efufwbdmV8wHuJ17XWR6XQeirnfsov86P8aphqpJbQunkTRE15QI9rsPzdW6s1W1 +1r8n553hKUHTLCtNbum/klce/IcjNJOSB/yhzlrjIcV0eUIallNgYbA7bnRf0nzgw WH/7Vo3W5fXBw== Subject: [PATCH 05/10] xfs: create helpers to convert rt block numbers to rt extent numbers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:28 -0800 Message-ID: <167243876881.727509.13937918096939769614.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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. Signed-off-by: Darrick J. Wong --- include/libxfs.h | 1 + libxfs/xfs_bmap.c | 7 +++---- libxfs/xfs_rtbitmap.c | 4 ++-- libxfs/xfs_rtbitmap.h | 17 +++++++++++++++++ libxfs/xfs_swapext.c | 7 ++++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/libxfs.h b/include/libxfs.h index 661964b8a1e..26202dede67 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -20,6 +20,7 @@ #include "bitops.h" #include "kmem.h" #include "libfrog/radix-tree.h" +#include "libfrog/div64.h" #include "atomic.h" #include "spinlock.h" diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 025298db1e8..5fbfc5372c9 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5365,7 +5365,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; @@ -5462,8 +5461,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. @@ -5510,7 +5508,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/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 70424ffb7d3..f74618323b4 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1029,13 +1029,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/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index e2a36fc157c..bdd4858a794 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/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/libxfs/xfs_swapext.c b/libxfs/xfs_swapext.c index d2f0c89571d..718600019a7 100644 --- a/libxfs/xfs_swapext.c +++ b/libxfs/xfs_swapext.c @@ -28,6 +28,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; @@ -213,19 +214,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; From patchwork Fri Dec 30 22:19:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085645 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 DD50FC4332F for ; Sat, 31 Dec 2022 02:23:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbiLaCXV (ORCPT ); Fri, 30 Dec 2022 21:23:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236221AbiLaCXU (ORCPT ); Fri, 30 Dec 2022 21:23:20 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E9DA1A23D for ; Fri, 30 Dec 2022 18:23:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0B55461CB1 for ; Sat, 31 Dec 2022 02:23:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64CEDC433D2; Sat, 31 Dec 2022 02:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453398; bh=yFoELNdPaEWhPPPvv0MJxpEMtp7RLJ5ku740hwKJmSw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DtXKARCge8zvDMa0XFY4FQps4ZvNHTLOn3W1bZG9hamjsM4AdtY0bBtCPV32p3JqV Kv7ec7nwSi2aUze49f/AH8o0uxF1S2mGGSPLQ8ZrETykC7IHKScx5ah62TnO6MYcnj VvGHldlzeNSb7SJVG4yqb32UyccaTZEJ9PpA4VmYLJn0fIKaDcVtP6yOOIPjpW2OAN 6EhD9N6avOY0gyiCWTyq2cdDsbwgOsg5ytjBqHCBv+wsX08lKMF+IWmkr37Ltj/4bW 60awen0WwSGV6qjYg83geaEvgIiFM6iNPsvTMdzP5xNVdtpOsZzq0UoA6zhZpw3+8A UbRic89p/Xivg== Subject: [PATCH 06/10] xfs: convert do_div calls to xfs_rtb_to_rtx helper calls From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:28 -0800 Message-ID: <167243876895.727509.11114523582352015622.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 --- libxfs/xfs_bmap.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 5fbfc5372c9..3637b07feba 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4915,12 +4915,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 From patchwork Fri Dec 30 22:19:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085646 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 6F797C4332F for ; Sat, 31 Dec 2022 02:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236221AbiLaCXi (ORCPT ); Fri, 30 Dec 2022 21:23:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236215AbiLaCXh (ORCPT ); Fri, 30 Dec 2022 21:23:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A754919C12 for ; Fri, 30 Dec 2022 18:23:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 507BDB81E0E for ; Sat, 31 Dec 2022 02:23:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02CDBC433D2; Sat, 31 Dec 2022 02:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453414; bh=GLz7od4ocL289uRHQQCdRtTVz9WOkpG5uBHiZTHWO+k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=V6SCJU7YIEwwCtTvDuqeizbWmpqmXgbQ60Yw2DM8iWuGL8tYJJtiF6LUlXvGFRJkp 7X7s+OgCyERftcOxoBBvT2UKuyZTmJq0K2o80NySsfRfPopQ9okwkvdQwTxQjHa6aY 8FU7/cbMe51mlOc17OoKNaCcJZ1zxmCOFyj+z4Fj9cOHoGCXxKxUhTU4PaxrMVY30L ZxHTxB8cRNBoyyT4GYyzxc1MRn7SZu+yWNSgkaslsM1gcF2VkM59F0CaF8O7U13z+D xIk1HzJo2cYdSDBTttF1kqw5UPGvV+Wbx8y4wWKkkxRd28DNzLOl9dgVZzrYOGtVeq oSJ+Z2fzWsSUQ== Subject: [PATCH 07/10] xfs: create rt extent rounding helpers for realtime extent blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:29 -0800 Message-ID: <167243876908.727509.5702400227090536615.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 --- libfrog/div64.h | 14 ++++++++++++++ libxfs/libxfs_priv.h | 8 -------- libxfs/xfs_rtbitmap.h | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/libfrog/div64.h b/libfrog/div64.h index 265487916fc..9317b28aad4 100644 --- a/libfrog/div64.h +++ b/libfrog/div64.h @@ -66,4 +66,18 @@ div64_u64_rem(uint64_t dividend, uint64_t divisor, uint64_t *remainder) return dividend / divisor; } +static inline uint64_t rounddown_64(uint64_t x, uint32_t y) +{ + do_div(x, y); + return x * y; +} + +static inline uint64_t +roundup_64(uint64_t x, uint32_t y) +{ + x += y - 1; + do_div(x, y); + return x * y; +} + #endif /* LIBFROG_DIV64_H_ */ diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 49441ac787f..71abfdbe401 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -363,14 +363,6 @@ roundup_pow_of_two(uint v) return 0; } -static inline uint64_t -roundup_64(uint64_t x, uint32_t y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static inline uint64_t howmany_64(uint64_t x, uint32_t y) { diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index bdd4858a794..bc51d3bfc7c 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/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. */ From patchwork Fri Dec 30 22:19:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085647 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 E455AC4332F for ; Sat, 31 Dec 2022 02:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236222AbiLaCXv (ORCPT ); Fri, 30 Dec 2022 21:23:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236215AbiLaCXv (ORCPT ); Fri, 30 Dec 2022 21:23:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E4AE19C12 for ; Fri, 30 Dec 2022 18:23:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1A17261CBB for ; Sat, 31 Dec 2022 02:23:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7919FC433D2; Sat, 31 Dec 2022 02:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453429; bh=Y9+YQlNUaEVi7eydmWZiSyacyrCGJuqqAq3Gi/L96Wo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Gfe9z7e2GyxLKdnk7sbqLQyP8teAHkjbDKCVB/q5uRnJ2jgrweuf7mwbCiqQ6KDbO ogyCfT4iW2PGw1UpX87wxKu/P7wB1idU2negkjJyz1j26DYAELWsw51pKcKfJh92wF q1fsN6uF9XUaf2drqoP2Qw17Y5bxTh/8dnsPMso14IO62Cayrgqo2e5rOZdTW9TAZT uURYjYpMouDXCTGDRKjMoAWJs2ZcvPkKEhfq8zMLmQdmx5LRJ2dKGCWy0sEkUMk1eO zajwSplDdIQwhLRohYCEJY3w7wIgQeYcXxVvU/1A9HU5d6heCAq/rN2N7cyBbDVy/X 45TobiHwfno9A== Subject: [PATCH 08/10] xfs: use shifting and masking when converting rt extents, if possible From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:29 -0800 Message-ID: <167243876921.727509.1590098999260165627.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 --- include/xfs_mount.h | 2 ++ libxfs/libxfs_priv.h | 24 ++++++++++++++++++++++++ libxfs/xfs_rtbitmap.h | 20 ++++++++++++++++++++ libxfs/xfs_sb.c | 2 ++ 4 files changed, 48 insertions(+) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 4347098dc7e..6de360d33d3 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -67,6 +67,7 @@ typedef struct xfs_mount { uint8_t m_blkbb_log; /* blocklog - BBSHIFT */ uint8_t m_sectbb_log; /* sectorlog - BBSHIFT */ uint8_t m_agno_log; /* log #ag's */ + 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 */ @@ -88,6 +89,7 @@ typedef struct xfs_mount { uint m_ag_max_usable; /* max space per AG */ struct radix_tree_root m_perag_tree; uint64_t m_features; /* active filesystem features */ + uint64_t m_rtxblkmask; /* rt extent block mask */ unsigned long m_opstate; /* dynamic state flags */ bool m_finobt_nores; /* no per-AG finobt resv. */ uint m_qflags; /* quota status flags */ diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 71abfdbe401..268c52b508d 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -371,6 +371,30 @@ howmany_64(uint64_t x, uint32_t y) return x; } +/* If @b is a power of 2, return log2(b). Else return -1. */ +static inline int8_t log2_if_power2(unsigned long b) +{ + unsigned long mask = 1; + unsigned int i; + unsigned int ret = 1; + + if (!is_power_of_2(b)) + return -1; + + for (i = 0; i < NBBY * sizeof(unsigned long); i++, mask <<= 1) { + if (b & mask) + ret = i; + } + + return ret; +} + +/* 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; +} + /* buffer management */ #define XBF_TRYLOCK 0 #define XBF_UNMAPPED 0 diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index bc51d3bfc7c..9dd791181ca 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/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/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 55a5c5fc631..8605c91e212 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -950,6 +950,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); From patchwork Fri Dec 30 22:19:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085648 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 C64B6C4332F for ; Sat, 31 Dec 2022 02:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236223AbiLaCYI (ORCPT ); Fri, 30 Dec 2022 21:24:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236215AbiLaCYG (ORCPT ); Fri, 30 Dec 2022 21:24:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F27A19C12 for ; Fri, 30 Dec 2022 18:24:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A00A161CBF for ; Sat, 31 Dec 2022 02:24:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A51EC433D2; Sat, 31 Dec 2022 02:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453445; bh=zcPsXmyhnw2ndlyW4IdPQMN0o0bk10UApbKdnmJ3y2w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=uJ67EMe0iFFbIxqFRMowclzrTlxq44+P+gZ8qdyvRObKsxIGk/l77lie7s3TAb1TR y/bOXPn2E65BgOTh+nZV8fkCERKobcqjGW6w9q9oI6/YFTxQTbIy7677fUMthTkQVz 56SRZFhokqRps6MRcgpkdG2vWdhiK+MJMqEY9zucgqPC25N1toFyqv9kD3KEPJBzby hzJocPOeTYn+Y0/Md+SpHgTdvooqJQFAwPE6mwTES8zKayBZ0Y3aA2QbHnqEOoxO8Z DxJnUnZZKN0ttJirdXYAAGl2AsU1Bfhi94xyWWk3ikHxfSOkZBubw/WSv3ywwm4sU8 4e+zyoG2Ojm2A== Subject: [PATCH 09/10] xfs_repair: convert utility to use new rt extent helpers and types From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:29 -0800 Message-ID: <167243876934.727509.595013064865664971.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 the repair program to use the new realtime extent types and helper functions instead of open-coding them. Signed-off-by: Darrick J. Wong --- repair/agheader.h | 2 +- repair/dinode.c | 21 ++++++++++++--------- repair/incore.c | 16 ++++++++-------- repair/incore.h | 4 ++-- repair/phase4.c | 16 ++++++++-------- repair/rt.c | 4 ++-- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/repair/agheader.h b/repair/agheader.h index a63827c8725..e3e4a21e02b 100644 --- a/repair/agheader.h +++ b/repair/agheader.h @@ -11,7 +11,7 @@ typedef struct fs_geometry { uint32_t sb_blocksize; /* blocksize (bytes) */ xfs_rfsblock_t sb_dblocks; /* # data blocks */ xfs_rfsblock_t sb_rblocks; /* # realtime blocks */ - xfs_rtblock_t sb_rextents; /* # realtime extents */ + xfs_rtbxlen_t sb_rextents; /* # realtime extents */ xfs_fsblock_t sb_logstart; /* starting log block # */ xfs_agblock_t sb_rextsize; /* realtime extent size (blocks )*/ xfs_agblock_t sb_agblocks; /* # of blocks per ag */ diff --git a/repair/dinode.c b/repair/dinode.c index cc2c3474634..e66f93abb1d 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -194,13 +194,13 @@ process_rt_rec_dups( xfs_ino_t ino, struct xfs_bmbt_irec *irec) { - xfs_fsblock_t b; - xfs_rtblock_t ext; + xfs_rtblock_t b; + xfs_rtxnum_t ext; - for (b = rounddown(irec->br_startblock, mp->m_sb.sb_rextsize); + for (b = xfs_rtb_rounddown_rtx(mp, irec->br_startblock); b < irec->br_startblock + irec->br_blockcount; b += mp->m_sb.sb_rextsize) { - ext = (xfs_rtblock_t) b / mp->m_sb.sb_rextsize; + ext = xfs_rtb_to_rtxt(mp, b); if (search_rt_dup_extent(mp, ext)) { do_warn( _("data fork in rt ino %" PRIu64 " claims dup rt extent," @@ -224,14 +224,17 @@ process_rt_rec_state( struct xfs_bmbt_irec *irec) { xfs_fsblock_t b = irec->br_startblock; - xfs_rtblock_t ext; + xfs_rtxnum_t ext; int state; do { - ext = (xfs_rtblock_t)b / mp->m_sb.sb_rextsize; + xfs_extlen_t mod; + + ext = xfs_rtb_to_rtxt(mp, b); state = get_rtbmap(ext); - if ((b % mp->m_sb.sb_rextsize) != 0) { + xfs_rtb_to_rtx(mp, b, &mod); + if (mod) { /* * We are midway through a partially written extent. * If we don't find the state that gets set in the @@ -242,7 +245,7 @@ process_rt_rec_state( do_error( _("data fork in rt inode %" PRIu64 " found invalid rt extent %"PRIu64" state %d at rt block %"PRIu64"\n"), ino, ext, state, b); - b = roundup(b, mp->m_sb.sb_rextsize); + b = xfs_rtb_roundup_rtx(mp, b); continue; } @@ -2321,7 +2324,7 @@ validate_extsize( */ if ((flags & XFS_DIFLAG_EXTSZINHERIT) && (flags & XFS_DIFLAG_RTINHERIT) && - value % mp->m_sb.sb_rextsize > 0) + xfs_extlen_to_rtxmod(mp, value) > 0) misaligned = true; /* diff --git a/repair/incore.c b/repair/incore.c index f7a89e70d91..06edaf0d605 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -178,21 +178,21 @@ static size_t rt_bmap_size; */ int get_rtbmap( - xfs_rtblock_t bno) + xfs_rtxnum_t rtx) { - return (*(rt_bmap + bno / XR_BB_NUM) >> - ((bno % XR_BB_NUM) * XR_BB)) & XR_BB_MASK; + return (*(rt_bmap + rtx / XR_BB_NUM) >> + ((rtx % XR_BB_NUM) * XR_BB)) & XR_BB_MASK; } void set_rtbmap( - xfs_rtblock_t bno, + xfs_rtxnum_t rtx, int state) { - *(rt_bmap + bno / XR_BB_NUM) = - ((*(rt_bmap + bno / XR_BB_NUM) & - (~((uint64_t) XR_BB_MASK << ((bno % XR_BB_NUM) * XR_BB)))) | - (((uint64_t) state) << ((bno % XR_BB_NUM) * XR_BB))); + *(rt_bmap + rtx / XR_BB_NUM) = + ((*(rt_bmap + rtx / XR_BB_NUM) & + (~((uint64_t) XR_BB_MASK << ((rtx % XR_BB_NUM) * XR_BB)))) | + (((uint64_t) state) << ((rtx % XR_BB_NUM) * XR_BB))); } static void diff --git a/repair/incore.h b/repair/incore.h index 53609f683af..c31b778a0fb 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -28,8 +28,8 @@ void set_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno, int get_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno, xfs_agblock_t maxbno, xfs_extlen_t *blen); -void set_rtbmap(xfs_rtblock_t bno, int state); -int get_rtbmap(xfs_rtblock_t bno); +void set_rtbmap(xfs_rtxnum_t rtx, int state); +int get_rtbmap(xfs_rtxnum_t rtx); static inline void set_bmap(xfs_agnumber_t agno, xfs_agblock_t agbno, int state) diff --git a/repair/phase4.c b/repair/phase4.c index 28ecf56f45b..cfdea1460e5 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -229,9 +229,9 @@ void phase4(xfs_mount_t *mp) { ino_tree_node_t *irec; - xfs_rtblock_t bno; - xfs_rtblock_t rt_start; - xfs_extlen_t rt_len; + xfs_rtxnum_t rtx; + xfs_rtxnum_t rt_start; + xfs_rtxlen_t rt_len; xfs_agnumber_t i; xfs_agblock_t j; xfs_agblock_t ag_end; @@ -330,14 +330,14 @@ phase4(xfs_mount_t *mp) rt_start = 0; rt_len = 0; - for (bno = 0; bno < mp->m_sb.sb_rextents; bno++) { - bstate = get_rtbmap(bno); + for (rtx = 0; rtx < mp->m_sb.sb_rextents; rtx++) { + bstate = get_rtbmap(rtx); switch (bstate) { case XR_E_BAD_STATE: default: do_warn( _("unknown rt extent state, extent %" PRIu64 "\n"), - bno); + rtx); fallthrough; case XR_E_METADATA: case XR_E_UNKNOWN: @@ -360,14 +360,14 @@ phase4(xfs_mount_t *mp) break; case XR_E_MULT: if (rt_start == 0) { - rt_start = bno; + rt_start = rtx; rt_len = 1; } else if (rt_len == XFS_MAX_BMBT_EXTLEN) { /* * large extent case */ add_rt_dup_extent(rt_start, rt_len); - rt_start = bno; + rt_start = rtx; rt_len = 1; } else rt_len++; diff --git a/repair/rt.c b/repair/rt.c index a4cca7aa223..947382e9ede 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -48,8 +48,8 @@ generate_rtinfo(xfs_mount_t *mp, xfs_rtword_t *words, xfs_suminfo_t *sumcompute) { - xfs_rtblock_t extno; - xfs_rtblock_t start_ext; + xfs_rtxnum_t extno; + xfs_rtxnum_t start_ext; int bitsperblock; int bmbno; xfs_rtword_t freebit; From patchwork Fri Dec 30 22:19:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085649 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 7F79EC4332F for ; Sat, 31 Dec 2022 02:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236215AbiLaCYW (ORCPT ); Fri, 30 Dec 2022 21:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236224AbiLaCYW (ORCPT ); Fri, 30 Dec 2022 21:24:22 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C49B1A23D for ; Fri, 30 Dec 2022 18:24:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 29B8561CBF for ; Sat, 31 Dec 2022 02:24:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F76EC433D2; Sat, 31 Dec 2022 02:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453460; bh=envFz4Xyr9C76L8PYjmvHgOzw8NoD3P76Vlob7m2utk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Y2BiLz/hTa8jIdbNVxL8mEjYRyLj7HPgLSqloL9LHLQlUye0AAO6rG3GbTdfA8l32 7QqyIYRBUev26uBdH5TEBP0iPgLQin4zqvHq3sjbHQl5lz1HKs39IBZosLoogffsJ4 dVwv27mq+kcV+QIoyDDR2CnY/NXyri9uoTw/oF+5y7idG8/34skt48Rh+MTLxYBPhE pytlHHOTB0A+63MEqGceExFzgdKCu/k4fRusRbOsdSO5i5rj3y5Gecr/sbKlXyhedV mQeEWc92DvbmkwHvwMUpJcdxlUjXZdjEGTLwjKvbEV1qFEQP4CBP7djVw2EpiLnvoM n9wdsf2Jc/8oQ== Subject: [PATCH 10/10] mkfs: convert utility to use new rt extent helpers and types From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:29 -0800 Message-ID: <167243876947.727509.11538531176959854902.stgit@magnolia> In-Reply-To: <167243876812.727509.17144221830951566022.stgit@magnolia> References: <167243876812.727509.17144221830951566022.stgit@magnolia> 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 the repair program to use the new realtime extent types and helper functions instead of open-coding them. Signed-off-by: Darrick J. Wong --- mkfs/proto.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mkfs/proto.c b/mkfs/proto.c index 484b5deced8..21fe2c7f972 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -913,21 +913,22 @@ rtfreesp_init( struct xfs_mount *mp) { struct xfs_trans *tp; - xfs_fileoff_t bno; - xfs_fileoff_t ebno; + xfs_rtxnum_t rtx; + xfs_rtxnum_t ertx; int error; - for (bno = 0; bno < mp->m_sb.sb_rextents; bno = ebno) { + for (rtx = 0; rtx < mp->m_sb.sb_rextents; rtx = ertx) { error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); if (error) res_failed(error); libxfs_trans_ijoin(tp, mp->m_rbmip, 0); - ebno = XFS_RTMIN(mp->m_sb.sb_rextents, - bno + NBBY * mp->m_sb.sb_blocksize); + ertx = XFS_RTMIN(mp->m_sb.sb_rextents, + rtx + NBBY * mp->m_sb.sb_blocksize); - error = -libxfs_rtfree_extent(tp, bno, (xfs_extlen_t)(ebno-bno)); + error = -libxfs_rtfree_extent(tp, rtx, + (xfs_rtxlen_t)(ertx - rtx)); if (error) { fail(_("Error initializing the realtime space"), error);