Commit 20914ff6 authored by Yuezhang Mo's avatar Yuezhang Mo Committed by Namjae Jeon

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: default avatarYuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: default avatarAndy Wu <Andy.Wu@sony.com>
Reviewed-by: default avatarAoyama Wataru <wataru.aoyama@sony.com>
Reviewed-by: default avatarSungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
parent a3ff29a9
...@@ -33,10 +33,9 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb, ...@@ -33,10 +33,9 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
struct exfat_chain *p_dir, int entry, unsigned short *uniname) struct exfat_chain *p_dir, int entry, unsigned short *uniname)
{ {
int i; 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 (exfat_get_dentry_set(&es, sb, p_dir, entry, ES_ALL_ENTRIES))
if (!es)
return; return;
/* /*
...@@ -45,8 +44,8 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb, ...@@ -45,8 +44,8 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
* Third entry : first file-name entry * Third entry : first file-name entry
* So, the index of first file-name dentry should start from 2. * So, the index of first file-name dentry should start from 2.
*/ */
for (i = 2; i < es->num_entries; i++) { for (i = 2; i < es.num_entries; i++) {
struct exfat_dentry *ep = exfat_get_dentry_cached(es, i); struct exfat_dentry *ep = exfat_get_dentry_cached(&es, i);
/* end of name entry */ /* end of name entry */
if (exfat_get_entry_type(ep) != TYPE_EXTEND) if (exfat_get_entry_type(ep) != TYPE_EXTEND)
...@@ -56,7 +55,7 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb, ...@@ -56,7 +55,7 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
uniname += EXFAT_FILE_NAME_LEN; 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 */ /* read a directory entry from the opened directory */
...@@ -619,7 +618,6 @@ int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync) ...@@ -619,7 +618,6 @@ int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
if (IS_DYNAMIC_ES(es)) if (IS_DYNAMIC_ES(es))
kfree(es->bh); kfree(es->bh);
kfree(es);
return err; return err;
} }
...@@ -816,14 +814,14 @@ struct exfat_dentry *exfat_get_dentry_cached( ...@@ -816,14 +814,14 @@ struct exfat_dentry *exfat_get_dentry_cached(
* pointer of entry set on success, * pointer of entry set on success,
* NULL on failure. * NULL on failure.
*/ */
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
struct exfat_chain *p_dir, int entry, unsigned int type) struct super_block *sb, struct exfat_chain *p_dir, int entry,
unsigned int type)
{ {
int ret, i, num_bh; int ret, i, num_bh;
unsigned int off, byte_offset, clu = 0; unsigned int off, byte_offset, clu = 0;
sector_t sec; sector_t sec;
struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_entry_set_cache *es;
struct exfat_dentry *ep; struct exfat_dentry *ep;
int num_entries; int num_entries;
enum exfat_validate_dentry_mode mode = ES_MODE_STARTED; enum exfat_validate_dentry_mode mode = ES_MODE_STARTED;
...@@ -831,17 +829,15 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, ...@@ -831,17 +829,15 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
if (p_dir->dir == DIR_DELETED) { if (p_dir->dir == DIR_DELETED) {
exfat_err(sb, "access to deleted dentry"); exfat_err(sb, "access to deleted dentry");
return NULL; return -EIO;
} }
byte_offset = EXFAT_DEN_TO_B(entry); byte_offset = EXFAT_DEN_TO_B(entry);
ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu); ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu);
if (ret) if (ret)
return NULL; return ret;
es = kzalloc(sizeof(*es), GFP_KERNEL); memset(es, 0, sizeof(*es));
if (!es)
return NULL;
es->sb = sb; es->sb = sb;
es->modified = false; es->modified = false;
...@@ -859,7 +855,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, ...@@ -859,7 +855,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
bh = sb_bread(sb, sec); bh = sb_bread(sb, sec);
if (!bh) if (!bh)
goto free_es; return -EIO;
es->bh[es->num_bh++] = bh; es->bh[es->num_bh++] = bh;
ep = exfat_get_dentry_cached(es, 0); ep = exfat_get_dentry_cached(es, 0);
...@@ -875,8 +871,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, ...@@ -875,8 +871,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); es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL);
if (!es->bh) { if (!es->bh) {
brelse(bh); brelse(bh);
kfree(es); return -ENOMEM;
return NULL;
} }
es->bh[0] = bh; es->bh[0] = bh;
} }
...@@ -905,11 +900,11 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, ...@@ -905,11 +900,11 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
goto free_es; goto free_es;
} }
return es; return 0;
free_es: free_es:
exfat_free_dentry_set(es, false); exfat_free_dentry_set(es, false);
return NULL; return -EIO;
} }
static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp) static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp)
......
...@@ -490,8 +490,9 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb, ...@@ -490,8 +490,9 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
struct exfat_chain *p_dir, int entry, struct buffer_head **bh); struct exfat_chain *p_dir, int entry, struct buffer_head **bh);
struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es, struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
int num); int num);
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
struct exfat_chain *p_dir, int entry, unsigned int type); 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_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); int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
......
...@@ -21,7 +21,7 @@ int __exfat_write_inode(struct inode *inode, int sync) ...@@ -21,7 +21,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
{ {
unsigned long long on_disk_size; unsigned long long on_disk_size;
struct exfat_dentry *ep, *ep2; 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 super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *ei = EXFAT_I(inode); struct exfat_inode_info *ei = EXFAT_I(inode);
...@@ -42,11 +42,10 @@ int __exfat_write_inode(struct inode *inode, int sync) ...@@ -42,11 +42,10 @@ int __exfat_write_inode(struct inode *inode, int sync)
exfat_set_volume_dirty(sb); exfat_set_volume_dirty(sb);
/* get the directory entry of given file or directory */ /* get the directory entry of given file or directory */
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES); if (exfat_get_dentry_set(&es, sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES))
if (!es)
return -EIO; return -EIO;
ep = exfat_get_dentry_cached(es, 0); ep = exfat_get_dentry_cached(&es, 0);
ep2 = exfat_get_dentry_cached(es, 1); ep2 = exfat_get_dentry_cached(&es, 1);
ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode)); ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode));
...@@ -83,8 +82,8 @@ int __exfat_write_inode(struct inode *inode, int sync) ...@@ -83,8 +82,8 @@ int __exfat_write_inode(struct inode *inode, int sync)
ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER; ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER;
} }
exfat_update_dir_chksum_with_entry_set(es); exfat_update_dir_chksum_with_entry_set(&es);
return exfat_free_dentry_set(es, sync); return exfat_free_dentry_set(&es, sync);
} }
int exfat_write_inode(struct inode *inode, struct writeback_control *wbc) int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
......
...@@ -604,7 +604,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname, ...@@ -604,7 +604,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *ei = EXFAT_I(dir); struct exfat_inode_info *ei = EXFAT_I(dir);
struct exfat_dentry *ep, *ep2; 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 */ /* for optimized dir & entry to prevent long traverse of cluster chain */
struct exfat_hint hint_opt; struct exfat_hint hint_opt;
...@@ -644,11 +644,10 @@ static int exfat_find(struct inode *dir, struct qstr *qname, ...@@ -644,11 +644,10 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
if (cdir.flags & ALLOC_NO_FAT_CHAIN) if (cdir.flags & ALLOC_NO_FAT_CHAIN)
cdir.size -= dentry / sbi->dentries_per_clu; cdir.size -= dentry / sbi->dentries_per_clu;
dentry = hint_opt.eidx; dentry = hint_opt.eidx;
es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES); if (exfat_get_dentry_set(&es, sb, &cdir, dentry, ES_2_ENTRIES))
if (!es)
return -EIO; return -EIO;
ep = exfat_get_dentry_cached(es, 0); ep = exfat_get_dentry_cached(&es, 0);
ep2 = exfat_get_dentry_cached(es, 1); ep2 = exfat_get_dentry_cached(&es, 1);
info->type = exfat_get_entry_type(ep); info->type = exfat_get_entry_type(ep);
info->attr = le16_to_cpu(ep->dentry.file.attr); info->attr = le16_to_cpu(ep->dentry.file.attr);
...@@ -677,7 +676,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname, ...@@ -677,7 +676,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
ep->dentry.file.access_time, ep->dentry.file.access_time,
ep->dentry.file.access_date, ep->dentry.file.access_date,
0); 0);
exfat_free_dentry_set(es, false); exfat_free_dentry_set(&es, false);
if (ei->start_clu == EXFAT_FREE_CLUSTER) { if (ei->start_clu == EXFAT_FREE_CLUSTER) {
exfat_fs_error(sb, exfat_fs_error(sb,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment