linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage
@ 2021-01-31 12:11 Alexander Lobakin
  2021-01-31 12:11 ` [PATCH v3 net-next 1/5] mm: constify page_is_pfmemalloc() argument Alexander Lobakin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-01-31 12:11 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  Cc: John Hubbard, David Rientjes, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Saeed Mahameed, Leon Romanovsky,
	Andrew Morton, Jesper Dangaard Brouer, Ilias Apalodimas,
	Jonathan Lemon, Willem de Bruijn, Randy Dunlap,
	Pablo Neira Ayuso, Dexuan Cui, Jakub Sitnicki, Marco Elver,
	Paolo Abeni, Alexander Lobakin, netdev, linux-kernel,
	intel-wired-lan, linux-rdma, linux-mm

page_is_pfmemalloc() is used mostly by networking drivers to test
if a page can be considered for reusing/recycling.
It doesn't write anything to the struct page itself, so its sole
argument can be constified, as well as the first argument of
skb_propagate_pfmemalloc().
In Page Pool core code, it can be simply inlined instead.
Most of the callers from NIC drivers were just doppelgangers of
the same condition tests. Derive them into a new common function
do deduplicate the code.

Since v2 [1]:
 - use more intuitive name for the new inline function since there's
   nothing "reserved" in remote pages (Jakub Kicinski, John Hubbard);
 - fold likely() inside the helper itself to make driver code a bit
   fancier (Jakub Kicinski);
 - split function introduction and using into two separate commits;
 - collect some more tags (Jesse Brandeburg, David Rientjes).

Since v1 [0]:
 - new: reduce code duplication by introducing a new common function
   to test if a page can be reused/recycled (David Rientjes);
 - collect autographs for Page Pool bits (Jesper Dangaard Brouer,
   Ilias Apalodimas).

[0] https://lore.kernel.org/netdev/20210125164612.243838-1-alobakin@pm.me
[1] https://lore.kernel.org/netdev/20210127201031.98544-1-alobakin@pm.me

Alexander Lobakin (5):
  mm: constify page_is_pfmemalloc() argument
  skbuff: constify skb_propagate_pfmemalloc() "page" argument
  net: introduce common dev_page_is_reusable()
  net: use the new dev_page_is_reusable() instead of private versions
  net: page_pool: simplify page recycling condition tests

 .../net/ethernet/hisilicon/hns3/hns3_enet.c   | 17 ++++++----------
 drivers/net/ethernet/intel/fm10k/fm10k_main.c | 13 ++++--------
 drivers/net/ethernet/intel/i40e/i40e_txrx.c   | 15 +-------------
 drivers/net/ethernet/intel/iavf/iavf_txrx.c   | 15 +-------------
 drivers/net/ethernet/intel/ice/ice_txrx.c     | 13 ++----------
 drivers/net/ethernet/intel/igb/igb_main.c     |  9 ++-------
 drivers/net/ethernet/intel/igc/igc_main.c     |  9 ++-------
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  9 ++-------
 .../net/ethernet/intel/ixgbevf/ixgbevf_main.c |  9 ++-------
 .../net/ethernet/mellanox/mlx5/core/en_rx.c   |  7 +------
 include/linux/mm.h                            |  2 +-
 include/linux/skbuff.h                        | 20 +++++++++++++++++--
 net/core/page_pool.c                          | 14 ++++---------
 13 files changed, 46 insertions(+), 106 deletions(-)

-- 
2.30.0



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

* [PATCH v3 net-next 1/5] mm: constify page_is_pfmemalloc() argument
  2021-01-31 12:11 [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Alexander Lobakin
@ 2021-01-31 12:11 ` Alexander Lobakin
  2021-01-31 12:11 ` [PATCH v3 net-next 3/5] net: introduce common dev_page_is_reusable() Alexander Lobakin
  2021-02-02  1:18 ` [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Jakub Kicinski
  2 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-01-31 12:11 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  Cc: John Hubbard, David Rientjes, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Saeed Mahameed, Leon Romanovsky,
	Andrew Morton, Jesper Dangaard Brouer, Ilias Apalodimas,
	Jonathan Lemon, Willem de Bruijn, Randy Dunlap,
	Pablo Neira Ayuso, Dexuan Cui, Jakub Sitnicki, Marco Elver,
	Paolo Abeni, Alexander Lobakin, netdev, linux-kernel,
	intel-wired-lan, linux-rdma, linux-mm

The function only tests for page->index, so its argument should be
const.

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Acked-by: David Rientjes <rientjes@google.com>
---
 include/linux/mm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index ecdf8a8cd6ae..078633d43af9 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1584,7 +1584,7 @@ struct address_space *page_mapping_file(struct page *page);
  * ALLOC_NO_WATERMARKS and the low watermark was not
  * met implying that the system is under some pressure.
  */
-static inline bool page_is_pfmemalloc(struct page *page)
+static inline bool page_is_pfmemalloc(const struct page *page)
 {
 	/*
 	 * Page index cannot be this large so this must be
-- 
2.30.0



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

* [PATCH v3 net-next 3/5] net: introduce common dev_page_is_reusable()
  2021-01-31 12:11 [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Alexander Lobakin
  2021-01-31 12:11 ` [PATCH v3 net-next 1/5] mm: constify page_is_pfmemalloc() argument Alexander Lobakin
@ 2021-01-31 12:11 ` Alexander Lobakin
       [not found]   ` <20210131122205.GL308988@casper.infradead.org>
  2021-02-02  1:18 ` [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Jakub Kicinski
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Lobakin @ 2021-01-31 12:11 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  Cc: John Hubbard, David Rientjes, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Saeed Mahameed, Leon Romanovsky,
	Andrew Morton, Jesper Dangaard Brouer, Ilias Apalodimas,
	Jonathan Lemon, Willem de Bruijn, Randy Dunlap,
	Pablo Neira Ayuso, Dexuan Cui, Jakub Sitnicki, Marco Elver,
	Paolo Abeni, Alexander Lobakin, netdev, linux-kernel,
	intel-wired-lan, linux-rdma, linux-mm

A bunch of drivers test the page before reusing/recycling for two
common conditions:
 - if a page was allocated under memory pressure (pfmemalloc page);
 - if a page was allocated at a distant memory node (to exclude
   slowdowns).

Introduce a new common inline for doing this, with likely() already
folded inside to make driver code a bit simpler.

Suggested-by: David Rientjes <rientjes@google.com>
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Acked-by: David Rientjes <rientjes@google.com>
---
 include/linux/skbuff.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index b027526da4f9..0e42c53b8ca9 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2938,6 +2938,22 @@ static inline struct page *dev_alloc_page(void)
 	return dev_alloc_pages(0);
 }
 
+/**
+ * dev_page_is_reusable - check whether a page can be reused for network Rx
+ * @page: the page to test
+ *
+ * A page shouldn't be considered for reusing/recycling if it was allocated
+ * under memory pressure or at a distant memory node.
+ *
+ * Returns false if this page should be returned to page allocator, true
+ * otherwise.
+ */
+static inline bool dev_page_is_reusable(const struct page *page)
+{
+	return likely(page_to_nid(page) == numa_mem_id() &&
+		      !page_is_pfmemalloc(page));
+}
+
 /**
  *	skb_propagate_pfmemalloc - Propagate pfmemalloc if skb is allocated after RX page
  *	@page: The page that was allocated from skb_alloc_page
-- 
2.30.0



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

* Re: [PATCH v3 net-next 3/5] net: introduce common dev_page_is_reusable()
       [not found]   ` <20210131122205.GL308988@casper.infradead.org>
@ 2021-01-31 12:57     ` Alexander Lobakin
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-01-31 12:57 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Alexander Lobakin, David S. Miller, Jakub Kicinski, John Hubbard,
	David Rientjes, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Saeed Mahameed, Leon Romanovsky, Andrew Morton,
	Jesper Dangaard Brouer, Ilias Apalodimas, Jonathan Lemon,
	Willem de Bruijn, Randy Dunlap, Pablo Neira Ayuso, Dexuan Cui,
	Jakub Sitnicki, Marco Elver, Paolo Abeni, netdev, linux-kernel,
	intel-wired-lan, linux-rdma, linux-mm

From: Matthew Wilcox <willy@infradead.org>
Date: Sun, 31 Jan 2021 12:22:05 +0000

> On Sun, Jan 31, 2021 at 12:11:52PM +0000, Alexander Lobakin wrote:
> > A bunch of drivers test the page before reusing/recycling for two
> > common conditions:
> >  - if a page was allocated under memory pressure (pfmemalloc page);
> >  - if a page was allocated at a distant memory node (to exclude
> >    slowdowns).
> >
> > Introduce a new common inline for doing this, with likely() already
> > folded inside to make driver code a bit simpler.
> 
> I don't see the need for the 'dev_' prefix.  That actually confuses me
> because it makes me think this is tied to ZONE_DEVICE or some such.

Several functions right above this one also use 'dev_' prefix. It's
a rather old mark that it's about network devices.

> So how about calling it just 'page_is_reusable' and putting it in mm.h
> with page_is_pfmemalloc() and making the comment a little less network-centric?

This pair of conditions (!pfmemalloc + local memory node) is really
specific to network drivers. I didn't see any other instances of such
tests, so I don't see a reason to place it in a more common mm.h.

> Or call it something like skb_page_is_recyclable() since it's only used
> by networking today.  But I bet it could/should be used more widely.

There's nothing about skb. Tested page is just a memory chunk for DMA
transaction. It can be used as skb head/frag, for XDP buffer/frame or
for XSK umem.

> > +/**
> > + * dev_page_is_reusable - check whether a page can be reused for network Rx
> > + * @page: the page to test
> > + *
> > + * A page shouldn't be considered for reusing/recycling if it was allocated
> > + * under memory pressure or at a distant memory node.
> > + *
> > + * Returns false if this page should be returned to page allocator, true
> > + * otherwise.
> > + */
> > +static inline bool dev_page_is_reusable(const struct page *page)
> > +{
> > +	return likely(page_to_nid(page) == numa_mem_id() &&
> > +		      !page_is_pfmemalloc(page));
> > +}
> > +

Al


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

* Re: [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage
  2021-01-31 12:11 [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Alexander Lobakin
  2021-01-31 12:11 ` [PATCH v3 net-next 1/5] mm: constify page_is_pfmemalloc() argument Alexander Lobakin
  2021-01-31 12:11 ` [PATCH v3 net-next 3/5] net: introduce common dev_page_is_reusable() Alexander Lobakin
@ 2021-02-02  1:18 ` Jakub Kicinski
  2021-02-02 13:13   ` Alexander Lobakin
  2 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2021-02-02  1:18 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: David S. Miller, John Hubbard, David Rientjes, Yisen Zhuang,
	Salil Mehta, Jesse Brandeburg, Tony Nguyen, Saeed Mahameed,
	Leon Romanovsky, Andrew Morton, Jesper Dangaard Brouer,
	Ilias Apalodimas, Jonathan Lemon, Willem de Bruijn, Randy Dunlap,
	Pablo Neira Ayuso, Dexuan Cui, Jakub Sitnicki, Marco Elver,
	Paolo Abeni, netdev, linux-kernel, intel-wired-lan, linux-rdma,
	linux-mm

On Sun, 31 Jan 2021 12:11:16 +0000 Alexander Lobakin wrote:
> page_is_pfmemalloc() is used mostly by networking drivers to test
> if a page can be considered for reusing/recycling.
> It doesn't write anything to the struct page itself, so its sole
> argument can be constified, as well as the first argument of
> skb_propagate_pfmemalloc().
> In Page Pool core code, it can be simply inlined instead.
> Most of the callers from NIC drivers were just doppelgangers of
> the same condition tests. Derive them into a new common function
> do deduplicate the code.

Please resend, this did not get into patchwork :/

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

* Re: [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage
  2021-02-02  1:18 ` [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Jakub Kicinski
@ 2021-02-02 13:13   ` Alexander Lobakin
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2021-02-02 13:13 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Alexander Lobakin, David S. Miller, John Hubbard, David Rientjes,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Saeed Mahameed, Leon Romanovsky, Andrew Morton,
	Jesper Dangaard Brouer, Ilias Apalodimas, Jonathan Lemon,
	Willem de Bruijn, Randy Dunlap, Pablo Neira Ayuso, Dexuan Cui,
	Jakub Sitnicki, Marco Elver, Paolo Abeni, netdev, linux-kernel,
	intel-wired-lan, linux-rdma, linux-mm

From: Jakub Kicinski <kuba@kernel.org>
Date: Mon, 1 Feb 2021 17:18:35 -0800

> On Sun, 31 Jan 2021 12:11:16 +0000 Alexander Lobakin wrote:
> > page_is_pfmemalloc() is used mostly by networking drivers to test
> > if a page can be considered for reusing/recycling.
> > It doesn't write anything to the struct page itself, so its sole
> > argument can be constified, as well as the first argument of
> > skb_propagate_pfmemalloc().
> > In Page Pool core code, it can be simply inlined instead.
> > Most of the callers from NIC drivers were just doppelgangers of
> > the same condition tests. Derive them into a new common function
> > do deduplicate the code.
> 
> Please resend, this did not get into patchwork :/

I suspected it would be so as I got reports about undelivered mails
due to unavailability of vger.kernel.org for some reasons Will do.

Al


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

end of thread, other threads:[~2021-02-02 13:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-31 12:11 [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Alexander Lobakin
2021-01-31 12:11 ` [PATCH v3 net-next 1/5] mm: constify page_is_pfmemalloc() argument Alexander Lobakin
2021-01-31 12:11 ` [PATCH v3 net-next 3/5] net: introduce common dev_page_is_reusable() Alexander Lobakin
     [not found]   ` <20210131122205.GL308988@casper.infradead.org>
2021-01-31 12:57     ` Alexander Lobakin
2021-02-02  1:18 ` [PATCH v3 net-next 0/5] net: consolidate page_is_pfmemalloc() usage Jakub Kicinski
2021-02-02 13:13   ` Alexander Lobakin

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).