public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Waiman Long <Waiman.Long@hp.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Jeff Layton <jlayton@redhat.com>,
	Miklos Szeredi <mszeredi@suse.cz>, Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Andi Kleen <andi@firstfloor.org>,
	"Chandramouleeswaran, Aswin" <aswin@hp.com>,
	"Norton, Scott J" <scott.norton@hp.com>
Subject: Re: [PATCH v6 01/14] spinlock: A new lockref structure for lockless update of refcount
Date: Sun, 14 Jul 2013 01:58:24 +0900	[thread overview]
Message-ID: <51E18730.2020105@hitachi.com> (raw)
In-Reply-To: <1373332204-10379-2-git-send-email-Waiman.Long@hp.com>

Hi,

(2013/07/09 10:09), Waiman Long wrote:> +/**
> + * lockref_put_or_lock - decrements count unless count <= 1 before decrement
> + * @lockcnt: pointer to lockref structure
> + * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
> + *
> + * The only difference between lockref_put_or_lock and lockref_put is that
> + * the former function will hold the lock on return while the latter one
> + * will free it on return.
> + */
> +static __always_inline int lockref_put_or_locked(struct lockref *lockcnt)

Here is a function name typo. _locked should be _lock.
And also, I think we should take a note here to tell this function does *not*
guarantee lockcnt->refcnt == 0 or 1 until unlocked if this returns 0.

> +{
> +	spin_lock(&lockcnt->lock);
> +	if (likely(lockcnt->refcnt > 1)) {
> +		lockcnt->refcnt--;
> +		spin_unlock(&lockcnt->lock);
> +		return 1;
> +	}
> +	return 0;
> +}

Using this implementation guarantees lockcnt->refcnt == 0 or 1 until unlocked
if this returns 0.

However, the below one looks not guarantee it. Since lockref_add_unless
and spinlock are not done atomically, there is a chance for someone
to increment it right before locking.

Or, I missed something?

> +/**
> + * lockref_put_or_lock - Decrements count unless the count is <= 1
> + *			 otherwise, the lock will be taken
> + * @lockcnt: pointer to struct lockref structure
> + * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
> + */
> +int
> +lockref_put_or_lock(struct lockref *lockcnt)
> +{
> +	if (lockref_add_unless(lockcnt, -1, 1))
> +		return 1;
> +	spin_lock(&lockcnt->lock);
> +	return 0;
> +}

BTW, it looks that your dcache patch knows this and keeps double check for
the case of lockcnt->refcnt > 1 in dput().

Thank you,

-- 
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com


  reply	other threads:[~2013-07-13 16:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-09  1:09 [PATCH v6 00/14] Lockless update of reference count protected by spinlock Waiman Long
2013-07-09  1:09 ` [PATCH v6 01/14] spinlock: A new lockref structure for lockless update of refcount Waiman Long
2013-07-13 16:58   ` Masami Hiramatsu [this message]
2013-07-15 21:00     ` Waiman Long
2013-07-09  1:09 ` [PATCH v6 02/14] spinlock: Enable x86 architecture to do lockless refcount update Waiman Long
2013-07-09  1:09 ` [PATCH v6 03/14] dcache: Add a new helper function d_count() to return refcount Waiman Long
2013-07-11 13:48   ` Waiman Long
2013-07-09  1:09 ` [PATCH v6 04/14] auto-fs: replace direct access of d_count with the d_count() helper Waiman Long
2013-07-09  1:09 ` [PATCH v6 05/14] ceph-fs: " Waiman Long
2013-07-09  1:09 ` [PATCH v6 06/14] coda-fs: " Waiman Long
2013-07-09  1:09 ` [PATCH v6 07/14] config-fs: " Waiman Long
2013-07-09  1:09 ` [PATCH v6 08/14] ecrypt-fs: " Waiman Long
2013-07-09  1:09 ` [PATCH v6 09/14] file locking: " Waiman Long
2013-07-09  1:10 ` [PATCH v6 10/14] nfs: " Waiman Long
2013-07-09  1:10 ` [PATCH v6 11/14] nilfs2: " Waiman Long
2013-07-09  1:10 ` [PATCH v6 12/14] lustre-fs: Use the standard d_count() helper to access refcount Waiman Long
2013-07-10  9:47   ` Peng, Tao
2013-07-09  1:10 ` [PATCH v6 13/14] dcache: rename d_count field of dentry to d_refcount Waiman Long
2013-07-09  1:10 ` [PATCH v6 14/14] dcache: Enable lockless update of refcount in dentry structure Waiman Long

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=51E18730.2020105@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=Waiman.Long@hp.com \
    --cc=andi@firstfloor.org \
    --cc=aswin@hp.com \
    --cc=benh@kernel.crashing.org \
    --cc=jlayton@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mszeredi@suse.cz \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=scott.norton@hp.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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