Skip to content

Commit fa438cc

Browse files
Eric DumazetDavid S. Miller
authored andcommitted
[NET]: Keep sk_backlog near sk_lock
sk_backlog is a critical field of struct sock. (known famous words) It is (ab)used in hot paths, in particular in release_sock(), tcp_recvmsg(), tcp_v4_rcv(), sk_receive_skb(). It really makes sense to place it next to sk_lock, because sk_backlog is only used after sk_lock locked (and thus memory cache line in L1 cache). This should reduce cache misses and sk_lock acquisition time. (In theory, we could only move the head pointer near sk_lock, and leaving tail far away, because 'tail' is normally not so hot, but keep it simple :) ) Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e317f6f commit fa438cc

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎include/net/sock.h‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ struct sock {
202202
unsigned short sk_type;
203203
int sk_rcvbuf;
204204
socket_lock_t sk_lock;
205+
/*
206+
* The backlog queue is special, it is always used with
207+
* the per-socket spinlock held and requires low latency
208+
* access. Therefore we special case it's implementation.
209+
*/
210+
struct {
211+
struct sk_buff *head;
212+
struct sk_buff *tail;
213+
} sk_backlog;
205214
wait_queue_head_t *sk_sleep;
206215
struct dst_entry *sk_dst_cache;
207216
struct xfrm_policy *sk_policy[2];
@@ -221,15 +230,6 @@ struct sock {
221230
int sk_rcvlowat;
222231
unsigned long sk_flags;
223232
unsigned long sk_lingertime;
224-
/*
225-
* The backlog queue is special, it is always used with
226-
* the per-socket spinlock held and requires low latency
227-
* access. Therefore we special case it's implementation.
228-
*/
229-
struct {
230-
struct sk_buff *head;
231-
struct sk_buff *tail;
232-
} sk_backlog;
233233
struct sk_buff_head sk_error_queue;
234234
struct proto *sk_prot_creator;
235235
rwlock_t sk_callback_lock;

‎net/core/sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
904904
sk_node_init(&newsk->sk_node);
905905
sock_lock_init(newsk);
906906
bh_lock_sock(newsk);
907+
newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
907908

908909
atomic_set(&newsk->sk_rmem_alloc, 0);
909910
atomic_set(&newsk->sk_wmem_alloc, 0);
@@ -923,7 +924,6 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
923924
newsk->sk_wmem_queued = 0;
924925
newsk->sk_forward_alloc = 0;
925926
newsk->sk_send_head = NULL;
926-
newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
927927
newsk->sk_userlocks = sk->sk_userlocks & ~SOCK_BINDPORT_LOCK;
928928

929929
sock_reset_flag(newsk, SOCK_DONE);

0 commit comments

Comments
 (0)