From nobody Mon Feb 9 16:17:00 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 33AC039901C; Wed, 14 Jan 2026 12:18:32 +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=1768393115; cv=none; b=pOIezsNS4fB+dw1KksS/tY2PzVoNUbp5tZltzHg1Yh+7YwVhxqzz6YiRDffjFNQBcoe0X4UiCuBJpyv4WCqTZVOGX2gOdsYXUjFVUUGo97lYDv8BPLCVvbEUFOkC5ug/KlXOfsel0MKIzUSf6fNJN5YQVvzn2HvFgmTU3IfUKX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768393115; c=relaxed/simple; bh=vhbO/+aBxW/vPqdx9L19jZqvSjNM1xaBM6Ja0kJ8RtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YGAQIBoc8O2LIz6MLpihSbpUiBkfG94WY5h2gYgNfD7h/1Ld972Ij6dzUUfFytha9nTfE7xnoofhPya/9VL5wsTksm/CT3CbRrD9bQyfP1tKgAY4MqUeM5dCWbCKda13vkqPZ2Qse5J461qIOuSXIhB3gMhS5BjbD9wx/kSyV0U= 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=IMchwroI; 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="IMchwroI" 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=jf 9MOLjnXyA3xixjpSo2YcZ4xdjbYE/iej+10bxKbYo=; b=IMchwroIJGwvK9jRGg clI+ZEysYumWwEsB9Iaq6QuNK+htqPqZHHOs+h2LM7e3PhT6m5/qySkxS2Su8eVH fjCvTeYATMwhwMDh9Z6Y7Jv1EhJhscvruZwlLig0L1gvZQIxeXYGiz7IDcdsmk4B d+aXohOeuQzIDyjw9zYuIBkJg= Received: from czl-ubuntu-pc.. (unknown []) by gzsmtp5 (Coremail) with SMTP id QCgvCgDHK3aCiWdpxg+ELQ--.67S2; Wed, 14 Jan 2026 20:18:13 +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 , Yuezhang Mo Subject: [PATCH v3 13/13] exfat: support multi-cluster for exfat_get_cluster Date: Wed, 14 Jan 2026 20:18:08 +0800 Message-ID: <20260114121808.616139-1-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260114121250.615064-1-chizhiling@163.com> References: <20260114121250.615064-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: QCgvCgDHK3aCiWdpxg+ELQ--.67S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw1fJw4kAF4UuFWkCF1rJFb_yoWrtF1Dpr W7KayrtrZxXa9ruw4xtr4kZFyS93Z7GFW7J347Jr98Crn0yr4F9rnFy3s0yF48Gw4kua1j vr1rKw1UurnrGaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UXNV9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+AW3VWlniYWDqQAA33 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling This patch introduces a count parameter to exfat_get_cluster, which serves as an input parameter for the caller to specify the desired number of clusters, and as an output parameter to store the length of consecutive clusters. This patch can improve read performance by reducing the number of get_block calls in sequential read scenarios. speacially in small cluster size. According to my test data, the performance improvement is approximately 10% when read FAT_CHAIN file with 512 bytes of cluster size. 454 MB/s -> 511 MB/s Suggested-by: Yuezhang Mo Signed-off-by: Chi Zhiling --- fs/exfat/cache.c | 56 +++++++++++++++++++++++++++++++++++++++++---- fs/exfat/exfat_fs.h | 2 +- fs/exfat/inode.c | 3 +-- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c index 5cdeac014a3d..7c8b4182f5de 100644 --- a/fs/exfat/cache.c +++ b/fs/exfat/cache.c @@ -259,13 +259,15 @@ static inline void cache_init(struct exfat_cache_id *= cid, } =20 int exfat_get_cluster(struct inode *inode, unsigned int cluster, - unsigned int *dclus, unsigned int *last_dclus) + unsigned int *dclus, unsigned int *count, + unsigned int *last_dclus) { struct super_block *sb =3D inode->i_sb; struct exfat_inode_info *ei =3D EXFAT_I(inode); struct buffer_head *bh =3D NULL; struct exfat_cache_id cid; unsigned int content, fclus; + unsigned int end =3D cluster + *count - 1; =20 if (ei->start_clu =3D=3D EXFAT_FREE_CLUSTER) { exfat_fs_error(sb, @@ -279,17 +281,33 @@ int exfat_get_cluster(struct inode *inode, unsigned i= nt cluster, *last_dclus =3D *dclus; =20 /* - * Don`t use exfat_cache if zero offset or non-cluster allocation + * This case should not exist, as exfat_map_cluster function doesn't + * call this routine when start_clu =3D=3D EXFAT_EOF_CLUSTER. + * This case is retained here for routine completeness. */ - if (cluster =3D=3D 0 || *dclus =3D=3D EXFAT_EOF_CLUSTER) + if (*dclus =3D=3D EXFAT_EOF_CLUSTER) { + *count =3D 0; + return 0; + } + + /* If only the first cluster is needed, return now. */ + if (fclus =3D=3D cluster && *count =3D=3D 1) return 0; =20 cache_init(&cid, fclus, *dclus); - exfat_cache_lookup(inode, &cid, cluster, cluster, &fclus, dclus); + /* + * Update the 'end' to exclude the next cache range, as clusters in + * different cache are typically not contiguous. + */ + end =3D exfat_cache_lookup(inode, &cid, cluster, end, &fclus, dclus); =20 - if (fclus =3D=3D cluster) + /* Return if the cache covers the entire range. */ + if (cid.fcluster + cid.nr_contig >=3D end) { + *count =3D end - cluster + 1; return 0; + } =20 + /* Find the first cluster we need. */ while (fclus < cluster) { if (exfat_ent_get(sb, *dclus, &content, &bh)) return -EIO; @@ -305,6 +323,34 @@ int exfat_get_cluster(struct inode *inode, unsigned in= t cluster, cache_init(&cid, fclus, *dclus); } =20 + /* + * Now the cid cache contains the first cluster requested, collect + * the remaining clusters of this contiguous extent. + */ + if (*dclus !=3D EXFAT_EOF_CLUSTER) { + unsigned int clu =3D *dclus; + + while (fclus < end) { + if (exfat_ent_get(sb, clu, &content, &bh)) + return -EIO; + if (++clu !=3D content) + break; + fclus++; + } + cid.nr_contig =3D fclus - cid.fcluster; + *count =3D fclus - cluster + 1; + + /* + * Cache this discontiguous cluster, we'll definitely need + * it later + */ + if (fclus < end && content !=3D EXFAT_EOF_CLUSTER) { + exfat_cache_add(inode, &cid); + cache_init(&cid, fclus + 1, content); + } + } else { + *count =3D 0; + } brelse(bh); exfat_cache_add(inode, &cid); return 0; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index e58d8eed5495..2dbed5f8ec26 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -486,7 +486,7 @@ int exfat_cache_init(void); void exfat_cache_shutdown(void); void exfat_cache_inval_inode(struct inode *inode); int exfat_get_cluster(struct inode *inode, unsigned int cluster, - unsigned int *dclus, unsigned int *last_dclus); + unsigned int *dclus, unsigned int *count, unsigned int *last_dclus); =20 /* dir.c */ extern const struct inode_operations exfat_dir_inode_operations; diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 410f9c98b8dc..86bce7ea2725 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -160,10 +160,9 @@ static int exfat_map_cluster(struct inode *inode, unsi= gned int clu_offset, } } else { int err =3D exfat_get_cluster(inode, clu_offset, - clu, &last_clu); + clu, count, &last_clu); if (err) return -EIO; - *count =3D (*clu =3D=3D EXFAT_EOF_CLUSTER) ? 0 : 1; } =20 if (*clu =3D=3D EXFAT_EOF_CLUSTER) { --=20 2.43.0