Skip to content

Commit

Permalink
page_pool: add a comment explaining the fragment counter usage
Browse files Browse the repository at this point in the history
When reading the page_pool code the first impression is that keeping
two separate counters, one being the page refcnt and the other being
fragment pp_frag_count, is counter-intuitive.

However without that fragment counter we don't know when to reliably
destroy or sync the outstanding DMA mappings.  So let's add a comment
explaining this part.

Reviewed-by: Alexander Duyck <[email protected]>
Signed-off-by: Ilias Apalodimas <[email protected]>
Acked-by: Jesper Dangaard Brouer <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
apalos authored and kuba-moo committed Feb 21, 2023
1 parent a00da30 commit 4d4266e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/net/page_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ void page_pool_put_defragged_page(struct page_pool *pool, struct page *page,
unsigned int dma_sync_size,
bool allow_direct);

/* pp_frag_count represents the number of writers who can update the page
* either by updating skb->data or via DMA mappings for the device.
* We can't rely on the page refcnt for that as we don't know who might be
* holding page references and we can't reliably destroy or sync DMA mappings
* of the fragments.
*
* When pp_frag_count reaches 0 we can either recycle the page if the page
* refcnt is 1 or return it back to the memory allocator and destroy any
* mappings we have.
*/
static inline void page_pool_fragment_page(struct page *page, long nr)
{
atomic_long_set(&page->pp_frag_count, nr);
Expand Down

0 comments on commit 4d4266e

Please sign in to comment.