From patchwork Thu Aug 8 15:27:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757651 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 4224F18F2D6 for ; Thu, 8 Aug 2024 15:28:28 +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=1723130909; cv=none; b=SWVWFZvrk0nnWdha6fhpbCfL8dTwdKktx0OAfFEDfXb4tBNKl3pOoHUMqC2KU6RJNPG4c7BXRrxHgTVzu91CL7TgY/POoDJu3D/LYbZKl7GrVga6+LGN/kAt82tTKeZtLp7v1qUkOBQ27uS7j7nAVYMk6148sb52bxDcqI35mZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130909; c=relaxed/simple; bh=1ffybEYeulSPO8MW/8FCE0+ONbLCqzpFEfbiRTvgEDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RDGVhoGrv9YAfTVCLn1WH5BESVxG5LKBrkRcgr6AlKES4jruj1HTN39YigFBhI2vJUquGsuH9N1j2d+8nHzIWvhUTBu2FML7BoGVLQ9kFdyzx2N6HboiD7Xs+DQALqOSfWQ8DsDNIermIEmNRM6wURfd0rZKvVlMvowzNFnCHfs= 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=KZ/HoF5N; 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="KZ/HoF5N" 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=KZ/HoF5NJ2/lKaY9VP5raDexKd sGG7lw8gF6s9K74sTrhcqy3/kS+5zc+/OmcDu/bTHJ7G4fCDYuNXh/oT9tYBfSgR/KJEHKnQQMRm6 FhVhlUrB20CQ8tV7trCxzlFUI4KCt69+pQGVq2pZoS/nNa675yRzSMB5Za0qAvdIuCqPSilFLHlKR YbBPmy1VMZ37mv9Lo+Pyx+aoZpy4GVk81kpYPU9rq/uKX1wcDhXHdOPg9Ugu6R2cYvqV9r4/QZPbP PX77YzmVtXY23TQEHWl4jBNzkVTqfBbSN67qiX+r1rW05xA7Kg4zuFbM8XiFm8aWxmSb8JxfeRZ2h 3hmlLDjg==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc53z-00000008kWF-3VMN; Thu, 08 Aug 2024 15:28:27 +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: Thu, 8 Aug 2024 08:27:27 -0700 Message-ID: <20240808152826.3028421-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 Thu Aug 8 15:27:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757659 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 A0021190063 for ; Thu, 8 Aug 2024 15:28:28 +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=1723130912; cv=none; b=jsphtmlmrbckTjghVlp/JvW3t3C1tJ7sNNwgnCUZ/7MibrJxOsNElMEXdJN7P34TFNmXkCApWENlWeISGcnig9LP54XTDH9HchAmNx74Kl2pK/Lf9BjYPc3f2agy5N9/zIoIhIGujePAXXDHQlmYA3w67sv/i7GcxBcEHLyy6QY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130912; c=relaxed/simple; bh=qcOZrHatrdmCkh/krTR43DXipZ7oi9ssbT/lnYPzh8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W0mS3t/aI9IPY6LtrvkHiON4ApnK+tARjFcAOB9K8okda6akP9uKw2+2xHJQ/z7ai8YM70zHw0aZn+MPykHrb7qdshpXRgAZYrk1hvr8PPN8G1XYT9C56cPfGOz085UZzg1CYZbh9Go68o0lF5zWvRIy2MGB6SD1tnENagMbi+Q= 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=xynuTrq/; 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="xynuTrq/" 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=xynuTrq/025zYVxukrQeA3G+rb evcYnHdUDNWyvz1LEqT1nx9vTPvo7HnNuC3KWVBY0emcYTDNxbRkWgifaAfKmcPwfUgU3GlFWGtVs l4nD5F8gAxkOJALMpmHsfB0cFkxf8ZeGTLoeDt/YxGfTHm6NoodHEEHj43Zp7QZ7PVbr5JgjrtDB4 vkuN/hQTQG/xROnFvFLp0EiCCuq+Y2+c0kRpKMJA39nrRZ+QRU6DmmBt5r0fCf6wYl1EaVfwXUtra 38DIGujSG3a1CbCAIWDvPIcadHrXh3Ms6ZsjF7BEAidci0Cn0ymx2BPrwBpnt93dB0ZMkIlx76L6C MzQjY/2A==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc540-00000008kWL-02io; Thu, 08 Aug 2024 15:28:28 +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: Thu, 8 Aug 2024 08:27:28 -0700 Message-ID: <20240808152826.3028421-3-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 Thu Aug 8 15:27:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757654 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 B4138190067 for ; Thu, 8 Aug 2024 15:28:28 +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=1723130910; cv=none; b=S8Jw9BmxHvyiDOknjKwYeFXKByqEBf/puJI9TBBMd4DRIzFL5vP1tMlw65JU12pFFzi7vkTlc50jYNfbOYy+bBZqDfmjO7O5dYAerE2XZpRbs4rquI9STCeZu5K4gYv1e+gg8CM6ornq5za9IR1WwIN2nxpK4qowp4tEfV+3lHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130910; c=relaxed/simple; bh=v8MwnvbvNtnmXSzY943jsIaLRSBB9RHgWxmytGelWSA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mDrBlFoSktvddLnLmW1PP+BcQGCBxy/QQG50BI7vlxHrSukE5+EQ9gP5N4i2c5UwG5j0YsiOQlrBlElXK6ZacnTQ6Ndq08WX7rcYBm6a9Z1O5FSGObzXLBcgn6DmdEU3Qdd5pk0qJLgwIL2PXCOwI2djT8vwBZZYob52f4vs2yc= 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=M/d85VrD; 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="M/d85VrD" 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=M/d85VrDKeW0z/P7rFzg+LSGfz RwNbW7RoFZMUO/DM27WAYgpLixiRJt3Pq840mqo9S3BZwK+RlupokWmRZV39dTAQenep3WBqhwFjA b05O68yz+4Z+Jp+9FjGnkm7WvfO1eQWC2ZbM+yd3nTK6fgvz5kgjsrw4jCnaxDz+WW73qOE9MHyMb pdEd6EeAyTcYD7E1tsXPHHN2mPh5NPrzHCLXS8JII0iuZN3yiiJn6N+bmnGkXT/vBJTqEFaQZcQGU q5aIcZt+V4iZ0eIeyxsa+ORejS9SwEpltMJQHu/8J+1PVfZeeICui2AIsZPK4d0d4ZiaZD3WpSObQ es+tRlUQ==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc540-00000008kWU-0ofG; Thu, 08 Aug 2024 15:28:28 +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: Thu, 8 Aug 2024 08:27:29 -0700 Message-ID: <20240808152826.3028421-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 Thu Aug 8 15:27:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757652 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 E12DF190468 for ; Thu, 8 Aug 2024 15:28:28 +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=1723130910; cv=none; b=Ury+NygcTmnmWoH87HA8dKp67Wa0geMdFhg3UaKn2RqZ4wsv69a2N0bgzP0ACUz0pV+TL7McwQcOy4UFzQ0wbLKbv51wXMIjq1NOPJICMOsAqe49FFNqsd0v4GVbENlSEj9TCymQJySL4kUkeWzZ6pLmnEtvI+//de19A5CGHFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130910; c=relaxed/simple; bh=2TgH0p5TosrlSsMxGUROgGAE8R2IehSYh2uS77SHBtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hdEoW7Wu/Sww29RJvRxsiNRUE6DyCB2Ge1ziwUc/pn6va5AylMHHsrSjg5JOQSj1U+tAEenD3UkTup5wQW8D4aUlcIYFwDQ1Z79KMzT2d/zqoUAZ+shYDddbBPs3lFHEAW19zW96PuYCXurTaAF7/BwioDw9R2a2+N1h1wJ+MYU= 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=mXRo82ga; 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="mXRo82ga" 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=5apWJdn802bBJYi7AzwrCJlPHotmf/dCE+yMU+gJqj4=; b=mXRo82gaFzbR87otzsdYP/8Gym rKulBq6z31AJ5X5GZLVF2UokgHfaSV6yRGpFAwH4Z+LsffcqgUkTMTj994UYjL2+uR4zDevZ896ry KilVsyIgyp84mq2WyZzam1JyEuW32pBo8+3Yd5dTncHzIxtBERyt16JLb80kcb2tr7zwt2IJRTVt7 QsrTfjkDPOZPSkGWTEdQQ9225FZO+FtSV27ruIyMfK0tcGq/aomWVAMF37JM8UmkhyDFRvuHSpKcr +VJOvNRF+xJgvdGrwTznwBrwdjFyoRNDt4e1EQNhk6HGVcBEwNnng/+iF0SP/OhbpMLLzfZK2Ej3h MOjo0Jqw==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc540-00000008kWa-1bIW; Thu, 08 Aug 2024 15:28:28 +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: Thu, 8 Aug 2024 08:27:30 -0700 Message-ID: <20240808152826.3028421-5-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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_shutdown 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 Thu Aug 8 15:27:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757653 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 53941190072 for ; Thu, 8 Aug 2024 15:28:29 +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=1723130910; cv=none; b=kGJBo8FYsdkFQJMhoAI5K8aO8dzYsj8OWp6DvASwcEb4GF/MTfHZQx9srbHhAOliBMFuLqb7Epiz1Q1gGvFpwfPOfIqkIRRUJyia+O7dlb81O1iGD7/HfV24pd6CvjWHlP9MAE1thF2gz0r/3/Tdo3r1JZ/DY4w+AMrcJHvabNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130910; c=relaxed/simple; bh=J6Leu8/NjO23GT58hVUMPeJM2l3c+SYzc021Q0VWY/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jWkwRg85cFQAfYdIHOUQX2TqKIgb7exZ4glWTIqYpe7eXr1tIBGpZnhw1pFqndETeYc5UXqq+1KP3Z/0A9ANZmUJjhAgTyNDGdSDQqM3lfx97ObfgUTrO3t37W4WQ1sABYUKS57ZtYf0BKsLVlI54b+x3uG4f2xOoxmbcIQpaXA= 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=IyAblN0c; 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="IyAblN0c" 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=IyAblN0cep1O54c9KOt2IbKoiD C3+xFfba4wD9xH4y162AAK1LS7+RbCddChkjZ9rRWQx6bNbnWluJdeZphjWRTxt0j1oIG04ItAmtc Uj9X3boI0OsBUMKqBloh5CW0rH2leB8jw+C1V6c+7z5DOKhNFWFW2l0XxzzHX+YZEkOLvwTToyFkv 4SOO2JS/WmqSf5h50aFeQWfA+l96WcyXfjF9NsfulZ/WBF78ilgiXGiDm5d0C9Kp0gpPWH2Uara06 iXE/Utxat2m4NPRSMFSfXMvlLtm00x8+7vXD8MhomlEev4oFJCmhPzOrXB6f9vf46nTEHEViJ/IRB AtyppXTA==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc540-00000008kWh-2tbN; Thu, 08 Aug 2024 15:28:28 +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: Thu, 8 Aug 2024 08:27:31 -0700 Message-ID: <20240808152826.3028421-6-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 Thu Aug 8 15:27:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757655 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 7B84F19046A for ; Thu, 8 Aug 2024 15:28:29 +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=1723130910; cv=none; b=nOcghjhLOEe/OdO+fuMABUdw7ZPcLSLLcHLC5POmg94BRQCW+0nXyfLT1bABTMY/JZsqYZeXF3+hdEsnql59+cRudWwHisZJBB1ot5w6LX+gXglofR4aQSbfoYpU3/3lo3HzozSj1n/nCHYMMMpu8ldIhi6wz2nGxvcZFSVBL7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130910; c=relaxed/simple; bh=aM/WPl11H58JTmAWWCzx4g8EipOBoKHGlfb0riWuvbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qdt2pZDKWH6KixtjKflj2e9m2lCMnc2hyxoUYRg09Ybfygu/ONQ4mL65wbXBcSupJ+NZJKH13mSzdpAUvzw0U6mCxPezbGwGGOHYfAHgoFCf2e+rUUrkMzSPJ1xI+n1/pI4/hRIfyxnYStALmPRazFCMiK6RgEspVjVPtUDVnRQ= 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=hpVc+/pf; 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="hpVc+/pf" 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=hpVc+/pfs0IBO9cplKrBbI+uHI rdlGJYL9mXriy69lykY4Vo1B+UChjiXOXVENRHmWO2Iaz3pR4UWCj5Z0EUTGaUGmlN21ko+FDYP82 rU+L8wLf/0J6MHEbkjWEkt3KvVYEGuugZcgdLBJfL+9Bf9jWIctzNZyGEhq8aIabExAPQjEoourwJ tSWVEdoDsT/vibQgQjyKLpbVI+gosx5yNgerDJkEWFk1brXTHwt3cl+dapQII78rN8noGe2nuuU9N 1TQFhFqWk0GGAmSujZ20M4eLexag+ugnDWQR2t6rtJy3mJRHfXIVWCApe6VwJ53lKUhZNhDG1chvh VgrbAzTw==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc541-00000008kWr-034g; Thu, 08 Aug 2024 15:28:29 +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: Thu, 8 Aug 2024 08:27:32 -0700 Message-ID: <20240808152826.3028421-7-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 Thu Aug 8 15:27:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13757656 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 B09E819047A for ; Thu, 8 Aug 2024 15:28:29 +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=1723130911; cv=none; b=mCvFWhlBx9oDftEE7LzpvULwfWNOhRxGWWgAfGn29spOTfF0QONbA65P92F8VqT1syzJU+i6W+kCSpxkihXs3p4sp5ZVoeJaC9GcG0JEx74wDfNN7CKF0uMlwdLBEpJknBOLZjDdOryP9Y3KXWpXpxrE32QkMvxeBw4gaH2edK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130911; c=relaxed/simple; bh=8//IyHH2UxdcO8DZauXXyB3/vGpvdzDHOnpIoBEVXU0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SuwbOhCvWSnnUcRzTfhgNWPx64l86mOoFHtm83z6u1L+rvjnj4GDbHS74TyvHrtSTG+9YPiO/JZYSHc8RzA8De809VATLTQnAVAj8NhQbcd3RF1FMSEAHWZH1jile459T/X+vKfeGEwywSHuDIYyDXBj7y0QB4Uu74oZdUYIuIA= 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=L6CyxXe6; 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="L6CyxXe6" 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=vQuJegpM089kECOq4DIYSw1jMJAARhUns4DObOmiRJM=; b=L6CyxXe6P9SC/hq+5ATCCzTxlz D9U3GKGNijXsF+9ERq/zF9000TYJrLsRdtSz8cjcHXS0g82/JPhVr3oveIU5mJBR3MQ2PQ4aQEHTy uTzqpRw/AxsY7dYlgpd9hVH03YYcFCUMjr+8YL+7Kfnj6wG5TTmiJiEJC1GnkPrDy0mgxemFBeaFS Fu3mhpa7qTbtg6/Ufrfi7QrSl6MSjbuhRLVNcUv3XG9E9Qc1kzxSc83rXd6mpDP59We4OL2FjW4fo vaguPlm6LhxxKK5gzpTSPqgcCJrYIMZhPJOoM0E7X+aUvbSvxrTSUU4ePxahA4a2zJpT+lpXdI8a/ b7afLIlg==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc541-00000008kXG-0xjF; Thu, 08 Aug 2024 15:28:29 +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: Thu, 8 Aug 2024 08:27:33 -0700 Message-ID: <20240808152826.3028421-8-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 30b553ac8f56bb..f1593690ba88d2 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1234,9 +1234,9 @@ 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)) { + if (xfs_can_free_eofblocks(ip)) { xfs_free_eofblocks(ip); xfs_iflags_set(ip, XFS_EOFBLOCKS_RELEASED); } From patchwork Thu Aug 8 15:27: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: 13757657 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 DA6B9190477 for ; Thu, 8 Aug 2024 15:28:29 +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=1723130911; cv=none; b=dnzFg0If5vvNWdYzVuvJnEbR3aViK8bi052LuTHBbHru0ojRUphDzjgNXjWma5+/THO4zdGXuhwN+aL3qomPUXrAQ1l6YjJvv+OY1q/B4NiUQnx96hekmOQki126RHpAJ//CgRff3wVfYRUE3VmTvODp04T1en3izPPjVaTHlRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130911; c=relaxed/simple; bh=Dl5MaigYOAPQ68kwjH9IryRR6Kjf2nByPXWhszyp14U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZC6MVShFiqxDxeLJRGLuUZOlF6rZPlKPJ3j49oHAgNwqa7ImZLn8R1k8kPwzXeEtNtAPdG2SbIkRx43d2L0+++5blGy+lmAcecdn+6adfvOYVYS3vYKmZpE64yEo1TQL5Bboxm8L1Euv28E1imKYwyA3js6BRxdH7buySxTQlFY= 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=HZvncQYA; 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="HZvncQYA" 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=HZvncQYAE72eTuS9JP7XHT1BmL KN7dV0bOgPutWogO++NkyZqo1pD31ga4zHQsi5wnwmFNEHWXhQd789V8Kq7ZejekD3C0Y9tvS4LN5 SDxvNVIHh73PClYylw6aydmfv219Jts7CAeNSDI01vupN4qI7uSTkYww8p03EtGJ8tt8agEobXARM d53nN4EFdptggl/xZOCiEe0CTT4hsxyZXD+5CFnWlPrx3B2TnhGr9635vMNjNU0EtTEzYpeNDyA9K 8pRdQQQl9B/NNzJnvVQBn2eWG5Z9VBvyCrW7S06yk5oBERTjk04A6FuBBEAxYrA4alKLZ94bh7YXt kY6jdSuQ==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc541-00000008kXQ-1mJ9; Thu, 08 Aug 2024 15:28:29 +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: Thu, 8 Aug 2024 08:27:34 -0700 Message-ID: <20240808152826.3028421-9-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 Thu Aug 8 15:27: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: 13757658 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 31CC6190499 for ; Thu, 8 Aug 2024 15:28:30 +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=1723130911; cv=none; b=YJlW/um0hQ1oiS5CFoMt+aL7MfHKBRN1CbK/aLBhdjPqaX+i3+lIvNjnGUl+fl5HiLuzvKxWPolml0dKECqF1K+NNg41y6vIXakTpy6tPSFYgRBe+kRSaYmgts+UCa2S+WrgiwOxqXLcjRaoQKuTAvLMG7ZmZzujPJMhAY/SRc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723130911; c=relaxed/simple; bh=5+UUpO6S3VmYBhsgLAtVjzH/JvKZ0+Pe4F6dRl0KP74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aaM22BVZ+KzqH+Goalpsi0zmo4nUTI4hrV5tgJH/Y6oPWldByTFyRZrn+BkkUEzaGnzXbyUnxLlOcl5aoA9ZtwBsGYZWM4Xsgbr85oqnDGZASqmvjeGIWshOxsFphuoZHnLMe4UXnn5amMr3nZ9jl71fGWpxHcm0Ue68MwOV3uE= 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=hhcSD/0Z; 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="hhcSD/0Z" 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=V5j5VFzmWrk70fbT2Ja9cUuW3rjTTkYJ4FQrPgYIQjY=; b=hhcSD/0ZICyzdW0uLHG6f6EPVb KDi9EulwySEswPlhFP7B8AtQu6+U+ytwUHNp0FoK7mOGYk6vPpdJMYvlKZzaysdny+/YHDwGpw7j8 u0DQv2hMpbtl8z6KFqeufwUZ4jjscsEw/ayu9ljTrf1iL3GUsuS3S/FhkpL3WFDwKavvSOKppWe69 WyC0XEWg/bqM/4wWw+ohzY8sHuZbdpxXadGfYNYyccbU7Ly4l16jBZHPchhZZJFKDaS5SfKmKJ4Oz PpN9nBK9REZMh7IBrow0LHE5pnaa0x0DjOpzP0b+CbKMuIUzhmLkGma0phQC9YHJwfHyyxlDHZzPL PihCRsCg==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sc541-00000008kXW-2XKl; Thu, 08 Aug 2024 15:28:29 +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: Thu, 8 Aug 2024 08:27:35 -0700 Message-ID: <20240808152826.3028421-10-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240808152826.3028421-1-hch@lst.de> References: <20240808152826.3028421-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 f1593690ba88d2..f244b8e8056f66 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;