Skip to contentSkip to conversation

chelsio: add headroom in RX path

PATCH Applied Eric Dumazet 3 participants 7 messages Mar 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chelsio: add headroom in RX path

From: Eric Dumazet <[email protected]>

Drivers should reserve some headroom in skb used in receive path, to avoid future head reallocation.

One possible way to do that is to use dev_alloc_skb() instead of alloc_skb(), so that NET_SKB_PAD bytes are reserved.

---
 drivers/net/ethernet/chelsio/cxgb/sge.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/chelsio/cxgb/sge.c +1 -1
index 4829769..89bef50 100644
@@ -835,7 +835,7 @@ static void refill_free_list(struct sge *sge, struct freelQ *q)
 		struct sk_buff *skb;
 		dma_addr_t mapping;
 
-		skb = alloc_skb(q->rx_buffer_size, GFP_ATOMIC);
+		skb = dev_alloc_skb(q->rx_buffer_size);
 		if (!skb)
 			break;
 
maintainer Applied
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Wed, 20 Mar 2013 09:33:19 -0700

Quoted 9 lines

From: Eric Dumazet <[email protected]>

Drivers should reserve some headroom in skb used in receive path, to avoid future head reallocation.

One possible way to do that is to use dev_alloc_skb() instead of alloc_skb(), so that NET_SKB_PAD bytes are reserved.

Applied, thanks Eric.

#2 lore raw

PATCH 1/1 chelsio: use netdev_alloc_skb

In reply to Eric Dumazet

This extends on Eric's patch. It uses netdev_alloc_skb which fixes a couple of other issues.
* driver was never setting skb->dev on the received buffer
* copybreak allocation wasn't padding buffer
* copybreak assumed that ip alignment padding was always 2 (it is platform dependent)

Compile tested only, don't have this hardware.

drivers/net/ethernet/chelsio/cxgb/sge.c +5 -5
@@ -835,7 +835,7 @@ static void refill_free_list(struct sge
 		struct sk_buff *skb;
 		dma_addr_t mapping;
 
-		skb = dev_alloc_skb(q->rx_buffer_size);
+		skb = netdev_alloc_skb(sge->netdev, q->rx_buffer_size);
 		if (!skb)
 			break;
 
@@ -1039,18 +1039,18 @@ MODULE_PARM_DESC(copybreak, "Receive cop
  *	threshold and the packet is too big to copy, or (b) the packet should
  *	be copied but there is no memory for the copy.
  */
-static inline struct sk_buff *get_packet(struct pci_dev *pdev,
+static inline struct sk_buff *get_packet(struct net_device *netdev,
+					 struct pci_dev *pdev,
 					 struct freelQ *fl, unsigned int len)
 {
 	struct sk_buff *skb;
 	const struct freelQ_ce *ce = &fl->centries[fl->cidx];
 
 	if (len < copybreak) {
-		skb = alloc_skb(len + 2, GFP_ATOMIC);
+		skb = netdev_alloc_skb_ip_align(netdev, len + 2);
 		if (!skb)
 			goto use_orig_buf;
 
-		skb_reserve(skb, 2);	/* align IP header */
 		skb_put(skb, len);
 		pci_dma_sync_single_for_cpu(pdev,
 					    dma_unmap_addr(ce, dma_addr),
@@ -1360,7 +1360,7 @@ static void sge_rx(struct sge *sge, stru
 	struct sge_port_stats *st;
 	struct net_device *dev;
 
-	skb = get_packet(adapter->pdev, fl, len - sge->rx_pkt_pad);
+	skb = get_packet(sge->netdev, adapter->pdev, fl, len - sge->rx_pkt_pad);
 	if (unlikely(!skb)) {
 		sge->stats.rx_drops++;
 		return;
#3 lore raw

Re: [PATCH] chelsio: use netdev_alloc_skb

Quoted 14 lines · Stephen Hemminger

This extends on Eric's patch. It uses netdev_alloc_skb which fixes a couple of other issues.
* driver was never setting skb->dev on the received buffer
* copybreak allocation wasn't padding buffer
* copybreak assumed that ip alignment padding was always 2 (it is platform dependent)

Compile tested only, don't have this hardware.

drivers/net/ethernet/chelsio/cxgb/sge.c static void refill_free_list(struct sge · line 840

Quoted 7 lines
drivers/net/ethernet/chelsio/cxgb/sge.c +1 -1
@@ -835,7 +835,7 @@ static void refill_free_list(struct sge
 		struct sk_buff *skb;
 		dma_addr_t mapping;
 
-		skb = dev_alloc_skb(q->rx_buffer_size);
+		skb = netdev_alloc_skb(sge->netdev, q->rx_buffer_size);
 		if (!skb)
 			break;

Well, this (skb->dev = dev) is done in eth_type_trans()

Many drivers use dev_alloc_skb(), I am not sure we really want to change them.

#4 lore raw

PATCH v2 1/1 chelsio: use netdev_alloc_skb_ip_align

Use netdev_alloc_sk_ip_align in the case where packet is copied. This handles case where NET_IP_ALIGN == 0 as well as adding required header padding.

drivers/net/ethernet/chelsio/cxgb/sge.c +1 -2
@@ -1046,11 +1046,10 @@ static inline struct sk_buff *get_packet
 	const struct freelQ_ce *ce = &fl->centries[fl->cidx];
 
 	if (len < copybreak) {
-		skb = alloc_skb(len + 2, GFP_ATOMIC);
+		skb = netdev_alloc_skb_ip_align(NULL, len);
 		if (!skb)
 			goto use_orig_buf;
 
-		skb_reserve(skb, 2);	/* align IP header */
 		skb_put(skb, len);
 		pci_dma_sync_single_for_cpu(pdev,
 					    dma_unmap_addr(ce, dma_addr),
maintainer Applied
#5 lore raw

Re: [PATCH v2] chelsio: use netdev_alloc_skb_ip_align

From: Stephen Hemminger <[email protected]>
Date: Wed, 20 Mar 2013 12:02:41 -0700

Quoted 5 lines

Use netdev_alloc_sk_ip_align in the case where packet is copied. This handles case where NET_IP_ALIGN == 0 as well as adding required header padding.

Applied, thanks Stephen.

#6 lore raw

Re: [PATCH] chelsio: use netdev_alloc_skb

In reply to Stephen Hemminger

drivers/net/ethernet/chelsio/cxgb/sge.c MODULE_PARM_DESC(copybreak, "Receive cop · line 1052

Quoted 5 lines · Stephen Hemminger
drivers/net/ethernet/chelsio/cxgb/sge.c +1 -1
-		skb = alloc_skb(len + 2, GFP_ATOMIC);
+		skb = netdev_alloc_skb_ip_align(netdev, len + 2);
 		if (!skb)
 			goto use_orig_buf;

If you use the helper, no need for 'len + 2' but :

netdev_alloc_skb_ip_align(netdev, len);