Skip to content

Commit 24dd1fa

Browse files
Eric Dumazetdavem330
authored andcommitted
net: move bsockets outside of read only beginning of struct inet_hashinfo
And switch bsockets to atomic_t since it might be changed in parallel. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5add300 commit 24dd1fa

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎include/net/inet_hashtables.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct inet_hashinfo {
134134
struct inet_bind_hashbucket *bhash;
135135

136136
unsigned int bhash_size;
137-
int bsockets;
137+
/* 4 bytes hole on 64 bit */
138138

139139
struct kmem_cache *bind_bucket_cachep;
140140

@@ -151,6 +151,7 @@ struct inet_hashinfo {
151151
struct inet_listen_hashbucket listening_hash[INET_LHTABLE_SIZE]
152152
____cacheline_aligned_in_smp;
153153

154+
atomic_t bsockets;
154155
};
155156

156157
static inline struct inet_ehash_bucket *inet_ehash_bucket(

‎net/ipv4/inet_connection_sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
119119
(tb->num_owners < smallest_size || smallest_size == -1)) {
120120
smallest_size = tb->num_owners;
121121
smallest_rover = rover;
122-
if (hashinfo->bsockets > (high - low) + 1) {
122+
if (atomic_read(&hashinfo->bsockets) > (high - low) + 1) {
123123
spin_unlock(&head->lock);
124124
snum = smallest_rover;
125125
goto have_snum;

‎net/ipv4/inet_hashtables.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
6262
{
6363
struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
6464

65-
hashinfo->bsockets++;
65+
atomic_inc(&hashinfo->bsockets);
6666

6767
inet_sk(sk)->num = snum;
6868
sk_add_bind_node(sk, &tb->owners);
@@ -81,7 +81,7 @@ static void __inet_put_port(struct sock *sk)
8181
struct inet_bind_hashbucket *head = &hashinfo->bhash[bhash];
8282
struct inet_bind_bucket *tb;
8383

84-
hashinfo->bsockets--;
84+
atomic_dec(&hashinfo->bsockets);
8585

8686
spin_lock(&head->lock);
8787
tb = inet_csk(sk)->icsk_bind_hash;
@@ -532,6 +532,7 @@ void inet_hashinfo_init(struct inet_hashinfo *h)
532532
{
533533
int i;
534534

535+
atomic_set(&h->bsockets, 0);
535536
for (i = 0; i < INET_LHTABLE_SIZE; i++) {
536537
spin_lock_init(&h->listening_hash[i].lock);
537538
INIT_HLIST_NULLS_HEAD(&h->listening_hash[i].head,

0 commit comments

Comments
 (0)