All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] gro: a couple of minor optimization
@ 2022-02-04 11:28 Paolo Abeni
  2022-02-04 11:28 ` [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle Paolo Abeni
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Paolo Abeni @ 2022-02-04 11:28 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin, Eric Dumazet,
	Alexander H Duyck

This series collects a couple of small optimizations for the GRO engine,
reducing slightly the number of cycles for dev_gro_receive().
The delta is within noise range in tput tests, but with big TCP coming
every cycle saved from the GRO engine will count - I hope ;)

v1 -> v2:
 - a few cleanup suggested from Alexander(s)
 - moved away the more controversial 3rd patch

Paolo Abeni (2):
  net: gro: avoid re-computing truesize twice on recycle
  net: gro: minor optimization for dev_gro_receive()

 include/net/gro.h | 52 +++++++++++++++++++++++++----------------------
 net/core/gro.c    | 16 ++++-----------
 2 files changed, 32 insertions(+), 36 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle
  2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
@ 2022-02-04 11:28 ` Paolo Abeni
  2022-02-04 16:34   ` Eric Dumazet
  2022-02-04 11:28 ` [PATCH net-next 2/2] net: gro: minor optimization for dev_gro_receive() Paolo Abeni
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Paolo Abeni @ 2022-02-04 11:28 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin, Eric Dumazet,
	Alexander H Duyck

After commit 5e10da5385d2 ("skbuff: allow 'slow_gro' for skb
carring sock reference") and commit af352460b465 ("net: fix GRO
skb truesize update") the truesize of the skb with stolen head is
properly updated by the GRO engine, we don't need anymore resetting
it at recycle time.

v1 -> v2:
 - clarify the commit message (Alexander)

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/core/gro.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/core/gro.c b/net/core/gro.c
index a11b286d1495..d43d42215bdb 100644
--- a/net/core/gro.c
+++ b/net/core/gro.c
@@ -634,7 +634,6 @@ static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
 
 	skb->encapsulation = 0;
 	skb_shinfo(skb)->gso_type = 0;
-	skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
 	if (unlikely(skb->slow_gro)) {
 		skb_orphan(skb);
 		skb_ext_reset(skb);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next 2/2] net: gro: minor optimization for dev_gro_receive()
  2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
  2022-02-04 11:28 ` [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle Paolo Abeni
@ 2022-02-04 11:28 ` Paolo Abeni
  2022-02-04 11:34 ` [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Paolo Abeni @ 2022-02-04 11:28 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin, Eric Dumazet,
	Alexander H Duyck

While inspecting some perf report, I noticed that the compiler
emits suboptimal code for the napi CB initialization, fetching
and storing multiple times the memory for flags bitfield.
This is with gcc 10.3.1, but I observed the same with older compiler
versions.

We can help the compiler to do a nicer work clearing several
fields at once using an u32 alias. The generated code is quite
smaller, with the same number of conditional.

Before:
objdump -t net/core/gro.o | grep " F .text"
0000000000000bb0 l     F .text	0000000000000357 dev_gro_receive

After:
0000000000000bb0 l     F .text	000000000000033c dev_gro_receive

v1  -> v2:
 - use struct_group (Alexander and Alex)

RFC -> v1:
 - use __struct_group to delimit the zeroed area (Alexander)

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 include/net/gro.h | 52 +++++++++++++++++++++++++----------------------
 net/core/gro.c    | 15 ++++----------
 2 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/include/net/gro.h b/include/net/gro.h
index 8f75802d50fd..a765fedda5c4 100644
--- a/include/net/gro.h
+++ b/include/net/gro.h
@@ -29,46 +29,50 @@ struct napi_gro_cb {
 	/* Number of segments aggregated. */
 	u16	count;
 
-	/* Start offset for remote checksum offload */
-	u16	gro_remcsum_start;
+	/* Used in ipv6_gro_receive() and foo-over-udp */
+	u16	proto;
 
 	/* jiffies when first packet was created/queued */
 	unsigned long age;
 
-	/* Used in ipv6_gro_receive() and foo-over-udp */
-	u16	proto;
+	/* portion of the cb set to zero at every gro iteration */
+	struct_group(zeroed,
+
+		/* Start offset for remote checksum offload */
+		u16	gro_remcsum_start;
 
-	/* This is non-zero if the packet may be of the same flow. */
-	u8	same_flow:1;
+		/* This is non-zero if the packet may be of the same flow. */
+		u8	same_flow:1;
 
-	/* Used in tunnel GRO receive */
-	u8	encap_mark:1;
+		/* Used in tunnel GRO receive */
+		u8	encap_mark:1;
 
-	/* GRO checksum is valid */
-	u8	csum_valid:1;
+		/* GRO checksum is valid */
+		u8	csum_valid:1;
 
-	/* Number of checksums via CHECKSUM_UNNECESSARY */
-	u8	csum_cnt:3;
+		/* Number of checksums via CHECKSUM_UNNECESSARY */
+		u8	csum_cnt:3;
 
-	/* Free the skb? */
-	u8	free:2;
+		/* Free the skb? */
+		u8	free:2;
 #define NAPI_GRO_FREE		  1
 #define NAPI_GRO_FREE_STOLEN_HEAD 2
 
-	/* Used in foo-over-udp, set in udp[46]_gro_receive */
-	u8	is_ipv6:1;
+		/* Used in foo-over-udp, set in udp[46]_gro_receive */
+		u8	is_ipv6:1;
 
-	/* Used in GRE, set in fou/gue_gro_receive */
-	u8	is_fou:1;
+		/* Used in GRE, set in fou/gue_gro_receive */
+		u8	is_fou:1;
 
-	/* Used to determine if flush_id can be ignored */
-	u8	is_atomic:1;
+		/* Used to determine if flush_id can be ignored */
+		u8	is_atomic:1;
 
-	/* Number of gro_receive callbacks this packet already went through */
-	u8 recursion_counter:4;
+		/* Number of gro_receive callbacks this packet already went through */
+		u8 recursion_counter:4;
 
-	/* GRO is done by frag_list pointer chaining. */
-	u8	is_flist:1;
+		/* GRO is done by frag_list pointer chaining. */
+		u8	is_flist:1;
+	);
 
 	/* used to support CHECKSUM_COMPLETE for tunneling protocols */
 	__wsum	csum;
diff --git a/net/core/gro.c b/net/core/gro.c
index d43d42215bdb..ee5e7e889d8b 100644
--- a/net/core/gro.c
+++ b/net/core/gro.c
@@ -459,29 +459,22 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
 
 		skb_set_network_header(skb, skb_gro_offset(skb));
 		skb_reset_mac_len(skb);
-		NAPI_GRO_CB(skb)->same_flow = 0;
+		BUILD_BUG_ON(sizeof_field(struct napi_gro_cb, zeroed) != sizeof(u32));
+		BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct napi_gro_cb, zeroed),
+					 sizeof(u32))); /* Avoid slow unaligned acc */
+		*(u32 *)&NAPI_GRO_CB(skb)->zeroed = 0;
 		NAPI_GRO_CB(skb)->flush = skb_is_gso(skb) || skb_has_frag_list(skb);
-		NAPI_GRO_CB(skb)->free = 0;
-		NAPI_GRO_CB(skb)->encap_mark = 0;
-		NAPI_GRO_CB(skb)->recursion_counter = 0;
-		NAPI_GRO_CB(skb)->is_fou = 0;
 		NAPI_GRO_CB(skb)->is_atomic = 1;
-		NAPI_GRO_CB(skb)->gro_remcsum_start = 0;
 
 		/* Setup for GRO checksum validation */
 		switch (skb->ip_summed) {
 		case CHECKSUM_COMPLETE:
 			NAPI_GRO_CB(skb)->csum = skb->csum;
 			NAPI_GRO_CB(skb)->csum_valid = 1;
-			NAPI_GRO_CB(skb)->csum_cnt = 0;
 			break;
 		case CHECKSUM_UNNECESSARY:
 			NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1;
-			NAPI_GRO_CB(skb)->csum_valid = 0;
 			break;
-		default:
-			NAPI_GRO_CB(skb)->csum_cnt = 0;
-			NAPI_GRO_CB(skb)->csum_valid = 0;
 		}
 
 		pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 0/2] gro: a couple of minor optimization
  2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
  2022-02-04 11:28 ` [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle Paolo Abeni
  2022-02-04 11:28 ` [PATCH net-next 2/2] net: gro: minor optimization for dev_gro_receive() Paolo Abeni
@ 2022-02-04 11:34 ` Paolo Abeni
  2022-02-05  9:51   ` David Miller
  2022-02-04 12:16 ` Alexander Lobakin
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Paolo Abeni @ 2022-02-04 11:34 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Jakub Kicinski, Alexander Lobakin, Eric Dumazet,
	Alexander H Duyck

On Fri, 2022-02-04 at 12:28 +0100, Paolo Abeni wrote:
> This series collects a couple of small optimizations for the GRO engine,
> reducing slightly the number of cycles for dev_gro_receive().
> The delta is within noise range in tput tests, but with big TCP coming
> every cycle saved from the GRO engine will count - I hope ;)
> 
> v1 -> v2:
>  - a few cleanup suggested from Alexander(s)
>  - moved away the more controversial 3rd patch
> 
> Paolo Abeni (2):
>   net: gro: avoid re-computing truesize twice on recycle
>   net: gro: minor optimization for dev_gro_receive()
> 
>  include/net/gro.h | 52 +++++++++++++++++++++++++----------------------
>  net/core/gro.c    | 16 ++++-----------
>  2 files changed, 32 insertions(+), 36 deletions(-)

This is really a v2. Please let me know if you prefer a formal repost.

Thanks!

Paolo


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 0/2] gro: a couple of minor optimization
  2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
                   ` (2 preceding siblings ...)
  2022-02-04 11:34 ` [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
@ 2022-02-04 12:16 ` Alexander Lobakin
  2022-02-04 15:55 ` Alexander Duyck
  2022-02-05 15:20 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 9+ messages in thread
From: Alexander Lobakin @ 2022-02-04 12:16 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Alexander Lobakin, netdev, David S. Miller, Jakub Kicinski,
	Eric Dumazet, Alexander H Duyck

From: Paolo Abeni <pabeni@redhat.com>
Date: Fri,  4 Feb 2022 12:28:35 +0100

> This series collects a couple of small optimizations for the GRO engine,
> reducing slightly the number of cycles for dev_gro_receive().
> The delta is within noise range in tput tests, but with big TCP coming
> every cycle saved from the GRO engine will count - I hope ;)
> 
> v1 -> v2:
>  - a few cleanup suggested from Alexander(s)
>  - moved away the more controversial 3rd patch
> 
> Paolo Abeni (2):
>   net: gro: avoid re-computing truesize twice on recycle
>   net: gro: minor optimization for dev_gro_receive()

Looks nice to me now, thanks!
For the series:

Reviewed-by: Alexander Lobakin <alexandr.lobakin@intel.com>

> 
>  include/net/gro.h | 52 +++++++++++++++++++++++++----------------------
>  net/core/gro.c    | 16 ++++-----------
>  2 files changed, 32 insertions(+), 36 deletions(-)
> 
> -- 
> 2.34.1

Al

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 0/2] gro: a couple of minor optimization
  2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
                   ` (3 preceding siblings ...)
  2022-02-04 12:16 ` Alexander Lobakin
@ 2022-02-04 15:55 ` Alexander Duyck
  2022-02-05 15:20 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 9+ messages in thread
From: Alexander Duyck @ 2022-02-04 15:55 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Netdev, David S. Miller, Jakub Kicinski, Alexander Lobakin, Eric Dumazet

On Fri, Feb 4, 2022 at 3:29 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> This series collects a couple of small optimizations for the GRO engine,
> reducing slightly the number of cycles for dev_gro_receive().
> The delta is within noise range in tput tests, but with big TCP coming
> every cycle saved from the GRO engine will count - I hope ;)
>
> v1 -> v2:
>  - a few cleanup suggested from Alexander(s)
>  - moved away the more controversial 3rd patch
>
> Paolo Abeni (2):
>   net: gro: avoid re-computing truesize twice on recycle
>   net: gro: minor optimization for dev_gro_receive()
>
>  include/net/gro.h | 52 +++++++++++++++++++++++++----------------------
>  net/core/gro.c    | 16 ++++-----------
>  2 files changed, 32 insertions(+), 36 deletions(-)

This addresses the concern I had.

Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle
  2022-02-04 11:28 ` [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle Paolo Abeni
@ 2022-02-04 16:34   ` Eric Dumazet
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2022-02-04 16:34 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, David S. Miller, Jakub Kicinski, Alexander Lobakin,
	Alexander H Duyck

On Fri, Feb 4, 2022 at 3:29 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> After commit 5e10da5385d2 ("skbuff: allow 'slow_gro' for skb
> carring sock reference") and commit af352460b465 ("net: fix GRO
> skb truesize update") the truesize of the skb with stolen head is
> properly updated by the GRO engine, we don't need anymore resetting
> it at recycle time.
>
> v1 -> v2:
>  - clarify the commit message (Alexander)
>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 0/2] gro: a couple of minor optimization
  2022-02-04 11:34 ` [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
@ 2022-02-05  9:51   ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2022-02-05  9:51 UTC (permalink / raw)
  To: pabeni; +Cc: netdev, kuba, alexandr.lobakin, edumazet, alexander.duyck

From: Paolo Abeni <pabeni@redhat.com>
Date: Fri, 04 Feb 2022 12:34:03 +0100

> On Fri, 2022-02-04 at 12:28 +0100, Paolo Abeni wrote:
>> This series collects a couple of small optimizations for the GRO engine,
>> reducing slightly the number of cycles for dev_gro_receive().
>> The delta is within noise range in tput tests, but with big TCP coming
>> every cycle saved from the GRO engine will count - I hope ;)
>> 
>> v1 -> v2:
>>  - a few cleanup suggested from Alexander(s)
>>  - moved away the more controversial 3rd patch
>> 
>> Paolo Abeni (2):
>>   net: gro: avoid re-computing truesize twice on recycle
>>   net: gro: minor optimization for dev_gro_receive()
>> 
>>  include/net/gro.h | 52 +++++++++++++++++++++++++----------------------
>>  net/core/gro.c    | 16 ++++-----------
>>  2 files changed, 32 insertions(+), 36 deletions(-)
> 
> This is really a v2. Please let me know if you prefer a formal repost.

Not necessary.

Thank you.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next 0/2] gro: a couple of minor optimization
  2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
                   ` (4 preceding siblings ...)
  2022-02-04 15:55 ` Alexander Duyck
@ 2022-02-05 15:20 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-05 15:20 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, davem, kuba, alexandr.lobakin, edumazet, alexander.duyck

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri,  4 Feb 2022 12:28:35 +0100 you wrote:
> This series collects a couple of small optimizations for the GRO engine,
> reducing slightly the number of cycles for dev_gro_receive().
> The delta is within noise range in tput tests, but with big TCP coming
> every cycle saved from the GRO engine will count - I hope ;)
> 
> v1 -> v2:
>  - a few cleanup suggested from Alexander(s)
>  - moved away the more controversial 3rd patch
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: gro: avoid re-computing truesize twice on recycle
    https://git.kernel.org/netdev/net-next/c/7881453e4adf
  - [net-next,2/2] net: gro: minor optimization for dev_gro_receive()
    https://git.kernel.org/netdev/net-next/c/de5a1f3ce4c8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-05 15:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 11:28 [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
2022-02-04 11:28 ` [PATCH net-next 1/2] net: gro: avoid re-computing truesize twice on recycle Paolo Abeni
2022-02-04 16:34   ` Eric Dumazet
2022-02-04 11:28 ` [PATCH net-next 2/2] net: gro: minor optimization for dev_gro_receive() Paolo Abeni
2022-02-04 11:34 ` [PATCH net-next 0/2] gro: a couple of minor optimization Paolo Abeni
2022-02-05  9:51   ` David Miller
2022-02-04 12:16 ` Alexander Lobakin
2022-02-04 15:55 ` Alexander Duyck
2022-02-05 15:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.