From: "Denis V. Lunev" <den-3ImXcnM4P+0@public.gmane.org>
To: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
Cc: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org,
ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org
Subject: Re: [patch 2/3][NETNS45][V2] make timewait unhash lock free
Date: Thu, 27 Sep 2007 16:46:28 +0400 [thread overview]
Message-ID: <46FBA624.2070203@sw.ru> (raw)
In-Reply-To: <20070927111212.651097600-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
Sorry for a delay in answer. A was ill last three days.
Some stylistic comments inside
Daniel Lezcano wrote:
> From: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
>
> The network namespace cleanup will remove all timewait sockets
> related to it because there are pointless.
>
> The problem is we need to browse the established hash table and
> for that we need to take the lock. For each timesocket we call
> inet_deschedule and this one take the established hash table lock
> too.
>
> The following patchset split the removing of the established hash
> into two parts, one removing the node from the hash and another
> taking the lock and calling the first one.
>
> The network namespace cleanup can be done calling the lock free
> function.
>
> Signed-off-by: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
> ---
> include/net/inet_timewait_sock.h | 13 ++++++++++++
> net/ipv4/inet_timewait_sock.c | 40 +++++++++++++++++++++++++++------------
> 2 files changed, 41 insertions(+), 12 deletions(-)
>
> Index: linux-2.6-netns/net/ipv4/inet_timewait_sock.c
> ===================================================================
> --- linux-2.6-netns.orig/net/ipv4/inet_timewait_sock.c
> +++ linux-2.6-netns/net/ipv4/inet_timewait_sock.c
> @@ -13,25 +13,28 @@
> #include <net/inet_timewait_sock.h>
> #include <net/ip.h>
>
> -/* Must be called with locally disabled BHs. */
> -static void __inet_twsk_kill(struct inet_timewait_sock *tw,
> - struct inet_hashinfo *hashinfo)
> +static inline int inet_twsk_unehash(struct inet_timewait_sock *tw,
> + struct inet_hashinfo *hashinfo)
> {
> - struct inet_bind_hashbucket *bhead;
> - struct inet_bind_bucket *tb;
> - /* Unlink from established hashes. */
> - struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, tw->tw_hash);
> + struct inet_ehash_bucket *ehead =
> + inet_ehash_bucket(hashinfo, tw->tw_hash);
>
> write_lock(&ehead->lock);
> - if (hlist_unhashed(&tw->tw_node)) {
> + if (__inet_twsk_unehash(tw)) {
> write_unlock(&ehead->lock);
> - return;
> + return 1;
> }
> - __hlist_del(&tw->tw_node);
> - sk_node_init(&tw->tw_node);
> write_unlock(&ehead->lock);
>
> - /* Disassociate with bind bucket. */
> + return 0;
> +}
as far as I can understand the code, it will look better as below
struct inet_ehash_bucket *ehead =
inet_ehash_bucket(hashinfo, tw->tw_hash);
int ret;
write_lock(&ehead->lock);
ret = __inet_twsk_unehash(tw);
write_unlock(&ehead->lock);
return ret;
> +
> +void inet_twsk_unbhash(struct inet_timewait_sock *tw,
> + struct inet_hashinfo *hashinfo)
> +{
> + struct inet_bind_hashbucket *bhead;
> + struct inet_bind_bucket *tb;
> +
> bhead = &hashinfo->bhash[inet_bhashfn(tw->tw_net, tw->tw_num, hashinfo->bhash_size)];
> spin_lock(&bhead->lock);
> tb = tw->tw_tb;
> @@ -39,6 +42,19 @@ static void __inet_twsk_kill(struct inet
> tw->tw_tb = NULL;
> inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
> spin_unlock(&bhead->lock);
> +}
> +
> +/* Must be called with locally disabled BHs. */
> +static void __inet_twsk_kill(struct inet_timewait_sock *tw,
> + struct inet_hashinfo *hashinfo)
> +{
> + /* Unlink from established hashes. */
> + if (inet_twsk_unehash(tw, hashinfo))
> + return;
> +
> + /* Disassociate with bind bucket. */
> + inet_twsk_unbhash(tw, hashinfo);
> +
> #ifdef SOCK_REFCNT_DEBUG
> if (atomic_read(&tw->tw_refcnt) != 1) {
> printk(KERN_DEBUG "%s timewait_sock %p refcnt=%d\n",
> Index: linux-2.6-netns/include/net/inet_timewait_sock.h
> ===================================================================
> --- linux-2.6-netns.orig/include/net/inet_timewait_sock.h
> +++ linux-2.6-netns/include/net/inet_timewait_sock.h
> @@ -173,6 +173,19 @@ static inline int inet_twsk_del_dead_nod
> return 0;
> }
>
> +static inline int __inet_twsk_unehash(struct inet_timewait_sock *tw)
> +{
> + if (hlist_unhashed(&tw->tw_node))
> + return 1;
> + __hlist_del(&tw->tw_node);
> + sk_node_init(&tw->tw_node);
> +
>> see above about inet_twsk_unehash. We should insert
/* Disassociate with bind bucket. */
>> here
> + return 0;
> +}
> +
> +extern void inet_twsk_unbhash(struct inet_timewait_sock *tw,
> + struct inet_hashinfo *hashinfo);
> +
> #define inet_twsk_for_each(tw, node, head) \
> hlist_for_each_entry(tw, node, head, tw_node)
>
>
next prev parent reply other threads:[~2007-09-27 12:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-27 11:04 [patch 0/3][NETNS45][V2] remove timewait sockets at namespace exit Daniel Lezcano
2007-09-27 11:04 ` [patch 1/3][NETNS45][V2] add a reference to the netns for timewait Daniel Lezcano
[not found] ` <20070927111208.092780734-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-09-27 12:34 ` Denis V. Lunev
2007-09-27 11:04 ` [patch 2/3][NETNS45][V2] make timewait unhash lock free Daniel Lezcano
[not found] ` <20070927111212.651097600-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-09-27 12:46 ` Denis V. Lunev [this message]
[not found] ` <46FBA624.2070203-3ImXcnM4P+0@public.gmane.org>
2007-09-27 13:09 ` Daniel Lezcano
[not found] ` <46FBAB6C.6010908-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-09-27 13:18 ` Denis V. Lunev
2007-09-27 11:04 ` [patch 3/3][NETNS45][V2] remove timewait sockets at cleanup Daniel Lezcano
[not found] ` <20070927111219.179053451-WECHFHqYCmGD/CxQmPlnQ0FT0OZdM7KVQQ4Iyu8u01E@public.gmane.org>
2007-09-27 13:22 ` Denis V. Lunev
[not found] ` <46FBAE9B.7030707-3ImXcnM4P+0@public.gmane.org>
2007-09-27 14:38 ` Daniel Lezcano
[not found] ` <46FBC058.8020003-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-09-28 6:47 ` Denis V. Lunev
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=46FBA624.2070203@sw.ru \
--to=den-3imxcnm4p+0@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
--cc=dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.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