linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/inode: No need to take ->i_lock right after alloc_inode()
@ 2013-12-14 20:54 Richard Weinberger
  2014-01-08 10:21 ` Richard Weinberger
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Weinberger @ 2013-12-14 20:54 UTC (permalink / raw)
  To: viro
  Cc: dchinner, hch, eric.dumazet, linux-fsdevel, linux-kernel,
	Richard Weinberger

In all three cases, new_inode_pseudo(), iget_locked() and iget5_locked(),
we own the new inode exclusively at this point and therefore taking
->i_lock to protect ->i_state/->i_hash against concurrent access is superfluous.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/inode.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 4bcdad3..5f2a735 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -869,9 +869,7 @@ struct inode *new_inode_pseudo(struct super_block *sb)
 	struct inode *inode = alloc_inode(sb);
 
 	if (inode) {
-		spin_lock(&inode->i_lock);
 		inode->i_state = 0;
-		spin_unlock(&inode->i_lock);
 		INIT_LIST_HEAD(&inode->i_sb_list);
 	}
 	return inode;
@@ -1025,10 +1023,8 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
 			if (set(inode, data))
 				goto set_failed;
 
-			spin_lock(&inode->i_lock);
 			inode->i_state = I_NEW;
 			hlist_add_head(&inode->i_hash, head);
-			spin_unlock(&inode->i_lock);
 			inode_sb_list_add(inode);
 			spin_unlock(&inode_hash_lock);
 
@@ -1092,10 +1088,8 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
 		old = find_inode_fast(sb, head, ino);
 		if (!old) {
 			inode->i_ino = ino;
-			spin_lock(&inode->i_lock);
 			inode->i_state = I_NEW;
 			hlist_add_head(&inode->i_hash, head);
-			spin_unlock(&inode->i_lock);
 			inode_sb_list_add(inode);
 			spin_unlock(&inode_hash_lock);
 
-- 
1.8.4.2

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

* Re: [PATCH] fs/inode: No need to take ->i_lock right after alloc_inode()
  2013-12-14 20:54 [PATCH] fs/inode: No need to take ->i_lock right after alloc_inode() Richard Weinberger
@ 2014-01-08 10:21 ` Richard Weinberger
  2014-01-10  9:22   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Weinberger @ 2014-01-08 10:21 UTC (permalink / raw)
  To: viro; +Cc: dchinner, hch, eric.dumazet, linux-fsdevel, linux-kernel

Am Samstag, 14. Dezember 2013, 21:54:55 schrieb Richard Weinberger:
> In all three cases, new_inode_pseudo(), iget_locked() and iget5_locked(),
> we own the new inode exclusively at this point and therefore taking
> ->i_lock to protect ->i_state/->i_hash against concurrent access is
> superfluous.
> 
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
>  fs/inode.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 4bcdad3..5f2a735 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -869,9 +869,7 @@ struct inode *new_inode_pseudo(struct super_block *sb)
>  	struct inode *inode = alloc_inode(sb);
> 
>  	if (inode) {
> -		spin_lock(&inode->i_lock);
>  		inode->i_state = 0;
> -		spin_unlock(&inode->i_lock);
>  		INIT_LIST_HEAD(&inode->i_sb_list);
>  	}
>  	return inode;
> @@ -1025,10 +1023,8 @@ struct inode *iget5_locked(struct super_block *sb,
> unsigned long hashval, if (set(inode, data))
>  				goto set_failed;
> 
> -			spin_lock(&inode->i_lock);
>  			inode->i_state = I_NEW;
>  			hlist_add_head(&inode->i_hash, head);
> -			spin_unlock(&inode->i_lock);
>  			inode_sb_list_add(inode);
>  			spin_unlock(&inode_hash_lock);
> 
> @@ -1092,10 +1088,8 @@ struct inode *iget_locked(struct super_block *sb,
> unsigned long ino) old = find_inode_fast(sb, head, ino);
>  		if (!old) {
>  			inode->i_ino = ino;
> -			spin_lock(&inode->i_lock);
>  			inode->i_state = I_NEW;
>  			hlist_add_head(&inode->i_hash, head);
> -			spin_unlock(&inode->i_lock);
>  			inode_sb_list_add(inode);
>  			spin_unlock(&inode_hash_lock);

Any comments on this?

Thanks,
//richard

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

* Re: [PATCH] fs/inode: No need to take ->i_lock right after alloc_inode()
  2014-01-08 10:21 ` Richard Weinberger
@ 2014-01-10  9:22   ` Christoph Hellwig
  2014-01-10  9:48     ` Richard Weinberger
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2014-01-10  9:22 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: viro, dchinner, hch, eric.dumazet, linux-fsdevel, linux-kernel

On Wed, Jan 08, 2014 at 11:21:13AM +0100, Richard Weinberger wrote:
> > In all three cases, new_inode_pseudo(), iget_locked() and iget5_locked(),
> > we own the new inode exclusively at this point and therefore taking
> > ->i_lock to protect ->i_state/->i_hash against concurrent access is
> > superfluous.

We'd still need some sort of barrier to make sure the state is visible
to all CPUs before it becomes visible, usually by another spin_unlock
happing later.  If you have a workload where removing these is critical
please document these issues in the code and resubmit it with an explanation
of the workload where it helps.  If it's just a cleanup I wouldn't bother
with it.

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

* Re: [PATCH] fs/inode: No need to take ->i_lock right after alloc_inode()
  2014-01-10  9:22   ` Christoph Hellwig
@ 2014-01-10  9:48     ` Richard Weinberger
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Weinberger @ 2014-01-10  9:48 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: viro, dchinner, eric.dumazet, linux-fsdevel, linux-kernel

Am Freitag, 10. Januar 2014, 10:22:29 schrieb Christoph Hellwig:
> On Wed, Jan 08, 2014 at 11:21:13AM +0100, Richard Weinberger wrote:
> > > In all three cases, new_inode_pseudo(), iget_locked() and
> > > iget5_locked(),
> > > we own the new inode exclusively at this point and therefore taking
> > > ->i_lock to protect ->i_state/->i_hash against concurrent access is
> > > superfluous.
> 
> We'd still need some sort of barrier to make sure the state is visible
> to all CPUs before it becomes visible, usually by another spin_unlock
> happing later.  If you have a workload where removing these is critical
> please document these issues in the code and resubmit it with an explanation
> of the workload where it helps.  If it's just a cleanup I wouldn't bother
> with it.

The patch was indented as cleanup patch, but as you pointed out I've failed to
think about the barrier.
Let's drop the patch. :D

Thanks,
//richard

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

end of thread, other threads:[~2014-01-10  9:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-14 20:54 [PATCH] fs/inode: No need to take ->i_lock right after alloc_inode() Richard Weinberger
2014-01-08 10:21 ` Richard Weinberger
2014-01-10  9:22   ` Christoph Hellwig
2014-01-10  9:48     ` Richard Weinberger

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