Skip to content

Commit

Permalink
fs: icache RCU free inodes
Browse files Browse the repository at this point in the history
RCU free the struct inode. This will allow:

- Subsequent store-free path walking patch. The inode must be consulted for
  permissions when walking, so an RCU inode reference is a must.
- sb_inode_list_lock to be moved inside i_lock because sb list walkers who want
  to take i_lock no longer need to take sb_inode_list_lock to walk the list in
  the first place. This will simplify and optimize locking.
- Could remove some nested trylock loops in dcache code
- Could potentially simplify things a bit in VM land. Do not need to take the
  page lock to follow page->mapping.

The downsides of this is the performance cost of using RCU. In a simple
creat/unlink microbenchmark, performance drops by about 10% due to inability to
reuse cache-hot slab objects. As iterations increase and RCU freeing starts
kicking over, this increases to about 20%.

In cases where inode lifetimes are longer (ie. many inodes may be allocated
during the average life span of a single inode), a lot of this cache reuse is
not applicable, so the regression caused by this patch is smaller.

The cache-hot regression could largely be avoided by using SLAB_DESTROY_BY_RCU,
however this adds some complexity to list walking and store-free path walking,
so I prefer to implement this at a later date, if it is shown to be a win in
real situations. I haven't found a regression in any non-micro benchmark so I
doubt it will be a problem.

Signed-off-by: Nick Piggin <[email protected]>
  • Loading branch information
Nick Piggin committed Jan 7, 2011
1 parent 77812a1 commit fa0d7e3
Show file tree
Hide file tree
Showing 60 changed files with 490 additions and 68 deletions.
14 changes: 14 additions & 0 deletions Documentation/filesystems/porting
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,17 @@ look at examples of other filesystems) for guidance.
for details of what locks to replace dcache_lock with in order to protect
particular things. Most of the time, a filesystem only needs ->d_lock, which
protects *all* the dcache state of a given dentry.

--
[mandatory]

Filesystems must RCU-free their inodes, if they can have been accessed
via rcu-walk path walk (basically, if the file can have had a path name in the
vfs namespace).

i_dentry and i_rcu share storage in a union, and the vfs expects
i_dentry to be reinitialized before it is freed, so an:

INIT_LIST_HEAD(&inode->i_dentry);

must be done in the RCU callback.
10 changes: 8 additions & 2 deletions arch/powerpc/platforms/cell/spufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ spufs_alloc_inode(struct super_block *sb)
return &ei->vfs_inode;
}

static void
spufs_destroy_inode(struct inode *inode)
static void spufs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
}

static void spufs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, spufs_i_callback);
}

static void
spufs_init_once(void *p)
{
Expand Down
9 changes: 8 additions & 1 deletion drivers/staging/pohmelfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ const struct address_space_operations pohmelfs_aops = {
.set_page_dirty = __set_page_dirty_nobuffers,
};

static void pohmelfs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(pohmelfs_inode_cache, POHMELFS_I(inode));
}

/*
* ->detroy_inode() callback. Deletes inode from the caches
* and frees private data.
Expand All @@ -842,8 +849,8 @@ static void pohmelfs_destroy_inode(struct inode *inode)

dprintk("%s: pi: %p, inode: %p, ino: %llu.\n",
__func__, pi, &pi->vfs_inode, pi->ino);
kmem_cache_free(pohmelfs_inode_cache, pi);
atomic_long_dec(&psb->total_inodes);
call_rcu(&inode->i_rcu, pohmelfs_i_callback);
}

/*
Expand Down
9 changes: 8 additions & 1 deletion drivers/staging/smbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ static struct inode *smb_alloc_inode(struct super_block *sb)
return &ei->vfs_inode;
}

static void smb_destroy_inode(struct inode *inode)
static void smb_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(smb_inode_cachep, SMB_I(inode));
}

static void smb_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, smb_i_callback);
}

static void init_once(void *foo)
{
struct smb_inode_info *ei = (struct smb_inode_info *) foo;
Expand Down
9 changes: 8 additions & 1 deletion fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,17 @@ struct inode *v9fs_alloc_inode(struct super_block *sb)
*
*/

void v9fs_destroy_inode(struct inode *inode)
static void v9fs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
}

void v9fs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, v9fs_i_callback);
}
#endif

/**
Expand Down
9 changes: 8 additions & 1 deletion fs/adfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,18 @@ static struct inode *adfs_alloc_inode(struct super_block *sb)
return &ei->vfs_inode;
}

static void adfs_destroy_inode(struct inode *inode)
static void adfs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(adfs_inode_cachep, ADFS_I(inode));
}

static void adfs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, adfs_i_callback);
}

static void init_once(void *foo)
{
struct adfs_inode_info *ei = (struct adfs_inode_info *) foo;
Expand Down
9 changes: 8 additions & 1 deletion fs/affs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ static struct inode *affs_alloc_inode(struct super_block *sb)
return &i->vfs_inode;
}

static void affs_destroy_inode(struct inode *inode)
static void affs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
}

static void affs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, affs_i_callback);
}

static void init_once(void *foo)
{
struct affs_inode_info *ei = (struct affs_inode_info *) foo;
Expand Down
10 changes: 9 additions & 1 deletion fs/afs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@ static struct inode *afs_alloc_inode(struct super_block *sb)
return &vnode->vfs_inode;
}

static void afs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct afs_vnode *vnode = AFS_FS_I(inode);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(afs_inode_cachep, vnode);
}

/*
* destroy an AFS inode struct
*/
Expand All @@ -511,7 +519,7 @@ static void afs_destroy_inode(struct inode *inode)

ASSERTCMP(vnode->server, ==, NULL);

kmem_cache_free(afs_inode_cachep, vnode);
call_rcu(&inode->i_rcu, afs_i_callback);
atomic_dec(&afs_count_active_inodes);
}

Expand Down
10 changes: 8 additions & 2 deletions fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,18 @@ befs_alloc_inode(struct super_block *sb)
return &bi->vfs_inode;
}

static void
befs_destroy_inode(struct inode *inode)
static void befs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(befs_inode_cachep, BEFS_I(inode));
}

static void befs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, befs_i_callback);
}

static void init_once(void *foo)
{
struct befs_inode_info *bi = (struct befs_inode_info *) foo;
Expand Down
9 changes: 8 additions & 1 deletion fs/bfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,18 @@ static struct inode *bfs_alloc_inode(struct super_block *sb)
return &bi->vfs_inode;
}

static void bfs_destroy_inode(struct inode *inode)
static void bfs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(bfs_inode_cachep, BFS_I(inode));
}

static void bfs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, bfs_i_callback);
}

static void init_once(void *foo)
{
struct bfs_inode_info *bi = foo;
Expand Down
9 changes: 8 additions & 1 deletion fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,20 @@ static struct inode *bdev_alloc_inode(struct super_block *sb)
return &ei->vfs_inode;
}

static void bdev_destroy_inode(struct inode *inode)
static void bdev_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct bdev_inode *bdi = BDEV_I(inode);

INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(bdev_cachep, bdi);
}

static void bdev_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, bdev_i_callback);
}

static void init_once(void *foo)
{
struct bdev_inode *ei = (struct bdev_inode *) foo;
Expand Down
9 changes: 8 additions & 1 deletion fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6495,6 +6495,13 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
return inode;
}

static void btrfs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
}

void btrfs_destroy_inode(struct inode *inode)
{
struct btrfs_ordered_extent *ordered;
Expand Down Expand Up @@ -6564,7 +6571,7 @@ void btrfs_destroy_inode(struct inode *inode)
inode_tree_del(inode);
btrfs_drop_extent_cache(inode, 0, (u64)-1, 0);
free:
kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
call_rcu(&inode->i_rcu, btrfs_i_callback);
}

int btrfs_drop_inode(struct inode *inode)
Expand Down
11 changes: 10 additions & 1 deletion fs/ceph/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ struct inode *ceph_alloc_inode(struct super_block *sb)
return &ci->vfs_inode;
}

static void ceph_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct ceph_inode_info *ci = ceph_inode(inode);

INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(ceph_inode_cachep, ci);
}

void ceph_destroy_inode(struct inode *inode)
{
struct ceph_inode_info *ci = ceph_inode(inode);
Expand Down Expand Up @@ -407,7 +416,7 @@ void ceph_destroy_inode(struct inode *inode)
if (ci->i_xattrs.prealloc_blob)
ceph_buffer_put(ci->i_xattrs.prealloc_blob);

kmem_cache_free(ceph_inode_cachep, ci);
call_rcu(&inode->i_rcu, ceph_i_callback);
}


Expand Down
9 changes: 8 additions & 1 deletion fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,17 @@ cifs_alloc_inode(struct super_block *sb)
return &cifs_inode->vfs_inode;
}

static void cifs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
}

static void
cifs_destroy_inode(struct inode *inode)
{
kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
call_rcu(&inode->i_rcu, cifs_i_callback);
}

static void
Expand Down
9 changes: 8 additions & 1 deletion fs/coda/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ static struct inode *coda_alloc_inode(struct super_block *sb)
return &ei->vfs_inode;
}

static void coda_destroy_inode(struct inode *inode)
static void coda_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(coda_inode_cachep, ITOC(inode));
}

static void coda_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, coda_i_callback);
}

static void init_once(void *foo)
{
struct coda_inode_info *ei = (struct coda_inode_info *) foo;
Expand Down
12 changes: 11 additions & 1 deletion fs/ecryptfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ static struct inode *ecryptfs_alloc_inode(struct super_block *sb)
return inode;
}

static void ecryptfs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct ecryptfs_inode_info *inode_info;
inode_info = ecryptfs_inode_to_private(inode);

INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(ecryptfs_inode_info_cache, inode_info);
}

/**
* ecryptfs_destroy_inode
* @inode: The ecryptfs inode
Expand All @@ -88,7 +98,7 @@ static void ecryptfs_destroy_inode(struct inode *inode)
}
}
ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat);
kmem_cache_free(ecryptfs_inode_info_cache, inode_info);
call_rcu(&inode->i_rcu, ecryptfs_i_callback);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion fs/efs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ static struct inode *efs_alloc_inode(struct super_block *sb)
return &ei->vfs_inode;
}

static void efs_destroy_inode(struct inode *inode)
static void efs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(efs_inode_cachep, INODE_INFO(inode));
}

static void efs_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, efs_i_callback);
}

static void init_once(void *foo)
{
struct efs_inode_info *ei = (struct efs_inode_info *) foo;
Expand Down
9 changes: 8 additions & 1 deletion fs/exofs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,19 @@ static struct inode *exofs_alloc_inode(struct super_block *sb)
return &oi->vfs_inode;
}

static void exofs_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
INIT_LIST_HEAD(&inode->i_dentry);
kmem_cache_free(exofs_inode_cachep, exofs_i(inode));
}

/*
* Remove an inode from the cache
*/
static void exofs_destroy_inode(struct inode *inode)
{
kmem_cache_free(exofs_inode_cachep, exofs_i(inode));
call_rcu(&inode->i_rcu, exofs_i_callback);
}

/*
Expand Down
Loading

0 comments on commit fa0d7e3

Please sign in to comment.