From nobody Mon Dec 15 21:47:13 2025 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 9D6831547D5 for ; Wed, 15 Jan 2025 05:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736919631; cv=none; b=aIOk4kEglkOGI0rMCtYpMqdxKRQMIYL8eaPyBznyUIlAuSBruMuWMvK8lJcujzrH5K+YlpMSnCZ7fV7ut116vUESmQKCeIaZxPjjo2f+O9a8feyIHz1Ga6R8WPK7JfkmHtizFNKwmR8VdA8pPkuwmAoROyHx3hJrEs5Yr+sYl2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736919631; c=relaxed/simple; bh=Wwf/zllDVjKOsyhEXdXoUAziyDlC8raTlclT/Bp8DH0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=V9udBL/l5eMDtlfrr9SaQa8WKo2eb1NUx2LE3pg4lIt7bJqADJSuFp09fbq8o7vFdCC3cUHXpkuC4zMr5zehZ/DnjK2uQatdT0JT80zMa5KiRT8o0QMqRZNER/Dp6P8JSVb4c/pWDUDUmBs28WXk4RoN75ImB+1jbohdOC5nE78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 50F5dpFl086005; Wed, 15 Jan 2025 13:39:51 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4YXvr84Tsmz2NhqqX; Wed, 15 Jan 2025 13:36:40 +0800 (CST) Received: from tj10379pcu1.spreadtrum.com (10.5.32.15) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 15 Jan 2025 13:39:49 +0800 From: Yi Sun To: , CC: , , , , , Subject: [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range() Date: Wed, 15 Jan 2025 13:39:43 +0800 Message-ID: <20250115053943.2450661-1-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 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 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 50F5dpFl086005 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Chao Yu --- 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 c43d64898d8b..00fcac45f1bb 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.25.1