Skip to content

Commit 81b496b

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp/dccp: shrink struct listen_sock
We no longer use hash_rnd, nr_table_entries and syn_table[] For a listener with a backlog of 10 millions sockets, this saves 80 MBytes of vmalloced memory. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 079096f commit 81b496b

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

include/net/request_sock.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ extern int sysctl_max_syn_backlog;
125125
*/
126126
struct listen_sock {
127127
u32 max_qlen_log;
128-
u32 hash_rnd;
129-
u32 nr_table_entries;
130-
struct request_sock *syn_table[0];
131128
};
132129

133130
/*

net/core/request_sock.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,11 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
4646
nr_table_entries = min_t(u32, nr_table_entries, sysctl_max_syn_backlog);
4747
nr_table_entries = max_t(u32, nr_table_entries, 8);
4848
nr_table_entries = roundup_pow_of_two(nr_table_entries + 1);
49-
lopt_size += nr_table_entries * sizeof(struct request_sock *);
5049

51-
if (lopt_size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
52-
lopt = kzalloc(lopt_size, GFP_KERNEL |
53-
__GFP_NOWARN |
54-
__GFP_NORETRY);
55-
if (!lopt)
56-
lopt = vzalloc(lopt_size);
50+
lopt = kzalloc(lopt_size, GFP_KERNEL);
5751
if (!lopt)
5852
return -ENOMEM;
5953

60-
get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd));
6154
spin_lock_init(&queue->rskq_lock);
6255
spin_lock_init(&queue->syn_wait_lock);
6356

@@ -68,7 +61,6 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
6861
queue->fastopenq.max_qlen = 0;
6962

7063
queue->rskq_accept_head = NULL;
71-
lopt->nr_table_entries = nr_table_entries;
7264
lopt->max_qlen_log = ilog2(nr_table_entries);
7365

7466
spin_lock_bh(&queue->syn_wait_lock);
@@ -81,7 +73,7 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
8173
void __reqsk_queue_destroy(struct request_sock_queue *queue)
8274
{
8375
/* This is an error recovery path only, no locking needed */
84-
kvfree(queue->listen_opt);
76+
kfree(queue->listen_opt);
8577
}
8678

8779
static inline struct listen_sock *reqsk_queue_yank_listen_sk(
@@ -102,7 +94,7 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
10294
struct listen_sock *lopt = reqsk_queue_yank_listen_sk(queue);
10395

10496
/* cleaning is done by req timers */
105-
kvfree(lopt);
97+
kfree(lopt);
10698
}
10799

108100
/*

0 commit comments

Comments
 (0)