net/mlx5e: RX, Remove internal page_cache
authorDragos Tatulea <dtatulea@nvidia.com>
Tue, 13 Dec 2022 12:37:07 +0000 (14:37 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 28 Mar 2023 20:43:57 +0000 (13:43 -0700)
This patch removes the internal rx page_cache and uses the generic
page_pool api only. It used to be that the page_pool couldn't handle all
the mlx5 driver usecases, but with the introduction of skb recycling and
page fragmentaton in the page_pool full switch can now be made. Some
benfits of this transition:
* Better page recycling in the cases when the page_cache was suffering
  from head of queue blocking. The page_pool doesn't have this issue.
* DMA mapping/unmapping can be managed by the page_pool.
* mlx5e_rq size reduced by more than 50% due to the page_cache array
  being deleted.

This patch only removes the page_cache. Downstream patches will enable
the required page_pool features and will add further fine-tuning.

Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c

index b38fbacbb4d1a979e34d48ab037d83718d83b5e7..2684e7af5a7a51d14b39809218195e4bee0ed075 100644 (file)
@@ -628,11 +628,6 @@ struct mlx5e_mpw_info {
 #define MLX5E_CACHE_UNIT (MLX5_MPWRQ_MAX_PAGES_PER_WQE > NAPI_POLL_WEIGHT ? \
                          MLX5_MPWRQ_MAX_PAGES_PER_WQE : NAPI_POLL_WEIGHT)
 #define MLX5E_CACHE_SIZE       (4 * roundup_pow_of_two(MLX5E_CACHE_UNIT))
-struct mlx5e_page_cache {
-       u32 head;
-       u32 tail;
-       struct page *page_cache[MLX5E_CACHE_SIZE];
-};
 
 struct mlx5e_rq;
 typedef void (*mlx5e_fp_handle_rx_cqe)(struct mlx5e_rq*, struct mlx5_cqe64*);
@@ -745,7 +740,6 @@ struct mlx5e_rq {
        struct mlx5e_rq_stats *stats;
        struct mlx5e_cq        cq;
        struct mlx5e_cq_decomp cqd;
-       struct mlx5e_page_cache page_cache;
        struct hwtstamp_config *tstamp;
        struct mlx5_clock      *clock;
        struct mlx5e_icosq    *icosq;
index 77f81d74ff30b493f69f4f9a7ee7dba97a21b8e4..b0322a20b71b10d2736368c3436499f020c9699e 100644 (file)
@@ -900,9 +900,6 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
                rq->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
        }
 
-       rq->page_cache.head = 0;
-       rq->page_cache.tail = 0;
-
        return 0;
 
 err_destroy_page_pool:
@@ -933,7 +930,6 @@ err_rq_xdp_prog:
 static void mlx5e_free_rq(struct mlx5e_rq *rq)
 {
        struct bpf_prog *old_prog;
-       int i;
 
        if (xdp_rxq_info_is_reg(&rq->xdp_rxq)) {
                old_prog = rcu_dereference_protected(rq->xdp_prog,
@@ -953,15 +949,6 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)
                mlx5e_free_wqe_alloc_info(rq);
        }
 
-       for (i = rq->page_cache.head; i != rq->page_cache.tail;
-            i = (i + 1) & (MLX5E_CACHE_SIZE - 1)) {
-               /* With AF_XDP, page_cache is not used, so this loop is not
-                * entered, and it's safe to call mlx5e_page_release_dynamic
-                * directly.
-                */
-               mlx5e_page_release_dynamic(rq, rq->page_cache.page_cache[i], false);
-       }
-
        xdp_rxq_info_unreg(&rq->xdp_rxq);
        page_pool_destroy(rq->page_pool);
        mlx5_wq_destroy(&rq->wq_ctrl);
index 7057db954f6fc2b7b44f103dccb478cd865c8c58..192f12a7d9a961f5a652f1f950f139a4bdc3d27b 100644 (file)
@@ -271,60 +271,10 @@ static inline u32 mlx5e_decompress_cqes_start(struct mlx5e_rq *rq,
        return mlx5e_decompress_cqes_cont(rq, wq, 1, budget_rem);
 }
 
-static inline bool mlx5e_rx_cache_put(struct mlx5e_rq *rq, struct page *page)
-{
-       struct mlx5e_page_cache *cache = &rq->page_cache;
-       u32 tail_next = (cache->tail + 1) & (MLX5E_CACHE_SIZE - 1);
-       struct mlx5e_rq_stats *stats = rq->stats;
-
-       if (tail_next == cache->head) {
-               stats->cache_full++;
-               return false;
-       }
-
-       if (!dev_page_is_reusable(page)) {
-               stats->cache_waive++;
-               return false;
-       }
-
-       cache->page_cache[cache->tail] = page;
-       cache->tail = tail_next;
-       return true;
-}
-
-static inline bool mlx5e_rx_cache_get(struct mlx5e_rq *rq, struct page **pagep)
-{
-       struct mlx5e_page_cache *cache = &rq->page_cache;
-       struct mlx5e_rq_stats *stats = rq->stats;
-       dma_addr_t addr;
-
-       if (unlikely(cache->head == cache->tail)) {
-               stats->cache_empty++;
-               return false;
-       }
-
-       if (page_ref_count(cache->page_cache[cache->head]) != 1) {
-               stats->cache_busy++;
-               return false;
-       }
-
-       *pagep = cache->page_cache[cache->head];
-       cache->head = (cache->head + 1) & (MLX5E_CACHE_SIZE - 1);
-       stats->cache_reuse++;
-
-       addr = page_pool_get_dma_addr(*pagep);
-       /* Non-XSK always uses PAGE_SIZE. */
-       dma_sync_single_for_device(rq->pdev, addr, PAGE_SIZE, rq->buff.map_dir);
-       return true;
-}
-
 static inline int mlx5e_page_alloc_pool(struct mlx5e_rq *rq, struct page **pagep)
 {
        dma_addr_t addr;
 
-       if (mlx5e_rx_cache_get(rq, pagep))
-               return 0;
-
        *pagep = page_pool_dev_alloc_pages(rq->page_pool);
        if (unlikely(!*pagep))
                return -ENOMEM;
@@ -353,9 +303,6 @@ void mlx5e_page_dma_unmap(struct mlx5e_rq *rq, struct page *page)
 void mlx5e_page_release_dynamic(struct mlx5e_rq *rq, struct page *page, bool recycle)
 {
        if (likely(recycle)) {
-               if (mlx5e_rx_cache_put(rq, page))
-                       return;
-
                mlx5e_page_dma_unmap(rq, page);
                page_pool_recycle_direct(rq->page_pool, page);
        } else {