From: Eric Dumazet <dada1@cosmosbay.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH] NET : keep sk_backlog near sk_lock
Date: Thu, 22 Feb 2007 15:50:15 +0100 [thread overview]
Message-ID: <200702221550.15280.dada1@cosmosbay.com> (raw)
In-Reply-To: <200702221122.02806.dada1@cosmosbay.com>
[-- Attachment #1: Type: text/plain, Size: 616 bytes --]
Hi David
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 :) )
Thank you
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: sk_backlog.patch --]
[-- Type: text/plain, Size: 1829 bytes --]
--- linux/include/net/sock.h 2007-02-22 16:21:36.000000000 +0100
+++ linux-ed/include/net/sock.h 2007-02-22 16:21:36.000000000 +0100
@@ -202,6 +202,15 @@ struct sock {
unsigned short sk_type;
int sk_rcvbuf;
socket_lock_t sk_lock;
+ /*
+ * The backlog queue is special, it is always used with
+ * the per-socket spinlock held and requires low latency
+ * access. Therefore we special case it's implementation.
+ */
+ struct {
+ struct sk_buff *head;
+ struct sk_buff *tail;
+ } sk_backlog;
wait_queue_head_t *sk_sleep;
struct dst_entry *sk_dst_cache;
struct xfrm_policy *sk_policy[2];
@@ -221,15 +230,6 @@ struct sock {
int sk_rcvlowat;
unsigned long sk_flags;
unsigned long sk_lingertime;
- /*
- * The backlog queue is special, it is always used with
- * the per-socket spinlock held and requires low latency
- * access. Therefore we special case it's implementation.
- */
- struct {
- struct sk_buff *head;
- struct sk_buff *tail;
- } sk_backlog;
struct sk_buff_head sk_error_queue;
struct proto *sk_prot_creator;
rwlock_t sk_callback_lock;
--- linux/net/core/sock.c 2007-02-22 16:21:36.000000000 +0100
+++ linux-ed/net/core/sock.c 2007-02-22 16:21:36.000000000 +0100
@@ -904,6 +904,7 @@ struct sock *sk_clone(const struct sock
sk_node_init(&newsk->sk_node);
sock_lock_init(newsk);
bh_lock_sock(newsk);
+ newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
atomic_set(&newsk->sk_rmem_alloc, 0);
atomic_set(&newsk->sk_wmem_alloc, 0);
@@ -923,7 +924,6 @@ struct sock *sk_clone(const struct sock
newsk->sk_wmem_queued = 0;
newsk->sk_forward_alloc = 0;
newsk->sk_send_head = NULL;
- newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL;
newsk->sk_userlocks = sk->sk_userlocks & ~SOCK_BINDPORT_LOCK;
sock_reset_flag(newsk, SOCK_DONE);
next prev parent reply other threads:[~2007-02-22 14:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-15 23:46 [PATCH] Use random32() in net/ipv4/multipath Joe Perches
2007-02-22 9:26 ` David Miller
2007-02-22 10:22 ` [PATCH] TCP : keep copied_seq, rcv_wup and rcv_next together Eric Dumazet
2007-02-22 10:32 ` David Miller
2007-02-22 10:43 ` Eric Dumazet
2007-02-22 11:02 ` David Miller
2007-02-22 11:11 ` [PATCH, take 2] " Eric Dumazet
2007-02-22 11:22 ` David Miller
2007-02-22 14:50 ` Eric Dumazet [this message]
2007-03-05 0:05 ` [PATCH] NET : keep sk_backlog near sk_lock David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200702221550.15280.dada1@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).