mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/2] preserve the next empty-entry hint after allocation
@ 2026-06-10 13:55 Yang Wen
  2026-06-12 13:39 ` Namjae Jeon
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Wen @ 2026-06-10 13:55 UTC (permalink / raw)
  To: linkinjeon, sj1557.seo; +Cc: yuezhang.mo, linux-fsdevel, linux-kernel, Yang Wen

Advance and preserve the empty-entry hint when only part of a contiguous
empty range is consumed.

This allows the next file creation to reuse the remaining range without
scanning the directory again.

Signed-off-by: Yang Wen <anmuxixixi@gmail.com>
---
 fs/exfat/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index fe26fbf6a0f2..10c58bb7f422 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -273,6 +273,34 @@ static int exfat_check_max_dentries(struct inode *inode)
 	return 0;
 }
 
+static int exfat_cache_next_empty_entry(struct super_block *sb,
+		struct exfat_inode_info *ei, struct exfat_hint_femp *hint_femp,
+		int dentry, int num_entries)
+{
+	int next, cur_clu, next_clu;
+	struct exfat_sb_info *sbi = EXFAT_SB(sb);
+	struct exfat_hint_femp next_hint;
+
+	if (hint_femp->eidx == EXFAT_HINT_NONE ||
+	    hint_femp->eidx != dentry ||
+	    hint_femp->count <= num_entries)
+		return 0;
+
+	next = dentry + num_entries;
+	next_hint = *hint_femp;
+	next_hint.eidx = next;
+	next_hint.count -= num_entries;
+
+	cur_clu = dentry / sbi->dentries_per_clu;
+	next_clu = next / sbi->dentries_per_clu;
+	if (next_clu > cur_clu &&
+	    exfat_chain_advance(sb, &next_hint.cur, next_clu - cur_clu))
+		return -EIO;
+
+	ei->hint_femp = next_hint;
+	return 0;
+}
+
 /*
  * Find an empty directory entry set.
  *
@@ -302,6 +330,7 @@ int exfat_find_empty_entry(struct inode *inode,
 	struct exfat_sb_info *sbi = EXFAT_SB(sb);
 	struct exfat_inode_info *ei = EXFAT_I(inode);
 	struct exfat_hint_femp hint_femp;
+	struct exfat_hint_femp prev_hint_femp;
 
 	hint_femp.eidx = EXFAT_HINT_NONE;
 
@@ -314,8 +343,13 @@ int exfat_find_empty_entry(struct inode *inode,
 			exfat_bytes_to_cluster(sbi, i_size_read(inode)),
 			ei->flags);
 
-	while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir,
-					num_entries, es)) < 0) {
+	for (;;) {
+		prev_hint_femp = hint_femp;
+		dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir,
+				num_entries, es);
+		if (dentry >= 0)
+			break;
+
 		if (dentry != -ENOSPC)
 			return dentry;
 
@@ -382,6 +416,13 @@ int exfat_find_empty_entry(struct inode *inode,
 		inode->i_blocks += sbi->cluster_size >> 9;
 	}
 
+	ret = exfat_cache_next_empty_entry(sb, ei, &prev_hint_femp, dentry,
+			num_entries);
+	if (ret) {
+		exfat_put_dentry_set(es, false);
+		return ret;
+	}
+
 	p_dir->dir = exfat_sector_to_cluster(sbi, es->bh[0]->b_blocknr);
 	p_dir->size -= dentry / sbi->dentries_per_clu;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] preserve the next empty-entry hint after allocation
  2026-06-10 13:55 [PATCH 2/2] preserve the next empty-entry hint after allocation Yang Wen
@ 2026-06-12 13:39 ` Namjae Jeon
  2026-06-13 13:14   ` Yang Wen
  0 siblings, 1 reply; 3+ messages in thread
From: Namjae Jeon @ 2026-06-12 13:39 UTC (permalink / raw)
  To: Yang Wen; +Cc: sj1557.seo, yuezhang.mo, linux-fsdevel, linux-kernel

> +       ret = exfat_cache_next_empty_entry(sb, ei, &prev_hint_femp, dentry,
> +                       num_entries);
The empty-entry hint is only an optimization, so failure to advance
the hint should not make file creation fail with -EIO.
Could you make exfat_cache_next_empty_entry() return void and simply
skip caching the hint if exfat_chain_advance() fails?

> +       if (ret) {
> +               exfat_put_dentry_set(es, false);
> +               return ret;
> +       }
> +
>         p_dir->dir = exfat_sector_to_cluster(sbi, es->bh[0]->b_blocknr);
>         p_dir->size -= dentry / sbi->dentries_per_clu;
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] preserve the next empty-entry hint after allocation
  2026-06-12 13:39 ` Namjae Jeon
@ 2026-06-13 13:14   ` Yang Wen
  0 siblings, 0 replies; 3+ messages in thread
From: Yang Wen @ 2026-06-13 13:14 UTC (permalink / raw)
  To: linkinjeon
  Cc: anmuxixixi, linux-fsdevel, linux-kernel, sj1557.seo, yuezhang.mo

> The empty-entry hint is only an optimization, so failure to advance
> the hint should not make file creation fail with -EIO.
> Could you make exfat_cache_next_empty_entry() return void and simply
> skip caching the hint if exfat_chain_advance() fails?
Yes, that makes sense. I will update it in v2.

Thanks for the review.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-13 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-10 13:55 [PATCH 2/2] preserve the next empty-entry hint after allocation Yang Wen
2026-06-12 13:39 ` Namjae Jeon
2026-06-13 13:14   ` Yang Wen

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®