Skip to content

Commit d46d132

Browse files
edumazetdavem330
authored andcommitted
bnx2x: use netdev_alloc_frag()
Using netdev_alloc_frag() instead of kmalloc() permits better GRO or TCP coalescing behavior, as skb_gro_receive() doesn't have to fallback to frag_list overhead. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Dmitry Kravkov <dmitry@broadcom.com> Cc: Eilon Greenstein <eilong@broadcom.com> Acked-by: Dmitry Kravkov <dmitry@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d825da2 commit d46d132

2 files changed

Lines changed: 32 additions & 13 deletions

File tree

‎drivers/net/ethernet/broadcom/bnx2x/bnx2x.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ struct bnx2x_fastpath {
489489
u32 ustorm_rx_prods_offset;
490490

491491
u32 rx_buf_size;
492-
492+
u32 rx_frag_size; /* 0 if kmalloced(), or rx_buf_size + NET_SKB_PAD */
493493
dma_addr_t status_blk_mapping;
494494

495495
enum bnx2x_tpa_mode_t mode;

‎drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,23 @@ static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
552552
return 0;
553553
}
554554

555+
static void bnx2x_frag_free(const struct bnx2x_fastpath *fp, void *data)
556+
{
557+
if (fp->rx_frag_size)
558+
put_page(virt_to_head_page(data));
559+
else
560+
kfree(data);
561+
}
562+
563+
static void *bnx2x_frag_alloc(const struct bnx2x_fastpath *fp)
564+
{
565+
if (fp->rx_frag_size)
566+
return netdev_alloc_frag(fp->rx_frag_size);
567+
568+
return kmalloc(fp->rx_buf_size + NET_SKB_PAD, GFP_ATOMIC);
569+
}
570+
571+
555572
static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
556573
struct bnx2x_agg_info *tpa_info,
557574
u16 pages,
@@ -574,15 +591,14 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
574591
goto drop;
575592

576593
/* Try to allocate the new data */
577-
new_data = kmalloc(fp->rx_buf_size + NET_SKB_PAD, GFP_ATOMIC);
578-
594+
new_data = bnx2x_frag_alloc(fp);
579595
/* Unmap skb in the pool anyway, as we are going to change
580596
pool entry status to BNX2X_TPA_STOP even if new skb allocation
581597
fails. */
582598
dma_unmap_single(&bp->pdev->dev, dma_unmap_addr(rx_buf, mapping),
583599
fp->rx_buf_size, DMA_FROM_DEVICE);
584600
if (likely(new_data))
585-
skb = build_skb(data, 0);
601+
skb = build_skb(data, fp->rx_frag_size);
586602

587603
if (likely(skb)) {
588604
#ifdef BNX2X_STOP_ON_ERROR
@@ -619,7 +635,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
619635

620636
return;
621637
}
622-
kfree(new_data);
638+
bnx2x_frag_free(fp, new_data);
623639
drop:
624640
/* drop the packet and keep the buffer in the bin */
625641
DP(NETIF_MSG_RX_STATUS,
@@ -635,15 +651,15 @@ static int bnx2x_alloc_rx_data(struct bnx2x *bp,
635651
struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
636652
dma_addr_t mapping;
637653

638-
data = kmalloc(fp->rx_buf_size + NET_SKB_PAD, GFP_ATOMIC);
654+
data = bnx2x_frag_alloc(fp);
639655
if (unlikely(data == NULL))
640656
return -ENOMEM;
641657

642658
mapping = dma_map_single(&bp->pdev->dev, data + NET_SKB_PAD,
643659
fp->rx_buf_size,
644660
DMA_FROM_DEVICE);
645661
if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
646-
kfree(data);
662+
bnx2x_frag_free(fp, data);
647663
BNX2X_ERR("Can't map rx data\n");
648664
return -ENOMEM;
649665
}
@@ -845,9 +861,9 @@ int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
845861
dma_unmap_addr(rx_buf, mapping),
846862
fp->rx_buf_size,
847863
DMA_FROM_DEVICE);
848-
skb = build_skb(data, 0);
864+
skb = build_skb(data, fp->rx_frag_size);
849865
if (unlikely(!skb)) {
850-
kfree(data);
866+
bnx2x_frag_free(fp, data);
851867
bnx2x_fp_qstats(bp, fp)->
852868
rx_skb_alloc_failed++;
853869
goto next_rx;
@@ -1145,7 +1161,7 @@ static void bnx2x_free_tpa_pool(struct bnx2x *bp,
11451161
dma_unmap_single(&bp->pdev->dev,
11461162
dma_unmap_addr(first_buf, mapping),
11471163
fp->rx_buf_size, DMA_FROM_DEVICE);
1148-
kfree(data);
1164+
bnx2x_frag_free(fp, data);
11491165
first_buf->data = NULL;
11501166
}
11511167
}
@@ -1190,8 +1206,7 @@ void bnx2x_init_rx_rings(struct bnx2x *bp)
11901206
struct sw_rx_bd *first_buf =
11911207
&tpa_info->first_buf;
11921208

1193-
first_buf->data = kmalloc(fp->rx_buf_size + NET_SKB_PAD,
1194-
GFP_ATOMIC);
1209+
first_buf->data = bnx2x_frag_alloc(fp);
11951210
if (!first_buf->data) {
11961211
BNX2X_ERR("Failed to allocate TPA skb pool for queue[%d] - disabling TPA on this queue!\n",
11971212
j);
@@ -1323,7 +1338,7 @@ static void bnx2x_free_rx_bds(struct bnx2x_fastpath *fp)
13231338
fp->rx_buf_size, DMA_FROM_DEVICE);
13241339

13251340
rx_buf->data = NULL;
1326-
kfree(data);
1341+
bnx2x_frag_free(fp, data);
13271342
}
13281343
}
13291344

@@ -1782,6 +1797,10 @@ static void bnx2x_set_rx_buf_size(struct bnx2x *bp)
17821797
mtu +
17831798
BNX2X_FW_RX_ALIGN_END;
17841799
/* Note : rx_buf_size doesnt take into account NET_SKB_PAD */
1800+
if (fp->rx_buf_size + NET_SKB_PAD <= PAGE_SIZE)
1801+
fp->rx_frag_size = fp->rx_buf_size + NET_SKB_PAD;
1802+
else
1803+
fp->rx_frag_size = 0;
17851804
}
17861805
}
17871806

0 commit comments

Comments
 (0)