Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

f2fs: fix to calculate max length of contiguous free slots correctly

When lookuping for creating, we will try to record the level of current dentry
hash table if current dentry has enough contiguous slots for storing name of new
file which will be created later, this can save our lookup time when add a link
into parent dir.

But currently in find_target_dentry, our current length of contiguous free slots
is not calculated correctly. This make us leaving some holes in dentry block
occasionally, it wastes our space of dentry block.

Let's refactor the lookup flow for max slots as following to fix this issue:
a) increase max_len if current slot is free;
b) update max_slots with max_len if max_len is larger than max_slots;
c) reset max_len to zero if current slot is not free.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Chao Yu and committed by
Jaegeuk Kim
bda19076 57ed1e95

+4 -7
+4 -7
fs/f2fs/dir.c
··· 127 127 *max_slots = 0; 128 128 while (bit_pos < d->max) { 129 129 if (!test_bit_le(bit_pos, d->bitmap)) { 130 - if (bit_pos == 0) 131 - max_len = 1; 132 - else if (!test_bit_le(bit_pos - 1, d->bitmap)) 133 - max_len++; 134 130 bit_pos++; 131 + max_len++; 135 132 continue; 136 133 } 134 + 137 135 de = &d->dentry[bit_pos]; 138 136 if (early_match_name(name->len, namehash, de) && 139 137 !memcmp(d->filename[bit_pos], name->name, name->len)) 140 138 goto found; 141 139 142 - if (max_slots && max_len > *max_slots) { 140 + if (max_slots && max_len > *max_slots) 143 141 *max_slots = max_len; 144 - max_len = 0; 145 - } 142 + max_len = 0; 146 143 147 144 /* remain bug on condition */ 148 145 if (unlikely(!de->name_len))