lkml.org 
[lkml]   [2019]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[net-next v3 PATCH] page_pool: handle page recycle for NUMA_NO_NODE condition
From
Date
The check in pool_page_reusable (page_to_nid(page) == pool->p.nid) is
not valid if page_pool was configured with pool->p.nid = NUMA_NO_NODE.

The goal of the NUMA changes in commit d5394610b1ba ("page_pool: Don't
recycle non-reusable pages"), were to have RX-pages that belongs to the
same NUMA node as the CPU processing RX-packet during softirq/NAPI. As
illustrated by the performance measurements.

This patch moves the NAPI checks out of fast-path, and at the same time
solves the NUMA_NO_NODE issue.

First realize that alloc_pages_node() with pool->p.nid = NUMA_NO_NODE
will lookup current CPU nid (Numa ID) via numa_mem_id(), which is used
as the the preferred nid. It is only in rare situations, where
e.g. NUMA zone runs dry, that page gets doesn't get allocated from
preferred nid. The page_pool API allows drivers to control the nid
themselves via controlling pool->p.nid.

This patch moves the NAPI check to when alloc cache is refilled, via
dequeuing/consuming pages from the ptr_ring. Thus, we can allow placing
pages from remote NUMA into the ptr_ring, as the dequeue/consume step
will check the NUMA node. All current drivers using page_pool will
alloc/refill RX-ring from same CPU running softirq/NAPI process.

Drivers that control the nid explicitly, also use page_pool_update_nid
when changing nid runtime. To speed up transision to new nid the alloc
cache is now flushed on nid changes. This force pages to come from
ptr_ring, which does the appropate nid check.

For the NUMA_NO_NODE case, when a NIC IRQ is moved to another NUMA
node, then ptr_ring will be emptied in 65 (PP_ALLOC_CACHE_REFILL+1)
chunks per allocation and allocation fall-through to the real
page-allocator with the new nid derived from numa_mem_id(). We accept
that transitioning the alloc cache doesn't happen immediately.

Fixes: d5394610b1ba ("page_pool: Don't recycle non-reusable pages")
Reported-by: Li RongQing <lirongqing@baidu.com>
Reported-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
net/core/page_pool.c | 64 ++++++++++++++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index a6aefe989043..37316ea66937 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -96,19 +96,22 @@ struct page_pool *page_pool_create(const struct page_pool_params *params)
}
EXPORT_SYMBOL(page_pool_create);

+static void __page_pool_return_page(struct page_pool *pool, struct page *page);
+
/* fast path */
static struct page *__page_pool_get_cached(struct page_pool *pool)
{
struct ptr_ring *r = &pool->ring;
+ struct page *first_page, *page;
bool refill = false;
- struct page *page;
+ int i, curr_nid;

/* Test for safe-context, caller should provide this guarantee */
if (likely(in_serving_softirq())) {
if (likely(pool->alloc.count)) {
/* Fast-path */
- page = pool->alloc.cache[--pool->alloc.count];
- return page;
+ first_page = pool->alloc.cache[--pool->alloc.count];
+ return first_page;
}
refill = true;
}
@@ -117,17 +120,42 @@ static struct page *__page_pool_get_cached(struct page_pool *pool)
if (__ptr_ring_empty(r))
return NULL;

- /* Slow-path: Get page from locked ring queue,
- * refill alloc array if requested.
+ /* Softirq guarantee CPU and thus NUMA node is stable. This,
+ * assumes CPU refilling driver RX-ring will also run RX-NAPI.
*/
+ curr_nid = numa_mem_id();
+
+ /* Slower-path: Get pages from locked ring queue */
spin_lock(&r->consumer_lock);
- page = __ptr_ring_consume(r);
- if (refill)
- pool->alloc.count = __ptr_ring_consume_batched(r,
- pool->alloc.cache,
- PP_ALLOC_CACHE_REFILL);
+ first_page = __ptr_ring_consume(r);
+
+ /* Fallback to page-allocator if NUMA node doesn't match */
+ if (first_page && unlikely(!(page_to_nid(first_page) == curr_nid))) {
+ __page_pool_return_page(pool, first_page);
+ first_page = NULL;
+ }
+
+ if (unlikely(!refill))
+ goto out;
+
+ /* Refill alloc array, but only if NUMA node match */
+ for (i = 0; i < PP_ALLOC_CACHE_REFILL; i++) {
+ page = __ptr_ring_consume(r);
+ if (unlikely(!page))
+ break;
+
+ if (likely(page_to_nid(page) == curr_nid)) {
+ pool->alloc.cache[pool->alloc.count++] = page;
+ } else {
+ /* Release page to page-allocator, assume
+ * refcnt == 1 invariant of cached pages
+ */
+ __page_pool_return_page(pool, page);
+ }
+ }
+out:
spin_unlock(&r->consumer_lock);
- return page;
+ return first_page;
}

static void page_pool_dma_sync_for_device(struct page_pool *pool,
@@ -311,13 +339,10 @@ static bool __page_pool_recycle_direct(struct page *page,

/* page is NOT reusable when:
* 1) allocated when system is under some pressure. (page_is_pfmemalloc)
- * 2) belongs to a different NUMA node than pool->p.nid.
- *
- * To update pool->p.nid users must call page_pool_update_nid.
*/
static bool pool_page_reusable(struct page_pool *pool, struct page *page)
{
- return !page_is_pfmemalloc(page) && page_to_nid(page) == pool->p.nid;
+ return !page_is_pfmemalloc(page);
}

void __page_pool_put_page(struct page_pool *pool, struct page *page,
@@ -484,7 +509,16 @@ EXPORT_SYMBOL(page_pool_destroy);
/* Caller must provide appropriate safe context, e.g. NAPI. */
void page_pool_update_nid(struct page_pool *pool, int new_nid)
{
+ struct page *page;
+
+ WARN_ON(!in_serving_softirq());
trace_page_pool_update_nid(pool, new_nid);
pool->p.nid = new_nid;
+
+ /* Flush pool alloc cache, as refill will check NUMA node */
+ while (pool->alloc.count) {
+ page = pool->alloc.cache[--pool->alloc.count];
+ __page_pool_return_page(pool, page);
+ }
}
EXPORT_SYMBOL(page_pool_update_nid);

\
 
 \ /
  Last update: 2019-12-18 00:18    [W:0.112 / U:7.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site