Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d73f8f2 authored by Jonathan Lemon's avatar Jonathan Lemon Committed by David S. Miller
Browse files

page_pool: fix logic in __page_pool_get_cached



__page_pool_get_cached() will return NULL when the ring is
empty, even if there are pages present in the lookaside cache.

It is also possible to refill the cache, and then return a
NULL page.

Restructure the logic so eliminate both cases.

Signed-off-by: default avatarJonathan Lemon <jonathan.lemon@gmail.com>
Acked-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Acked-by: default avatarIlias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4b58c9b1
Loading
Loading
Loading
Loading
+16 −23
Original line number Diff line number Diff line
@@ -82,12 +82,9 @@ EXPORT_SYMBOL(page_pool_create);
static struct page *__page_pool_get_cached(struct page_pool *pool)
{
	struct ptr_ring *r = &pool->ring;
	bool refill = false;
	struct page *page;

	/* Quicker fallback, avoid locks when ring is empty */
	if (__ptr_ring_empty(r))
		return NULL;

	/* Test for safe-context, caller should provide this guarantee */
	if (likely(in_serving_softirq())) {
		if (likely(pool->alloc.count)) {
@@ -95,30 +92,26 @@ static struct page *__page_pool_get_cached(struct page_pool *pool)
			page = pool->alloc.cache[--pool->alloc.count];
			return page;
		}
		/* Slower-path: Alloc array empty, time to refill
		 *
		 * Open-coded bulk ptr_ring consumer.
		 *
		 * Discussion: the ring consumer lock is not really
		 * needed due to the softirq/NAPI protection, but
		 * later need the ability to reclaim pages on the
		 * ring. Thus, keeping the locks.
		refill = true;
	}

	/* Quicker fallback, avoid locks when ring is empty */
	if (__ptr_ring_empty(r))
		return NULL;

	/* Slow-path: Get page from locked ring queue,
	 * refill alloc array if requested.
	 */
	spin_lock(&r->consumer_lock);
		while ((page = __ptr_ring_consume(r))) {
			if (pool->alloc.count == PP_ALLOC_CACHE_REFILL)
				break;
			pool->alloc.cache[pool->alloc.count++] = page;
		}
	page = __ptr_ring_consume(r);
	if (refill)
		pool->alloc.count = __ptr_ring_consume_batched(r,
							pool->alloc.cache,
							PP_ALLOC_CACHE_REFILL);
	spin_unlock(&r->consumer_lock);
	return page;
}

	/* Slow-path: Get page from locked ring queue */
	page = ptr_ring_consume(&pool->ring);
	return page;
}

/* slow path */
noinline
static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool,