diff mbox series

[v2,net-next,3/3] skbuff: recycle GRO_MERGED_FREE skbs into NAPI skb cache

Message ID 20210113133635.39402-3-alobakin@pm.me (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series skbuff: introduce skbuff_heads reusing and bulking | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 16 maintainers not CCed: nogikh@google.com elver@google.com jiri@mellanox.com ap420073@gmail.com decui@microsoft.com andriin@fb.com bjorn.topel@intel.com herbert@gondor.apana.org.au rdunlap@infradead.org jakub@cloudflare.com xiyou.wangcong@gmail.com daniel@iogearbox.net pabeni@redhat.com pablo@netfilter.org gustavoars@kernel.org ast@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 8835 this patch: 8835
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 58 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 9246 this patch: 9246
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Alexander Lobakin Jan. 13, 2021, 1:37 p.m. UTC
Instead of immediate freeing, recycle GRO_MERGED_FREE skbs into
NAPI skb cache. This is safe, because napi_gro_receive() and
napi_gro_frags() are called only inside NAPI softirq context.
As many drivers call napi_alloc_skb()/napi_get_frags() on their
receive path, this becomes especially useful.

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 include/linux/skbuff.h |  1 +
 net/core/dev.c         |  9 +--------
 net/core/skbuff.c      | 12 +++++++++---
 3 files changed, 11 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 7a057b1f1eb8..507f1598e446 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2888,6 +2888,7 @@  void napi_consume_skb(struct sk_buff *skb, int budget);
 
 void __kfree_skb_flush(void);
 void __kfree_skb_defer(struct sk_buff *skb);
+void napi_skb_free_stolen_head(struct sk_buff *skb);
 
 /**
  * __dev_alloc_pages - allocate page for network Rx
diff --git a/net/core/dev.c b/net/core/dev.c
index e4d77c8abe76..c28f0d601378 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6054,13 +6054,6 @@  struct packet_offload *gro_find_complete_by_type(__be16 type)
 }
 EXPORT_SYMBOL(gro_find_complete_by_type);
 
-static void napi_skb_free_stolen_head(struct sk_buff *skb)
-{
-	skb_dst_drop(skb);
-	skb_ext_put(skb);
-	kmem_cache_free(skbuff_head_cache, skb);
-}
-
 static gro_result_t napi_skb_finish(struct napi_struct *napi,
 				    struct sk_buff *skb,
 				    gro_result_t ret)
@@ -6074,7 +6067,7 @@  static gro_result_t napi_skb_finish(struct napi_struct *napi,
 		if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
 			napi_skb_free_stolen_head(skb);
 		else
-			__kfree_skb(skb);
+			__kfree_skb_defer(skb);
 		break;
 
 	case GRO_HELD:
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f42a3a04b918..bf6f92f1f4c7 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -902,9 +902,6 @@  static void napi_skb_cache_put(struct sk_buff *skb)
 {
 	struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
 
-	/* drop skb->head and call any destructors for packet */
-	skb_release_all(skb);
-
 	nc->skb_cache[nc->skb_count++] = skb;
 
 	if (unlikely(nc->skb_count == NAPI_SKB_CACHE_SIZE)) {
@@ -916,6 +913,14 @@  static void napi_skb_cache_put(struct sk_buff *skb)
 
 void __kfree_skb_defer(struct sk_buff *skb)
 {
+	skb_release_all(skb);
+	napi_skb_cache_put(skb);
+}
+
+void napi_skb_free_stolen_head(struct sk_buff *skb)
+{
+	skb_dst_drop(skb);
+	skb_ext_put(skb);
 	napi_skb_cache_put(skb);
 }
 
@@ -941,6 +946,7 @@  void napi_consume_skb(struct sk_buff *skb, int budget)
 		return;
 	}
 
+	skb_release_all(skb);
 	napi_skb_cache_put(skb);
 }
 EXPORT_SYMBOL(napi_consume_skb);