Skip to content

Commit 20914ff

Browse files
YuezhangMonamjaejeon
authored andcommitted
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 <[email protected]> Reviewed-by: Andy Wu <[email protected]> Reviewed-by: Aoyama Wataru <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent a3ff29a commit 20914ff

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

fs/exfat/dir.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
3333
struct exfat_chain *p_dir, int entry, unsigned short *uniname)
3434
{
3535
int i;
36-
struct exfat_entry_set_cache *es;
36+
struct exfat_entry_set_cache es;
3737

38-
es = exfat_get_dentry_set(sb, p_dir, entry, ES_ALL_ENTRIES);
39-
if (!es)
38+
if (exfat_get_dentry_set(&es, sb, p_dir, entry, ES_ALL_ENTRIES))
4039
return;
4140

4241
/*
@@ -45,8 +44,8 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
4544
* Third entry : first file-name entry
4645
* So, the index of first file-name dentry should start from 2.
4746
*/
48-
for (i = 2; i < es->num_entries; i++) {
49-
struct exfat_dentry *ep = exfat_get_dentry_cached(es, i);
47+
for (i = 2; i < es.num_entries; i++) {
48+
struct exfat_dentry *ep = exfat_get_dentry_cached(&es, i);
5049

5150
/* end of name entry */
5251
if (exfat_get_entry_type(ep) != TYPE_EXTEND)
@@ -56,7 +55,7 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
5655
uniname += EXFAT_FILE_NAME_LEN;
5756
}
5857

59-
exfat_free_dentry_set(es, false);
58+
exfat_free_dentry_set(&es, false);
6059
}
6160

6261
/* 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)
619618
if (IS_DYNAMIC_ES(es))
620619
kfree(es->bh);
621620

622-
kfree(es);
623621
return err;
624622
}
625623

@@ -816,32 +814,30 @@ struct exfat_dentry *exfat_get_dentry_cached(
816814
* pointer of entry set on success,
817815
* NULL on failure.
818816
*/
819-
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
820-
struct exfat_chain *p_dir, int entry, unsigned int type)
817+
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
818+
struct super_block *sb, struct exfat_chain *p_dir, int entry,
819+
unsigned int type)
821820
{
822821
int ret, i, num_bh;
823822
unsigned int off, byte_offset, clu = 0;
824823
sector_t sec;
825824
struct exfat_sb_info *sbi = EXFAT_SB(sb);
826-
struct exfat_entry_set_cache *es;
827825
struct exfat_dentry *ep;
828826
int num_entries;
829827
enum exfat_validate_dentry_mode mode = ES_MODE_STARTED;
830828
struct buffer_head *bh;
831829

832830
if (p_dir->dir == DIR_DELETED) {
833831
exfat_err(sb, "access to deleted dentry");
834-
return NULL;
832+
return -EIO;
835833
}
836834

837835
byte_offset = EXFAT_DEN_TO_B(entry);
838836
ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu);
839837
if (ret)
840-
return NULL;
838+
return ret;
841839

842-
es = kzalloc(sizeof(*es), GFP_KERNEL);
843-
if (!es)
844-
return NULL;
840+
memset(es, 0, sizeof(*es));
845841
es->sb = sb;
846842
es->modified = false;
847843

@@ -859,7 +855,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
859855

860856
bh = sb_bread(sb, sec);
861857
if (!bh)
862-
goto free_es;
858+
return -EIO;
863859
es->bh[es->num_bh++] = bh;
864860

865861
ep = exfat_get_dentry_cached(es, 0);
@@ -875,8 +871,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
875871
es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL);
876872
if (!es->bh) {
877873
brelse(bh);
878-
kfree(es);
879-
return NULL;
874+
return -ENOMEM;
880875
}
881876
es->bh[0] = bh;
882877
}
@@ -905,11 +900,11 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
905900
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
906901
goto free_es;
907902
}
908-
return es;
903+
return 0;
909904

910905
free_es:
911906
exfat_free_dentry_set(es, false);
912-
return NULL;
907+
return -EIO;
913908
}
914909

915910
static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp)

fs/exfat/exfat_fs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,9 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
490490
struct exfat_chain *p_dir, int entry, struct buffer_head **bh);
491491
struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
492492
int num);
493-
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
494-
struct exfat_chain *p_dir, int entry, unsigned int type);
493+
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
494+
struct super_block *sb, struct exfat_chain *p_dir, int entry,
495+
unsigned int type);
495496
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
496497
int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
497498

fs/exfat/inode.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
2121
{
2222
unsigned long long on_disk_size;
2323
struct exfat_dentry *ep, *ep2;
24-
struct exfat_entry_set_cache *es = NULL;
24+
struct exfat_entry_set_cache es;
2525
struct super_block *sb = inode->i_sb;
2626
struct exfat_sb_info *sbi = EXFAT_SB(sb);
2727
struct exfat_inode_info *ei = EXFAT_I(inode);
@@ -42,11 +42,10 @@ int __exfat_write_inode(struct inode *inode, int sync)
4242
exfat_set_volume_dirty(sb);
4343

4444
/* get the directory entry of given file or directory */
45-
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES);
46-
if (!es)
45+
if (exfat_get_dentry_set(&es, sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES))
4746
return -EIO;
48-
ep = exfat_get_dentry_cached(es, 0);
49-
ep2 = exfat_get_dentry_cached(es, 1);
47+
ep = exfat_get_dentry_cached(&es, 0);
48+
ep2 = exfat_get_dentry_cached(&es, 1);
5049

5150
ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode));
5251

@@ -83,8 +82,8 @@ int __exfat_write_inode(struct inode *inode, int sync)
8382
ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER;
8483
}
8584

86-
exfat_update_dir_chksum_with_entry_set(es);
87-
return exfat_free_dentry_set(es, sync);
85+
exfat_update_dir_chksum_with_entry_set(&es);
86+
return exfat_free_dentry_set(&es, sync);
8887
}
8988

9089
int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)

fs/exfat/namei.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
604604
struct exfat_sb_info *sbi = EXFAT_SB(sb);
605605
struct exfat_inode_info *ei = EXFAT_I(dir);
606606
struct exfat_dentry *ep, *ep2;
607-
struct exfat_entry_set_cache *es;
607+
struct exfat_entry_set_cache es;
608608
/* for optimized dir & entry to prevent long traverse of cluster chain */
609609
struct exfat_hint hint_opt;
610610

@@ -644,11 +644,10 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
644644
if (cdir.flags & ALLOC_NO_FAT_CHAIN)
645645
cdir.size -= dentry / sbi->dentries_per_clu;
646646
dentry = hint_opt.eidx;
647-
es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES);
648-
if (!es)
647+
if (exfat_get_dentry_set(&es, sb, &cdir, dentry, ES_2_ENTRIES))
649648
return -EIO;
650-
ep = exfat_get_dentry_cached(es, 0);
651-
ep2 = exfat_get_dentry_cached(es, 1);
649+
ep = exfat_get_dentry_cached(&es, 0);
650+
ep2 = exfat_get_dentry_cached(&es, 1);
652651

653652
info->type = exfat_get_entry_type(ep);
654653
info->attr = le16_to_cpu(ep->dentry.file.attr);
@@ -677,7 +676,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
677676
ep->dentry.file.access_time,
678677
ep->dentry.file.access_date,
679678
0);
680-
exfat_free_dentry_set(es, false);
679+
exfat_free_dentry_set(&es, false);
681680

682681
if (ei->start_clu == EXFAT_FREE_CLUSTER) {
683682
exfat_fs_error(sb,

0 commit comments

Comments
 (0)