From nobody Sun Dec 14 11:32:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 37E7522D4EC for ; Thu, 16 Jan 2025 17:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737048283; cv=none; b=NFlvYJT6q4OgGsoxJKeHOOe7e+jNkN82BHcZvmG6nPLWEc9ZhpJrIkc/G7lIfKzPCMA532HouDHBK4yXAFcqJsnFKfW7BNQBpmibk0HEauJYmeLyxOgigArxmuk7nww2oKLzvd0m9K+TxwsMb9VR2el2cKJ24O2pvFUKPLvU8i8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737048283; c=relaxed/simple; bh=FZHDVA07TuX/CpfIs82bSFvSPD6dz+VV672WlmDYwVo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HsbyA6r65ziSFMmG7qhA9CoTheLtuXHPkbntDYQAKfkVPfZ4QouqcAvVl98WCqf2Lj1UoHTD1vOR8HW5DEjhyjfsnA1Mdht3aU4oCgQdrZT4gVWPUHHYxDNKVPZwtMMHCQnB+1S1qa0L0n0vYRGtV7lvJW6bSSTBe7BFB+cD8QI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W0eLJrMw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W0eLJrMw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97462C4AF09; Thu, 16 Jan 2025 17:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737048282; bh=FZHDVA07TuX/CpfIs82bSFvSPD6dz+VV672WlmDYwVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W0eLJrMwWmk+t2Y35jcsjkPkmFHHQT8NN3AcJATjQwDfn5x1YDTmoMbNYfVlQRVFX iH+VUXG9jwSERdS61zxABG/cT/UQmK7Xc42ckYDkBgCh07Q0QCrslj0+4LGUINht0H x2OkE6vxO3qwXhbBBAzFhWPI5GpN9Givxw/A1ZB3Yl5aVPbFKS1JmLavear26oSZsh GuM84GZ9g/Vvkh/Cfm2U9uVEH6662qUSDk9OCTgG1t3/1VV/SaosqthcwTFlVrxrpM jcKQu9Zg8wDfQoBzT8rlglMx7MKL9ofs27WQfc3jW+z/QlrLKQCP1CV7sATaIZxkfo XHItPrRmScbTA== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Yi Sun , Jaegeuk Kim Subject: [PATCH 2/2] f2fs: Optimize f2fs_truncate_data_blocks_range() Date: Thu, 16 Jan 2025 17:19:44 +0000 Message-ID: <20250116172438.2143971-3-jaegeuk@kernel.org> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog In-Reply-To: <20250116172438.2143971-1-jaegeuk@kernel.org> References: <20250116172438.2143971-1-jaegeuk@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yi Sun Function f2fs_invalidate_blocks() can process consecutive blocks at a time, so f2fs_truncate_data_blocks_range() is optimized to use the new functionality of f2fs_invalidate_blocks(). Add two variables @blkstart and @blklen, @blkstart records the first address of the consecutive blocks, and @blkstart records the number of consecutive blocks. Signed-off-by: Yi Sun Signed-off-by: Jaegeuk Kim --- fs/f2fs/file.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 902f8f50cc27..6572970a988a 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -621,8 +621,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_d= ata *dn, int count) int cluster_index =3D 0, valid_blocks =3D 0; int cluster_size =3D F2FS_I(dn->inode)->i_cluster_size; bool released =3D !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks); + block_t blkstart; + int blklen =3D 0; =20 addr =3D get_dnode_addr(dn->inode, dn->node_page) + ofs; + blkstart =3D le32_to_cpu(*addr); =20 /* Assumption: truncation starts with cluster */ for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) { @@ -638,26 +641,44 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_= data *dn, int count) } =20 if (blkaddr =3D=3D NULL_ADDR) - continue; + goto next; =20 f2fs_set_data_blkaddr(dn, NULL_ADDR); =20 if (__is_valid_data_blkaddr(blkaddr)) { if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE)) - continue; + goto next; if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr, DATA_GENERIC_ENHANCE)) - continue; + goto next; if (compressed_cluster) valid_blocks++; } =20 - f2fs_invalidate_blocks(sbi, blkaddr, 1); + if (blkstart + blklen =3D=3D blkaddr) { + blklen++; + } else { + f2fs_invalidate_blocks(sbi, blkstart, blklen); + blkstart =3D blkaddr; + blklen =3D 1; + } =20 if (!released || blkaddr !=3D COMPRESS_ADDR) nr_free++; + + continue; + +next: + if (blklen) + f2fs_invalidate_blocks(sbi, blkstart, blklen); + + blkstart =3D le32_to_cpu(*(addr + 1)); + blklen =3D 0; } =20 + if (blklen) + f2fs_invalidate_blocks(sbi, blkstart, blklen); + if (compressed_cluster) f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false); =20 --=20 2.48.0.rc2.279.g1de40edade-goog