exfat: move exfat_entry_set_cache from heap to stack

The size of struct exfat_entry_set_cache is only 56 bytes on
64-bit system, and allocating from stack is more efficient than
allocating from heap.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
This commit is contained in:
Yuezhang Mo 2022-11-26 12:25:14 +09:00 committed by Namjae Jeon
parent 5d4023f071
commit 7771b09c4d
4 changed files with 29 additions and 35 deletions

35
dir.c
View File

@ -34,10 +34,9 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
struct exfat_chain *p_dir, int entry, unsigned short *uniname)
{
int i;
struct exfat_entry_set_cache *es;
struct exfat_entry_set_cache es;
es = exfat_get_dentry_set(sb, p_dir, entry, ES_ALL_ENTRIES);
if (!es)
if (exfat_get_dentry_set(&es, sb, p_dir, entry, ES_ALL_ENTRIES))
return;
/*
@ -46,8 +45,8 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
* Third entry : first file-name entry
* So, the index of first file-name dentry should start from 2.
*/
for (i = 2; i < es->num_entries; i++) {
struct exfat_dentry *ep = exfat_get_dentry_cached(es, i);
for (i = 2; i < es.num_entries; i++) {
struct exfat_dentry *ep = exfat_get_dentry_cached(&es, i);
/* end of name entry */
if (exfat_get_entry_type(ep) != TYPE_EXTEND)
@ -57,7 +56,7 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
uniname += EXFAT_FILE_NAME_LEN;
}
exfat_free_dentry_set(es, false);
exfat_free_dentry_set(&es, false);
}
/* read a directory entry from the opened directory */
@ -630,7 +629,6 @@ int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
if (IS_DYNAMIC_ES(es))
kfree(es->bh);
kfree(es);
return err;
}
@ -827,14 +825,14 @@ struct exfat_dentry *exfat_get_dentry_cached(
* pointer of entry set on success,
* NULL on failure.
*/
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
struct exfat_chain *p_dir, int entry, unsigned int type)
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
struct super_block *sb, struct exfat_chain *p_dir, int entry,
unsigned int type)
{
int ret, i, num_bh;
unsigned int off, byte_offset, clu = 0;
sector_t sec;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_entry_set_cache *es;
struct exfat_dentry *ep;
int num_entries;
enum exfat_validate_dentry_mode mode = ES_MODE_STARTED;
@ -842,17 +840,15 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
if (p_dir->dir == DIR_DELETED) {
exfat_err(sb, "access to deleted dentry");
return NULL;
return -EIO;
}
byte_offset = EXFAT_DEN_TO_B(entry);
ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu);
if (ret)
return NULL;
return ret;
es = kzalloc(sizeof(*es), GFP_KERNEL);
if (!es)
return NULL;
memset(es, 0, sizeof(*es));
es->sb = sb;
es->modified = false;
@ -870,7 +866,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
bh = sb_bread(sb, sec);
if (!bh)
goto free_es;
return -EIO;
es->bh[es->num_bh++] = bh;
ep = exfat_get_dentry_cached(es, 0);
@ -886,8 +882,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL);
if (!es->bh) {
brelse(bh);
kfree(es);
return NULL;
return -ENOMEM;
}
es->bh[0] = bh;
}
@ -916,11 +911,11 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
goto free_es;
}
return es;
return 0;
free_es:
exfat_free_dentry_set(es, false);
return NULL;
return -EIO;
}
static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp)

View File

@ -526,8 +526,9 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
struct exfat_chain *p_dir, int entry, struct buffer_head **bh);
struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
int num);
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
struct exfat_chain *p_dir, int entry, unsigned int type);
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
struct super_block *sb, struct exfat_chain *p_dir, int entry,
unsigned int type);
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);

13
inode.c
View File

@ -23,7 +23,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
{
unsigned long long on_disk_size;
struct exfat_dentry *ep, *ep2;
struct exfat_entry_set_cache *es = NULL;
struct exfat_entry_set_cache es;
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *ei = EXFAT_I(inode);
@ -44,11 +44,10 @@ int __exfat_write_inode(struct inode *inode, int sync)
exfat_set_volume_dirty(sb);
/* get the directory entry of given file or directory */
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES);
if (!es)
if (exfat_get_dentry_set(&es, sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES))
return -EIO;
ep = exfat_get_dentry_cached(es, 0);
ep2 = exfat_get_dentry_cached(es, 1);
ep = exfat_get_dentry_cached(&es, 0);
ep2 = exfat_get_dentry_cached(&es, 1);
ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode));
@ -85,8 +84,8 @@ int __exfat_write_inode(struct inode *inode, int sync)
ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER;
}
exfat_update_dir_chksum_with_entry_set(es);
return exfat_free_dentry_set(es, sync);
exfat_update_dir_chksum_with_entry_set(&es);
return exfat_free_dentry_set(&es, sync);
}
int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)

11
namei.c
View File

@ -654,7 +654,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *ei = EXFAT_I(dir);
struct exfat_dentry *ep, *ep2;
struct exfat_entry_set_cache *es;
struct exfat_entry_set_cache es;
/* for optimized dir & entry to prevent long traverse of cluster chain */
struct exfat_hint hint_opt;
@ -702,11 +702,10 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
if (cdir.flags & ALLOC_NO_FAT_CHAIN)
cdir.size -= dentry / sbi->dentries_per_clu;
dentry = hint_opt.eidx;
es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES);
if (!es)
if (exfat_get_dentry_set(&es, sb, &cdir, dentry, ES_2_ENTRIES))
return -EIO;
ep = exfat_get_dentry_cached(es, 0);
ep2 = exfat_get_dentry_cached(es, 1);
ep = exfat_get_dentry_cached(&es, 0);
ep2 = exfat_get_dentry_cached(&es, 1);
info->type = exfat_get_entry_type(ep);
info->attr = le16_to_cpu(ep->dentry.file.attr);
@ -735,7 +734,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
ep->dentry.file.access_time,
ep->dentry.file.access_date,
0);
exfat_free_dentry_set(es, false);
exfat_free_dentry_set(&es, false);
if (ei->start_clu == EXFAT_FREE_CLUSTER) {
exfat_fs_error(sb,