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

mm/shmem.c: make shmem_mapping() inline

shmem_mapping() isn't worth an out-of-line call from any callsite.

So make it inline by
- make shmem_aops global
- export shmem_aops
- inline the shmem_mapping()

and replace the direct call 'shmem_aops' with shmem_mapping()
in shmem.c.

Link: https://lkml.kernel.org/r/20201115165207.GA265355@rlk
Signed-off-by: Hui Su <sh_def@163.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Hui Su and committed by
Linus Torvalds
30e6a51d 46268094

+11 -11
+5 -1
include/linux/shmem_fs.h
··· 67 67 unsigned long len, unsigned long pgoff, unsigned long flags); 68 68 extern int shmem_lock(struct file *file, int lock, struct user_struct *user); 69 69 #ifdef CONFIG_SHMEM 70 - extern bool shmem_mapping(struct address_space *mapping); 70 + extern const struct address_space_operations shmem_aops; 71 + static inline bool shmem_mapping(struct address_space *mapping) 72 + { 73 + return mapping->a_ops == &shmem_aops; 74 + } 71 75 #else 72 76 static inline bool shmem_mapping(struct address_space *mapping) 73 77 {
+6 -10
mm/shmem.c
··· 246 246 } 247 247 248 248 static const struct super_operations shmem_ops; 249 - static const struct address_space_operations shmem_aops; 249 + const struct address_space_operations shmem_aops; 250 250 static const struct file_operations shmem_file_operations; 251 251 static const struct inode_operations shmem_inode_operations; 252 252 static const struct inode_operations shmem_dir_inode_operations; ··· 1152 1152 struct shmem_inode_info *info = SHMEM_I(inode); 1153 1153 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); 1154 1154 1155 - if (inode->i_mapping->a_ops == &shmem_aops) { 1155 + if (shmem_mapping(inode->i_mapping)) { 1156 1156 shmem_unacct_size(info->flags, inode->i_size); 1157 1157 inode->i_size = 0; 1158 1158 shmem_truncate_range(inode, 0, (loff_t)-1); ··· 1858 1858 } 1859 1859 1860 1860 /* shmem_symlink() */ 1861 - if (mapping->a_ops != &shmem_aops) 1861 + if (!shmem_mapping(mapping)) 1862 1862 goto alloc_nohuge; 1863 1863 if (shmem_huge == SHMEM_HUGE_DENY || sgp_huge == SGP_NOHUGE) 1864 1864 goto alloc_nohuge; ··· 2350 2350 } else 2351 2351 shmem_free_inode(sb); 2352 2352 return inode; 2353 - } 2354 - 2355 - bool shmem_mapping(struct address_space *mapping) 2356 - { 2357 - return mapping->a_ops == &shmem_aops; 2358 2353 } 2359 2354 2360 2355 static int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, ··· 3860 3865 kmem_cache_destroy(shmem_inode_cachep); 3861 3866 } 3862 3867 3863 - static const struct address_space_operations shmem_aops = { 3868 + const struct address_space_operations shmem_aops = { 3864 3869 .writepage = shmem_writepage, 3865 3870 .set_page_dirty = __set_page_dirty_no_writeback, 3866 3871 #ifdef CONFIG_TMPFS ··· 3872 3877 #endif 3873 3878 .error_remove_page = generic_error_remove_page, 3874 3879 }; 3880 + EXPORT_SYMBOL(shmem_aops); 3875 3881 3876 3882 static const struct file_operations shmem_file_operations = { 3877 3883 .mmap = shmem_mmap, ··· 4308 4312 struct page *page; 4309 4313 int error; 4310 4314 4311 - BUG_ON(mapping->a_ops != &shmem_aops); 4315 + BUG_ON(!shmem_mapping(mapping)); 4312 4316 error = shmem_getpage_gfp(inode, index, &page, SGP_CACHE, 4313 4317 gfp, NULL, NULL, NULL); 4314 4318 if (error)