Re: [External] Re: [PATCH 10/17] fs: introduce alloc_inode_sb() to allocate filesystems specific inode

From: Muchun Song
Date: Tue May 11 2021 - 23:20:50 EST


On Wed, May 12, 2021 at 7:40 AM Dave Chinner <david@xxxxxxxxxxxxx> wrote:
>
> On Tue, May 11, 2021 at 06:46:40PM +0800, Muchun Song wrote:
> > The allocated inode cache will be added into its memcg lru list later,
> > but we do not allocate list_lru in the later patch. So the caller should
> > call kmem_cache_alloc_lru() to allocate inode and related list_lru.
> > Introduce alloc_inode_sb() to do that and convert all inodes allocation
> > to it.
>
> FWIW, this probably needs a documentation update to mention that
> inodes should always be allocated through alloc_inode_sb() rather
> than kmem_cache_alloc(). It's a "** mandatory **" requirement as per
> Documentation/filesytems/porting.rst.

Make sense to me. I'll fix it in the next version.

>
> Also,
>
> > diff --git a/include/linux/fs.h b/include/linux/fs.h
> > index c3c88fdb9b2a..d8d5d4eb68d6 100644
> > --- a/include/linux/fs.h
> > +++ b/include/linux/fs.h
> > @@ -41,6 +41,7 @@
> > #include <linux/stddef.h>
> > #include <linux/mount.h>
> > #include <linux/cred.h>
> > +#include <linux/slab.h>
> >
> > #include <asm/byteorder.h>
> > #include <uapi/linux/fs.h>
> > @@ -3200,6 +3201,12 @@ extern void free_inode_nonrcu(struct inode *inode);
> > extern int should_remove_suid(struct dentry *);
> > extern int file_remove_privs(struct file *);
> >
> > +static inline void *
> > +alloc_inode_sb(struct super_block *sb, struct kmem_cache *cache, gfp_t gfp)
> > +{
> > + return kmem_cache_alloc_lru(cache, &sb->s_inode_lru, gfp);
> > +}
> > +
>
> This really needs a kerneldoc comment explaining that it must be
> used for allocating inodes to set up the inode reclaim context
> correctly....

Will do.

>
> /me wonders if we should add a BUG_ON() check in inode_init_always()
> to capture filesystems that don't call through
> kmem_cache_alloc_lru() for inodes?

Good point. IMHO, I think that the BUG_ON check may be useful.
Actually, it can catch such bugs.

Any suggestions from others?

Thanks.

>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@xxxxxxxxxxxxx