From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
chris.mason@oracle.com, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 09/18] fs: rework icount to be a locked variable
Date: Fri, 8 Oct 2010 18:50:01 +1100 [thread overview]
Message-ID: <20101008075001.GT4681@dastard> (raw)
In-Reply-To: <20101008072749.GB7831@lst.de>
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
next prev parent reply other threads:[~2010-10-08 7:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
2010-10-08 8:17 ` Christoph Hellwig
2010-10-08 13:16 ` Chris Mason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101008075001.GT4681@dastard \
--to=david@fromorbit.com \
--cc=chris.mason@oracle.com \
--cc=hch@lst.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox