linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 09/18] fs: rework icount to be a locked variable
       [not found] ` <1286515292-15882-10-git-send-email-david@fromorbit.com>
@ 2010-10-08  7:27   ` Christoph Hellwig
  2010-10-08  7:50     ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2010-10-08  7:27 UTC (permalink / raw)
  To: Dave Chinner; +Cc: linux-fsdevel, linux-kernel, chris.mason, linux-btrfs

> index 2953e9f..9f04478 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1964,8 +1964,14 @@ void btrfs_add_delayed_iput(struct inode *inode)
>  	struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
>  	struct delayed_iput *delayed;
>  
> -	if (atomic_add_unless(&inode->i_count, -1, 1))
> +	/* XXX: filesystems should not play refcount games like this */
> +	spin_lock(&inode->i_lock);
> +	if (inode->i_ref > 1) {
> +		inode->i_ref--;
> +		spin_unlock(&inode->i_lock);
>  		return;
> +	}
> +	spin_unlock(&inode->i_lock);

Yeah, all that i_count/i_ref mess in btrfs needs some serious work.
Chris?

> +
> +/*
> + * inode_lock must be held
> + */
> +void iref_locked(struct inode *inode)
> +{
> +	inode->i_ref++;
> +}
>  EXPORT_SYMBOL_GPL(iref_locked);

I'm a big fan of _GPL exports, but adding this for a trivial counter
increment seems a bit weird. 

>  int iref_read(struct inode *inode)
>  {
> -	return atomic_read(&inode->i_count);
> +	int ref;
> +
> +	spin_lock(&inode->i_lock);
> +	ref = inode->i_ref;
> +	spin_unlock(&inode->i_lock);
> +	return ref;
>  }

There's no need to lock a normal 32-bit variable for readers.

> +		inode->i_ref--;
> +		if (inode->i_ref == 0) {

		if (--inode->i_ref == 0) {

might be a bit more idiomatic.


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

* Re: [PATCH 09/18] fs: rework icount to be a locked variable
  2010-10-08  7:27   ` [PATCH 09/18] fs: rework icount to be a locked variable Christoph Hellwig
@ 2010-10-08  7:50     ` Dave Chinner
  2010-10-08  8:17       ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Chinner @ 2010-10-08  7:50 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-fsdevel, linux-kernel, chris.mason, linux-btrfs

On Fri, Oct 08, 2010 at 03:27:49AM -0400, Christoph Hellwig wrote:
> > index 2953e9f..9f04478 100644
> > --- a/fs/btrfs/inode.c
> > +++ b/fs/btrfs/inode.c
> > @@ -1964,8 +1964,14 @@ void btrfs_add_delayed_iput(struct inode *inode)
> >  	struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
> >  	struct delayed_iput *delayed;
> >  
> > -	if (atomic_add_unless(&inode->i_count, -1, 1))
> > +	/* XXX: filesystems should not play refcount games like this */
> > +	spin_lock(&inode->i_lock);
> > +	if (inode->i_ref > 1) {
> > +		inode->i_ref--;
> > +		spin_unlock(&inode->i_lock);
> >  		return;
> > +	}
> > +	spin_unlock(&inode->i_lock);
> 
> Yeah, all that i_count/i_ref mess in btrfs needs some serious work.
> Chris?
> 
> > +
> > +/*
> > + * inode_lock must be held
> > + */
> > +void iref_locked(struct inode *inode)
> > +{
> > +	inode->i_ref++;
> > +}
> >  EXPORT_SYMBOL_GPL(iref_locked);
> 
> I'm a big fan of _GPL exports, but adding this for a trivial counter
> increment seems a bit weird. 

OK, will drop the _GPL.
> 
> >  int iref_read(struct inode *inode)
> >  {
> > -	return atomic_read(&inode->i_count);
> > +	int ref;
> > +
> > +	spin_lock(&inode->i_lock);
> > +	ref = inode->i_ref;
> > +	spin_unlock(&inode->i_lock);
> > +	return ref;
> >  }
> 
> There's no need to lock a normal 32-bit variable for readers.

Ok, but will need a memory barrier instead?

> 
> > +		inode->i_ref--;
> > +		if (inode->i_ref == 0) {
> 
> 		if (--inode->i_ref == 0) {
> 
> might be a bit more idiomatic.

OK.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 09/18] fs: rework icount to be a locked variable
  2010-10-08  7:50     ` Dave Chinner
@ 2010-10-08  8:17       ` Christoph Hellwig
  2010-10-08 13:16         ` Chris Mason
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2010-10-08  8:17 UTC (permalink / raw)
  To: Dave Chinner
  Cc: Christoph Hellwig, linux-fsdevel, linux-kernel, chris.mason, linux-btrfs

On Fri, Oct 08, 2010 at 06:50:01PM +1100, Dave Chinner wrote:
> > There's no need to lock a normal 32-bit variable for readers.
> 
> Ok, but will need a memory barrier instead?

Isn't spin_unlock supposed to be one?  I'll need some of the locking
experts to shime in.

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

* Re: [PATCH 09/18] fs: rework icount to be a locked variable
  2010-10-08  8:17       ` Christoph Hellwig
@ 2010-10-08 13:16         ` Chris Mason
  0 siblings, 0 replies; 4+ messages in thread
From: Chris Mason @ 2010-10-08 13:16 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Dave Chinner, linux-fsdevel, linux-kernel, linux-btrfs

On Fri, Oct 08, 2010 at 10:17:14AM +0200, Christoph Hellwig wrote:
> On Fri, Oct 08, 2010 at 06:50:01PM +1100, Dave Chinner wrote:
> > > There's no need to lock a normal 32-bit variable for readers.
> > 
> > Ok, but will need a memory barrier instead?
> 
> Isn't spin_unlock supposed to be one?  I'll need some of the locking
> experts to shime in.

Not really a locking expert, but the locking operations are supposed to
have an implicit barrier.

-chris


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

end of thread, other threads:[~2010-10-08 13:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1286515292-15882-1-git-send-email-david@fromorbit.com>
     [not found] ` <1286515292-15882-10-git-send-email-david@fromorbit.com>
2010-10-08  7:27   ` [PATCH 09/18] fs: rework icount to be a locked variable Christoph Hellwig
2010-10-08  7:50     ` Dave Chinner
2010-10-08  8:17       ` Christoph Hellwig
2010-10-08 13:16         ` Chris Mason

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