Skip to contentSkip to conversation

preserve the next empty-entry hint after allocation

PATCH Superseded Yang Wen 2 participants 3 messages Jun 10 – Jun 13

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yang Wen

author
#0 lore raw

PATCH 2/2 preserve the next empty-entry hint after allocation

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.

---
 fs/exfat/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)
fs/exfat/namei.c +43 -2
index fe26fbf6a0f2..10c58bb7f422 100644
@@ -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;
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw

fs/exfat/namei.c int exfat_find_empty_entry(struct inode *inode, · line 420

Quoted 2 lines
fs/exfat/namei.c +2 -0
+       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?

Quoted 11 lines
fs/exfat/namei.c +5 -1
+       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

author
#2 lore raw
Quoted 4 lines

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.