From: Yang Wen <anmuxixixi@gmail.com>
To: linkinjeon@kernel.org, sj1557.seo@samsung.com
Cc: yuezhang.mo@sony.com, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, Yang Wen <anmuxixixi@gmail.com>
Subject: [PATCH 2/2] preserve the next empty-entry hint after allocation
Date: Wed, 10 Jun 2026 21:55:11 +0800 [thread overview]
Message-ID: <20260610135511.203041-1-anmuxixixi@gmail.com> (raw)
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
next reply other threads:[~2026-06-10 13:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 13:55 Yang Wen [this message]
2026-06-12 13:39 ` Namjae Jeon
2026-06-13 13:14 ` Yang Wen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260610135511.203041-1-anmuxixixi@gmail.com \
--to=anmuxixixi@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=yuezhang.mo@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®