* [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers
@ 2017-06-26 17:01 Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 1/2] udp: move scratch area helpers into the include file Paolo Abeni
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paolo Abeni @ 2017-06-26 17:01 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Eric Dumazet
When bringing in the recent cache optimization for the UDP protocol, I forgot
to leverage the newly introduced scratched area helpers in the UDPv6 code path.
As a result, the UDPv6 implementation suffers some unnecessary performance
penality when compared to v4.
This series aim to bring back UDPv6 on equal footing in respect to v4.
The first patch moves the shared helpers to the common include files, while
the second uses them in the UDPv6 code.
This gives 5-8% performance improvement for a system under flood with small
UDPv6 packets. The performance delta is less than the one reported on the
original patch set because the UDPv6 code path already leveraged some of the
optimization.
Paolo Abeni (2):
udp: move scratch area helpers into the include file
ipv6: udp: leverage scratch area helpers
include/net/udp.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
net/ipv4/udp.c | 60 ------------------------------------------------------
net/ipv6/udp.c | 14 ++++++++-----
3 files changed, 70 insertions(+), 65 deletions(-)
--
2.9.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next 1/2] udp: move scratch area helpers into the include file
2017-06-26 17:01 [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers Paolo Abeni
@ 2017-06-26 17:01 ` Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 2/2] ipv6: udp: leverage scratch area helpers Paolo Abeni
2017-06-27 19:44 ` [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Abeni @ 2017-06-26 17:01 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Eric Dumazet
So that they can be later used by the IPv6 code, too.
Also lift the comments a bit.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
include/net/udp.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
net/ipv4/udp.c | 60 ------------------------------------------------------
2 files changed, 61 insertions(+), 60 deletions(-)
diff --git a/include/net/udp.h b/include/net/udp.h
index 1468dbd..972ce4b 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -302,6 +302,67 @@ struct sock *__udp6_lib_lookup(struct net *net,
struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
__be16 sport, __be16 dport);
+/* UDP uses skb->dev_scratch to cache as much information as possible and avoid
+ * possibly multiple cache miss on dequeue()
+ */
+#if BITS_PER_LONG == 64
+
+/* truesize, len and the bit needed to compute skb_csum_unnecessary will be on
+ * cold cache lines at recvmsg time.
+ * skb->len can be stored on 16 bits since the udp header has been already
+ * validated and pulled.
+ */
+struct udp_dev_scratch {
+ u32 truesize;
+ u16 len;
+ bool is_linear;
+ bool csum_unnecessary;
+};
+
+static inline unsigned int udp_skb_len(struct sk_buff *skb)
+{
+ return ((struct udp_dev_scratch *)&skb->dev_scratch)->len;
+}
+
+static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
+{
+ return ((struct udp_dev_scratch *)&skb->dev_scratch)->csum_unnecessary;
+}
+
+static inline bool udp_skb_is_linear(struct sk_buff *skb)
+{
+ return ((struct udp_dev_scratch *)&skb->dev_scratch)->is_linear;
+}
+
+#else
+static inline unsigned int udp_skb_len(struct sk_buff *skb)
+{
+ return skb->len;
+}
+
+static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
+{
+ return skb_csum_unnecessary(skb);
+}
+
+static inline bool udp_skb_is_linear(struct sk_buff *skb)
+{
+ return !skb_is_nonlinear(skb);
+}
+#endif
+
+static inline int copy_linear_skb(struct sk_buff *skb, int len, int off,
+ struct iov_iter *to)
+{
+ int n, copy = len - off;
+
+ n = copy_to_iter(skb->data + off, copy, to);
+ if (n == copy)
+ return 0;
+
+ return -EFAULT;
+}
+
/*
* SNMP statistics for UDP and UDP-Lite
*/
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 47c7aa0..86fad2a 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1163,24 +1163,7 @@ int udp_sendpage(struct sock *sk, struct page *page, int offset,
return ret;
}
-/* Copy as much information as possible into skb->dev_scratch to avoid
- * possibly multiple cache miss on dequeue();
- */
#if BITS_PER_LONG == 64
-
-/* we can store multiple info here: truesize, len and the bit needed to
- * compute skb_csum_unnecessary will be on cold cache lines at recvmsg
- * time.
- * skb->len can be stored on 16 bits since the udp header has been already
- * validated and pulled.
- */
-struct udp_dev_scratch {
- u32 truesize;
- u16 len;
- bool is_linear;
- bool csum_unnecessary;
-};
-
static void udp_set_dev_scratch(struct sk_buff *skb)
{
struct udp_dev_scratch *scratch;
@@ -1197,22 +1180,6 @@ static int udp_skb_truesize(struct sk_buff *skb)
{
return ((struct udp_dev_scratch *)&skb->dev_scratch)->truesize;
}
-
-static unsigned int udp_skb_len(struct sk_buff *skb)
-{
- return ((struct udp_dev_scratch *)&skb->dev_scratch)->len;
-}
-
-static bool udp_skb_csum_unnecessary(struct sk_buff *skb)
-{
- return ((struct udp_dev_scratch *)&skb->dev_scratch)->csum_unnecessary;
-}
-
-static bool udp_skb_is_linear(struct sk_buff *skb)
-{
- return ((struct udp_dev_scratch *)&skb->dev_scratch)->is_linear;
-}
-
#else
static void udp_set_dev_scratch(struct sk_buff *skb)
{
@@ -1223,21 +1190,6 @@ static int udp_skb_truesize(struct sk_buff *skb)
{
return skb->dev_scratch;
}
-
-static unsigned int udp_skb_len(struct sk_buff *skb)
-{
- return skb->len;
-}
-
-static bool udp_skb_csum_unnecessary(struct sk_buff *skb)
-{
- return skb_csum_unnecessary(skb);
-}
-
-static bool udp_skb_is_linear(struct sk_buff *skb)
-{
- return !skb_is_nonlinear(skb);
-}
#endif
/* fully reclaim rmem/fwd memory allocated for skb */
@@ -1598,18 +1550,6 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
}
EXPORT_SYMBOL_GPL(__skb_recv_udp);
-static int copy_linear_skb(struct sk_buff *skb, int len, int off,
- struct iov_iter *to)
-{
- int n, copy = len - off;
-
- n = copy_to_iter(skb->data + off, copy, to);
- if (n == copy)
- return 0;
-
- return -EFAULT;
-}
-
/*
* This should be easy, if there is something there we
* return it, otherwise we block.
--
2.9.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] ipv6: udp: leverage scratch area helpers
2017-06-26 17:01 [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 1/2] udp: move scratch area helpers into the include file Paolo Abeni
@ 2017-06-26 17:01 ` Paolo Abeni
2017-06-27 19:44 ` [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Abeni @ 2017-06-26 17:01 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Eric Dumazet
The commit b65ac44674dd ("udp: try to avoid 2 cache miss on dequeue")
leveraged the scratched area helpers for UDP v4 but I forgot to
update accordingly the IPv6 code path.
This change extends the scratch area usage to the IPv6 code, synching
the two implementations and giving some performance benefit.
IPv6 is again almost on the same level of IPv4, performance-wide.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
net/ipv6/udp.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index d1d7288..450829d 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -362,7 +362,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (!skb)
return err;
- ulen = skb->len;
+ ulen = udp_skb_len(skb);
copied = len;
if (copied > ulen - off)
copied = ulen - off;
@@ -379,14 +379,18 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (copied < ulen || peeking ||
(is_udplite && UDP_SKB_CB(skb)->partial_cov)) {
- checksum_valid = !udp_lib_checksum_complete(skb);
+ checksum_valid = udp_skb_csum_unnecessary(skb) ||
+ !__udp_lib_checksum_complete(skb);
if (!checksum_valid)
goto csum_copy_err;
}
- if (checksum_valid || skb_csum_unnecessary(skb))
- err = skb_copy_datagram_msg(skb, off, msg, copied);
- else {
+ if (checksum_valid || udp_skb_csum_unnecessary(skb)) {
+ if (udp_skb_is_linear(skb))
+ err = copy_linear_skb(skb, copied, off, &msg->msg_iter);
+ else
+ err = skb_copy_datagram_msg(skb, off, msg, copied);
+ } else {
err = skb_copy_and_csum_datagram_msg(skb, off, msg);
if (err == -EINVAL)
goto csum_copy_err;
--
2.9.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers
2017-06-26 17:01 [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 1/2] udp: move scratch area helpers into the include file Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 2/2] ipv6: udp: leverage scratch area helpers Paolo Abeni
@ 2017-06-27 19:44 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-06-27 19:44 UTC (permalink / raw)
To: pabeni; +Cc: netdev, edumazet
From: Paolo Abeni <pabeni@redhat.com>
Date: Mon, 26 Jun 2017 19:01:49 +0200
> When bringing in the recent cache optimization for the UDP protocol, I forgot
> to leverage the newly introduced scratched area helpers in the UDPv6 code path.
> As a result, the UDPv6 implementation suffers some unnecessary performance
> penality when compared to v4.
>
> This series aim to bring back UDPv6 on equal footing in respect to v4.
> The first patch moves the shared helpers to the common include files, while
> the second uses them in the UDPv6 code.
>
> This gives 5-8% performance improvement for a system under flood with small
> UDPv6 packets. The performance delta is less than the one reported on the
> original patch set because the UDPv6 code path already leveraged some of the
> optimization.
Series applied, thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-27 19:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-26 17:01 [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 1/2] udp: move scratch area helpers into the include file Paolo Abeni
2017-06-26 17:01 ` [PATCH net-next 2/2] ipv6: udp: leverage scratch area helpers Paolo Abeni
2017-06-27 19:44 ` [PATCH net-next 0/2] ipv6: udp: exploit dev_scratch helpers David Miller
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).