From: Eric Dumazet <eric.dumazet@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: David Miller <davem@davemloft.net>,
netdev@vger.kernel.org, jamal <hadi@cyberus.ca>,
Daniel Lezcano <dlezcano@fr.ibm.com>
Subject: Re: [PATCH 6/7] net: Use rcu lookups in inet_twsk_purge.
Date: Thu, 03 Dec 2009 14:17:41 +0100 [thread overview]
Message-ID: <4B17BA75.1040302@gmail.com> (raw)
In-Reply-To: <1259843349-3810-6-git-send-email-ebiederm@xmission.com>
Eric W. Biederman a écrit :
> From: Eric W. Biederman <ebiederm@xmission.com>
>
> While we are looking up entries to free there is no reason to take
> the lock in inet_twsk_purge. We have to drop locks and restart
> occassionally anyway so adding a few more in case we get on the
> wrong list because of a timewait move is no big deal. At the
> same time not taking the lock for long periods of time is much
> more polite to the rest of the users of the hash table.
>
> In my test configuration of killing 4k network namespaces
> this change causes 4k back to back runs of inet_twsk_purge on an
> empty hash table to go from roughly 20.7s to 3.3s, and the total
> time to destroy 4k network namespaces goes from roughly 44s to
> 3.3s.
>
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Very nice patch Eric
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
> ---
> net/ipv4/inet_timewait_sock.c | 39 ++++++++++++++++++++++++---------------
> 1 files changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
> index 1f5d508..683ecec 100644
> --- a/net/ipv4/inet_timewait_sock.c
> +++ b/net/ipv4/inet_timewait_sock.c
> @@ -427,31 +427,40 @@ void inet_twsk_purge(struct net *net, struct inet_hashinfo *hashinfo,
> struct inet_timewait_sock *tw;
> struct sock *sk;
> struct hlist_nulls_node *node;
> - int h;
> + unsigned int slot;
>
> - local_bh_disable();
> - for (h = 0; h <= hashinfo->ehash_mask; h++) {
> - struct inet_ehash_bucket *head =
> - inet_ehash_bucket(hashinfo, h);
> - spinlock_t *lock = inet_ehash_lockp(hashinfo, h);
> + for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
> + struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
> +restart_rcu:
> + rcu_read_lock();
> restart:
> - spin_lock(lock);
> - sk_nulls_for_each(sk, node, &head->twchain) {
> -
> + sk_nulls_for_each_rcu(sk, node, &head->twchain) {
> tw = inet_twsk(sk);
> if (!net_eq(twsk_net(tw), net) ||
> tw->tw_family != family)
> continue;
>
> - atomic_inc(&tw->tw_refcnt);
> - spin_unlock(lock);
> + if (unlikely(!atomic_inc_not_zero(&tw->tw_refcnt)))
> + continue;
> +
> + if (unlikely(!net_eq(twsk_net(tw), net) ||
> + tw->tw_family != family)) {
> + inet_twsk_put(tw);
> + goto restart;
> + }
> +
> + rcu_read_unlock();
> inet_twsk_deschedule(tw, twdr);
> inet_twsk_put(tw);
> -
> - goto restart;
> + goto restart_rcu;
> }
> - spin_unlock(lock);
> + /* If the nulls value we got at the end of this lookup is
> + * not the expected one, we must restart lookup.
> + * We probably met an item that was moved to another chain.
> + */
> + if (get_nulls_value(node) != slot)
> + goto restart;
> + rcu_read_unlock();
> }
> - local_bh_enable();
> }
> EXPORT_SYMBOL_GPL(inet_twsk_purge);
next prev parent reply other threads:[~2009-12-03 13:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-03 12:27 [PATCH 0/7] Batched netns improvements Eric W. Biederman
2009-12-03 12:29 ` [PATCH 1/7] net: Add support for batching network namespace cleanups Eric W. Biederman
2009-12-03 12:29 ` [PATCH 2/7] net: Move network device exit batching Eric W. Biederman
2009-12-03 12:29 ` [PATCH 3/7] net: Allow xfrm_user_net_exit to batch efficiently Eric W. Biederman
2009-12-03 12:29 ` [PATCH 4/7] netns: Add an explicit rcu_barrier to unregister_pernet_{device|subsys} Eric W. Biederman
2009-12-03 12:29 ` [PATCH 5/7] net: Allow fib_rule_unregister to batch Eric W. Biederman
2009-12-03 12:29 ` [PATCH 6/7] net: Use rcu lookups in inet_twsk_purge Eric W. Biederman
2009-12-03 13:17 ` Eric Dumazet [this message]
2009-12-03 12:29 ` [PATCH 7/7] net: Batch inet_twsk_purge Eric W. Biederman
2009-12-03 13:23 ` Eric Dumazet
2009-12-03 13:36 ` Eric W. Biederman
2009-12-03 20:24 ` David Miller
2009-12-03 20:45 ` Eric W. Biederman
2009-12-03 13:06 ` [PATCH 0/7] Batched netns improvements jamal
2009-12-03 13:23 ` Eric W. Biederman
2009-12-03 20:24 ` David Miller
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=4B17BA75.1040302@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=dlezcano@fr.ibm.com \
--cc=ebiederm@xmission.com \
--cc=hadi@cyberus.ca \
--cc=netdev@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;
as well as URLs for NNTP newsgroup(s).