fix page refcount not decrease when free page

Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
Jim Ma 2022-11-23 01:19:36 +08:00
parent 2eae66c0fa
commit 8cb8c8ae0e
2 changed files with 21 additions and 2 deletions

View File

@ -201,3 +201,22 @@ static inline bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
*legacy_u32 = src[0]; *legacy_u32 = src[0];
return retval; return retval;
} }
static inline int page_ref_sub_and_test(struct page *page, int nr)
{
int ret = atomic_sub_and_test(nr, &page->_count);
return ret;
}
static inline void __page_frag_cache_drain(struct page *page, unsigned int count)
{
if (page_ref_sub_and_test(page, count)) {
unsigned int order = compound_order(page);
// TODO optimize with free_unref_page
// if (order == 0)
// free_unref_page(page);
// else
__free_pages(page, order);
}
}

View File

@ -374,7 +374,7 @@ static void igc_clean_rx_ring(struct igc_ring *rx_ring)
buffer_info->dma, buffer_info->dma,
igc_rx_pg_size(rx_ring), igc_rx_pg_size(rx_ring),
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
__free_pages(buffer_info->page, igc_rx_pg_order(rx_ring)); __page_frag_cache_drain(buffer_info->page, buffer_info->pagecnt_bias);
i++; i++;
if (i == rx_ring->count) if (i == rx_ring->count)
@ -1763,7 +1763,7 @@ static void igc_put_rx_buffer(struct igc_ring *rx_ring,
dma_unmap_page(rx_ring->dev, rx_buffer->dma, dma_unmap_page(rx_ring->dev, rx_buffer->dma,
igc_rx_pg_size(rx_ring), igc_rx_pg_size(rx_ring),
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
__free_pages(rx_buffer->page, igc_rx_pg_order(rx_ring)); __page_frag_cache_drain(rx_buffer->page, rx_buffer->pagecnt_bias);
} }
/* clear contents of rx_buffer */ /* clear contents of rx_buffer */