mm/shmem.c: make shmem_mapping() inline
Subsystems (2)
PATCH v2 1/1 mm/shmem.c: make shmem_mapping() inline
inline the shmem_mapping(), and use shmem_mapping() instead of 'inode->i_mapping->a_ops == &shmem_aops' in shmem_evict_inode().
v1->v2:
remove the inline for func declaration in shmem_fs.h
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
@@ -1152,7 +1152,7 @@ static void shmem_evict_inode(struct inode *inode)struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -if (inode->i_mapping->a_ops == &shmem_aops) { +if (shmem_mapping (inode->i_mapping)) {shmem_unacct_size (info->flags, inode->i_size); inode->i_size =0 ;shmem_truncate_range (inode,0 , (loff_t)-1 );
@@ -2352,7 +2352,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inodereturn inode; } -bool shmem_mapping (struct address_space *mapping) +inline bool shmem_mapping (struct address_space *mapping) {return mapping->a_ops == &shmem_aops; }
Signature · 1 line
2.29.0
Andrew Morton
maintainerQuoted 18 lines · On Sat, 14 Nov 2020 13:51:34 +0800 Hui Su <[email protected]> wrote:
inline the
shmem_mapping(), and useshmem_mapping()instead of 'inode->i_mapping->a_ops==&shmem_aops' inshmem_evict_inode()....
mm/shmem.c +1
-1@@ -1152,7 +1152,7 @@ static void shmem_evict_inode(struct inode *inode)struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -if (inode->i_mapping->a_ops == &shmem_aops) { +if (shmem_mapping (inode->i_mapping)) {shmem_unacct_size (info->flags, inode->i_size); inode->i_size =0 ;shmem_truncate_range (inode,0 , (loff_t)-1 );
mm/shmem.c static struct inode *shmem_get_inode(struct super_block *sb, const struct inode · line 2358
Quoted 8 lines
mm/shmem.c +1
-1@@ -2352,7 +2352,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inodereturn inode; } -bool shmem_mapping (struct address_space *mapping) +inline bool shmem_mapping (struct address_space *mapping) {return mapping->a_ops == &shmem_aops; }
huh. I'd have expected the inlining in shmem_evict_inode() to not work because the compiler hasn't seen the definition yet. But gcc has evidently become smarter about that.
But really, shmem_mapping() isn't worth an out-of-line call from any callsite - it would be best to make it inlined everywhere.
- make shmem_aops global
- declare shmem_aops in shmem_fs.h
- export shmem_aops to modules for drivers/dma-buf/udmabuf.c
- include linux/fs.h in shmem_fs.h for address_space_operations (we already include fs.h via swap.h, but we shouldn't depend on that)
- make shmem_mapping() a static inline in shmem_fs.h.
Quoted 9 lines · Andrew Morton
But really,
shmem_mapping()isn't worth an out-of-line call from any callsite - it would be best to make it inlined everywhere.- make
shmem_aopsglobal
- declareshmem_aopsinshmem_fs.h
- exportshmem_aopsto modules fordrivers/dma-buf/udmabuf.c
- includelinux/fs.hinshmem_fs.hforaddress_space_operations(we already includefs.hviaswap.h, but we shouldn't depend on that)
- makeshmem_mapping()a static inline inshmem_fs.h.
... or use an AS_ bit to make shmem_mapping() global inline without exposing the shmem_aops symbol. We're not short of AS_ bits, and it's probably even cheaper than a pointer comparison.
A really good changelog would explain why we need shmem_mapping() everywhere that we currently use it. It's not immediately obvious why so many places need to know.
Quoted 36 lines · Andrew Morton
Quoted 18 lines · On Sat, 14 Nov 2020 13:51:34 +0800 Hui Su <[email protected]> wrote:
inline the
shmem_mapping(), and useshmem_mapping()instead of 'inode->i_mapping->a_ops==&shmem_aops' inshmem_evict_inode()....
mm/shmem.c +1
-1@@ -1152,7 +1152,7 @@ static void shmem_evict_inode(struct inode *inode)struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -if (inode->i_mapping->a_ops == &shmem_aops) { +if (shmem_mapping (inode->i_mapping)) {shmem_unacct_size (info->flags, inode->i_size); inode->i_size =0 ;shmem_truncate_range (inode,0 , (loff_t)-1 );mm/shmem.c static struct inode *shmem_get_inode(struct super_block *sb, const struct inode · line 2358
Quoted 8 lines
mm/shmem.c +1
-1@@ -2352,7 +2352,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inodereturn inode; } -bool shmem_mapping (struct address_space *mapping) +inline bool shmem_mapping (struct address_space *mapping) {return mapping->a_ops == &shmem_aops; }huh. I'd have expected the inlining in
shmem_evict_inode()to not work because the compiler hasn't seen the definition yet. But gcc has evidently become smarter about that.But really,
shmem_mapping()isn't worth an out-of-line call from any callsite - it would be best to make it inlined everywhere.
Quoted 6 lines
- make
shmem_aopsglobal
- declareshmem_aopsinshmem_fs.h
- exportshmem_aopsto modules fordrivers/dma-buf/udmabuf.c
- includelinux/fs.hinshmem_fs.hforaddress_space_operations(we already includefs.hviaswap.h, but we shouldn't depend on that)
- makeshmem_mapping()a static inline inshmem_fs.h.
Yeah, thanks.
i will resend a PATCH V3 later.