Re: [PATCH] fs: reduce pointers while using file_ra_state_init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 18:19 26/07, Matthew Wilcox wrote:
> On Mon, Jul 26, 2021 at 11:46:47AM -0500, Goldwyn Rodrigues wrote:
> > Simplification.
> > 
> > file_ra_state_init() take struct address_space *, just to use inode
> > pointer by dereferencing from mapping->host.
> > 
> > The callers also derive mapping either by file->f_mapping, or
> > even file->f_mapping->host->i_mapping.
> > 
> > Change file_ra_state_init() to accept struct inode * to reduce pointer
> > dereferencing, both in the callee and the caller.
> > 
> > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx>
> 
> Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
> 
> (some adjacent comments)
> 
> > diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> > index 4806295116d8..c43bf9915cda 100644
> > --- a/fs/btrfs/free-space-cache.c
> > +++ b/fs/btrfs/free-space-cache.c
> > @@ -351,7 +351,7 @@ static void readahead_cache(struct inode *inode)
> >  	if (!ra)
> >  		return;
> >  
> > -	file_ra_state_init(ra, inode->i_mapping);
> > +	file_ra_state_init(ra, inode);
> >  	last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT;
> >  
> >  	page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index);
> 
> Why does btrfs allocate a file_ra_state using kmalloc instead of
> on the stack?
> 
> > +++ b/include/linux/fs.h
> > @@ -3260,7 +3260,7 @@ extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
> >  
> >  
> >  extern void
> > -file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
> > +file_ra_state_init(struct file_ra_state *ra, struct inode *inode);
> 
> This should move to pagemap.h (and lose the extern).
> I'd put it near the definition of VM_READAHEAD_PAGES.
> 
> > diff --git a/mm/readahead.c b/mm/readahead.c
> > index d589f147f4c2..3541941df5e7 100644
> > --- a/mm/readahead.c
> > +++ b/mm/readahead.c
> > @@ -31,9 +31,9 @@
> >   * memset *ra to zero.
> >   */
> >  void
> > -file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping)
> > +file_ra_state_init(struct file_ra_state *ra, struct inode *inode)
> >  {
> > -	ra->ra_pages = inode_to_bdi(mapping->host)->ra_pages;
> > +	ra->ra_pages = inode_to_bdi(inode)->ra_pages;
> >  	ra->prev_pos = -1;
> >  }
> >  EXPORT_SYMBOL_GPL(file_ra_state_init);
> 
> I'm not entirely sure why this function is out-of-line, tbh.
> Would it make more sense for it to be static inline in a header?

Which one? pagemap.h or fs.h does not know of inode_to_bdi(), should
linux/backing-dev.h be included?

-- 
Goldwyn



[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux