From patchwork Tue Aug 13 07:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761465 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 B63346F2F3 for ; Tue, 13 Aug 2024 07:39:59 +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=1723534802; cv=none; b=HjAHiiz2nSOpA+gD3con9wF/R8fNLBQ0JOif7fYjRC5rfB1ILsMr53qxeMCw95E96FyY65coOiR+Ifj7kOIxDecZIr5hqbjGzIugtzYhFkfk5o0jFf3nfgFkDX8Fybesy/cTPPSEllJKI3I9CTNo7+8QiXDh94A2lEiCXHnFeRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534802; c=relaxed/simple; bh=1ffybEYeulSPO8MW/8FCE0+ONbLCqzpFEfbiRTvgEDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eW8R4aeut+rGLxYDHB09vwiX/mG9VpXeYwg/BDqzdC0dCDXUSAcydiRp3FbzGsapC6fLOtKiAyFsQR75u0i+yBI//jm/BGbCuqcKUQ4dNZEIzj8sBYh/8cnVydQ/50BHx/FO4s8wTZ7VLBoNpX/dKJm9/0D2nY4sQ8S7MMIDSBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=z9fnQYI9; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="z9fnQYI9" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=C2rqm8DhjKyNE7zY2hAiGy5FC8ZJZ94IpLrv2EErJZQ=; b=z9fnQYI911/A/o7CXp2KZA71fX YroFTJ6WcwJT1HsBrPD3QXazDaCyY6jq60GsRM+vAkBAb9CfauzhDVUM+DppFR7AePDXglvQDxHls T93qeOFR4z3aPY1g0LoIg9/JP1a2zQaKKHrAnfJy0/L1Pi8jaUeurY75F2F3iHm9kNfZJidKC/r6h 4O6Zp4Z/63m0G0DPb/WrUk8s4t/tRMZ3Ao1uuahRxE+OR0eMmpXrCdxYDRR5oxWRjhM6z+N9wpZXe BnONYeO+V/S9gHT7XNLasj70KrYRAqfbHfCe79+EeFRISidHCOoeX0JR1HXEiRr9SObSYMU2u1jL/ yI/nfVNg==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8M-00000002l7s-2rMw; Tue, 13 Aug 2024 07:39:59 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 1/9] xfs: remove the i_mode check in xfs_release Date: Tue, 13 Aug 2024 09:39:34 +0200 Message-ID: <20240813073952.81360-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfs_release is only called from xfs_file_release, which is wired up as the f_op->release handler for regular files only. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_inode.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 7dc6f326936cad..c7249257155881 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1086,9 +1086,6 @@ xfs_release( xfs_mount_t *mp = ip->i_mount; int error = 0; - if (!S_ISREG(VFS_I(ip)->i_mode) || (VFS_I(ip)->i_mode == 0)) - return 0; - /* If this is a read-only mount, don't do this (would generate I/O) */ if (xfs_is_readonly(mp)) return 0; From patchwork Tue Aug 13 07:39:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761466 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 BE65269DFF for ; Tue, 13 Aug 2024 07:40:03 +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=1723534805; cv=none; b=bwSCqZH9yofUteGEvvFZICgAEYUyOqmLJrmdoUcdWTleV5oqeq/42nEPugAhApmsOi5Kuo7MzYr0kAftp1X9syUknSQDjD0AdDOph9Qh5tC6zb02/aahxHBh9Qv2CjrMtX7dM5tTj3atY08aQgFjfgl96JQtwkeKDPj2/3MLY5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534805; c=relaxed/simple; bh=qcOZrHatrdmCkh/krTR43DXipZ7oi9ssbT/lnYPzh8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B0NaziJiNQxNYJgAX+A6+MTN1uzN8YSdzL/Y2HuaMjl1fgI4QCUob/NwiMO1vOjz/SAJysorCxqIRWtw6VFL1aU21/95wa2LVfz/dfCpzoLERuw5YCrUEn64p548iqz4jDVqcXYsXiCb/f4vTN4g52RsHYZ5gWgtCRCdVF5iTjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=4rmm9bua; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="4rmm9bua" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6w5WKwu+GuyQYt+XcbZowmclgAuDwQMqE2g8AYeoGxo=; b=4rmm9buaA5wPFFZD5ulW3XWGWW 9LCXZIXd4NwL/GsjDdQuxxJE/obZ4J3CMXS9CR0Of0QwLduU0lEkvKMtuN8oJ3uR/cY32dVcV24pn IFnyuTEBFvL6T6tnZbWDhnDT+PF44hk/PAGgPgHgyu45Kw8j5OvsrIOJVUYrpLeqjo+PSrlxIJN90 JOh/1Mvl49scLn3S+OeZfhe6gM1jD0NzF0oE3lUID7SlZKrPIjKUmoDrAD1Iuz9xNcA1Nh+SWiz9N cbTA+V30Xs8ggOPl9bI9S26L+Uge0xOxAL4Fq2DQVSsoEoWjXrB7uGDSbcb73bYcJCCzjkTVkNsZ+ m8bh+e3g==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8Q-00000002l81-3X2a; Tue, 13 Aug 2024 07:40:03 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 2/9] xfs: refactor f_op->release handling Date: Tue, 13 Aug 2024 09:39:35 +0200 Message-ID: <20240813073952.81360-3-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Currently f_op->release is split in not very obvious ways. Fix that by folding xfs_release into xfs_file_release. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 71 +++++++++++++++++++++++++++++++++++++++-- fs/xfs/xfs_inode.c | 79 ---------------------------------------------- fs/xfs/xfs_inode.h | 1 - 3 files changed, 68 insertions(+), 83 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 4cdc54dc96862e..11732fe1c657c9 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1177,10 +1177,75 @@ xfs_dir_open( STATIC int xfs_file_release( - struct inode *inode, - struct file *filp) + struct inode *inode, + struct file *file) { - return xfs_release(XFS_I(inode)); + struct xfs_inode *ip = XFS_I(inode); + struct xfs_mount *mp = ip->i_mount; + int error; + + /* If this is a read-only mount, don't generate I/O */ + if (xfs_is_readonly(mp)) + return 0; + + /* + * If we previously truncated this file and removed old data in the + * process, we want to initiate "early" writeout on the last close. + * This is an attempt to combat the notorious NULL files problem which + * is particularly noticeable from a truncate down, buffered (re-)write + * (delalloc), followed by a crash. What we are effectively doing here + * is significantly reducing the time window where we'd otherwise be + * exposed to that problem. + */ + if (!xfs_is_shutdown(mp) && + xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED)) { + xfs_iflags_clear(ip, XFS_IDIRTY_RELEASE); + if (ip->i_delayed_blks > 0) { + error = filemap_flush(inode->i_mapping); + if (error) + return error; + } + } + + /* + * XFS aggressively preallocates post-EOF space to generate contiguous + * allocations for writers that append to the end of the file and we + * try to free these when an open file context is released. + * + * There is no point in freeing blocks here for open but unlinked files + * as they will be taken care of by the inactivation path soon. + * + * If we can't get the iolock just skip truncating the blocks past EOF + * because we could deadlock with the mmap_lock otherwise. We'll get + * another chance to drop them once the last reference to the inode is + * dropped, so we'll never leak blocks permanently. + */ + if (inode->i_nlink && xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { + if (xfs_can_free_eofblocks(ip) && + !xfs_iflags_test(ip, XFS_IDIRTY_RELEASE)) { + /* + * Check if the inode is being opened, written and + * closed frequently and we have delayed allocation + * blocks outstanding (e.g. streaming writes from the + * NFS server), truncating the blocks past EOF will + * cause fragmentation to occur. + * + * In this case don't do the truncation, but we have to + * be careful how we detect this case. Blocks beyond EOF + * show up as i_delayed_blks even when the inode is + * clean, so we need to truncate them away first before + * checking for a dirty release. Hence on the first + * dirty close we will still remove the speculative + * allocation, but after that we will leave it in place. + */ + error = xfs_free_eofblocks(ip); + if (!error && ip->i_delayed_blks) + xfs_iflags_set(ip, XFS_IDIRTY_RELEASE); + } + xfs_iunlock(ip, XFS_IOLOCK_EXCL); + } + + return error; } STATIC int diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index c7249257155881..a283312033e562 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1079,85 +1079,6 @@ xfs_itruncate_extents_flags( return error; } -int -xfs_release( - xfs_inode_t *ip) -{ - xfs_mount_t *mp = ip->i_mount; - int error = 0; - - /* If this is a read-only mount, don't do this (would generate I/O) */ - if (xfs_is_readonly(mp)) - return 0; - - if (!xfs_is_shutdown(mp)) { - int truncated; - - /* - * If we previously truncated this file and removed old data - * in the process, we want to initiate "early" writeout on - * the last close. This is an attempt to combat the notorious - * NULL files problem which is particularly noticeable from a - * truncate down, buffered (re-)write (delalloc), followed by - * a crash. What we are effectively doing here is - * significantly reducing the time window where we'd otherwise - * be exposed to that problem. - */ - truncated = xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED); - if (truncated) { - xfs_iflags_clear(ip, XFS_IDIRTY_RELEASE); - if (ip->i_delayed_blks > 0) { - error = filemap_flush(VFS_I(ip)->i_mapping); - if (error) - return error; - } - } - } - - if (VFS_I(ip)->i_nlink == 0) - return 0; - - /* - * If we can't get the iolock just skip truncating the blocks past EOF - * because we could deadlock with the mmap_lock otherwise. We'll get - * another chance to drop them once the last reference to the inode is - * dropped, so we'll never leak blocks permanently. - */ - if (!xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) - return 0; - - if (xfs_can_free_eofblocks(ip)) { - /* - * Check if the inode is being opened, written and closed - * frequently and we have delayed allocation blocks outstanding - * (e.g. streaming writes from the NFS server), truncating the - * blocks past EOF will cause fragmentation to occur. - * - * In this case don't do the truncation, but we have to be - * careful how we detect this case. Blocks beyond EOF show up as - * i_delayed_blks even when the inode is clean, so we need to - * truncate them away first before checking for a dirty release. - * Hence on the first dirty close we will still remove the - * speculative allocation, but after that we will leave it in - * place. - */ - if (xfs_iflags_test(ip, XFS_IDIRTY_RELEASE)) - goto out_unlock; - - error = xfs_free_eofblocks(ip); - if (error) - goto out_unlock; - - /* delalloc blocks after truncation means it really is dirty */ - if (ip->i_delayed_blks) - xfs_iflags_set(ip, XFS_IDIRTY_RELEASE); - } - -out_unlock: - xfs_iunlock(ip, XFS_IOLOCK_EXCL); - return error; -} - /* * Mark all the buffers attached to this directory stale. In theory we should * never be freeing a directory with any blocks at all, but this covers the diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 51defdebef30ed..6ec83fab66266a 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -512,7 +512,6 @@ enum layout_break_reason { #define XFS_INHERIT_GID(pip) \ (xfs_has_grpid((pip)->i_mount) || (VFS_I(pip)->i_mode & S_ISGID)) -int xfs_release(struct xfs_inode *ip); int xfs_inactive(struct xfs_inode *ip); int xfs_lookup(struct xfs_inode *dp, const struct xfs_name *name, struct xfs_inode **ipp, struct xfs_name *ci_name); From patchwork Tue Aug 13 07:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761467 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 A535758ABF for ; Tue, 13 Aug 2024 07:40:07 +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=1723534808; cv=none; b=N7emfnV7NvX4hsi/OLSi5BlhMAC8+gq1UyDEjNGEUBlUrmpzYmEB2KZvXBIc3nutr6p+heWgySCNS/4Yo6bK0h53tq/sblRRHtkaiKepHHzsnPXHdcfohN2fOSyJXnnm74fqRRuUgwz6uJNhfeEZN29asKj+2pShnImYivA71Q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534808; c=relaxed/simple; bh=v8MwnvbvNtnmXSzY943jsIaLRSBB9RHgWxmytGelWSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TeJ6mriRse/P4ccB9W4NpRUqlGMNH2jL/5kz+YvyHIbN60/lCfsZo8QwxkGdURNIElNYoOmiiuPKxJwBNmufwd6WBnNY5kgaiGZXNor0+8qpAWSM3VbCpl44m2mDHFirijiqUtmocxzdgOq+zNSyNoOTbjFjUP/8Mo3URA8tZQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=LQOmjfHW; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LQOmjfHW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=csA3mBRj+AdrxmsmZfswdPz2GMhOXLgIuIxCdd0oJo4=; b=LQOmjfHW47PK6iYCrF0AeHaubN mee5zwEME7KUDabjvppyYjUnHroZNspASLxP+ejHpW5tGMoFtcTQNgEwtKlULKLKV0w5QsWgrFkBp ssehjh2cTrOVPpV36Bck3bjfNOHT9+dANOTqUvfuY0N1kNqIwn2HqoPiws/5Je9gAwThUPXC3Ooxk F1CZPkqQ1qD0ANFst4cNR7XsLJT7Jghny3COlXjaEQaK5+yVfAv+CtRQI41Q9NgviS2jJgLM8TrrL XrELpK+Az/AYkRp6Br3BbvGfgzOOoXbiODDvM2RaBvqqnVcUiMztPr10ys3GjTRhiQhcFsvAG2vmI s5J7CcfA==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8U-00000002l8j-2cZ5; Tue, 13 Aug 2024 07:40:07 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 3/9] xfs: don't bother returning errors from xfs_file_release Date: Tue, 13 Aug 2024 09:39:36 +0200 Message-ID: <20240813073952.81360-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html While ->release returns int, the only caller ignores the return value. As we're only doing cleanup work there isn't much of a point in return a value to start with, so just document the situation instead. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 11732fe1c657c9..17dfbaca1c581c 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1175,6 +1175,10 @@ xfs_dir_open( return error; } +/* + * Don't bother propagating errors. We're just doing cleanup, and the caller + * ignores the return value anyway. + */ STATIC int xfs_file_release( struct inode *inode, @@ -1182,7 +1186,6 @@ xfs_file_release( { struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; - int error; /* If this is a read-only mount, don't generate I/O */ if (xfs_is_readonly(mp)) @@ -1200,11 +1203,8 @@ xfs_file_release( if (!xfs_is_shutdown(mp) && xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED)) { xfs_iflags_clear(ip, XFS_IDIRTY_RELEASE); - if (ip->i_delayed_blks > 0) { - error = filemap_flush(inode->i_mapping); - if (error) - return error; - } + if (ip->i_delayed_blks > 0) + filemap_flush(inode->i_mapping); } /* @@ -1238,14 +1238,14 @@ xfs_file_release( * dirty close we will still remove the speculative * allocation, but after that we will leave it in place. */ - error = xfs_free_eofblocks(ip); - if (!error && ip->i_delayed_blks) + xfs_free_eofblocks(ip); + if (ip->i_delayed_blks) xfs_iflags_set(ip, XFS_IDIRTY_RELEASE); } xfs_iunlock(ip, XFS_IOLOCK_EXCL); } - return error; + return 0; } STATIC int From patchwork Tue Aug 13 07:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761468 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 E2DA473440 for ; Tue, 13 Aug 2024 07:40:10 +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=1723534812; cv=none; b=PEu+8Jg6L9HX1zGqXMMiVD7fspmdi4T8uuMlTix4W6c99fcLf/6Hg2AHbERNvtojR0cm2iviL0J4jYr5R+ED5kqrEIg6MttIn1DiR6RAQdJXX+XcfL6uLh5eRC8ANJzeTOWR2YiRFNdXREcgbvPheAlSTumvptn1VgROhcmCv+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534812; c=relaxed/simple; bh=0Drdnd72/Ix05pIHUK0jr7RafWKeesBrsYreeJwOkh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PmK4fWYXamFxaYh+GXF76S1ejVfevktozI9aStv1FpxCYtiedTYF7y4yEszQh9x86CApYvKnI7qDQhyHeXcwoz+jWuNjS7LP+7vD4M+shqQpct8VcI6RoJSrRLuHx1UbRlRkwhHFG5QInLXYWy9EdHnStLxcmqYYdKzNqRA17zk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Fteo9h1G; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Fteo9h1G" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=KTOgUjOmthP3IRDH+hOUuMpX3veZJQr7Ng4yG6l8TAg=; b=Fteo9h1GCI0ljqTj3PbUhJzGDh cXqOwT/4gHfEQb+uNaUuOc1sIzk8eZgrNDYcJsyF1gVdBeU/td1+L/BzyxC6bjsce3u8reRwCz0xm lKbTGiqPGUrxnB9hZE6Sj0jJvxu4JQ56hY8TgLkOMxZtWzwDpmc/IFRc1HgTG3dBatkz8aArLttuo NHn8pyaWbrr4ozdKH8TPlYgibvDtNmVRHjvGq6rr8SpI8EygY/LmjwRsxSU7RzgheQd7JiOBeqGI4 mMAo9/FdMHcrotAhRXmiJpAKuWHhVflwzV6p2X9LQiAUnGIvOatxSZoyieUK1tl6FTCwfzzWr8zpr VoWzVxfQ==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8X-00000002l9S-45oQ; Tue, 13 Aug 2024 07:40:10 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 4/9] xfs: skip all of xfs_file_release when shut down Date: Tue, 13 Aug 2024 09:39:37 +0200 Message-ID: <20240813073952.81360-5-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html There is no point in trying to free post-EOF blocks when the file system is shutdown, as it will just error out ASAP. Instead return instantly when xfs_file_release is called on a shut down file system. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 17dfbaca1c581c..dae8dd1223550d 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1187,8 +1187,11 @@ xfs_file_release( struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; - /* If this is a read-only mount, don't generate I/O */ - if (xfs_is_readonly(mp)) + /* + * If this is a read-only mount or the file system has been shut down, + * don't generate I/O. + */ + if (xfs_is_readonly(mp) || xfs_is_shutdown(mp)) return 0; /* @@ -1200,8 +1203,7 @@ xfs_file_release( * is significantly reducing the time window where we'd otherwise be * exposed to that problem. */ - if (!xfs_is_shutdown(mp) && - xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED)) { + if (xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED)) { xfs_iflags_clear(ip, XFS_IDIRTY_RELEASE); if (ip->i_delayed_blks > 0) filemap_flush(inode->i_mapping); From patchwork Tue Aug 13 07:39:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761469 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 0B34E76025 for ; Tue, 13 Aug 2024 07:40:14 +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=1723534816; cv=none; b=DKb+qapa4Qr4QNND1/jFP0AJt4rnFOQHFvE++JEpy31cTnnUPBc8d6/LeMSqIhLWBv1FA6t9O+kGYEwmpzkuLGtq+aKDkf35HqwwgE6C1/syajrQvXmNhCB5+zlhkXH/2jXWathav+ZWKZLLxPvRcGfJ+GIh3saTdD91yYklr7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534816; c=relaxed/simple; bh=J6Leu8/NjO23GT58hVUMPeJM2l3c+SYzc021Q0VWY/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lTKoLzgPwJBkfEvduFyRc65BtbWnUOim9pQ6ZhJxUjdPaEtbLUiKzQwBtcEtGBXYPi++T2y+4iYp4DlX9v4EsNWWO5zJvjU6FZYTIa7WLtddcK8xJUjlTRhTiT4a2hz/4G5PStT7121dP+EIbTBDrDwwEfxyeYvp4gh/OfGx+dM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=K1Dfyl6X; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="K1Dfyl6X" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=QobfccF+bzo+Z4/oCpc3aso3/9FbArdyguCNPPZZfCk=; b=K1Dfyl6XgdAYb0UFw7y4ThxnQF LUcLTMfarHyAK/FEnvqkhXnx7xCbaBnUSqmnCM6tUsXYNdgEDWebwqENR8J8w8wN+2erc9IvdhczV CMWLbYxqd/5W1NlhIHY4lxPlKvFryoykj4qS6oWBRmiHgsouT/92jDjI13MOS0oIurSE4Xq0IhrlF UeSoE/5Ji81S9wSA35LW3GQnL4eRTariNCnYQZiRnVuiTyr27laRLZ5zYtKdELcHe509jn4WrdcHd 4ulwDbhILD8AyASw2ZhB1aiRlvFRgP25iD2oacUCYKUl5vZMqhovMfR6KR/R/QcFxPUMzurpLI9D5 dzCh8sXg==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8b-00000002l9p-4B1D; Tue, 13 Aug 2024 07:40:14 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 5/9] xfs: don't free post-EOF blocks on read close Date: Tue, 13 Aug 2024 09:39:38 +0200 Message-ID: <20240813073952.81360-6-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html From: Dave Chinner When we have a workload that does open/read/close in parallel with other allocation, the file becomes rapidly fragmented. This is due to close() calling xfs_file_release() and removing the speculative preallocation beyond EOF. Add a check for a writable context to xfs_file_release to skip the post-EOF block freeing (an the similarly pointless flushing on truncate down). Before: Test 1: sync write fragmentation counts /mnt/scratch/file.0: 919 /mnt/scratch/file.1: 916 /mnt/scratch/file.2: 919 /mnt/scratch/file.3: 920 /mnt/scratch/file.4: 920 /mnt/scratch/file.5: 921 /mnt/scratch/file.6: 916 /mnt/scratch/file.7: 918 After: Test 1: sync write fragmentation counts /mnt/scratch/file.0: 24 /mnt/scratch/file.1: 24 /mnt/scratch/file.2: 11 /mnt/scratch/file.3: 24 /mnt/scratch/file.4: 3 /mnt/scratch/file.5: 24 /mnt/scratch/file.6: 24 /mnt/scratch/file.7: 23 Signed-off-by: Dave Chinner [darrick: wordsmithing, fix commit message] Signed-off-by: Darrick J. Wong [hch: ported to the new ->release code structure] Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index dae8dd1223550d..60424e64230743 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1217,12 +1217,18 @@ xfs_file_release( * There is no point in freeing blocks here for open but unlinked files * as they will be taken care of by the inactivation path soon. * + * When releasing a read-only context, don't flush data or trim post-EOF + * blocks. This avoids open/read/close workloads from removing EOF + * blocks that other writers depend upon to reduce fragmentation. + * * If we can't get the iolock just skip truncating the blocks past EOF * because we could deadlock with the mmap_lock otherwise. We'll get * another chance to drop them once the last reference to the inode is * dropped, so we'll never leak blocks permanently. */ - if (inode->i_nlink && xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { + if (inode->i_nlink && + (file->f_mode & FMODE_WRITE) && + xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { if (xfs_can_free_eofblocks(ip) && !xfs_iflags_test(ip, XFS_IDIRTY_RELEASE)) { /* From patchwork Tue Aug 13 07:39:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761470 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 CB22669DFF for ; Tue, 13 Aug 2024 07:40:18 +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=1723534820; cv=none; b=LZ32c3j8Gf+MpVYlY6mBe/pt3kFU8wj6m3ci/wl628INum5cHJxLc3m5XrjdqSuoecnXELUl/CkTh35233WANOcf1HSv7DNoRghSZM2VU82cfW7IQGd3IaSbs7PDVJ35+CP2Eea4wWkTyjnwAhIrxqU7D68KZ7Do9ydxJF4D+Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534820; c=relaxed/simple; bh=aM/WPl11H58JTmAWWCzx4g8EipOBoKHGlfb0riWuvbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NdG4iyHb/ioaevibOX/7XZLaDUh/IdwoSZZV7LPOdEtDWZNSbNU9u94ikr5nO6eXuHt943veINnRDjyyu/cNocVVKQM8tk8dSRdPCZ5rr0YB18Vvpe30pEsbBGo8gXxl2FJaHq3SH/iTd5d54tZAgsrYJ3o7gBifg2R71V2TgV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Hj7a8sk6; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Hj7a8sk6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=TqjBvadcDJzqC2jtXCmwYVEUMaCBL6CCD10LTBau94E=; b=Hj7a8sk6Rhzc4UivbkOOXIdJnJ NunpUN2DXjq6Y6j61FDieLc84Ylp9LZhW480g0XBG17VwSnhq+I48pAiAt5/Ty1T2Djrd5SVjdLIs 6CRncqxVT5qK6J54iGaonTvujCMR5fSsE8t6mtNF8pE71S9wCr95f1iy7WFCM3O9sDyIqoeuyJjQb lkUrDQouKzZPNstZeulfFv5pRXvpIbYwpCj16MNpmdgSb8Z9uwQqkqNVEWaEXgv2jFn31RO6WaEU5 /GoQGnABA1d03tDAIiGHtp3Ftu/7dv0JZF7RUmqTJ5wWUWatMWktoB2PKEa8gx7Yv02t8OoOw/CF1 huEWwE7Q==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8f-00000002lBE-3i0O; Tue, 13 Aug 2024 07:40:18 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 6/9] xfs: only free posteof blocks on first close Date: Tue, 13 Aug 2024 09:39:39 +0200 Message-ID: <20240813073952.81360-7-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html From: "Darrick J. Wong" Certain workloads fragment files on XFS very badly, such as a software package that creates a number of threads, each of which repeatedly run the sequence: open a file, perform a synchronous write, and close the file, which defeats the speculative preallocation mechanism. We work around this problem by only deleting posteof blocks the /first/ time a file is closed to preserve the behavior that unpacking a tarball lays out files one after the other with no gaps. Signed-off-by: Darrick J. Wong [hch: rebased, updated comment, renamed the flag] Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 32 +++++++++++--------------------- fs/xfs/xfs_inode.h | 4 ++-- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 60424e64230743..30b553ac8f56bb 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1204,15 +1204,21 @@ xfs_file_release( * exposed to that problem. */ if (xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED)) { - xfs_iflags_clear(ip, XFS_IDIRTY_RELEASE); + xfs_iflags_clear(ip, XFS_EOFBLOCKS_RELEASED); if (ip->i_delayed_blks > 0) filemap_flush(inode->i_mapping); } /* * XFS aggressively preallocates post-EOF space to generate contiguous - * allocations for writers that append to the end of the file and we - * try to free these when an open file context is released. + * allocations for writers that append to the end of the file. + * + * To support workloads that close and reopen the file frequently, these + * preallocations usually persist after a close unless it is the first + * close for the inode. This is a tradeoff to generate tightly packed + * data layouts for unpacking tarballs or similar archives that write + * one file after another without going back to it while keeping the + * preallocation for files that have recurring open/write/close cycles. * * There is no point in freeing blocks here for open but unlinked files * as they will be taken care of by the inactivation path soon. @@ -1230,25 +1236,9 @@ xfs_file_release( (file->f_mode & FMODE_WRITE) && xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { if (xfs_can_free_eofblocks(ip) && - !xfs_iflags_test(ip, XFS_IDIRTY_RELEASE)) { - /* - * Check if the inode is being opened, written and - * closed frequently and we have delayed allocation - * blocks outstanding (e.g. streaming writes from the - * NFS server), truncating the blocks past EOF will - * cause fragmentation to occur. - * - * In this case don't do the truncation, but we have to - * be careful how we detect this case. Blocks beyond EOF - * show up as i_delayed_blks even when the inode is - * clean, so we need to truncate them away first before - * checking for a dirty release. Hence on the first - * dirty close we will still remove the speculative - * allocation, but after that we will leave it in place. - */ + !xfs_iflags_test(ip, XFS_EOFBLOCKS_RELEASED)) { xfs_free_eofblocks(ip); - if (ip->i_delayed_blks) - xfs_iflags_set(ip, XFS_IDIRTY_RELEASE); + xfs_iflags_set(ip, XFS_EOFBLOCKS_RELEASED); } xfs_iunlock(ip, XFS_IOLOCK_EXCL); } diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 6ec83fab66266a..2763a9ffa643db 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -335,7 +335,7 @@ static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip) #define XFS_INEW (1 << 3) /* inode has just been allocated */ #define XFS_IPRESERVE_DM_FIELDS (1 << 4) /* has legacy DMAPI fields set */ #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */ -#define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */ +#define XFS_EOFBLOCKS_RELEASED (1 << 6) /* eofblocks were freed in ->release */ #define XFS_IFLUSHING (1 << 7) /* inode is being flushed */ #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */ #define XFS_IPINNED (1 << __XFS_IPINNED_BIT) @@ -382,7 +382,7 @@ static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip) */ #define XFS_IRECLAIM_RESET_FLAGS \ (XFS_IRECLAIMABLE | XFS_IRECLAIM | \ - XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | XFS_NEED_INACTIVE | \ + XFS_EOFBLOCKS_RELEASED | XFS_ITRUNCATED | XFS_NEED_INACTIVE | \ XFS_INACTIVATING | XFS_IQUOTAUNCHECKED) /* From patchwork Tue Aug 13 07:39:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761471 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 AC34C58ABF for ; Tue, 13 Aug 2024 07:40:22 +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=1723534823; cv=none; b=hlP7N0erkMnqdOh3fOMByWAXm37zBICOxe3vdkZBfOhCBRS4uDO8iTx6/bVGoT4047FJHy7jVPNOlOBao/p4VK6I7j98JKpHI77Yk4hGXuJXLzdAjhAecgnoFpG20KrIioF78yYyOSHL7a6FvO04h1RoUkbz5zsWF6qOh/rgqaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534823; c=relaxed/simple; bh=zGEcu+2Ivl0BseYmA0etc4/tyxn0EJRyCKPWqU/PXeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Elw5RmnCGCXUHAlZyIY688XqC6j+feOf+fRk5oU5Ky0dThU2effI7ipskMEkYMDZuJeEOXKacZgabjyJi3n0TFacef2rm2wP042vcCJuO2wlWwWxIPmk4mDFVgv5Jdkc2MPnayzmNpZztAtaLaTSGoIDHRLlEqWTiVF7LUlmlUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Ddfonv2J; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Ddfonv2J" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=5V7XlQxY7gcnXWKqYjiJ/vZtW2JFilicOMNs6wdcGgs=; b=Ddfonv2JvdBUM6AIAxUCCuopxd Av9XKmH/O1IZfQnGVU/LtLwC8BZ0FpO9Zn9MDDgSIbKq9NiUGoylAZtxJ9aUZfa3p7Lb2P5CK+1Yr 0Mpa1zio/5FV9K6iQYnhRY86Dmtof7UwvjUNH5WfsgcWBkvXlCO//Db3elIxo2Evror8/LYZaOu7y qcMq7zBcccCEC9vbOM69TOtTGKCdHqk6X5iwYbluEQo1WYHvnJY7zajOSOEAsL58RP4OsmdjeaxaL Idjve0R5M0BpyoU4ZxQezD/E4EewE5kyLqgz1qBr/CzOh+60epXgfQFRNx7ypCqKjb6l9Qqwoupvf MthA3Bbw==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8j-00000002lC1-3gdT; Tue, 13 Aug 2024 07:40:22 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 7/9] xfs: check XFS_EOFBLOCKS_RELEASED earlier in xfs_release_eofblocks Date: Tue, 13 Aug 2024 09:39:40 +0200 Message-ID: <20240813073952.81360-8-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html If the XFS_EOFBLOCKS_RELEASED flag is set, we are not going to free the eofblocks, so don't bother locking the inode or performing the checks in xfs_can_free_eofblocks. Also switch to a test_and_set operation once the iolock has been acquire so that only the caller that sets it actually frees the post-EOF blocks. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 30b553ac8f56bb..986448d1ff3c0c 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1234,12 +1234,11 @@ xfs_file_release( */ if (inode->i_nlink && (file->f_mode & FMODE_WRITE) && + !xfs_iflags_test(ip, XFS_EOFBLOCKS_RELEASED) && xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { if (xfs_can_free_eofblocks(ip) && - !xfs_iflags_test(ip, XFS_EOFBLOCKS_RELEASED)) { + !xfs_iflags_test_and_set(ip, XFS_EOFBLOCKS_RELEASED)) xfs_free_eofblocks(ip); - xfs_iflags_set(ip, XFS_EOFBLOCKS_RELEASED); - } xfs_iunlock(ip, XFS_IOLOCK_EXCL); } From patchwork Tue Aug 13 07:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761472 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 9ADD958ABF for ; Tue, 13 Aug 2024 07:40:27 +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=1723534828; cv=none; b=eUcoJJRUMjbGwh8t+ckdAkfuq9DJ2w7LTG58G2Y51/tjCxP24F4eqM8OlqIjaARus2sZ5yyrN5UrmO7E7FofZyygQyJw+ehWJrr4KzX2b1wGTO8RDlwwvFPFz+wgIY6kL17du+IttWo5QaGfSxHxkAQfSyC/N+yEaWtNef9jRXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534828; c=relaxed/simple; bh=Dl5MaigYOAPQ68kwjH9IryRR6Kjf2nByPXWhszyp14U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dJuzC/odVfyPWo9i0/EafX86V0SOYYWhQK2SbTa+g1uy6ijgvEg9Aaex1XzLBsYkX7kOccY8PVkuX3LlnpKrvQIkoIocaIi6tUrKuNFqrbIKrin4LGoAJGugyAEuTttuOQxa9D6Yk1jbeFuHMTtQxLZhg77h2+kr8p0u6cRbQWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=cZ6lM/Bt; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="cZ6lM/Bt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=DjF6ucnJBIWGCwOnYkS1ECrAhhls1IrKDFiA1tfmPcc=; b=cZ6lM/Btqjk9O9qGhAoe8EVRe/ yw9H8L4MSTueH98ApD+4VGLNaED1y54QUkm0MbBv0uQpjujnDcAiyvtQdwXLOfhx+4gpYCm3F5iXO SlF7/CpmRp9X0dNVjdApTf6gC+uYixlNxFJhyibspc44KAkUJINbnzhBAKXQzcPW0wRtHQ62+8T9x NmE67beaH1AWoWXkr6zabjtn0DOhsK5cqphlTlVeEriNnHFREVIg3dRcWY2AjXlL95x8jWqPm1URs oeAjdhEfE5PR7chZ8xeQSPUukdM/Qk1q0BEFVZg+pGD6qEPCE+SNaEDmit+UcUk8vZcwwpJI8Qrf3 HsRoxbgw==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8o-00000002lCf-1c2I; Tue, 13 Aug 2024 07:40:27 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 8/9] xfs: simplify extent lookup in xfs_can_free_eofblocks Date: Tue, 13 Aug 2024 09:39:41 +0200 Message-ID: <20240813073952.81360-9-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfs_can_free_eofblocks just cares if there is an extent beyond EOF. Replace the call to xfs_bmapi_read with a xfs_iext_lookup_extent as we've already checked that extents are read in earlier. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_bmap_util.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index fe2e2c93097550..9c42cfb62cf2dc 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -492,12 +492,12 @@ bool xfs_can_free_eofblocks( struct xfs_inode *ip) { - struct xfs_bmbt_irec imap; struct xfs_mount *mp = ip->i_mount; + bool found_blocks = false; xfs_fileoff_t end_fsb; xfs_fileoff_t last_fsb; - int nimaps = 1; - int error; + struct xfs_bmbt_irec imap; + struct xfs_iext_cursor icur; /* * Caller must either hold the exclusive io lock; or be inactivating @@ -544,21 +544,13 @@ xfs_can_free_eofblocks( return false; /* - * Look up the mapping for the first block past EOF. If we can't find - * it, there's nothing to free. + * Check if there is an post-EOF extent to free. */ xfs_ilock(ip, XFS_ILOCK_SHARED); - error = xfs_bmapi_read(ip, end_fsb, last_fsb - end_fsb, &imap, &nimaps, - 0); + if (xfs_iext_lookup_extent(ip, &ip->i_df, end_fsb, &icur, &imap)) + found_blocks = true; xfs_iunlock(ip, XFS_ILOCK_SHARED); - if (error || nimaps == 0) - return false; - - /* - * If there's a real mapping there or there are delayed allocation - * reservations, then we have post-EOF blocks to try to free. - */ - return imap.br_startblock != HOLESTARTBLOCK || ip->i_delayed_blks; + return found_blocks; } /* From patchwork Tue Aug 13 07:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13761473 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 32A3158ABF for ; Tue, 13 Aug 2024 07:40:31 +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=1723534832; cv=none; b=KEnlInoz1Hls0eD/rJf5mv2E2xvzuUHm36wcPxe5hHb7gVLdBGfW0MTlgXTv/RutGfh8ldnh9Ivv5aDkvj96HGw2qnUZBhUd3AXfEFpGRoIkRWA0e4+vViP0QHG1H6IZ5hqxTnC06W9tFPVZYYeWnV7S4IrDg0IsWhhkhDhui28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723534832; c=relaxed/simple; bh=IgNnX77TruHwlPbFmP1sNDl8aysBjNoJhPkOU8utgvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r8coHVpMlc0iYfguRXy8SVYxa5iX10zSrv8UheiOftI7Sam5QqBLRMeQLNVsyUblFaLsS46FDk6o18P59FF2hP7JzRkdji/1IP4uPsPhI+RksN2ua83gem6kLVPhIRQ/2x48i9FEHw6ylOfrkJCQwAm0qbEqm4U6rXEEiAmvNA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=odXXh8dR; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="odXXh8dR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=t/6itKJSb5fga8/5T/Vx3R+vP2lP+c0eRJ48C4ZfaMg=; b=odXXh8dRiyDtM51ixyPWB9w1u4 HU65mFGDI6mtw8XeuxRQIw6AMNpibKvgQniMoA/Pu6zg/9JbMnoydyXItuZVLoITMp7qiXSB7/+Ks 8U4vK2SDWWg0w8T+8Pc7YGAniBwHwUNSWImNpkrHh/NIZM+4iaaj76Y/1vby3Gtkc5WwuRKX7cfJf KvgWf+z58F3wfhlM0AjlkdLP50ZQbI5jtTF07ZfPv/oebwU72mN4fQHwPKYi0//Yjm1sVx5ZQnCb1 a7EUgDVmXAYH5b8tl/itH/citZyg3KoSE1x2+5NwwVgNhQIvWWdvIUbu6MMmaPGhz3GsopGZrgqcb FX0Y77ew==; Received: from 2a02-8389-2341-5b80-d764-33aa-2f69-5c44.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d764:33aa:2f69:5c44] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdm8s-00000002lDw-0ze8; Tue, 13 Aug 2024 07:40:30 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH 9/9] xfs: reclaim speculative preallocations for append only files Date: Tue, 13 Aug 2024 09:39:42 +0200 Message-ID: <20240813073952.81360-10-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813073952.81360-1-hch@lst.de> References: <20240813073952.81360-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html The XFS XFS_DIFLAG_APPEND maps to the VFS S_APPEND flag, which forbids writes that don't append at the current EOF. But the commit originally adding XFS_DIFLAG_APPEND support (commit a23321e766d in xfs xfs-import repository) also checked it to skip releasing speculative preallocations, which doesn't make any sense. Another commit (dd9f438e3290 in the xfs-import repository) later extended that flag to also report these speculation preallocations which should not exist in getbmap. Remove these checks as nothing XFS_DIFLAG_APPEND implies that preallocations beyond EOF should exist, but explicitly check for XFS_DIFLAG_APPEND in xfs_file_release to bypass the algorithm that discard preallocations on the first close as append only files aren't expected to be written to only once. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_bmap_util.c | 12 +++++------- fs/xfs/xfs_file.c | 4 ++++ fs/xfs/xfs_icache.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 9c42cfb62cf2dc..0f1e3289255c2e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -331,8 +331,7 @@ xfs_getbmap( } if (xfs_get_extsz_hint(ip) || - (ip->i_diflags & - (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND))) + (ip->i_diflags & XFS_DIFLAG_PREALLOC)) max_len = mp->m_super->s_maxbytes; else max_len = XFS_ISIZE(ip); @@ -524,12 +523,11 @@ xfs_can_free_eofblocks( return false; /* - * Only free real extents for inodes with persistent preallocations or - * the append-only flag. + * Do not free real extents in preallocated files unless the file has + * delalloc blocks and we are forced to remove them. */ - if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) - if (ip->i_delayed_blks == 0) - return false; + if ((ip->i_diflags & XFS_DIFLAG_PREALLOC) && !ip->i_delayed_blks) + return false; /* * Do not try to free post-EOF blocks if EOF is beyond the end of the diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 986448d1ff3c0c..0d258c21b9897f 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1220,6 +1220,9 @@ xfs_file_release( * one file after another without going back to it while keeping the * preallocation for files that have recurring open/write/close cycles. * + * This heuristic is skipped for inodes with the append-only flag as + * that flag is rather pointless for inodes written only once. + * * There is no point in freeing blocks here for open but unlinked files * as they will be taken care of by the inactivation path soon. * @@ -1234,6 +1237,7 @@ xfs_file_release( */ if (inode->i_nlink && (file->f_mode & FMODE_WRITE) && + !(ip->i_diflags & XFS_DIFLAG_APPEND) && !xfs_iflags_test(ip, XFS_EOFBLOCKS_RELEASED) && xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) { if (xfs_can_free_eofblocks(ip) && diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index cf629302d48e74..e995e2f6152dbd 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -1159,7 +1159,7 @@ xfs_inode_free_eofblocks( if (xfs_can_free_eofblocks(ip)) return xfs_free_eofblocks(ip); - /* inode could be preallocated or append-only */ + /* inode could be preallocated */ trace_xfs_inode_free_eofblocks_invalid(ip); xfs_inode_clear_eofblocks_tag(ip); return 0;