linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm/shmem.c: make shmem_mapping() inline
@ 2020-11-14  5:51 Hui Su
  2020-11-14 18:50 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Hui Su @ 2020-11-14  5:51 UTC (permalink / raw)
  To: hughd, akpm, linux-mm, linux-kernel, pankaj.gupta.linux, lkp; +Cc: sh_def

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

Reviewed-by: Pankaj Gupta <pankaj.gupta@cloud.ionos.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Hui Su <sh_def@163.com>
---
 mm/shmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 537c137698f8..7395d8e8226a 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -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 inode
 	return inode;
 }
 
-bool shmem_mapping(struct address_space *mapping)
+inline bool shmem_mapping(struct address_space *mapping)
 {
 	return mapping->a_ops == &shmem_aops;
 }
-- 
2.29.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mm/shmem.c: make shmem_mapping() inline
  2020-11-14  5:51 [PATCH v2] mm/shmem.c: make shmem_mapping() inline Hui Su
@ 2020-11-14 18:50 ` Andrew Morton
  2020-11-14 19:11   ` Matthew Wilcox
  2020-11-15 16:19   ` Hui Su
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2020-11-14 18:50 UTC (permalink / raw)
  To: Hui Su; +Cc: hughd, linux-mm, linux-kernel, pankaj.gupta.linux, lkp

On Sat, 14 Nov 2020 13:51:34 +0800 Hui Su <sh_def@163.com> wrote:

> inline the shmem_mapping(), and use shmem_mapping()
> instead of 'inode->i_mapping->a_ops == &shmem_aops'
> in shmem_evict_inode().
> 
> ...
>
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -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 inode
>  	return 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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mm/shmem.c: make shmem_mapping() inline
  2020-11-14 18:50 ` Andrew Morton
@ 2020-11-14 19:11   ` Matthew Wilcox
  2020-11-15 16:19   ` Hui Su
  1 sibling, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2020-11-14 19:11 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Hui Su, hughd, linux-mm, linux-kernel, pankaj.gupta.linux, lkp

On Sat, Nov 14, 2020 at 10:50:39AM -0800, Andrew Morton wrote:
> 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.

... 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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mm/shmem.c: make shmem_mapping() inline
  2020-11-14 18:50 ` Andrew Morton
  2020-11-14 19:11   ` Matthew Wilcox
@ 2020-11-15 16:19   ` Hui Su
  1 sibling, 0 replies; 4+ messages in thread
From: Hui Su @ 2020-11-15 16:19 UTC (permalink / raw)
  To: Andrew Morton; +Cc: hughd, linux-mm, linux-kernel, lkp

On Sat, Nov 14, 2020 at 10:50:39AM -0800, Andrew Morton wrote:
> On Sat, 14 Nov 2020 13:51:34 +0800 Hui Su <sh_def@163.com> wrote:
> 
> > inline the shmem_mapping(), and use shmem_mapping()
> > instead of 'inode->i_mapping->a_ops == &shmem_aops'
> > in shmem_evict_inode().
> > 
> > ...
> >
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -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 inode
> >  	return 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.

Yeah, thanks.

i will resend a PATCH V3 later.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-15 16:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-14  5:51 [PATCH v2] mm/shmem.c: make shmem_mapping() inline Hui Su
2020-11-14 18:50 ` Andrew Morton
2020-11-14 19:11   ` Matthew Wilcox
2020-11-15 16:19   ` Hui Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).