Skip to contentSkip to conversation

net-next: Fix __inet_inherit_port() to correctly increment bsockets and num_owners

PATCH In review Nagendra Tomar 5 participants 10 messages Nov 27, 2010 – Nov 29, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net-next: Fix __inet_inherit_port() to correctly increment bsockets and num_owners

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

---

net/ipv4/inet_hashtables.c renamed from net/ipv4/inet_hashtables.c.orig +1 -2
@@ -133,8 +133,7 @@ int __inet_inherit_port(struct sock *sk,
 			}
 		}
 	}
-	sk_add_bind_node(child, &tb->owners);
-	inet_csk(child)->icsk_bind_hash = tb;
+	inet_bind_hash(child, tb, port);
 	spin_unlock(&head->lock);
 
 	return 0;

---

Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Nagendra Tomar

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

---

net/ipv4/inet_hashtables.c int __inet_inherit_port(struct sock *sk, · line 139

Quoted 9 lines
net/ipv4/inet_hashtables.c renamed from net/ipv4/inet_hashtables.c.orig +1 -2
@@ -133,8 +133,7 @@ int __inet_inherit_port(struct sock *sk,
 			}
 		}
 	}
-	sk_add_bind_node(child, &tb->owners);
-	inet_csk(child)->icsk_bind_hash = tb;
+	inet_bind_hash(child, tb, port);
 	spin_unlock(&head->lock);
 
 	return 0;

Thanks !

#2 lore raw
In reply to Nagendra Tomar

Hi.

Quoted 7 lines · Nagendra Tomar

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

Quoted 5 lines

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

Yup, things changed from that simple patch a lot.
Thanks for fixing it up.
Ack.

Signature · 1 line
	Evgeniy Polyakov
maintainer
#3 lore raw

From: Evgeniy Polyakov <[email protected]>
Date: Mon, 29 Nov 2010 02:00:41 +0300

Quoted 13 lines

Hi.

Quoted 10 lines · Nagendra Tomar

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

Quoted 6 lines
Quoted 2 lines

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

Yup, things changed from that simple patch a lot.
Thanks for fixing it up.
Ack.

I've decided to apply this to net-2.6, thanks everyone.

#4 lore raw
In reply to Evgeniy Polyakov
Quoted 13 lines · Evgeniy Polyakov

Hi.

Quoted 10 lines · Nagendra Tomar

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

Quoted 6 lines
Quoted 2 lines

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

Yup, things changed from that simple patch a lot.
Thanks for fixing it up.
Ack.

Probably I miss something, but since bsockets is increased by each passive connection now, it seems it will trigger "hash table is full" too early?

Jarek P.

#5 lore raw
Quoted 4 lines · Jarek Poplawski

Probably I miss something, but since bsockets is increased by each passive connection now, it seems it will trigger "hash table is full" too early?

bsockets is the number of bound sockets.

It must be increased for each passive connection, since they are bound :)

The value of bsockets is used to speedup bind() syscall, if few sockets are bound. If not, no optimization takes place.

#6 lore raw
In reply to Jarek Poplawski
Quoted 13 lines · Jarek Poplawski
Quoted 13 lines
Quoted 12 lines

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

Quoted 7 lines
Quoted 3 lines

Yup, things changed from that simple patch a lot.
Thanks for fixing it up.
Ack.

Probably I miss something, but since bsockets is increased by each passive connection now, it seems it will trigger "hash table is full" too early?

Why would it? bsockets and num_owners are supposed to be increased for each new socket added into the table, and are used as a hint to find a bucket with the smallest number of sockets in it.

Hash table insertion did not change, only bucket selection algorithm got a hint.

Signature · 1 line
	Evgeniy Polyakov
#7 lore raw
Quoted 22 lines · Evgeniy Polyakov
Quoted 13 lines · Jarek Poplawski
Quoted 13 lines
Quoted 12 lines

inet sockets corresponding to passive connections are added to the bind hash using ___inet_inherit_port(). These sockets are later removed from the bind hash using __inet_put_port(). These two functions are not exactly symmetrical. __inet_put_port() decrements hashinfo->bsockets and tb->num_owners, whereas ___inet_inherit_port() does not increment them. This results in both of these going to -ve values.

This patch fixes this by calling inet_bind_hash() from ___inet_inherit_port(), which does the right thing.

'bsockets' and 'num_owners' were introduced by commit a9d8f9110d7e953c (inet: Allowing more than 64k connections and heavily optimize bind(0))

Quoted 7 lines
Quoted 3 lines

Yup, things changed from that simple patch a lot.
Thanks for fixing it up.
Ack.

Probably I miss something, but since bsockets is increased by each passive connection now, it seems it will trigger "hash table is full" too early?

Quoted 6 lines

Why would it? bsockets and num_owners are supposed to be increased for each new socket added into the table, and are used as a hint to find a bucket with the smallest number of sockets in it.

Hash table insertion did not change, only bucket selection algorithm got a hint.

Evgeniy & Eric,

But it's compared to the numer of available port numbers in inet_csk_get_port():

     "if (atomic_read(&hashinfo->bsockets) > (high - low) + 1)"

Can't you have bsockets higher than this with only one port used?

Jarek P.

#8 lore raw
Quoted 9 lines · Jarek Poplawski

Evgeniy & Eric,

But it's compared to the numer of available port numbers in inet_csk_get_port():

     "if (atomic_read(&hashinfo->bsockets) > (high - low) + 1)"

Can't you have bsockets higher than this with only one port used?

Because we store tuples, not only port information.

You can have many sockets bound on a single port.

This 'optimization' was only meaningful on a machine you make only active connections, if you ask me...

Problem is, as soon as some passive connections are done, bsockets count becomes wrong. The patch fixes this, thats all.

#9 lore raw
Quoted 3 lines · Eric Dumazet
Quoted 1 line · Jarek Poplawski

Evgeniy & Eric,

Eric & Evgeniy ;-)

Quoted 8 lines
Quoted 7 lines

But it's compared to the numer of available port numbers in inet_csk_get_port():

     "if (atomic_read(&hashinfo->bsockets) > (high - low) + 1)"

Can't you have bsockets higher than this with only one port used?

Quoted 6 lines

Because we store tuples, not only port information.

You can have many sockets bound on a single port.

This 'optimization' was only meaningful on a machine you make only active connections, if you ask me...

That's what I've missed...

Quoted 2 lines

Problem is, as soon as some passive connections are done, bsockets count becomes wrong. The patch fixes this, thats all.

Sure, the numbers are correct now. I wondered about this optimization only.

Thanks for explanations,
Jarek P.