All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni at redhat.com>
To: mptcp at lists.01.org
Subject: [MPTCP] Re: [PATCH 2/4] mptcp: refactor token container.
Date: Mon, 25 May 2020 10:10:09 +0200	[thread overview]
Message-ID: <a451889bfdd8543d456ea9c6dc7ea3dc9043fb68.camel@redhat.com> (raw)
In-Reply-To: alpine.OSX.2.22.394.2005221656220.75205@rnpatelx-mobl1.amr.corp.intel.com

[-- Attachment #1: Type: text/plain, Size: 2235 bytes --]

Hi,

On Fri, 2020-05-22 at 17:34 -0700, Mat Martineau wrote:
> > +struct token_bucket {
> > +	spinlock_t		lock;
> > +	int			chain_len;
> > +	struct hlist_nulls_head	req_chain;
> > +	struct hlist_nulls_head	msk_chain;
> > +};
> 
> I remember a discussion a while ago about how we didn't really need two 
> radix trees for req & msk, since there's only one "token space". 
> Similarly, seems like we only need one linked list per bucket if we can 
> define a common structure to use in both sock types, like:
> 
> struct mptcp_token_node {
>  	struct hlist_nulls_node node;
>  	u32 value;
>  	bool is_req;
> };
> 
> It would use a little more space per mptcp_sock/req_sock and would require 
> extra code in the lookup to return the appropriate container pointer (req 
> or mptcp_sock), but would shrink the hash table or give us more buckets in 
> the same memory, which seems like a win.

LGTM, I'll try that.

[...]
> > struct mptcp_sock *mptcp_token_get_sock(u32 token)
> > {
> > -	struct sock *conn;
> > -
> > -	spin_lock_bh(&token_tree_lock);
> > -	conn = radix_tree_lookup(&token_tree, token);
> > -	if (conn) {
> > -		/* token still reserved? */
> > -		if (conn == (struct sock *)&token_used)
> > -			conn = NULL;
> > -		else
> > -			sock_hold(conn);
> > +	struct hlist_nulls_node *pos;
> > +	struct token_bucket *bucket;
> > +	struct mptcp_sock *msk;
> > +
> > +	rcu_read_lock();
> > +	bucket = token_bucket(token);
> > +
> > +again:
> > +	hlist_nulls_for_each_entry_rcu(msk, pos, &bucket->msk_chain,
> > +				       token_node) {
> > +		if (READ_ONCE(msk->token) != token)
> > +			continue;
> > +		if (!refcount_inc_not_zero(&((struct sock *)msk)->sk_refcnt))
> > +			goto not_found;
> > +		if (READ_ONCE(msk->token) != token)
> > +			goto again;
> 
> Checking msk->token twice here, but it doesn't look like it ever gets 
> changed after it's set?

AFAICT, this is the common list_nulls usage pattern. The problem is
that a msk can be freed and re-allocated concurrently by another CPU.
Since this lookup is lockless, the token value can possibly change
'under-the-wood' till we get a reference to the token - and forbit msk
de-allocation.

Cheers,

Paolo

             reply	other threads:[~2020-05-25  8:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25  8:10 Paolo Abeni [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-05-27 16:47 [MPTCP] Re: [PATCH 2/4] mptcp: refactor token container Christoph Paasch
2020-05-27 11:00 Paolo Abeni
2020-05-26 16:28 Mat Martineau
2020-05-26 16:23 Christoph Paasch
2020-05-25 17:41 Paolo Abeni
2020-05-25 10:42 Paolo Abeni
2020-05-23  1:10 Mat Martineau
2020-05-23  0:34 Mat Martineau
2020-05-22 19:06 Christoph Paasch
2020-05-22 17:37 Paolo Abeni
2020-05-22 16:06 Christoph Paasch

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=a451889bfdd8543d456ea9c6dc7ea3dc9043fb68.camel@redhat.com \
    --to=unknown@example.com \
    /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.