mbox series

[net-next,v5,0/5] page_pool: recycle buffers

Message ID 20210513165846.23722-1-mcroce@linux.microsoft.com
Headers show
Series page_pool: recycle buffers | expand

Message

Matteo Croce May 13, 2021, 4:58 p.m. UTC
From: Matteo Croce <mcroce@microsoft.com>

This is a respin of [1]

This patchset shows the plans for allowing page_pool to handle and
maintain DMA map/unmap of the pages it serves to the driver. For this
to work a return hook in the network core is introduced.

The overall purpose is to simplify drivers, by providing a page
allocation API that does recycling, such that each driver doesn't have
to reinvent its own recycling scheme. Using page_pool in a driver
does not require implementing XDP support, but it makes it trivially
easy to do so. Instead of allocating buffers specifically for SKBs
we now allocate a generic buffer and either wrap it on an SKB
(via build_skb) or create an XDP frame.
The recycling code leverages the XDP recycle APIs.

The Marvell mvpp2 and mvneta drivers are used in this patchset to
demonstrate how to use the API, and tested on a MacchiatoBIN
and EspressoBIN boards respectively.

Please let this going in on a future -rc1 so to allow enough time
to have wider tests.

Note that this series depends on the change "mm: fix struct page layout
on 32-bit systems"[2] which is not yet in master.

v4 -> v5:
- move the signature so it doesn't alias with page->mapping
- use an invalid pointer as magic
- incorporate Matthew Wilcox's changes for pfmemalloc pages
- move the __skb_frag_unref() changes to a preliminary patch
- refactor some cpp directives
- only attempt recycling if skb->head_frag
- clear skb->pp_recycle in pskb_expand_head()

v3 -> v4:
- store a pointer to page_pool instead of xdp_mem_info
- drop a patch which reduces xdp_mem_info size
- do the recycling in the page_pool code instead of xdp_return
- remove some unused headers include
- remove some useless forward declaration

v2 -> v3:
- added missing SOBs
- CCed the MM people

v1 -> v2:
- fix a commit message
- avoid setting pp_recycle multiple times on mvneta
- squash two patches to avoid breaking bisect

[1] https://lore.kernel.org/netdev/154413868810.21735.572808840657728172.stgit@firesoul/
[2] https://lore.kernel.org/linux-mm/20210510153211.1504886-1-willy@infradead.org/

Ilias Apalodimas (1):
  page_pool: Allow drivers to hint on SKB recycling

Matteo Croce (4):
  mm: add a signature in struct page
  skbuff: add a parameter to __skb_frag_unref
  mvpp2: recycle buffers
  mvneta: recycle buffers

 drivers/net/ethernet/marvell/mvneta.c         | 11 +++---
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 17 +++++-----
 drivers/net/ethernet/marvell/sky2.c           |  2 +-
 drivers/net/ethernet/mellanox/mlx4/en_rx.c    |  2 +-
 include/linux/mm.h                            | 12 ++++---
 include/linux/mm_types.h                      | 12 +++++++
 include/linux/skbuff.h                        | 34 ++++++++++++++++---
 include/net/page_pool.h                       | 11 ++++++
 net/core/page_pool.c                          | 27 +++++++++++++++
 net/core/skbuff.c                             | 25 +++++++++++---
 net/tls/tls_device.c                          |  2 +-
 11 files changed, 126 insertions(+), 29 deletions(-)

Comments

Matthew Wilcox May 14, 2021, 1 a.m. UTC | #1
On Thu, May 13, 2021 at 06:58:42PM +0200, Matteo Croce wrote:
>  		struct {	/* page_pool used by netstack */

> +			/**

> +			 * @pp_magic: magic value to avoid recycling non

> +			 * page_pool allocated pages.

> +			 * It aliases with page->lru.next


I'm not really keen on documenting what aliases with what.
pp_magic also aliases with compound_head, 'next' (for slab),
and dev_pagemap.  This is an O(n^2) documentation problem ...

I feel like I want to document the pfmemalloc bit in mm_types.h,
but I don't have a concrete suggestion yet.

> +++ b/include/net/page_pool.h

> @@ -63,6 +63,8 @@

>   */

>  #define PP_ALLOC_CACHE_SIZE	128

>  #define PP_ALLOC_CACHE_REFILL	64

> +#define PP_SIGNATURE		(POISON_POINTER_DELTA + 0x40)


I wonder if this wouldn't be better in linux/poison.h?
Matteo Croce May 14, 2021, 1:34 a.m. UTC | #2
On Fri, May 14, 2021 at 3:01 AM Matthew Wilcox <willy@infradead.org> wrote:
>

> On Thu, May 13, 2021 at 06:58:42PM +0200, Matteo Croce wrote:

> >               struct {        /* page_pool used by netstack */

> > +                     /**

> > +                      * @pp_magic: magic value to avoid recycling non

> > +                      * page_pool allocated pages.

> > +                      * It aliases with page->lru.next

>

> I'm not really keen on documenting what aliases with what.

> pp_magic also aliases with compound_head, 'next' (for slab),

> and dev_pagemap.  This is an O(n^2) documentation problem ...

>


Eric asked to document what page->signature aliases, so I did it in
the commit message and in a comment.
I can drop the code comment and leave it just the commit message.

> I feel like I want to document the pfmemalloc bit in mm_types.h,

> but I don't have a concrete suggestion yet.

>

> > +++ b/include/net/page_pool.h

> > @@ -63,6 +63,8 @@

> >   */

> >  #define PP_ALLOC_CACHE_SIZE  128

> >  #define PP_ALLOC_CACHE_REFILL        64

> > +#define PP_SIGNATURE         (POISON_POINTER_DELTA + 0x40)

>

> I wonder if this wouldn't be better in linux/poison.h?

>


I was thinking the same, I'll do it in the v6.

Regards,
-- 
per aspera ad upstream
Matteo Croce May 18, 2021, 3:44 p.m. UTC | #3
On Fri, May 14, 2021 at 3:01 AM Matthew Wilcox <willy@infradead.org> wrote:
>

> I feel like I want to document the pfmemalloc bit in mm_types.h,

> but I don't have a concrete suggestion yet.

>


Maybe simply:

/* Bit zero is set
 * Bit one if pfmemalloc page
 */
 unsigned long compound_head;

Regards,
-- 
per aspera ad upstream