Skip to contentSkip to conversation

page_pool: check for dma_sync_size earlier

PATCH Superseded Furong Xu 4 participants 17 messages Oct 10, 2024 – Oct 16, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Furong Xu

author
#0 lore raw

PATCH 1/1 page_pool: check for dma_sync_size earlier

Setting dma_sync_size to 0 is not illegal, and several drivers already did. We can save a couple of function calls if check for dma_sync_size earlier.

---
 net/core/page_pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/page_pool.c +1 -1
index a813d30d2135..fac52ba3f7c4 100644
@@ -454,7 +454,7 @@ page_pool_dma_sync_for_device(const struct page_pool *pool,
 			      netmem_ref netmem,
 			      u32 dma_sync_size)
 {
-	if (pool->dma_sync && dma_dev_need_sync(pool->p.dev))
+	if (dma_sync_size && pool->dma_sync && dma_dev_need_sync(pool->p.dev))
 		__page_pool_dma_sync_for_device(pool, netmem, dma_sync_size);
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 13 lines · Furong Xu

Setting dma_sync_size to 0 is not illegal, and several drivers already did. We can save a couple of function calls if check for dma_sync_size earlier.

---
 net/core/page_pool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/page_pool.c +0 -0
index a813d30d2135..fac52ba3f7c4 100644

net/core/page_pool.c page_pool_dma_sync_for_device(const struct page_pool *pool, · line 458

Quoted 6 lines
net/core/page_pool.c +1 -1
@@ -454,7 +454,7 @@ page_pool_dma_sync_for_device(const struct page_pool *pool,
 			      netmem_ref netmem,
 			      u32 dma_sync_size)
 {
-	if (pool->dma_sync && dma_dev_need_sync(pool->p.dev))
+	if (dma_sync_size && pool->dma_sync && dma_dev_need_sync(pool->p.dev))
 		__page_pool_dma_sync_for_device(pool, netmem, dma_sync_size);

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

Quoted 2 lines
net/core/page_pool.c +0 -0
 }
 
author
#2 lore raw
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

maintainer
#3 lore raw

Hi Furong,

Quoted 10 lines · Furong Xu
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

I am not sure I am following. Where does the stmmac driver call a sync with len 0?

Thanks
/Ilias

author
#4 lore raw

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Hi Furong,

Quoted 8 lines · Furong Xu
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

Quoted 5 lines
Quoted 2 lines

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

I am not sure I am following. Where does the stmmac driver call a sync with len 0?

For now, only drivers/net/ethernet/freescale/fec_main.c does.
And stmmac driver does not yet, but I will send another patch to make it call sync with len 0. This is a proper fix as Jakub Kicinski suggested.

#5 lore raw
Quoted 15 lines · Furong Xu

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Hi Furong,

Quoted 8 lines · Furong Xu
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

I am not sure I am following. Where does the stmmac driver call a sync with len 0?

For now, only drivers/net/ethernet/freescale/fec_main.c does.
And stmmac driver does not yet, but I will send another patch to make it call sync with len 0. This is a proper fix as Jakub Kicinski suggested.

In order to support the above use case, it seems there might be two options here:
1. Driver calls page_pool_create() without PP_FLAG_DMA_SYNC_DEV and handle the dma sync itself.
2. Page_pool may provides a non-dma-sync version of page_pool_put_page() API even when Driver calls page_pool_create() with PP_FLAG_DMA_SYNC_DEV.

Maybe option 2 is better one in the longer term as it may provide some flexibility for the user and enable removing of the DMA_SYNC_DEV in the future?

author
#6 lore raw

Hi Jakub,

Quoted 32 lines · Yunsheng Lin
Quoted 15 lines · Furong Xu

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Hi Furong,

Quoted 8 lines · Furong Xu
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

I am not sure I am following. Where does the stmmac driver call a sync with len 0?

For now, only drivers/net/ethernet/freescale/fec_main.c does.
And stmmac driver does not yet, but I will send another patch to make it call sync with len 0. This is a proper fix as Jakub Kicinski suggested.

In order to support the above use case, it seems there might be two options here:
1. Driver calls page_pool_create() without PP_FLAG_DMA_SYNC_DEV and handle the dma sync itself.
2. Page_pool may provides a non-dma-sync version of page_pool_put_page() API even when Driver calls page_pool_create() with PP_FLAG_DMA_SYNC_DEV.

Quoted 3 lines

Maybe option 2 is better one in the longer term as it may provide some flexibility for the user and enable removing of the DMA_SYNC_DEV in the future?

What is your opinion about this?
Thanks.

maintainer
#7 lore raw
Quoted 7 lines · On Fri, 11 Oct 2024 17:26:05 +0800 Furong Xu wrote:
Quoted 7 lines

In order to support the above use case, it seems there might be two options here:
1. Driver calls page_pool_create() without PP_FLAG_DMA_SYNC_DEV and handle the dma sync itself.
2. Page_pool may provides a non-dma-sync version of page_pool_put_page() API even when Driver calls page_pool_create() with PP_FLAG_DMA_SYNC_DEV.

Quoted 5 lines
Quoted 3 lines

Maybe option 2 is better one in the longer term as it may provide some flexibility for the user and enable removing of the DMA_SYNC_DEV in the future?

What is your opinion about this?

I think your patch is fine, but it's a micro optimization so you need to provide some measurement data to show how much of a performance improvement you're getting.

maintainer
#8 lore raw
In reply to Yunsheng Lin
Quoted 33 lines · Yunsheng Lin
Quoted 15 lines · Furong Xu

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Hi Furong,

Quoted 8 lines · Furong Xu
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

I am not sure I am following. Where does the stmmac driver call a sync with len 0?

For now, only drivers/net/ethernet/freescale/fec_main.c does.
And stmmac driver does not yet, but I will send another patch to make it call sync with len 0. This is a proper fix as Jakub Kicinski suggested.

In order to support the above use case, it seems there might be two options here:
1. Driver calls page_pool_create() without PP_FLAG_DMA_SYNC_DEV and handle the dma sync itself.
2. Page_pool may provides a non-dma-sync version of page_pool_put_page() API even when Driver calls page_pool_create() with PP_FLAG_DMA_SYNC_DEV.

Quoted 3 lines

Maybe option 2 is better one in the longer term as it may provide some flexibility for the user and enable removing of the DMA_SYNC_DEV in the future?

Case 2 would be what this patch does. We already treat -1 as the maximum DMA memory size. I think it's ok to treat 0 as 'don't sync'. I need to figure out why people need this.
IOW you still have to sync the page to use it. Now you can do it when allocating it, but why is that cheaper or preferable?

Thanks
/Ilias

#9 lore raw
Quoted 34 lines · Ilias Apalodimas
Quoted 33 lines · Yunsheng Lin
Quoted 15 lines · Furong Xu

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Hi Furong,

Quoted 8 lines · Furong Xu
Quoted 4 lines · Yunsheng Lin

Is there any reason that those drivers not to unset the PP_FLAG_DMA_SYNC_DEV when calling page_pool_create()?
Does it only need dma sync for some cases and not need dma sync for other cases? if so, why not do the dma sync in the driver instead?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The answer is in this commit:
https://git.kernel.org/netdev/net/c/5546da79e6cc

I am not sure I am following. Where does the stmmac driver call a sync with len 0?

For now, only drivers/net/ethernet/freescale/fec_main.c does.
And stmmac driver does not yet, but I will send another patch to make it call sync with len 0. This is a proper fix as Jakub Kicinski suggested.

In order to support the above use case, it seems there might be two options here:
1. Driver calls page_pool_create() without PP_FLAG_DMA_SYNC_DEV and handle the dma sync itself.
2. Page_pool may provides a non-dma-sync version of page_pool_put_page() API even when Driver calls page_pool_create() with PP_FLAG_DMA_SYNC_DEV.

Quoted 5 lines
Quoted 3 lines

Maybe option 2 is better one in the longer term as it may provide some flexibility for the user and enable removing of the DMA_SYNC_DEV in the future?

Case 2 would be what this patch does. We already treat -1 as the

I would prefer to add a new api to do that, as it makes the semantic more obvious and may enable removing some checking in the future.

And we may need to disable this 'feature' for frag relate API for now, as currently there may be multi callings to page_pool_put_netmem() for the same page, and dma_sync is only done for the last one, which means it might cause some problem for those usecases when using frag API.

Quoted 9 lines

maximum DMA memory size. I think it's ok to treat 0 as 'don't sync'. I need to figure out why people need this.
IOW you still have to sync the page to use it. Now you can do it when allocating it, but why is that cheaper or preferable?

Thanks
/Ilias

author
#10 lore raw

Hi Yunsheng,

Quoted 7 lines · Yunsheng Lin

I would prefer to add a new api to do that, as it makes the semantic more obvious and may enable removing some checking in the future.

And we may need to disable this 'feature' for frag relate API for now, as currently there may be multi callings to page_pool_put_netmem() for the same page, and dma_sync is only done for the last one, which means it might cause some problem for those usecases when using frag API.

I am not an expert on page_pool.
So would you mind sending a new patch to add a non-dma-sync version of page_pool_put_page() and CC it to me?
I am so glad to test it on my device ;)
Thanks.

#11 lore raw
Quoted 7 lines · Furong Xu

Hi Yunsheng,

Quoted 3 lines · Yunsheng Lin

I would prefer to add a new api to do that, as it makes the semantic more obvious and may enable removing some checking in the future.

Quoted 8 lines
Quoted 4 lines

And we may need to disable this 'feature' for frag relate API for now, as currently there may be multi callings to page_pool_put_netmem() for the same page, and dma_sync is only done for the last one, which means it might cause some problem for those usecases when using frag API.

I am not an expert on page_pool.
So would you mind sending a new patch to add a non-dma-sync version of page_pool_put_page() and CC it to me?

As I have at least two patchsets pending for the net-next, which seems it might take a while, so it might take a while for me to send another new patch.

Perhaps just add something like page_pool_put_page_nosync() as page_pool_put_full_page() does for the case of dma_sync_size being -1? and leave removing of extra checking as later refactoring and optimization.

As for the frag related API like page_pool_alloc_frag() and page_pool_alloc(), we don't really have a corresponding free side API for them, instead we reuse page_pool_put_page() for the free side, and don't really do any dma sync unless it is the last frag user of the same page, see the page_pool_is_last_ref() checking in page_pool_put_netmem().

So it might require more refactoring to support the usecase of this patch for frag API, for example we might need to pull the dma_sync operation out of __page_pool_put_page(), and put it in page_pool_put_netmem() so that dma_sync is also done for the non-last frag user too.
Or not support it for frag API for now as stmmac driver does not seem to be using frag API, and put a warning to catch the case of misusing of the 'feature' for frag API in the 'if' checking in page_pool_put_netmem() before returning? something like below:

include/net/page_pool/helpers.h +4 -1
@@ -317,8 +317,10 @@ static inline void page_pool_put_netmem(struct page_pool *pool,
         * allow registering MEM_TYPE_PAGE_POOL, but shield linker.
         */
 #ifdef CONFIG_PAGE_POOL
-       if (!page_pool_is_last_ref(netmem))
+       if (!page_pool_is_last_ref(netmem)) {
+		/* Big comment why frag API is not support yet */
+               DEBUG_NET_WARN_ON_ONCE(!dma_sync_size);
                return;
+       }
 
        page_pool_put_unrefed_netmem(pool, netmem, dma_sync_size, allow_direct);

#endif

Quoted 4 lines

I am so glad to test it on my device ;)
Thanks.

maintainer
#12 lore raw

Hi Yunsheng,

Quoted 47 lines · Yunsheng Lin
Quoted 7 lines · Furong Xu

Hi Yunsheng,

Quoted 3 lines · Yunsheng Lin

I would prefer to add a new api to do that, as it makes the semantic more obvious and may enable removing some checking in the future.

Quoted 8 lines
Quoted 4 lines

And we may need to disable this 'feature' for frag relate API for now, as currently there may be multi callings to page_pool_put_netmem() for the same page, and dma_sync is only done for the last one, which means it might cause some problem for those usecases when using frag API.

I am not an expert on page_pool.
So would you mind sending a new patch to add a non-dma-sync version of page_pool_put_page() and CC it to me?

As I have at least two patchsets pending for the net-next, which seems it might take a while, so it might take a while for me to send another new patch.

Perhaps just add something like page_pool_put_page_nosync() as page_pool_put_full_page() does for the case of dma_sync_size being -1? and leave removing of extra checking as later refactoring and optimization.

As for the frag related API like page_pool_alloc_frag() and page_pool_alloc(), we don't really have a corresponding free side API for them, instead we reuse page_pool_put_page() for the free side, and don't really do any dma sync unless it is the last frag user of the same page, see the page_pool_is_last_ref() checking in page_pool_put_netmem().

So it might require more refactoring to support the usecase of this patch for frag API, for example we might need to pull the dma_sync operation out of __page_pool_put_page(), and put it in page_pool_put_netmem() so that dma_sync is also done for the non-last frag user too.
Or not support it for frag API for now as stmmac driver does not seem to be using frag API, and put a warning to catch the case of misusing of the 'feature' for frag API in the 'if' checking in page_pool_put_netmem() before returning? something like below:

include/net/page_pool/helpers.h static inline void page_pool_put_netmem(struct page_pool *pool, · line 322

Quoted 7 lines
include/net/page_pool/helpers.h +3 -1
@@ -317,8 +317,10 @@ static inline void page_pool_put_netmem(struct page_pool *pool,
         * allow registering MEM_TYPE_PAGE_POOL, but shield linker.
         */
 #ifdef CONFIG_PAGE_POOL
-       if (!page_pool_is_last_ref(netmem))
+       if (!page_pool_is_last_ref(netmem)) {
+               /* Big comment why frag API is not support yet */
+               DEBUG_NET_WARN_ON_ONCE(!dma_sync_size);

Ok, since we do have a page_pool_put_full_page(), adding a variant for the nosync seems reasonable.
But can't the check above be part of that function instead of the core code?

Thanks
/Ilias

Quoted 11 lines
include/net/page_pool/helpers.h +1 -0
                return;
+       }
 
        page_pool_put_unrefed_netmem(pool, netmem, dma_sync_size, allow_direct);
 #endif
Quoted 6 lines

I am so glad to test it on my device ;)
Thanks.

#13 lore raw
Quoted 47 lines · Ilias Apalodimas

Hi Yunsheng,

Quoted 44 lines · Yunsheng Lin
Quoted 7 lines · Furong Xu

Hi Yunsheng,

Quoted 3 lines · Yunsheng Lin

I would prefer to add a new api to do that, as it makes the semantic more obvious and may enable removing some checking in the future.

Quoted 8 lines
Quoted 4 lines

And we may need to disable this 'feature' for frag relate API for now, as currently there may be multi callings to page_pool_put_netmem() for the same page, and dma_sync is only done for the last one, which means it might cause some problem for those usecases when using frag API.

I am not an expert on page_pool.
So would you mind sending a new patch to add a non-dma-sync version of page_pool_put_page() and CC it to me?

As I have at least two patchsets pending for the net-next, which seems it might take a while, so it might take a while for me to send another new patch.

Perhaps just add something like page_pool_put_page_nosync() as page_pool_put_full_page() does for the case of dma_sync_size being -1? and leave removing of extra checking as later refactoring and optimization.

As for the frag related API like page_pool_alloc_frag() and page_pool_alloc(), we don't really have a corresponding free side API for them, instead we reuse page_pool_put_page() for the free side, and don't really do any dma sync unless it is the last frag user of the same page, see the page_pool_is_last_ref() checking in page_pool_put_netmem().

So it might require more refactoring to support the usecase of this patch for frag API, for example we might need to pull the dma_sync operation out of __page_pool_put_page(), and put it in page_pool_put_netmem() so that dma_sync is also done for the non-last frag user too.
Or not support it for frag API for now as stmmac driver does not seem to be using frag API, and put a warning to catch the case of misusing of the 'feature' for frag API in the 'if' checking in page_pool_put_netmem() before returning? something like below:

Quoted 10 lines

include/net/page_pool/helpers.h static inline void page_pool_put_netmem(struct page_pool *pool, · line 322

Quoted 10 lines
include/net/page_pool/helpers.h +3 -1
@@ -317,8 +317,10 @@ static inline void page_pool_put_netmem(struct page_pool *pool,
         * allow registering MEM_TYPE_PAGE_POOL, but shield linker.
         */
 #ifdef CONFIG_PAGE_POOL
-       if (!page_pool_is_last_ref(netmem))
+       if (!page_pool_is_last_ref(netmem)) {
+               /* Big comment why frag API is not support yet */
+               DEBUG_NET_WARN_ON_ONCE(!dma_sync_size);

Note, the above checking is not 100% reliable, as which frag user is the last one depending on runtime excution.

Quoted 4 lines

Ok, since we do have a page_pool_put_full_page(), adding a variant for the nosync seems reasonable.
But can't the check above be part of that function instead of the core code?

I was thinking about something like below mirroring page_pool_put_full_page() for simplicity:
static inline void page_pool_put_page_nosync(struct page_pool *pool,
struct page *page, bool allow_direct)

{
	page_pool_put_netmem(pool, page_to_netmem(page), 0, allow_direct);
}

And do the dma_sync_size checking as this patch does in page_pool_dma_sync_for_device().

maintainer
#14 lore raw

Apologies for the noise. The last message was not clear text...

Quoted 49 lines · Yunsheng Lin
Quoted 47 lines · Ilias Apalodimas

Hi Yunsheng,

Quoted 44 lines · Yunsheng Lin
Quoted 7 lines · Furong Xu

Hi Yunsheng,

Quoted 3 lines · Yunsheng Lin

I would prefer to add a new api to do that, as it makes the semantic more obvious and may enable removing some checking in the future.

Quoted 8 lines
Quoted 4 lines

And we may need to disable this 'feature' for frag relate API for now, as currently there may be multi callings to page_pool_put_netmem() for the same page, and dma_sync is only done for the last one, which means it might cause some problem for those usecases when using frag API.

I am not an expert on page_pool.
So would you mind sending a new patch to add a non-dma-sync version of page_pool_put_page() and CC it to me?

As I have at least two patchsets pending for the net-next, which seems it might take a while, so it might take a while for me to send another new patch.

Perhaps just add something like page_pool_put_page_nosync() as page_pool_put_full_page() does for the case of dma_sync_size being -1? and leave removing of extra checking as later refactoring and optimization.

As for the frag related API like page_pool_alloc_frag() and page_pool_alloc(), we don't really have a corresponding free side API for them, instead we reuse page_pool_put_page() for the free side, and don't really do any dma sync unless it is the last frag user of the same page, see the page_pool_is_last_ref() checking in page_pool_put_netmem().

So it might require more refactoring to support the usecase of this patch for frag API, for example we might need to pull the dma_sync operation out of __page_pool_put_page(), and put it in page_pool_put_netmem() so that dma_sync is also done for the non-last frag user too.
Or not support it for frag API for now as stmmac driver does not seem to be using frag API, and put a warning to catch the case of misusing of the 'feature' for frag API in the 'if' checking in page_pool_put_netmem() before returning? something like below:

Quoted 13 lines
Quoted 10 lines

include/net/page_pool/helpers.h static inline void page_pool_put_netmem(struct page_pool *pool, · line 322

Quoted 10 lines
include/net/page_pool/helpers.h +3 -1
@@ -317,8 +317,10 @@ static inline void page_pool_put_netmem(struct page_pool *pool,
         * allow registering MEM_TYPE_PAGE_POOL, but shield linker.
         */
 #ifdef CONFIG_PAGE_POOL
-       if (!page_pool_is_last_ref(netmem))
+       if (!page_pool_is_last_ref(netmem)) {
+               /* Big comment why frag API is not support yet */
+               DEBUG_NET_WARN_ON_ONCE(!dma_sync_size);

Note, the above checking is not 100% reliable, as which frag user is the last one depending on runtime execution.

I am not sure I understand the problem here. If we are about to call page_pool_return_page() we don't care what happens to that page. If we end up calling __page_pool_put_page() it's the *callers* job now to sync the page now once all fragments are released. So why is this different from syncing an entire page?

Quoted 6 lines
Quoted 5 lines

Ok, since we do have a page_pool_put_full_page(), adding a variant for the nosync seems reasonable.
But can't the check above be part of that function instead of the core code?

Quoted 8 lines

I was thinking about something like below mirroring page_pool_put_full_page() for simplicity:
static inline void page_pool_put_page_nosync(struct page_pool *pool,
struct page *page, bool allow_direct)

{
        page_pool_put_netmem(pool, page_to_netmem(page), 0, allow_direct);
}

Yes, that's ok. But the question was about moving the !dma_sync_size warning. On second thought I think it's better if we leave it on the core code. But as I said above I am not sure why we need it.

Thanks
/Ilias

Quoted 2 lines

And do the dma_sync_size checking as this patch does in page_pool_dma_sync_for_device().

author
#15 lore raw

Hi Ilias,

Quoted 21 lines · Ilias Apalodimas

I am not sure I understand the problem here. If we are about to call page_pool_return_page() we don't care what happens to that page. If we end up calling __page_pool_put_page() it's the *callers* job now to sync the page now once all fragments are released. So why is this different from syncing an entire page?

Quoted 6 lines
Quoted 5 lines

Ok, since we do have a page_pool_put_full_page(), adding a variant for the nosync seems reasonable.
But can't the check above be part of that function instead of the core code?

Quoted 8 lines

I was thinking about something like below mirroring page_pool_put_full_page() for simplicity:
static inline void page_pool_put_page_nosync(struct page_pool *pool,
struct page *page, bool allow_direct)

{
        page_pool_put_netmem(pool, page_to_netmem(page), 0, allow_direct);
}
Quoted 3 lines

Yes, that's ok. But the question was about moving the !dma_sync_size warning. On second thought I think it's better if we leave it on the core code. But as I said above I am not sure why we need it.

You can read this:
https://git.kernel.org/netdev/net/c/b514c47ebf41
https://git.kernel.org/netdev/net/c/5546da79e6cc

drivers/net/ethernet/renesas/ravb_main.c and drivers/net/ethernet/freescale/fec_main.c are calling page_pool_put_page() with dma_sync_size setting to 0.

I will send another patchset to add page_pool_put_page_nosync() as Yunsheng Lin suggested, then convert drivers/net/ethernet/renesas/ravb_main.c and drivers/net/ethernet/freescale/fec_main.c to the new page_pool_put_page_nosync().

#16 lore raw
In reply to Ilias Apalodimas

On 2024/10/15 21:25, Ilias Apalodimas wrote:

...

Quoted 15 lines
Quoted 14 lines
Quoted 11 lines

include/net/page_pool/helpers.h static inline void page_pool_put_netmem(struct page_pool *pool, · line 322

Quoted 11 lines
include/net/page_pool/helpers.h +3 -1
@@ -317,8 +317,10 @@ static inline void page_pool_put_netmem(struct page_pool *pool,
         * allow registering MEM_TYPE_PAGE_POOL, but shield linker.
         */
 #ifdef CONFIG_PAGE_POOL
-       if (!page_pool_is_last_ref(netmem))
+       if (!page_pool_is_last_ref(netmem)) {
+               /* Big comment why frag API is not support yet */
+               DEBUG_NET_WARN_ON_ONCE(!dma_sync_size);

Note, the above checking is not 100% reliable, as which frag user is the last one depending on runtime execution.

Quoted 5 lines

I am not sure I understand the problem here. If we are about to call page_pool_return_page() we don't care what happens to that page. If we end up calling __page_pool_put_page() it's the *callers* job now to sync the page now once all fragments are released. So why is this different from syncing an entire page?

It also would be that we end up calling nothing for non-last-frag-user too when page_pool_is_last_ref() return false as the above 'if' checking in page_pool_put_netmem() if frag related API is used.

If the above happens, there is no dma_sync done here even if the caller passes a non-zero 'dma_sync_size' which means it is not supposed to call page_pool_put_unrefed_netmem() for the same page with both zero and non-zero 'dma_sync_size'.

For example:
1. If page_pool_put_page() with dma_sync_size being non-zero is first called for a page, and there might be no dma_sync operation if it is not the last frag.
2. Then page_pool_put_page() with dma_sync_size being zero is called for the same page to skip the dma_sync operation.

Then we might have problem here as the dma_sync operation is only expected to be skipped for a specific page fragment, but the above calling order causes the dma_sync operation to be skipped for the whole page.

IOW, there is currently no way to tell which fragment is being freed when page_pool_put_page() API is called for a page split into multi fragments now, so we might need to call page_pool_put_page() with 'dma_sync_size' all being '-1' if the page_pool is expected to do the dma sync operation for now.

Quoted 2 lines
Quoted 2 lines