linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache()
@ 2022-01-07  9:00 Yunsheng Lin
  2022-01-07 13:32 ` Jesper Dangaard Brouer
  2022-01-10  1:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Yunsheng Lin @ 2022-01-07  9:00 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, linux-kernel, hawk, ilias.apalodimas

As page_pool_refill_alloc_cache() is only called by
__page_pool_get_cached(), which assumes non-concurrent access
as suggested by the comment in __page_pool_get_cached(), and
ptr_ring allows concurrent access between consumer and producer,
so remove the spinlock in page_pool_refill_alloc_cache().

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
---
 net/core/page_pool.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 1a6978427d6c..6efad8b29e9c 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -130,9 +130,6 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool)
 	pref_nid = numa_mem_id(); /* will be zero like page_to_nid() */
 #endif
 
-	/* Slower-path: Get pages from locked ring queue */
-	spin_lock(&r->consumer_lock);
-
 	/* Refill alloc array, but only if NUMA match */
 	do {
 		page = __ptr_ring_consume(r);
@@ -157,7 +154,6 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool)
 	if (likely(pool->alloc.count > 0))
 		page = pool->alloc.cache[--pool->alloc.count];
 
-	spin_unlock(&r->consumer_lock);
 	return page;
 }
 
-- 
2.33.0


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

* Re: [PATCH net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache()
  2022-01-07  9:00 [PATCH net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache() Yunsheng Lin
@ 2022-01-07 13:32 ` Jesper Dangaard Brouer
  2022-01-10  1:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2022-01-07 13:32 UTC (permalink / raw)
  To: Yunsheng Lin, davem, kuba
  Cc: brouer, netdev, linux-kernel, hawk, ilias.apalodimas,
	Michael S. Tsirkin, Linux-MM



On 07/01/2022 10.00, Yunsheng Lin wrote:
> As page_pool_refill_alloc_cache() is only called by
> __page_pool_get_cached(), which assumes non-concurrent access
> as suggested by the comment in __page_pool_get_cached(), and
> ptr_ring allows concurrent access between consumer and producer,
> so remove the spinlock in page_pool_refill_alloc_cache().

This should be okay as __ptr_ring_consume() have a memory barrier via 
READ_ONCE in __ptr_ring_peek(). The code page_pool_empty_ring() also 
does ptr_ring consume, but drivers should already take care that this 
will not be called concurrently, as it is part of the teardown code path 
(which can only run concurrently with ptr_ring producer side).

Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>

The original reason behind this lock was that I was planning to allow 
the memory subsystem to reclaim pages sitting in page_pool's cache.
Unfortunately I never got around to implement this.

> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> ---
>   net/core/page_pool.c | 4 ----
>   1 file changed, 4 deletions(-)
> 
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 1a6978427d6c..6efad8b29e9c 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -130,9 +130,6 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool)
>   	pref_nid = numa_mem_id(); /* will be zero like page_to_nid() */
>   #endif
>   
> -	/* Slower-path: Get pages from locked ring queue */
> -	spin_lock(&r->consumer_lock);
> -
>   	/* Refill alloc array, but only if NUMA match */
>   	do {
>   		page = __ptr_ring_consume(r);
> @@ -157,7 +154,6 @@ static struct page *page_pool_refill_alloc_cache(struct page_pool *pool)
>   	if (likely(pool->alloc.count > 0))
>   		page = pool->alloc.cache[--pool->alloc.count];
>   
> -	spin_unlock(&r->consumer_lock);
>   	return page;
>   }
>   
> 


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

* Re: [PATCH net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache()
  2022-01-07  9:00 [PATCH net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache() Yunsheng Lin
  2022-01-07 13:32 ` Jesper Dangaard Brouer
@ 2022-01-10  1:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-10  1:00 UTC (permalink / raw)
  To: Yunsheng Lin; +Cc: davem, kuba, netdev, linux-kernel, hawk, ilias.apalodimas

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 7 Jan 2022 17:00:42 +0800 you wrote:
> As page_pool_refill_alloc_cache() is only called by
> __page_pool_get_cached(), which assumes non-concurrent access
> as suggested by the comment in __page_pool_get_cached(), and
> ptr_ring allows concurrent access between consumer and producer,
> so remove the spinlock in page_pool_refill_alloc_cache().
> 
> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> 
> [...]

Here is the summary with links:
  - [net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache()
    https://git.kernel.org/netdev/net-next/c/07b17f0f7485

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-01-10  1:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07  9:00 [PATCH net-next] page_pool: remove spinlock in page_pool_refill_alloc_cache() Yunsheng Lin
2022-01-07 13:32 ` Jesper Dangaard Brouer
2022-01-10  1:00 ` patchwork-bot+netdevbpf

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