All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 net-next 00/11] skbuff: introduce skbuff_heads bulking and reusing
@ 2021-02-10 16:28 Alexander Lobakin
  2021-02-10 16:28 ` [PATCH v4 net-next 01/11] skbuff: move __alloc_skb() next to the other skb allocation functions Alexander Lobakin
                   ` (10 more replies)
  0 siblings, 11 replies; 22+ messages in thread
From: Alexander Lobakin @ 2021-02-10 16:28 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  Cc: Jonathan Lemon, Eric Dumazet, Dmitry Vyukov, Willem de Bruijn,
	Alexander Lobakin, Randy Dunlap, Kevin Hao, Pablo Neira Ayuso,
	Jakub Sitnicki, Marco Elver, Dexuan Cui, Paolo Abeni,
	Jesper Dangaard Brouer, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Taehee Yoo, Cong Wang, Björn Töpel,
	Miaohe Lin, Guillaume Nault, Yonghong Song, zhudi,
	Michal Kubecek, Marcelo Ricardo Leitner, Dmitry Safonov,
	Yang Yingliang, Florian Westphal, Edward Cree, linux-kernel,
	netdev

Currently, all sorts of skb allocation always do allocate
skbuff_heads one by one via kmem_cache_alloc().
On the other hand, we have percpu napi_alloc_cache to store
skbuff_heads queued up for freeing and flush them by bulks.

We can use this cache not only for bulk-wiping, but also to obtain
heads for new skbs and avoid unconditional allocations, as well as
for bulk-allocating (like XDP's cpumap code and veth driver already
do).

As this might affect latencies, cache pressure and lots of hardware
and driver-dependent stuff, this new feature is mostly optional and
can be issued via:
 - a new napi_build_skb() function (as a replacement for build_skb());
 - existing {,__}napi_alloc_skb() and napi_get_frags() functions;
 - __alloc_skb() with passing SKB_ALLOC_NAPI in flags.

iperf3 showed 35-70 Mbps bumps for both TCP and UDP while performing
VLAN NAT on 1.2 GHz MIPS board. The boost is likely to be bigger
on more powerful hosts and NICs with tens of Mpps.

Note on skbuff_heads from distant slabs or pfmemalloc'ed slabs:
 - kmalloc()/kmem_cache_alloc() itself allows by default allocating
   memory from the remote nodes to defragment their slabs. This is
   controlled by sysctl, but according to this, skbuff_head from a
   remote node is an OK case;
 - The easiest way to check if the slab of skbuff_head is remote or
   pfmemalloc'ed is:

	if (!dev_page_is_reusable(virt_to_head_page(skb)))
		/* drop it */;

   ...*but*, regarding that most slabs are built of compound pages,
   virt_to_head_page() will hit unlikely-branch every single call.
   This check costed at least 20 Mbps in test scenarios and seems
   like it'd be better to _not_ do this.

Since v3 [2]:
 - make the feature mostly optional, so driver developers could
   decide whether to use it or not (Paolo Abeni).
   This reuses the old flag for __alloc_skb() and introduces
   a new napi_build_skb();
 - reduce bulk-allocation size from 32 to 16 elements (also Paolo).
   This equals to the value of XDP's devmap and veth batch processing
   (which were tested a lot) and should be sane enough;
 - don't waste cycles on explicit in_serving_softirq() check.

Since v2 [1]:
 - also cover {,__}alloc_skb() and {,__}build_skb() cases (became handy
   after the changes that pass tiny skbs requests to kmalloc layer);
 - cover the cache with KASAN instrumentation (suggested by Eric
   Dumazet, help of Dmitry Vyukov);
 - completely drop redundant __kfree_skb_flush() (also Eric);
 - lots of code cleanups;
 - expand the commit message with NUMA and pfmemalloc points (Jakub).

Since v1 [0]:
 - use one unified cache instead of two separate to greatly simplify
   the logics and reduce hotpath overhead (Edward Cree);
 - new: recycle also GRO_MERGED_FREE skbs instead of immediate
   freeing;
 - correct performance numbers after optimizations and performing
   lots of tests for different use cases.

[0] https://lore.kernel.org/netdev/20210111182655.12159-1-alobakin@pm.me
[1] https://lore.kernel.org/netdev/20210113133523.39205-1-alobakin@pm.me
[2] https://lore.kernel.org/netdev/20210209204533.327360-1-alobakin@pm.me

Alexander Lobakin (11):
  skbuff: move __alloc_skb() next to the other skb allocation functions
  skbuff: simplify kmalloc_reserve()
  skbuff: make __build_skb_around() return void
  skbuff: simplify __alloc_skb() a bit
  skbuff: use __build_skb_around() in __alloc_skb()
  skbuff: remove __kfree_skb_flush()
  skbuff: move NAPI cache declarations upper in the file
  skbuff: introduce {,__}napi_build_skb() which reuses NAPI cache heads
  skbuff: allow to optionally use NAPI cache from __alloc_skb()
  skbuff: allow to use NAPI cache from __napi_alloc_skb()
  skbuff: queue NAPI_MERGED_FREE skbs into NAPI cache instead of freeing

 include/linux/skbuff.h |   4 +-
 net/core/dev.c         |  15 +-
 net/core/skbuff.c      | 429 +++++++++++++++++++++++------------------
 3 files changed, 243 insertions(+), 205 deletions(-)

-- 
2.30.1



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

end of thread, other threads:[~2021-02-11 16:33 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 16:28 [PATCH v4 net-next 00/11] skbuff: introduce skbuff_heads bulking and reusing Alexander Lobakin
2021-02-10 16:28 ` [PATCH v4 net-next 01/11] skbuff: move __alloc_skb() next to the other skb allocation functions Alexander Lobakin
2021-02-10 16:28 ` [PATCH v4 net-next 02/11] skbuff: simplify kmalloc_reserve() Alexander Lobakin
2021-02-10 16:29 ` [PATCH v4 net-next 03/11] skbuff: make __build_skb_around() return void Alexander Lobakin
2021-02-10 16:29 ` [PATCH v4 net-next 04/11] skbuff: simplify __alloc_skb() a bit Alexander Lobakin
2021-02-10 16:29 ` [PATCH v4 net-next 05/11] skbuff: use __build_skb_around() in __alloc_skb() Alexander Lobakin
2021-02-10 16:29 ` [PATCH v4 net-next 06/11] skbuff: remove __kfree_skb_flush() Alexander Lobakin
2021-02-10 20:22   ` kernel test robot
2021-02-10 20:22     ` kernel test robot
2021-02-11  0:19   ` kernel test robot
2021-02-11  0:19     ` kernel test robot
2021-02-10 16:30 ` [PATCH v4 net-next 07/11] skbuff: move NAPI cache declarations upper in the file Alexander Lobakin
2021-02-10 16:30 ` [PATCH v4 net-next 08/11] skbuff: introduce {,__}napi_build_skb() which reuses NAPI cache heads Alexander Lobakin
2021-02-11 12:54   ` Jesper Dangaard Brouer
2021-02-11 14:38     ` Alexander Lobakin
2021-02-10 16:30 ` [PATCH v4 net-next 09/11] skbuff: allow to optionally use NAPI cache from __alloc_skb() Alexander Lobakin
2021-02-11 10:16   ` Paolo Abeni
2021-02-11 14:28     ` Alexander Lobakin
2021-02-11 14:55       ` Paolo Abeni
2021-02-11 15:26         ` Alexander Lobakin
2021-02-10 16:30 ` [PATCH v4 net-next 10/11] skbuff: allow to use NAPI cache from __napi_alloc_skb() Alexander Lobakin
2021-02-10 16:31 ` [PATCH v4 net-next 11/11] skbuff: queue NAPI_MERGED_FREE skbs into NAPI cache instead of freeing Alexander Lobakin

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.