Skip to content

Commit 10cbc8f

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp/dccp: remove struct listen_sock
It is enough to check listener sk_state, no need for an extra condition. max_qlen_log can be moved into struct request_sock_queue We can remove syn_wait_lock and the alignment it enforced. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ca6fb06 commit 10cbc8f

File tree

3 files changed

+11
-76
lines changed

3 files changed

+11
-76
lines changed

include/net/request_sock.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ static inline void reqsk_put(struct request_sock *req)
119119

120120
extern int sysctl_max_syn_backlog;
121121

122-
/** struct listen_sock - listen state
123-
*
124-
* @max_qlen_log - log_2 of maximal queued SYNs/REQUESTs
125-
*/
126-
struct listen_sock {
127-
u32 max_qlen_log;
128-
};
129-
130122
/*
131123
* For a TCP Fast Open listener -
132124
* lock - protects the access to all the reqsk, which is co-owned by
@@ -160,36 +152,26 @@ struct fastopen_queue {
160152
* @rskq_accept_head - FIFO head of established children
161153
* @rskq_accept_tail - FIFO tail of established children
162154
* @rskq_defer_accept - User waits for some data after accept()
163-
* @syn_wait_lock - serializer
164-
*
165-
* %syn_wait_lock is necessary only to avoid proc interface having to grab the main
166-
* lock sock while browsing the listening hash (otherwise it's deadlock prone).
167155
*
168156
*/
169157
struct request_sock_queue {
170158
spinlock_t rskq_lock;
171159
u8 rskq_defer_accept;
160+
u8 max_qlen_log;
172161
u32 synflood_warned;
173-
174162
atomic_t qlen;
175163
atomic_t young;
176164

177165
struct request_sock *rskq_accept_head;
178166
struct request_sock *rskq_accept_tail;
179-
struct listen_sock *listen_opt;
180167
struct fastopen_queue fastopenq; /* Check max_qlen != 0 to determine
181168
* if TFO is enabled.
182169
*/
183-
184-
/* temporary alignment, our goal is to get rid of this lock */
185-
spinlock_t syn_wait_lock ____cacheline_aligned_in_smp;
186170
};
187171

188-
int reqsk_queue_alloc(struct request_sock_queue *queue,
189-
unsigned int nr_table_entries);
172+
void reqsk_queue_alloc(struct request_sock_queue *queue,
173+
unsigned int nr_table_entries);
190174

191-
void __reqsk_queue_destroy(struct request_sock_queue *queue);
192-
void reqsk_queue_destroy(struct request_sock_queue *queue);
193175
void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
194176
bool reset);
195177

@@ -260,7 +242,7 @@ static inline int reqsk_queue_len_young(const struct request_sock_queue *queue)
260242

261243
static inline int reqsk_queue_is_full(const struct request_sock_queue *queue)
262244
{
263-
return reqsk_queue_len(queue) >> queue->listen_opt->max_qlen_log;
245+
return reqsk_queue_len(queue) >> queue->max_qlen_log;
264246
}
265247

266248
#endif /* _REQUEST_SOCK_H */

net/core/request_sock.c

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,14 @@
3737
int sysctl_max_syn_backlog = 256;
3838
EXPORT_SYMBOL(sysctl_max_syn_backlog);
3939

40-
int reqsk_queue_alloc(struct request_sock_queue *queue,
41-
unsigned int nr_table_entries)
40+
void reqsk_queue_alloc(struct request_sock_queue *queue,
41+
unsigned int nr_table_entries)
4242
{
43-
size_t lopt_size = sizeof(struct listen_sock);
44-
struct listen_sock *lopt = NULL;
45-
4643
nr_table_entries = min_t(u32, nr_table_entries, sysctl_max_syn_backlog);
4744
nr_table_entries = max_t(u32, nr_table_entries, 8);
4845
nr_table_entries = roundup_pow_of_two(nr_table_entries + 1);
4946

50-
lopt = kzalloc(lopt_size, GFP_KERNEL);
51-
if (!lopt)
52-
return -ENOMEM;
53-
5447
spin_lock_init(&queue->rskq_lock);
55-
spin_lock_init(&queue->syn_wait_lock);
5648

5749
spin_lock_init(&queue->fastopenq.lock);
5850
queue->fastopenq.rskq_rst_head = NULL;
@@ -61,40 +53,7 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
6153
queue->fastopenq.max_qlen = 0;
6254

6355
queue->rskq_accept_head = NULL;
64-
lopt->max_qlen_log = ilog2(nr_table_entries);
65-
66-
spin_lock_bh(&queue->syn_wait_lock);
67-
queue->listen_opt = lopt;
68-
spin_unlock_bh(&queue->syn_wait_lock);
69-
70-
return 0;
71-
}
72-
73-
void __reqsk_queue_destroy(struct request_sock_queue *queue)
74-
{
75-
/* This is an error recovery path only, no locking needed */
76-
kfree(queue->listen_opt);
77-
}
78-
79-
static inline struct listen_sock *reqsk_queue_yank_listen_sk(
80-
struct request_sock_queue *queue)
81-
{
82-
struct listen_sock *lopt;
83-
84-
spin_lock_bh(&queue->syn_wait_lock);
85-
lopt = queue->listen_opt;
86-
queue->listen_opt = NULL;
87-
spin_unlock_bh(&queue->syn_wait_lock);
88-
89-
return lopt;
90-
}
91-
92-
void reqsk_queue_destroy(struct request_sock_queue *queue)
93-
{
94-
struct listen_sock *lopt = reqsk_queue_yank_listen_sk(queue);
95-
96-
/* cleaning is done by req timers */
97-
kfree(lopt);
56+
queue->max_qlen_log = ilog2(nr_table_entries);
9857
}
9958

10059
/*

net/ipv4/inet_connection_sock.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,11 @@ static void reqsk_timer_handler(unsigned long data)
552552
struct sock *sk_listener = req->rsk_listener;
553553
struct inet_connection_sock *icsk = inet_csk(sk_listener);
554554
struct request_sock_queue *queue = &icsk->icsk_accept_queue;
555-
struct listen_sock *lopt = queue->listen_opt;
556555
int qlen, expire = 0, resend = 0;
557556
int max_retries, thresh;
558557
u8 defer_accept;
559558

560-
if (sk_listener->sk_state != TCP_LISTEN || !lopt)
559+
if (sk_listener->sk_state != TCP_LISTEN)
561560
goto drop;
562561

563562
max_retries = icsk->icsk_syn_retries ? : sysctl_tcp_synack_retries;
@@ -580,7 +579,7 @@ static void reqsk_timer_handler(unsigned long data)
580579
* ones are about to clog our table.
581580
*/
582581
qlen = reqsk_queue_len(queue);
583-
if (qlen >> (lopt->max_qlen_log - 1)) {
582+
if (qlen >> (queue->max_qlen_log - 1)) {
584583
int young = reqsk_queue_len_young(queue) << 1;
585584

586585
while (thresh > 2) {
@@ -730,12 +729,10 @@ EXPORT_SYMBOL(inet_csk_prepare_forced_close);
730729

731730
int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
732731
{
733-
struct inet_sock *inet = inet_sk(sk);
734732
struct inet_connection_sock *icsk = inet_csk(sk);
735-
int rc = reqsk_queue_alloc(&icsk->icsk_accept_queue, nr_table_entries);
733+
struct inet_sock *inet = inet_sk(sk);
736734

737-
if (rc != 0)
738-
return rc;
735+
reqsk_queue_alloc(&icsk->icsk_accept_queue, nr_table_entries);
739736

740737
sk->sk_max_ack_backlog = 0;
741738
sk->sk_ack_backlog = 0;
@@ -757,7 +754,6 @@ int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
757754
}
758755

759756
sk->sk_state = TCP_CLOSE;
760-
__reqsk_queue_destroy(&icsk->icsk_accept_queue);
761757
return -EADDRINUSE;
762758
}
763759
EXPORT_SYMBOL_GPL(inet_csk_listen_start);
@@ -780,8 +776,6 @@ void inet_csk_listen_stop(struct sock *sk)
780776
* To be honest, we are not able to make either
781777
* of the variants now. --ANK
782778
*/
783-
reqsk_queue_destroy(queue);
784-
785779
while ((req = reqsk_queue_remove(queue, sk)) != NULL) {
786780
struct sock *child = req->sk;
787781

0 commit comments

Comments
 (0)