From: Malahal Naineni <malahal@us.ibm.com>
To: Fengguang Wu <fengguang.wu@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>,
Linux-NFS <linux-nfs@vger.kernel.org>,
Trond.Myklebust@netapp.com
Subject: Re: rpcauth_lookup_credcache() lock contentions
Date: Thu, 5 Jul 2012 10:05:09 -0500 [thread overview]
Message-ID: <20120705150509.GA12981@us.ibm.com> (raw)
In-Reply-To: <20120705131105.GA13775@localhost>
Fengguang Wu [fengguang.wu@intel.com] wrote:
> > diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> > index 727e506..645769e 100644
> > --- a/net/sunrpc/auth.c
> > +++ b/net/sunrpc/auth.c
> > @@ -364,13 +364,24 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
> > hlist_for_each_entry_rcu(entry, pos, &cache->hashtable[nr], cr_hash) {
> > if (!entry->cr_ops->crmatch(acred, entry, flags))
> > continue;
> > - spin_lock(&cache->lock);
> > if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) == 0) {
> > - spin_unlock(&cache->lock);
> > continue;
> > }
> > - cred = get_rpccred(entry);
> > - spin_unlock(&cache->lock);
> > + cred = entry;
I know very little about this code, so take this with grain of salt!
The cred symbol is set above but there is no guaranty that you will use
it. If you don't win, you should set it to NULL.
> > + if (atomic_add_return(1, &cred->cr_count) == 1) {
> > + /*
> > + * When the count was 0 we could race with the GC.
> > + * Take the lock and recheck.
> > + */
> > + spin_lock(&cache->lock);
> > + if (!test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags)) {
> > + /* Lost the race. */
> > + atomic_dec(&cred->cr_count);
> > + spin_unlock(&cache->lock);
> > + continue;
If you execute the above "continue" statement, you will have stale "cred"
where the original code may end up with NULL cred. I don't know if that
can happen really though.
> > + }
> > + spin_unlock(&cache->lock);
> > + }
> > break;
Setting cred to entry just before the above break and using entry in the
above code should be fine, I believe.
> > }
> > rcu_read_unlock();
> > --
> > 1.7.7
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2012-07-05 15:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20120623122604.GA10887@localhost>
2012-06-23 15:07 ` rpcauth_lookup_credcache() lock contentions Fengguang Wu
2012-06-24 21:34 ` Andi Kleen
2012-06-25 1:21 ` Myklebust, Trond
2012-06-25 2:45 ` Andi Kleen
2012-06-25 2:42 ` Fengguang Wu
2012-06-27 18:03 ` Andi Kleen
2012-06-27 18:36 ` Myklebust, Trond
2012-07-05 13:11 ` Fengguang Wu
2012-07-05 15:05 ` Malahal Naineni [this message]
2012-07-05 16:29 ` Andi Kleen
2012-07-05 16:27 ` Andi Kleen
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=20120705150509.GA12981@us.ibm.com \
--to=malahal@us.ibm.com \
--cc=Trond.Myklebust@netapp.com \
--cc=ak@linux.intel.com \
--cc=fengguang.wu@intel.com \
--cc=linux-nfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.