Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa0d7e3d authored by Nick Piggin's avatar Nick Piggin
Browse files

fs: icache RCU free inodes



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: default avatarNick Piggin <npiggin@kernel.dk>
parent 77812a1e
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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.
+8 −2
Original line number Diff line number Diff line
@@ -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)
{
+8 −1
Original line number Diff line number Diff line
@@ -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.
@@ -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);
}

/*
+8 −1
Original line number Diff line number Diff line
@@ -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;
+8 −1
Original line number Diff line number Diff line
@@ -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

/**
Loading