mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: <davem@davemloft.net>, <kuba@kernel.org>, <pabeni@redhat.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Yunsheng Lin <linyunsheng@huawei.com>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	Alexander Duyck <alexander.duyck@gmail.com>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Eric Dumazet <edumazet@google.com>
Subject: [RFC 2/3] page_pool: support non-frag page for page_pool_alloc_frag()
Date: Tue, 16 May 2023 20:48:00 +0800	[thread overview]
Message-ID: <20230516124801.2465-3-linyunsheng@huawei.com> (raw)
In-Reply-To: <20230516124801.2465-1-linyunsheng@huawei.com>

There is performance penalty with using page frag support when
user requests a larger frag size and a page only supports one
frag user, see [1].

It seems like user may request different frag size depending
on the mtu and packet size, provide an option to allocate
non-frag page when user has requested a frag size larger than
a specific size, so that user has a unified interface for the
memory allocation with least memory utilization and performance
penalty.

1. https://lore.kernel.org/netdev/ZEU+vospFdm08IeE@localhost.localdomain/

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
CC: Lorenzo Bianconi <lorenzo@kernel.org>
CC: Alexander Duyck <alexander.duyck@gmail.com>
---
 include/net/page_pool.h |  9 +++++++++
 net/core/page_pool.c    | 10 ++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index 14ac46297ae4..d1c57c0c8f49 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -163,6 +163,7 @@ struct page_pool {
 	unsigned int frag_offset;
 	struct page *frag_page;
 	long frag_users;
+	unsigned int max_frag_size;
 
 #ifdef CONFIG_PAGE_POOL_STATS
 	/* these stats are incremented while in softirq context */
@@ -213,6 +214,14 @@ struct page_pool {
 	u64 destroy_cnt;
 };
 
+/* Called after page_pool_create() */
+static inline void page_pool_set_max_frag_size(struct page_pool *pool,
+					       unsigned int max_frag_size)
+{
+	pool->max_frag_size = min_t(unsigned int, max_frag_size,
+				    PAGE_SIZE << pool->p.order);
+}
+
 struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp);
 
 static inline struct page *page_pool_dev_alloc_pages(struct page_pool *pool)
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 5d93c5dc0549..aab6147f28af 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -198,6 +198,8 @@ static int page_pool_init(struct page_pool *pool,
 	if (pool->p.flags & PP_FLAG_DMA_MAP)
 		get_device(pool->p.dev);
 
+	page_pool_set_max_frag_size(pool, PAGE_SIZE << pool->p.order);
+
 	return 0;
 }
 
@@ -699,10 +701,14 @@ struct page *page_pool_alloc_frag(struct page_pool *pool,
 	unsigned int max_size = PAGE_SIZE << pool->p.order;
 	struct page *page = pool->frag_page;
 
-	if (WARN_ON(PAGE_POOL_DMA_USE_PP_FRAG_COUNT ||
-		    size > max_size))
+	if (WARN_ON(PAGE_POOL_DMA_USE_PP_FRAG_COUNT))
 		return NULL;
 
+	if (unlikely(size > pool->max_frag_size)) {
+		*offset = 0;
+		return page_pool_alloc_pages(pool, gfp);
+	}
+
 	size = ALIGN(size, dma_get_cache_alignment());
 	*offset = pool->frag_offset;
 
-- 
2.33.0


  parent reply	other threads:[~2023-05-16 12:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 12:47 [RFC 0/3] " Yunsheng Lin
2023-05-16 12:47 ` [RFC 1/3] page_pool: unify frag page and non-frag page handling Yunsheng Lin
2023-05-16 12:48 ` Yunsheng Lin [this message]
2023-05-16 12:48 ` [RFC 3/3] page_pool: introduce 'struct page_pool_frag' Yunsheng Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230516124801.2465-3-linyunsheng@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=alexander.duyck@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®