From nobody Thu Apr 9 16:28:03 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 22D5037CD29; Tue, 3 Mar 2026 03:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507751; cv=none; b=ISCajUDxOkjevvHfkr+fzDKRocdwuMNahcdoLLbgGGanWNhRZKftCHcaBlH1beOCLYzDV1OLS91mGFpJzz81Jrnox+BrgNjyDxJI5X3StVG99ss1Hbc0joqXeMvnpshfatIYKzBuFp+1CosCa1Cjz8giPjd9BSaWX5BZO/LM41o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772507751; c=relaxed/simple; bh=w8rNkWEjUFCXjSAhc3cIFAG542b2c3mihzEDpHI9qfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDBvD+LorvcV5rijQrv0/eNFMqtAq6fFCps8JPQa1SurgJdVDwaWWT2Epzbw4GwA+eT1Y6GxLFJIbVxl4bM/K7+Hk+4kehNsrc71TMAt1LeekkIwLm78dVFGnFMIU4uCRZaDA+Xst2XQ7UTzJHyxGgPBg4qBpiH1cyZOrPyVnco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=nVA5AFcB; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="nVA5AFcB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=ZL gy4MSlrRZC+zc/j95iZRJF8V8QJqf5zvBN0CeFOkQ=; b=nVA5AFcBaZsbMjh45q ixuwskp/2G0t72/HC0TatB++vsjmn5QBs6on1ixVXK/u15kK/Z+YlYkPATlXsIEn ZFgQ35pfKP88AI3IDKAJ7FH+twZPwdaRe4g9kFSYEZ0DcJ3YQB8sYcCIeAEiPGMZ Jr2lt2Z20Tu5ODcfdscNSpg+s= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgAXh6xQUqZpOLCWQw--.188S7; Tue, 03 Mar 2026 11:15:34 +0800 (CST) From: Chi Zhiling To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Namjae Jeon , Sungjong Seo , Yuezhang Mo , Chi Zhiling Subject: [PATCH v2 5/6] exfat: optimize exfat_chain_cont_cluster with cached buffer heads Date: Tue, 3 Mar 2026 11:14:08 +0800 Message-ID: <20260303031409.129136-6-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260303031409.129136-1-chizhiling@163.com> References: <20260303031409.129136-1-chizhiling@163.com> 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-CM-TRANSID: PygvCgAXh6xQUqZpOLCWQw--.188S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFy8tFyDXr48KF15tw1DKFg_yoWrJr1fpF ZIka93tr4UJ3ZFv3Z7tw4kXr1fC397J3WkGa13G34fAr90yFnY9ry8Kry8try0kayDuFyY vF4UtF15CwnrWFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2XdUUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xatS2mmUlaMBgAA3G Content-Type: text/plain; charset="utf-8" From: Chi Zhiling When converting files from NO_FAT_CHAIN to FAT_CHAIN format, profiling reveals significant time spent in mark_buffer_dirty() and exfat_mirror_bh() operations. This overhead occurs because each FAT entry modification triggers a full block dirty marking and mirroring operation. For consecutive clusters that reside in the same block, optimize by caching the buffer head and performing dirty marking only once at the end of the block's modifications. Performance improvements for converting a 30GB file: | Cluster Size | Before Patch | After Patch | Speedup | |--------------|--------------|-------------|---------| | 512 bytes | 4.243s | 1.866s | 2.27x | | 4KB | 0.863s | 0.236s | 3.66x | | 32KB | 0.069s | 0.034s | 2.03x | | 256KB | 0.012s | 0.006s | 2.00x | Signed-off-by: Chi Zhiling --- fs/exfat/fatent.c | 49 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index 4177a933e0be..a973aa4de57b 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -32,6 +32,17 @@ static int exfat_mirror_bh(struct super_block *sb, struc= t buffer_head *bh) return err; } =20 +static int exfat_end_bh(struct super_block *sb, struct buffer_head *bh) +{ + int err; + + exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); + err =3D exfat_mirror_bh(sb, bh); + brelse(bh); + + return err; +} + static int __exfat_ent_get(struct super_block *sb, unsigned int loc, unsigned int *content, struct buffer_head **last) { @@ -62,29 +73,40 @@ static int __exfat_ent_get(struct super_block *sb, unsi= gned int loc, return 0; } =20 -int exfat_ent_set(struct super_block *sb, unsigned int loc, - unsigned int content) +static int __exfat_ent_set(struct super_block *sb, unsigned int loc, + unsigned int content, struct buffer_head **cache) { - unsigned int off; sector_t sec; __le32 *fat_entry; - struct buffer_head *bh; + struct buffer_head *bh =3D cache ? *cache : NULL; + unsigned int off; =20 sec =3D FAT_ENT_OFFSET_SECTOR(sb, loc); off =3D FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc); =20 - bh =3D sb_bread(sb, sec); - if (!bh) - return -EIO; + if (!bh || bh->b_blocknr !=3D sec || !buffer_uptodate(bh)) { + if (bh) + exfat_end_bh(sb, bh); + bh =3D sb_bread(sb, sec); + if (cache) + *cache =3D bh; + if (unlikely(!bh)) + return -EIO; + } =20 fat_entry =3D (__le32 *)&(bh->b_data[off]); *fat_entry =3D cpu_to_le32(content); - exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); - exfat_mirror_bh(sb, bh); - brelse(bh); + if (!cache) + exfat_end_bh(sb, bh); return 0; } =20 +int exfat_ent_set(struct super_block *sb, unsigned int loc, + unsigned int content) +{ + return __exfat_ent_set(sb, loc, content, NULL); +} + /* * Caller must release the buffer_head if no error return. */ @@ -170,6 +192,7 @@ int exfat_blk_readahead(struct super_block *sb, sector_= t sec, int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, unsigned int len) { + struct buffer_head *bh =3D NULL; sector_t sec, end, ra; blkcnt_t ra_cnt =3D 0; =20 @@ -183,14 +206,16 @@ int exfat_chain_cont_cluster(struct super_block *sb, = unsigned int chain, sec =3D FAT_ENT_OFFSET_SECTOR(sb, chain); exfat_blk_readahead(sb, sec, &ra, &ra_cnt, end); =20 - if (exfat_ent_set(sb, chain, chain + 1)) + if (__exfat_ent_set(sb, chain, chain + 1, &bh)) return -EIO; chain++; len--; } =20 - if (exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER)) + if (__exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER, &bh)) return -EIO; + + exfat_end_bh(sb, bh); return 0; } =20 --=20 2.43.0