Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp690653lqs; Fri, 14 Jun 2024 02:49:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYHLiHSn0S+HptROy7rWzfcuK6gEzpNaAw5e0hwqCYhlLLwAQLrXqkeOZg06RqBaSspnyuJOHRPqbdI6UifkRlq6+rbzDcjN+a4Undeg== X-Google-Smtp-Source: AGHT+IFjqP3/GtN19R0YO03we1R1qMhBeX9GvlStzMQ3oF7ble8OVWZYp/kSB7lSXJK2kooUxh3b X-Received: by 2002:a17:906:cb99:b0:a6e:fccb:7146 with SMTP id a640c23a62f3a-a6f60d296d9mr151990866b.23.1718358558065; Fri, 14 Jun 2024 02:49:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718358558; cv=pass; d=google.com; s=arc-20160816; b=xQYOMFpWIKUEB93CmaT3M+CQawAoKlV/5MB2DZdrfIVVP1VvuksDyOPoYoPVZZi50r MAmlN0MAUgZLZ7wbsnFbBxx4hrPRiRZId6n/8ju/QLnKXKZxL+1JIOhKUeR8RWLH1o3d wzKCEd0l0laYDafegbUgHHeL2KUYJYEKx0l9ta2Z0NnI5Qgw5bYJixm6VqF4/lrzkj71 9HkSxGyaQVAH7YnXpNw72fLiO45JrLcq6GJLO6Rr7ixCyuS5HlCaa1zq1lxrBPaDEY94 1AuzkLRiLQXiHpmR3gAjbknU+dKmx3AuJUbF6dfHmPW2ZRw5jWjyca1AsuBjLdU1eZuY CKxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lbxS/h3IReDeUhT/MBloXsxorV0i3LcgE2hrsf9Xl4k=; fh=Fd4PFnA3krwNIPOvLxQhGscKlAzzE71m6dr/VE1uxA8=; b=snGVQn6ArmrwAgMNWmnJq5UMu5ZMb1v+Glx3quj73jzmUA6xea7OS659++y7DVeZwD KOsJvgV7hva+WNBhcokqosw+EL23RJOCsarDRdJNFrAYwogv1DbUXT8ssnn7t8bDe12x 96C5yr+ZCxw0/z6V87yMeDuZQUNe5YHhTyQdKw0g+F3FrgKZlHtDLbS67zcGMDJ5FKgD fQWfCzSseVpB7RmvkmQhQEcgh/8X79NAAP+h/D3LU/OZQcsXdxUQZWHR67MxbB/qBvcT oYPymDU7gCR+RO4RLw4lQjoccOPmv61OAqgj/G+BwONCWWS46dTzDW52Yc5aS7VTOwGg vBfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Tmd1v7iE; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-214388-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214388-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e3b556si152768366b.820.2024.06.14.02.49.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 02:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214388-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Tmd1v7iE; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-214388-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214388-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7B2061F248FE for ; Fri, 14 Jun 2024 06:08:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C55EE1482F5; Fri, 14 Jun 2024 06:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Tmd1v7iE" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B6E419D895; Fri, 14 Jun 2024 06:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718345322; cv=none; b=IKdZ/lBQgruioeohN/DGd3XUXrxKIlUvpd+43ZNViJf8uE6sssUEeTkSYK/Jzk/lYheU9nierwGfcf8NO2iwOm+NLdabWWK+7k+7li6Gwqlx1ASNjNRUM8G0AA/ves24XpaWOUVVNuVyXSHA/MSisS+4gBwmTFoVhWLY+wAdglo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718345322; c=relaxed/simple; bh=8G/2mHwOwOhpItp5pcQRm+rnfp6/UqSj+cwzOmd5mMQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mhIjPR4Y6z/orvu8qRoLPe/yh3FSfcTw5i2Jvrs/DgVTxQVAE4PmGCM11mDREpmFH8oxCDUZj/9CAER6hVDKh/35ccNiWp+y1udFXIaILhanR3jd5otoTANEP5R5D1whIFSEBl1uZv+egjPvArxpDxuNj8DruAxi8DsIhkWUkZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Tmd1v7iE; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lbxS/h3IReDeUhT/MBloXsxorV0i3LcgE2hrsf9Xl4k=; b=Tmd1v7iE6OjbLzsCwusZObQZ62 NcQX7XnjUd5YPjCpUAhRvbCaBpechJQ67SE7IqkONRxIlVfD1+kgC1GS9BryUufXDCbc/q3P0fecY 9Xp8LAnGoNkLbckqoSmLzd8yZwFAg+C+QvJWZTePfmfmKntIFOLcFT3nZyQbRTg3e9BkFQEJ8/Gem ip3GsDdusCX4VV1XdAdev3jB0q9tpAKolXvRH7t95JOy7dLQJkAtwICMmC/b5cPVkpxhJLMJy1o7I E7FLDxourTfE/9132eobG2R6D5OfiHlNQn8nVPT0ZWL/0zVx7mlTw4o7J+S5Wnqa8DiPlc4J+wW6S SfoQfeWA==; Received: from hch by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI075-00000001aSh-04js; Fri, 14 Jun 2024 06:08:39 +0000 Date: Thu, 13 Jun 2024 23:08:38 -0700 From: Christoph Hellwig To: Zhang Yi Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: Re: [PATCH -next v5 7/8] xfs: speed up truncating down a big realtime inode Message-ID: References: <20240613090033.2246907-1-yi.zhang@huaweicloud.com> <20240613090033.2246907-8-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240613090033.2246907-8-yi.zhang@huaweicloud.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html On Thu, Jun 13, 2024 at 05:00:32PM +0800, Zhang Yi wrote: > From: Zhang Yi > > If we truncate down a big realtime inode, zero out the entire aligned > EOF extent could gets slow down as the rtextsize increases. Fortunately, > __xfs_bunmapi() would align the unmapped range to rtextsize, split and > convert the blocks beyond EOF to unwritten. So speed up this by > adjusting the unitsize to the filesystem blocksize when truncating down > a large realtime inode, let __xfs_bunmapi() convert the tail blocks to > unwritten, this could improve the performance significantly. > > # mkfs.xfs -f -rrtdev=/dev/pmem1s -f -m reflink=0,rmapbt=0, \ > -d rtinherit=1 -r extsize=$rtextsize /dev/pmem2s > # mount -ortdev=/dev/pmem1s /dev/pmem2s /mnt/scratch > # for i in {1..1000}; \ > do dd if=/dev/zero of=/mnt/scratch/$i bs=$rtextsize count=1024; done > # sync > # time for i in {1..1000}; \ > do xfs_io -c "truncate 4k" /mnt/scratch/$i; done > > rtextsize 8k 16k 32k 64k 256k 1024k > before: 9.601s 10.229s 11.153s 12.086s 12.259s 20.141s > after: 9.710s 9.642s 9.958s 9.441s 10.021s 10.526s > > Signed-off-by: Zhang Yi > --- > fs/xfs/xfs_inode.c | 10 ++++++++-- > fs/xfs/xfs_iops.c | 9 +++++++++ > 2 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c > index 92daa2279053..5e837ed093b0 100644 > --- a/fs/xfs/xfs_inode.c > +++ b/fs/xfs/xfs_inode.c > @@ -1487,6 +1487,7 @@ xfs_itruncate_extents_flags( > struct xfs_trans *tp = *tpp; > xfs_fileoff_t first_unmap_block; > int error = 0; > + unsigned int unitsize = xfs_inode_alloc_unitsize(ip); > > xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); > if (atomic_read(&VFS_I(ip)->i_count)) > @@ -1510,9 +1511,14 @@ xfs_itruncate_extents_flags( > * > * We have to free all the blocks to the bmbt maximum offset, even if > * the page cache can't scale that far. > + * > + * For big realtime inode, don't aligned to allocation unitsize, > + * it'll split the extent and convert the tail blocks to unwritten. > */ > + if (xfs_inode_has_bigrtalloc(ip)) > + unitsize = i_blocksize(VFS_I(ip)); > + first_unmap_block = XFS_B_TO_FSB(mp, roundup_64(new_size, unitsize)); If you expand what xfs_inode_alloc_unitsize and xfs_inode_has_bigrtalloc this is looking a bit silly: unsigned int blocks = 1; if (XFS_IS_REALTIME_INODE(ip)) blocks = ip->i_mount->m_sb.sb_rextsize; unitsize = XFS_FSB_TO_B(ip->i_mount, blocks); if (XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1) unsitsize = i_blocksize(inode); So I think we can simply drop this part now that the variant that zeroes the entire rtextent is gone. > @@ -862,6 +862,15 @@ xfs_setattr_truncate_data( > /* Truncate down */ > blocksize = xfs_inode_alloc_unitsize(ip); > > + /* > + * If it's a big realtime inode, zero out the entire EOF extent could > + * get slow down as the rtextsize increases, speed it up by adjusting > + * the blocksize to the filesystem blocksize, let __xfs_bunmapi() to > + * split the extent and convert the tail blocks to unwritten. > + */ > + if (xfs_inode_has_bigrtalloc(ip)) > + blocksize = i_blocksize(inode); Same here. And with that probably also the passing of the block size to the truncate_page helpers.