Skip to content

Commit 46f4017

Browse files
minakuba-moo
authored andcommitted
net: page_pool: factor out page_pool recycle check
The check is duplicated in 2 places, factor it out into a common helper. Signed-off-by: Mina Almasry <almasrymina@google.com> Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Link: https://lore.kernel.org/r/20240308204500.1112858-1-almasrymina@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ad32b3c commit 46f4017

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

net/core/page_pool.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ static bool page_pool_recycle_in_cache(struct page *page,
657657
return true;
658658
}
659659

660+
static bool __page_pool_page_can_be_recycled(const struct page *page)
661+
{
662+
return page_ref_count(page) == 1 && !page_is_pfmemalloc(page);
663+
}
664+
660665
/* If the page refcnt == 1, this will try to recycle the page.
661666
* if PP_FLAG_DMA_SYNC_DEV is set, we'll try to sync the DMA area for
662667
* the configured size min(dma_sync_size, pool->max_len).
@@ -678,7 +683,7 @@ __page_pool_put_page(struct page_pool *pool, struct page *page,
678683
* page is NOT reusable when allocated when system is under
679684
* some pressure. (page_is_pfmemalloc)
680685
*/
681-
if (likely(page_ref_count(page) == 1 && !page_is_pfmemalloc(page))) {
686+
if (likely(__page_pool_page_can_be_recycled(page))) {
682687
/* Read barrier done in page_ref_count / READ_ONCE */
683688

684689
if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV)
@@ -793,7 +798,7 @@ static struct page *page_pool_drain_frag(struct page_pool *pool,
793798
if (likely(page_pool_unref_page(page, drain_count)))
794799
return NULL;
795800

796-
if (page_ref_count(page) == 1 && !page_is_pfmemalloc(page)) {
801+
if (__page_pool_page_can_be_recycled(page)) {
797802
if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV)
798803
page_pool_dma_sync_for_device(pool, page, -1);
799804

0 commit comments

Comments
 (0)