* Re: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
@ 2025-12-30 9:06 Yuezhang.Mo
2025-12-31 2:35 ` Chi Zhiling
0 siblings, 1 reply; 7+ messages in thread
From: Yuezhang.Mo @ 2025-12-30 9:06 UTC (permalink / raw)
To: chizhiling
Cc: brauner, chizhiling, jack, linkinjeon, linux-fsdevel,
linux-kernel, sj1557.seo, viro, willy
> @@ -243,6 +244,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int cluster,
> struct buffer_head *bh = NULL;
> struct exfat_cache_id cid;
> unsigned int content, fclus;
> + unsigned int end = (*count <= 1) ? cluster : cluster + *count - 1;
In exfat_get_block, count is set as follows:
count = EXFAT_B_TO_CLU_ROUND_UP(bh_result->b_size, sbi);
So '*count' is always greater than or equal to 1, the above condition seems unnecessary.
> --- a/fs/exfat/inode.c
> +++ b/fs/exfat/inode.c
> @@ -134,6 +134,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
> struct exfat_inode_info *ei = EXFAT_I(inode);
> unsigned int local_clu_offset = clu_offset;
> unsigned int num_to_be_allocated = 0, num_clusters;
> + unsigned int hint_count = max(*count, 1);
Same as above, hint_count seems unnecessary.
> + /*
> + * Return on cache hit to keep the code simple.
> + */
> + if (fclus == cluster) {
> + *count = cid.fcluster + cid.nr_contig - fclus + 1;
> return 0;
If 'cid.fcluster + cid.nr_contig - fclus + 1 < *count', how about continuing to collect clusters?
The following clusters may be continuous.
> + while (fclus < end) {
> + if (exfat_ent_get(sb, clu, &content, &bh))
> + goto err;
> + if (++clu != content) {
> + /* TODO: read ahead if content valid */
> + break;
The next cluster index has been read and will definitely be used.
How about add it to the cache?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
2025-12-30 9:06 [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster Yuezhang.Mo
@ 2025-12-31 2:35 ` Chi Zhiling
2026-01-04 7:56 ` Yuezhang.Mo
0 siblings, 1 reply; 7+ messages in thread
From: Chi Zhiling @ 2025-12-31 2:35 UTC (permalink / raw)
To: Yuezhang.Mo
Cc: brauner, chizhiling, jack, linkinjeon, linux-fsdevel,
linux-kernel, sj1557.seo, viro, willy
On 12/30/25 17:06, Yuezhang.Mo@sony.com wrote:
>> @@ -243,6 +244,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int cluster,
>> struct buffer_head *bh = NULL;
>> struct exfat_cache_id cid;
>> unsigned int content, fclus;
>> + unsigned int end = (*count <= 1) ? cluster : cluster + *count - 1;
>
> In exfat_get_block, count is set as follows:
>
> count = EXFAT_B_TO_CLU_ROUND_UP(bh_result->b_size, sbi);
>
> So '*count' is always greater than or equal to 1, the above condition seems unnecessary.
Yes, it is unnecessary.
>
>> --- a/fs/exfat/inode.c
>> +++ b/fs/exfat/inode.c
>> @@ -134,6 +134,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
>> struct exfat_inode_info *ei = EXFAT_I(inode);
>> unsigned int local_clu_offset = clu_offset;
>> unsigned int num_to_be_allocated = 0, num_clusters;
>> + unsigned int hint_count = max(*count, 1);
>
> Same as above, hint_count seems unnecessary.
>
>> + /*
>> + * Return on cache hit to keep the code simple.
>> + */
>> + if (fclus == cluster) {
>> + *count = cid.fcluster + cid.nr_contig - fclus + 1;
>> return 0;
>
> If 'cid.fcluster + cid.nr_contig - fclus + 1 < *count', how about continuing to collect clusters?
> The following clusters may be continuous.
I'm glad you noticed this detail. It is necessary to explain this and
update it in the code comments.
The main reason why I didn't continue the collection was that the
subsequent clusters might also exist in the cache. This requires us to
search the cache again to confirm this, and this action might introduce
additional performance overhead.
I think we can continue to collect, but we need to check the cache
before doing so.
>
>> + while (fclus < end) {
>> + if (exfat_ent_get(sb, clu, &content, &bh))
>> + goto err;
>> + if (++clu != content) {
>> + /* TODO: read ahead if content valid */
>> + break;
>
> The next cluster index has been read and will definitely be used.
> How about add it to the cache?
Good idea!
will add it in v2,
thanks,
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
2025-12-31 2:35 ` Chi Zhiling
@ 2026-01-04 7:56 ` Yuezhang.Mo
2026-01-05 2:58 ` Chi Zhiling
0 siblings, 1 reply; 7+ messages in thread
From: Yuezhang.Mo @ 2026-01-04 7:56 UTC (permalink / raw)
To: Chi Zhiling
Cc: brauner, chizhiling, jack, linkinjeon, linux-fsdevel,
linux-kernel, sj1557.seo, viro, willy
> On 12/30/25 17:06, Yuezhang.Mo@sony.com wrote:
>>> + /*
>>> + * Return on cache hit to keep the code simple.
>>> + */
>>> + if (fclus == cluster) {
>>> + *count = cid.fcluster + cid.nr_contig - fclus + 1;
>>> return 0;
>>
>> If 'cid.fcluster + cid.nr_contig - fclus + 1 < *count', how about continuing to collect clusters?
>> The following clusters may be continuous.
>
> I'm glad you noticed this detail. It is necessary to explain this and
> update it in the code comments.
>
> The main reason why I didn't continue the collection was that the
> subsequent clusters might also exist in the cache. This requires us to
> search the cache again to confirm this, and this action might introduce
> additional performance overhead.
>
> I think we can continue to collect, but we need to check the cache
> before doing so.
>
So we also need to check the cache in the following, right?
```
/*
* Collect the remaining clusters of this contiguous extent.
*/
if (*dclus != EXFAT_EOF_CLUSTER) {
unsigned int clu = *dclus;
/*
* Now the cid cache contains the first cluster requested,
* Advance the fclus to the last cluster of contiguous
* extent, then update the count and cid cache accordingly.
*/
while (fclus < end) {
if (exfat_ent_get(sb, clu, &content, &bh))
goto err;
if (++clu != content) {
/* TODO: read ahead if content valid */
break;
}
fclus++;
}
cid.nr_contig = fclus - cid.fcluster;
*count = fclus - cluster + 1;
```
>>>
>>> + while (fclus < end) {
>>> + if (exfat_ent_get(sb, clu, &content, &bh))
>>> + goto err;
>>> + if (++clu != content) {
>>> + /* TODO: read ahead if content valid */
>>> + break;
>>
>> The next cluster index has been read and will definitely be used.
>> How about add it to the cache?
>
> Good idea!
> will add it in v2,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
2026-01-04 7:56 ` Yuezhang.Mo
@ 2026-01-05 2:58 ` Chi Zhiling
2026-01-06 7:32 ` Yuezhang.Mo
0 siblings, 1 reply; 7+ messages in thread
From: Chi Zhiling @ 2026-01-05 2:58 UTC (permalink / raw)
To: Yuezhang.Mo
Cc: brauner, chizhiling, jack, linkinjeon, linux-fsdevel,
linux-kernel, sj1557.seo, viro, willy
On 1/4/26 15:56, Yuezhang.Mo@sony.com wrote:
>> On 12/30/25 17:06, Yuezhang.Mo@sony.com wrote:
>>>> + /*
>>>> + * Return on cache hit to keep the code simple.
>>>> + */
>>>> + if (fclus == cluster) {
>>>> + *count = cid.fcluster + cid.nr_contig - fclus + 1;
>>>> return 0;
>>>
>>> If 'cid.fcluster + cid.nr_contig - fclus + 1 < *count', how about continuing to collect clusters?
>>> The following clusters may be continuous.
>>
>> I'm glad you noticed this detail. It is necessary to explain this and
>> update it in the code comments.
>>
>> The main reason why I didn't continue the collection was that the
>> subsequent clusters might also exist in the cache. This requires us to
>> search the cache again to confirm this, and this action might introduce
>> additional performance overhead.
>>
>> I think we can continue to collect, but we need to check the cache
>> before doing so.
>>
>
> So we also need to check the cache in the following, right?
Uh, I don't think it's necessary in here, because these clusters won't
exist in the cache.
In the cache_lru, all exfat_cache start from non-continuous clusters.
This is because exfat_get_cluster adds consecutive clusters to the cache
from left to right, which means that the left side of all caches is
non-continuous.
For instance, if a file contains two extents, [0,30] and [31,60], then
exfat_cache must start at either 0 or 31, right?
When we have found a cache is [31, 45], then there won't be [41, 60] in
the cache_lru.
So when we already get some head clusters of a continuous extent, the
tail cluster will definitely not be present in the cache.
---
Here are some modifications regarding this patch (which may be reflected
in the V2 version). Do you have any thoughts or suggestions on this?
diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c
index 1ec531859944..8ff416beea3c 100644
--- a/fs/exfat/cache.c
+++ b/fs/exfat/cache.c
@@ -80,6 +80,10 @@ static inline void exfat_cache_update_lru(struct
inode *inode,
list_move(&cache->cache_list, &ei->cache_lru);
}
+/*
+ * Return fcluster of the cache which behind fclus, or
+ * EXFAT_EOF_CLUSTER if no cache in there.
+ */
static bool exfat_cache_lookup(struct inode *inode,
unsigned int fclus, struct exfat_cache_id *cid,
unsigned int *cached_fclus, unsigned int *cached_dclus)
@@ -87,6 +91,7 @@ static bool exfat_cache_lookup(struct inode *inode,
struct exfat_inode_info *ei = EXFAT_I(inode);
static struct exfat_cache nohit = { .fcluster = 0, };
struct exfat_cache *hit = &nohit, *p;
+ unsigned int next = EXFAT_EOF_CLUSTER;
unsigned int offset;
spin_lock(&ei->cache_lru_lock);
@@ -98,8 +103,9 @@ static bool exfat_cache_lookup(struct inode *inode,
offset = hit->nr_contig;
} else {
offset = fclus - hit->fcluster;
- break;
}
+ } else if (p->fcluster > fclus && p->fcluster < next) {
+ next = p->fcluster;
}
}
if (hit != &nohit) {
@@ -114,7 +120,7 @@ static bool exfat_cache_lookup(struct inode *inode,
}
spin_unlock(&ei->cache_lru_lock);
- return hit != &nohit;
+ return next;
}
static struct exfat_cache *exfat_cache_merge(struct inode *inode,
@@ -243,7 +249,7 @@ int exfat_get_cluster(struct inode *inode, unsigned
int cluster,
struct exfat_inode_info *ei = EXFAT_I(inode);
struct buffer_head *bh = NULL;
struct exfat_cache_id cid;
- unsigned int content, fclus;
+ unsigned int content, fclus, next;
unsigned int end = cluster + *count - 1;
if (ei->start_clu == EXFAT_FREE_CLUSTER) {
@@ -272,14 +278,15 @@ int exfat_get_cluster(struct inode *inode,
unsigned int cluster,
return 0;
cache_init(&cid, fclus, *dclus);
- exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
+ next = exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
- /*
- * Return on cache hit to keep the code simple.
- */
if (fclus == cluster) {
- *count = cid.fcluster + cid.nr_contig - fclus + 1;
- return 0;
+ /* The cache includes all cluster requested */
+ if (cid.fcluster + cid.nr_contig >= end)
+ return 0;
+ /* No cache hole behind this cache */
+ if (next == cid.fcluster + cid.nr_contig + 1)
+ return 0;
}
/*
Thanks,
>
> ```
> /*
> * Collect the remaining clusters of this contiguous extent.
> */
> if (*dclus != EXFAT_EOF_CLUSTER) {
> unsigned int clu = *dclus;
>
> /*
> * Now the cid cache contains the first cluster requested,
> * Advance the fclus to the last cluster of contiguous
> * extent, then update the count and cid cache accordingly.
> */
> while (fclus < end) {
> if (exfat_ent_get(sb, clu, &content, &bh))
> goto err;
> if (++clu != content) {
> /* TODO: read ahead if content valid */
> break;
> }
> fclus++;
> }
> cid.nr_contig = fclus - cid.fcluster;
> *count = fclus - cluster + 1;
> ```
>
>>>>
>>>> + while (fclus < end) {
>>>> + if (exfat_ent_get(sb, clu, &content, &bh))
>>>> + goto err;
>>>> + if (++clu != content) {
>>>> + /* TODO: read ahead if content valid */
>>>> + break;
>>>
>>> The next cluster index has been read and will definitely be used.
>>> How about add it to the cache?
>>
>> Good idea!
>> will add it in v2,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
2026-01-05 2:58 ` Chi Zhiling
@ 2026-01-06 7:32 ` Yuezhang.Mo
2026-01-06 8:45 ` Chi Zhiling
0 siblings, 1 reply; 7+ messages in thread
From: Yuezhang.Mo @ 2026-01-06 7:32 UTC (permalink / raw)
To: Chi Zhiling
Cc: brauner, chizhiling, jack, linkinjeon, linux-fsdevel,
linux-kernel, sj1557.seo, viro, willy
> On 1/4/26 15:56, Yuezhang.Mo@sony.com wrote:
>>> On 12/30/25 17:06, Yuezhang.Mo@sony.com wrote:
>>>>> + /*
>>>>> + * Return on cache hit to keep the code simple.
>>>>> + */
>>>>> + if (fclus == cluster) {
>>>>> + *count = cid.fcluster + cid.nr_contig - fclus + 1;
>>>>> return 0;
>>>>
>>>> If 'cid.fcluster + cid.nr_contig - fclus + 1 < *count', how about continuing to collect clusters?
>>>> The following clusters may be continuous.
>>>
>>> I'm glad you noticed this detail. It is necessary to explain this and
>>> update it in the code comments.
>>>
>>> The main reason why I didn't continue the collection was that the
>>> subsequent clusters might also exist in the cache. This requires us to
>>> search the cache again to confirm this, and this action might introduce
>>> additional performance overhead.
>>>
>>> I think we can continue to collect, but we need to check the cache
>>> before doing so.
>>>
>>
>> So we also need to check the cache in the following, right?
>
> Uh, I don't think it's necessary in here, because these clusters won't
> exist in the cache.
>
> In the cache_lru, all exfat_cache start from non-continuous clusters.
> This is because exfat_get_cluster adds consecutive clusters to the cache
> from left to right, which means that the left side of all caches is
> non-continuous.
>
> For instance, if a file contains two extents, [0,30] and [31,60], then
> exfat_cache must start at either 0 or 31, right?
>
> When we have found a cache is [31, 45], then there won't be [41, 60] in
> the cache_lru.
>
> So when we already get some head clusters of a continuous extent, the
> tail cluster will definitely not be present in the cache.
>
Your understanding is correct, so if the cache only includes a part of the
requested clusters, we can continue to collect subsequent clusters.
>
> ---
>
> Here are some modifications regarding this patch (which may be reflected
> in the V2 version). Do you have any thoughts or suggestions on this?
>
Although these modifications make exfat_cache_lookup check the entire
cache every time, I think the modifications are reasonable since the cache
(EXFAT_MAX_CACHE is 16) is small.
>
> diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c
> index 1ec531859944..8ff416beea3c 100644
> --- a/fs/exfat/cache.c
> +++ b/fs/exfat/cache.c
> @@ -80,6 +80,10 @@ static inline void exfat_cache_update_lru(struct
> inode *inode,
> list_move(&cache->cache_list, &ei->cache_lru);
> }
>
> +/*
> + * Return fcluster of the cache which behind fclus, or
> + * EXFAT_EOF_CLUSTER if no cache in there.
> + */
> static bool exfat_cache_lookup(struct inode *inode,
> unsigned int fclus, struct exfat_cache_id *cid,
> unsigned int *cached_fclus, unsigned int *cached_dclus)
> @@ -87,6 +91,7 @@ static bool exfat_cache_lookup(struct inode *inode,
> struct exfat_inode_info *ei = EXFAT_I(inode);
> static struct exfat_cache nohit = { .fcluster = 0, };
> struct exfat_cache *hit = &nohit, *p;
> + unsigned int next = EXFAT_EOF_CLUSTER;
> unsigned int offset;
>
> spin_lock(&ei->cache_lru_lock);
> @@ -98,8 +103,9 @@ static bool exfat_cache_lookup(struct inode *inode,
> offset = hit->nr_contig;
> } else {
> offset = fclus - hit->fcluster;
> - break;
> }
> + } else if (p->fcluster > fclus && p->fcluster < next) {
> + next = p->fcluster;
> }
> }
> if (hit != &nohit) {
> @@ -114,7 +120,7 @@ static bool exfat_cache_lookup(struct inode *inode,
> }
> spin_unlock(&ei->cache_lru_lock);
>
> - return hit != &nohit;
> + return next;
> }
>
> static struct exfat_cache *exfat_cache_merge(struct inode *inode,
> @@ -243,7 +249,7 @@ int exfat_get_cluster(struct inode *inode, unsigned
> int cluster,
> struct exfat_inode_info *ei = EXFAT_I(inode);
> struct buffer_head *bh = NULL;
> struct exfat_cache_id cid;
> - unsigned int content, fclus;
> + unsigned int content, fclus, next;
> unsigned int end = cluster + *count - 1;
>
> if (ei->start_clu == EXFAT_FREE_CLUSTER) {
> @@ -272,14 +278,15 @@ int exfat_get_cluster(struct inode *inode,
> unsigned int cluster,
> return 0;
>
> cache_init(&cid, fclus, *dclus);
> - exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
> + next = exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
>
> - /*
> - * Return on cache hit to keep the code simple.
> - */
> if (fclus == cluster) {
> - *count = cid.fcluster + cid.nr_contig - fclus + 1;
If the cache only includes a part of the requested clusters and subsequent
clusters are not contiguous. '*count' is needed to set like above.
> - return 0;
> + /* The cache includes all cluster requested */
> + if (cid.fcluster + cid.nr_contig >= end)
> + return 0;
> + /* No cache hole behind this cache */
> + if (next == cid.fcluster + cid.nr_contig + 1)
> + return 0;
> }
>
> /*
>
>
> Thanks,
>
>>
>> ```
>> /*
>> * Collect the remaining clusters of this contiguous extent.
>> */
>> if (*dclus != EXFAT_EOF_CLUSTER) {
>> unsigned int clu = *dclus;
>>
>> /*
>> * Now the cid cache contains the first cluster requested,
>> * Advance the fclus to the last cluster of contiguous
>> * extent, then update the count and cid cache accordingly.
>> */
>> while (fclus < end) {
>> if (exfat_ent_get(sb, clu, &content, &bh))
>> goto err;
>> if (++clu != content) {
>> /* TODO: read ahead if content valid */
>> break;
>> }
>> fclus++;
>> }
>> cid.nr_contig = fclus - cid.fcluster;
>> *count = fclus - cluster + 1;
>> ```
>>
>>>>>
>>>>> + while (fclus < end) {
>>>>> + if (exfat_ent_get(sb, clu, &content, &bh))
>>>>> + goto err;
>>>>> + if (++clu != content) {
>>>>> + /* TODO: read ahead if content valid */
>>>>> + break;
>>>>
>>>> The next cluster index has been read and will definitely be used.
>>>> How about add it to the cache?
>>>
>>> Good idea!
>>> will add it in v2,
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
2026-01-06 7:32 ` Yuezhang.Mo
@ 2026-01-06 8:45 ` Chi Zhiling
0 siblings, 0 replies; 7+ messages in thread
From: Chi Zhiling @ 2026-01-06 8:45 UTC (permalink / raw)
To: Yuezhang.Mo
Cc: brauner, chizhiling, jack, linkinjeon, linux-fsdevel,
linux-kernel, sj1557.seo, viro, willy
On 1/6/26 15:32, Yuezhang.Mo@sony.com wrote:
>> On 1/4/26 15:56, Yuezhang.Mo@sony.com wrote:
>>>> On 12/30/25 17:06, Yuezhang.Mo@sony.com wrote:
>>>>>> + /*
>>>>>> + * Return on cache hit to keep the code simple.
>>>>>> + */
>>>>>> + if (fclus == cluster) {
>>>>>> + *count = cid.fcluster + cid.nr_contig - fclus + 1;
>>>>>> return 0;
>>>>>
>>>>> If 'cid.fcluster + cid.nr_contig - fclus + 1 < *count', how about continuing to collect clusters?
>>>>> The following clusters may be continuous.
>>>>
>>>> I'm glad you noticed this detail. It is necessary to explain this and
>>>> update it in the code comments.
>>>>
>>>> The main reason why I didn't continue the collection was that the
>>>> subsequent clusters might also exist in the cache. This requires us to
>>>> search the cache again to confirm this, and this action might introduce
>>>> additional performance overhead.
>>>>
>>>> I think we can continue to collect, but we need to check the cache
>>>> before doing so.
>>>>
>>>
>>> So we also need to check the cache in the following, right?
>>
>> Uh, I don't think it's necessary in here, because these clusters won't
>> exist in the cache.
>>
>> In the cache_lru, all exfat_cache start from non-continuous clusters.
>> This is because exfat_get_cluster adds consecutive clusters to the cache
>> from left to right, which means that the left side of all caches is
>> non-continuous.
>>
>> For instance, if a file contains two extents, [0,30] and [31,60], then
>> exfat_cache must start at either 0 or 31, right?
>>
>> When we have found a cache is [31, 45], then there won't be [41, 60] in
>> the cache_lru.
>>
>> So when we already get some head clusters of a continuous extent, the
>> tail cluster will definitely not be present in the cache.
>>
>
> Your understanding is correct, so if the cache only includes a part of the
> requested clusters, we can continue to collect subsequent clusters.
>
>>
>> ---
>>
>> Here are some modifications regarding this patch (which may be reflected
>> in the V2 version). Do you have any thoughts or suggestions on this?
>>
>
> Although these modifications make exfat_cache_lookup check the entire
> cache every time, I think the modifications are reasonable since the cache
> (EXFAT_MAX_CACHE is 16) is small.
I have improved it in v2. :)
>
>>
>> diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c
>> index 1ec531859944..8ff416beea3c 100644
>> --- a/fs/exfat/cache.c
>> +++ b/fs/exfat/cache.c
>> @@ -80,6 +80,10 @@ static inline void exfat_cache_update_lru(struct
>> inode *inode,
>> list_move(&cache->cache_list, &ei->cache_lru);
>> }
>>
>> +/*
>> + * Return fcluster of the cache which behind fclus, or
>> + * EXFAT_EOF_CLUSTER if no cache in there.
>> + */
>> static bool exfat_cache_lookup(struct inode *inode,
>> unsigned int fclus, struct exfat_cache_id *cid,
>> unsigned int *cached_fclus, unsigned int *cached_dclus)
>> @@ -87,6 +91,7 @@ static bool exfat_cache_lookup(struct inode *inode,
>> struct exfat_inode_info *ei = EXFAT_I(inode);
>> static struct exfat_cache nohit = { .fcluster = 0, };
>> struct exfat_cache *hit = &nohit, *p;
>> + unsigned int next = EXFAT_EOF_CLUSTER;
>> unsigned int offset;
>>
>> spin_lock(&ei->cache_lru_lock);
>> @@ -98,8 +103,9 @@ static bool exfat_cache_lookup(struct inode *inode,
>> offset = hit->nr_contig;
>> } else {
>> offset = fclus - hit->fcluster;
>> - break;
>> }
>> + } else if (p->fcluster > fclus && p->fcluster < next) {
>> + next = p->fcluster;
>> }
>> }
>> if (hit != &nohit) {
>> @@ -114,7 +120,7 @@ static bool exfat_cache_lookup(struct inode *inode,
>> }
>> spin_unlock(&ei->cache_lru_lock);
>>
>> - return hit != &nohit;
>> + return next;
>> }
>>
>> static struct exfat_cache *exfat_cache_merge(struct inode *inode,
>> @@ -243,7 +249,7 @@ int exfat_get_cluster(struct inode *inode, unsigned
>> int cluster,
>> struct exfat_inode_info *ei = EXFAT_I(inode);
>> struct buffer_head *bh = NULL;
>> struct exfat_cache_id cid;
>> - unsigned int content, fclus;
>> + unsigned int content, fclus, next;
>> unsigned int end = cluster + *count - 1;
>>
>> if (ei->start_clu == EXFAT_FREE_CLUSTER) {
>> @@ -272,14 +278,15 @@ int exfat_get_cluster(struct inode *inode,
>> unsigned int cluster,
>> return 0;
>>
>> cache_init(&cid, fclus, *dclus);
>> - exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
>> + next = exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
>>
>> - /*
>> - * Return on cache hit to keep the code simple.
>> - */
>> if (fclus == cluster) {
>> - *count = cid.fcluster + cid.nr_contig - fclus + 1;
>
> If the cache only includes a part of the requested clusters and subsequent
> clusters are not contiguous. '*count' is needed to set like above.
You are right, I will fix it in v2.
Thanks,
>
>> - return 0;
>> + /* The cache includes all cluster requested */
>> + if (cid.fcluster + cid.nr_contig >= end)
>> + return 0;
>> + /* No cache hole behind this cache */
>> + if (next == cid.fcluster + cid.nr_contig + 1)
>> + return 0;
>> }
>>
>> /*
>>
>>
>> Thanks,
>>
>>>
>>> ```
>>> /*
>>> * Collect the remaining clusters of this contiguous extent.
>>> */
>>> if (*dclus != EXFAT_EOF_CLUSTER) {
>>> unsigned int clu = *dclus;
>>>
>>> /*
>>> * Now the cid cache contains the first cluster requested,
>>> * Advance the fclus to the last cluster of contiguous
>>> * extent, then update the count and cid cache accordingly.
>>> */
>>> while (fclus < end) {
>>> if (exfat_ent_get(sb, clu, &content, &bh))
>>> goto err;
>>> if (++clu != content) {
>>> /* TODO: read ahead if content valid */
>>> break;
>>> }
>>> fclus++;
>>> }
>>> cid.nr_contig = fclus - cid.fcluster;
>>> *count = fclus - cluster + 1;
>>> ```
>>>
>>>>>>
>>>>>> + while (fclus < end) {
>>>>>> + if (exfat_ent_get(sb, clu, &content, &bh))
>>>>>> + goto err;
>>>>>> + if (++clu != content) {
>>>>>> + /* TODO: read ahead if content valid */
>>>>>> + break;
>>>>>
>>>>> The next cluster index has been read and will definitely be used.
>>>>> How about add it to the cache?
>>>>
>>>> Good idea!
>>>> will add it in v2,
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster
2025-12-26 9:44 [PATCH v1 0/9] Enable exfat_get_block to support obtaining multiple clusters Chi Zhiling
@ 2025-12-26 9:44 ` Chi Zhiling
0 siblings, 0 replies; 7+ messages in thread
From: Chi Zhiling @ 2025-12-26 9:44 UTC (permalink / raw)
To: linux-fsdevel, linux-kernel
Cc: Namjae Jeon, Sungjong Seo, Yuezhang Mo, Alexander Viro,
Christian Brauner, Jan Kara, Matthew Wilcox, Chi Zhiling
From: Chi Zhiling <chizhiling@kylinos.cn>
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
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
fs/exfat/cache.c | 51 +++++++++++++++++++++++++++++++++++++++++----
fs/exfat/exfat_fs.h | 2 +-
fs/exfat/inode.c | 5 +++--
3 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/fs/exfat/cache.c b/fs/exfat/cache.c
index 57a66c067394..80efe2e0393d 100644
--- a/fs/exfat/cache.c
+++ b/fs/exfat/cache.c
@@ -234,7 +234,8 @@ static inline void cache_init(struct exfat_cache_id *cid,
}
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 = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
@@ -243,6 +244,7 @@ int exfat_get_cluster(struct inode *inode, unsigned int cluster,
struct buffer_head *bh = NULL;
struct exfat_cache_id cid;
unsigned int content, fclus;
+ unsigned int end = (*count <= 1) ? cluster : cluster + *count - 1;
if (ei->start_clu == EXFAT_FREE_CLUSTER) {
exfat_fs_error(sb,
@@ -256,17 +258,33 @@ int exfat_get_cluster(struct inode *inode, unsigned int cluster,
*last_dclus = *dclus;
/*
- * 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 == EXFAT_EOF_CLUSTER.
+ * This case is retained here for routine completeness.
*/
- if (cluster == 0 || *dclus == EXFAT_EOF_CLUSTER)
+ if (*dclus == EXFAT_EOF_CLUSTER) {
+ *count = 0;
+ return 0;
+ }
+
+ /* If only the first cluster is needed, return now. */
+ if (fclus == cluster && *count == 1)
return 0;
cache_init(&cid, fclus, *dclus);
exfat_cache_lookup(inode, cluster, &cid, &fclus, dclus);
- if (fclus == cluster)
+ /*
+ * Return on cache hit to keep the code simple.
+ */
+ if (fclus == cluster) {
+ *count = cid.fcluster + cid.nr_contig - fclus + 1;
return 0;
+ }
+ /*
+ * Find the first cluster we need.
+ */
while (fclus < cluster) {
/* prevent the infinite loop of cluster chain */
if (fclus > limit) {
@@ -290,6 +308,31 @@ int exfat_get_cluster(struct inode *inode, unsigned int cluster,
cache_init(&cid, fclus, *dclus);
}
+ /*
+ * Collect the remaining clusters of this contiguous extent.
+ */
+ if (*dclus != EXFAT_EOF_CLUSTER) {
+ unsigned int clu = *dclus;
+
+ /*
+ * Now the cid cache contains the first cluster requested,
+ * Advance the fclus to the last cluster of contiguous
+ * extent, then update the count and cid cache accordingly.
+ */
+ while (fclus < end) {
+ if (exfat_ent_get(sb, clu, &content, &bh))
+ goto err;
+ if (++clu != content) {
+ /* TODO: read ahead if content valid */
+ break;
+ }
+ fclus++;
+ }
+ cid.nr_contig = fclus - cid.fcluster;
+ *count = fclus - cluster + 1;
+ } else {
+ *count = 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);
/* dir.c */
extern const struct inode_operations exfat_dir_inode_operations;
diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c
index 8c49ab15eafe..317bc363f7d9 100644
--- a/fs/exfat/inode.c
+++ b/fs/exfat/inode.c
@@ -134,6 +134,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
struct exfat_inode_info *ei = EXFAT_I(inode);
unsigned int local_clu_offset = clu_offset;
unsigned int num_to_be_allocated = 0, num_clusters;
+ unsigned int hint_count = max(*count, 1);
num_clusters = EXFAT_B_TO_CLU(exfat_ondisk_size(inode), sbi);
@@ -159,11 +160,11 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
*count = 0;
}
} else if (ei->type == TYPE_FILE) {
+ *count = hint_count;
int err = exfat_get_cluster(inode, clu_offset,
- clu, &last_clu);
+ clu, count, &last_clu);
if (err)
return -EIO;
- *count = (*clu == EXFAT_EOF_CLUSTER) ? 0 : 1;
} else {
unsigned int fclus = 0;
/* hint information */
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-01-06 8:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-30 9:06 [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster Yuezhang.Mo
2025-12-31 2:35 ` Chi Zhiling
2026-01-04 7:56 ` Yuezhang.Mo
2026-01-05 2:58 ` Chi Zhiling
2026-01-06 7:32 ` Yuezhang.Mo
2026-01-06 8:45 ` Chi Zhiling
-- strict thread matches above, loose matches on Subject: below --
2025-12-26 9:44 [PATCH v1 0/9] Enable exfat_get_block to support obtaining multiple clusters Chi Zhiling
2025-12-26 9:44 ` [PATCH v1 9/9] exfat: support multi-cluster for exfat_get_cluster Chi Zhiling
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®