* [PATCH net-next] tg3: use netdev_alloc_frag() API
@ 2012-05-19 7:15 Eric Dumazet
2012-05-19 7:19 ` David Miller
2012-05-19 7:33 ` [PATCH v2 " Eric Dumazet
0 siblings, 2 replies; 7+ messages in thread
From: Eric Dumazet @ 2012-05-19 7:15 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Matt Carlson, Michael Chan
From: Eric Dumazet <edumazet@google.com>
Update our reference driver to use netdev_alloc_frag() API instead of
the temporary custom allocator I introduced in commit 8d4057a938
(tg3: provide frags as skb head)
This removes the memory leak we had, since we could leak one page at
device dismantle.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Matt Carlson <mcarlson@broadcom.com>
Cc: Michael Chan <mchan@broadcom.com>
---
drivers/net/ethernet/broadcom/tg3.c | 38 +++-----------------------
drivers/net/ethernet/broadcom/tg3.h | 2 -
2 files changed, 5 insertions(+), 35 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 4230e70..d55df32 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -195,15 +195,6 @@ static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits)
#define TG3_RX_OFFSET(tp) (NET_SKB_PAD)
#endif
-/* This driver uses the new build_skb() API providing a frag as skb->head
- * This strategy permits better GRO aggregation, better TCP coalescing, and
- * better splice() implementation (avoids a copy from head to a page), at
- * minimal memory cost.
- * In this 2048 bytes block, we have enough room to store the MTU=1500 frame
- * and the struct skb_shared_info.
- */
-#define TG3_FRAGSIZE 2048
-
/* minimum number of free TX descriptors required to wake up TX process */
#define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4)
#define TG3_TX_BD_DMA_MAX_2K 2048
@@ -5631,25 +5622,6 @@ static void tg3_tx(struct tg3_napi *tnapi)
}
}
-static void *tg3_frag_alloc(struct tg3_rx_prodring_set *tpr)
-{
- void *data;
-
- if (tpr->rx_page_size < TG3_FRAGSIZE) {
- struct page *page = alloc_page(GFP_ATOMIC);
-
- if (!page)
- return NULL;
- atomic_add((PAGE_SIZE / TG3_FRAGSIZE) - 1, &page->_count);
- tpr->rx_page_addr = page_address(page);
- tpr->rx_page_size = PAGE_SIZE;
- }
- data = tpr->rx_page_addr;
- tpr->rx_page_addr += TG3_FRAGSIZE;
- tpr->rx_page_size -= TG3_FRAGSIZE;
- return data;
-}
-
static void tg3_frag_free(bool is_frag, void *data)
{
if (is_frag)
@@ -5668,7 +5640,7 @@ static void tg3_rx_data_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz)
pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping),
map_sz, PCI_DMA_FROMDEVICE);
- tg3_frag_free(skb_size <= TG3_FRAGSIZE, ri->data);
+ tg3_frag_free(skb_size <= PAGE_SIZE, ri->data);
ri->data = NULL;
}
@@ -5721,9 +5693,9 @@ static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr,
*/
skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) +
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
- if (skb_size <= TG3_FRAGSIZE) {
- data = tg3_frag_alloc(tpr);
- *frag_size = TG3_FRAGSIZE;
+ if (skb_size <= PAGE_SIZE) {
+ data = netdev_alloc_frag(skb_size);
+ *frag_size = skb_size;
} else {
data = kmalloc(skb_size, GFP_ATOMIC);
*frag_size = 0;
@@ -5736,7 +5708,7 @@ static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr,
data_size,
PCI_DMA_FROMDEVICE);
if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) {
- tg3_frag_free(skb_size <= TG3_FRAGSIZE, data);
+ tg3_frag_free(skb_size <= PAGE_SIZE, data);
return -EIO;
}
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index 7c85545..93865f8 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -2815,8 +2815,6 @@ struct tg3_rx_prodring_set {
struct ring_info *rx_jmb_buffers;
dma_addr_t rx_std_mapping;
dma_addr_t rx_jmb_mapping;
- void *rx_page_addr;
- unsigned int rx_page_size;
};
#define TG3_IRQ_MAX_VECS_RSS 5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] tg3: use netdev_alloc_frag() API
2012-05-19 7:15 [PATCH net-next] tg3: use netdev_alloc_frag() API Eric Dumazet
@ 2012-05-19 7:19 ` David Miller
2012-05-19 7:31 ` Eric Dumazet
2012-05-19 7:33 ` [PATCH v2 " Eric Dumazet
1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2012-05-19 7:19 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev, mcarlson, mchan
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sat, 19 May 2012 09:15:49 +0200
> From: Eric Dumazet <edumazet@google.com>
>
> Update our reference driver to use netdev_alloc_frag() API instead of
> the temporary custom allocator I introduced in commit 8d4057a938
> (tg3: provide frags as skb head)
>
> This removes the memory leak we had, since we could leak one page at
> device dismantle.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Hmmm, doesn't apply cleanly to net-next for some reason:
[davem@drr net-next]$ git am --signoff net-next-tg3-use-netdev_alloc_frag-API.patch
Applying: tg3: use netdev_alloc_frag() API
error: patch failed: drivers/net/ethernet/broadcom/tg3.c:5631
error: drivers/net/ethernet/broadcom/tg3.c: patch does not apply
Patch failed at 0001 tg3: use netdev_alloc_frag() API
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] tg3: use netdev_alloc_frag() API
2012-05-19 7:19 ` David Miller
@ 2012-05-19 7:31 ` Eric Dumazet
2012-05-19 8:01 ` David Miller
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2012-05-19 7:31 UTC (permalink / raw)
To: David Miller; +Cc: netdev, mcarlson, mchan
On Sat, 2012-05-19 at 03:19 -0400, David Miller wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Sat, 19 May 2012 09:15:49 +0200
>
> > From: Eric Dumazet <edumazet@google.com>
> >
> > Update our reference driver to use netdev_alloc_frag() API instead of
> > the temporary custom allocator I introduced in commit 8d4057a938
> > (tg3: provide frags as skb head)
> >
> > This removes the memory leak we had, since we could leak one page at
> > device dismantle.
> >
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
>
> Hmmm, doesn't apply cleanly to net-next for some reason:
>
> [davem@drr net-next]$ git am --signoff net-next-tg3-use-netdev_alloc_frag-API.patch
> Applying: tg3: use netdev_alloc_frag() API
> error: patch failed: drivers/net/ethernet/broadcom/tg3.c:5631
> error: drivers/net/ethernet/broadcom/tg3.c: patch does not apply
> Patch failed at 0001 tg3: use netdev_alloc_frag() API
> When you have resolved this problem run "git am --resolved".
> If you would prefer to skip this patch, instead run "git am --skip".
> To restore the original branch and stop patching run "git am --abort".
Indeed, there is an extra space at the end of one line in my tree... ???
atomic_add((PAGE_SIZE / TG3_FRAGSIZE) - 1, &page->_count); <HERE>
I submit a v2 immediately.
Sorry
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 net-next] tg3: use netdev_alloc_frag() API
2012-05-19 7:15 [PATCH net-next] tg3: use netdev_alloc_frag() API Eric Dumazet
2012-05-19 7:19 ` David Miller
@ 2012-05-19 7:33 ` Eric Dumazet
2012-05-19 8:03 ` David Miller
1 sibling, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2012-05-19 7:33 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Matt Carlson, Michael Chan
From: Eric Dumazet <edumazet@google.com>
Update our reference driver to use netdev_alloc_frag() API instead of
the temporary custom allocator I introduced in commit 8d4057a938
(tg3: provide frags as skb head)
This removes the memory leak we had, since we could leak one page at
device dismantle.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Matt Carlson <mcarlson@broadcom.com>
Cc: Michael Chan <mchan@broadcom.com>
---
drivers/net/ethernet/broadcom/tg3.c | 38 +++-----------------------
drivers/net/ethernet/broadcom/tg3.h | 2 -
2 files changed, 5 insertions(+), 35 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 39b92f5..d55df32 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -195,15 +195,6 @@ static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits)
#define TG3_RX_OFFSET(tp) (NET_SKB_PAD)
#endif
-/* This driver uses the new build_skb() API providing a frag as skb->head
- * This strategy permits better GRO aggregation, better TCP coalescing, and
- * better splice() implementation (avoids a copy from head to a page), at
- * minimal memory cost.
- * In this 2048 bytes block, we have enough room to store the MTU=1500 frame
- * and the struct skb_shared_info.
- */
-#define TG3_FRAGSIZE 2048
-
/* minimum number of free TX descriptors required to wake up TX process */
#define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4)
#define TG3_TX_BD_DMA_MAX_2K 2048
@@ -5631,25 +5622,6 @@ static void tg3_tx(struct tg3_napi *tnapi)
}
}
-static void *tg3_frag_alloc(struct tg3_rx_prodring_set *tpr)
-{
- void *data;
-
- if (tpr->rx_page_size < TG3_FRAGSIZE) {
- struct page *page = alloc_page(GFP_ATOMIC);
-
- if (!page)
- return NULL;
- atomic_add((PAGE_SIZE / TG3_FRAGSIZE) - 1, &page->_count);
- tpr->rx_page_addr = page_address(page);
- tpr->rx_page_size = PAGE_SIZE;
- }
- data = tpr->rx_page_addr;
- tpr->rx_page_addr += TG3_FRAGSIZE;
- tpr->rx_page_size -= TG3_FRAGSIZE;
- return data;
-}
-
static void tg3_frag_free(bool is_frag, void *data)
{
if (is_frag)
@@ -5668,7 +5640,7 @@ static void tg3_rx_data_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz)
pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping),
map_sz, PCI_DMA_FROMDEVICE);
- tg3_frag_free(skb_size <= TG3_FRAGSIZE, ri->data);
+ tg3_frag_free(skb_size <= PAGE_SIZE, ri->data);
ri->data = NULL;
}
@@ -5721,9 +5693,9 @@ static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr,
*/
skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) +
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
- if (skb_size <= TG3_FRAGSIZE) {
- data = tg3_frag_alloc(tpr);
- *frag_size = TG3_FRAGSIZE;
+ if (skb_size <= PAGE_SIZE) {
+ data = netdev_alloc_frag(skb_size);
+ *frag_size = skb_size;
} else {
data = kmalloc(skb_size, GFP_ATOMIC);
*frag_size = 0;
@@ -5736,7 +5708,7 @@ static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr,
data_size,
PCI_DMA_FROMDEVICE);
if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) {
- tg3_frag_free(skb_size <= TG3_FRAGSIZE, data);
+ tg3_frag_free(skb_size <= PAGE_SIZE, data);
return -EIO;
}
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index 7c85545..93865f8 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -2815,8 +2815,6 @@ struct tg3_rx_prodring_set {
struct ring_info *rx_jmb_buffers;
dma_addr_t rx_std_mapping;
dma_addr_t rx_jmb_mapping;
- void *rx_page_addr;
- unsigned int rx_page_size;
};
#define TG3_IRQ_MAX_VECS_RSS 5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] tg3: use netdev_alloc_frag() API
2012-05-19 7:31 ` Eric Dumazet
@ 2012-05-19 8:01 ` David Miller
2012-05-19 8:17 ` Eric Dumazet
0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2012-05-19 8:01 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev, mcarlson, mchan
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sat, 19 May 2012 09:31:41 +0200
> Indeed, there is an extra space at the end of one line in my tree... ???
>
> atomic_add((PAGE_SIZE / TG3_FRAGSIZE) - 1, &page->_count); <HERE>
I silently fix trailing whitespace errors in your patches.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 net-next] tg3: use netdev_alloc_frag() API
2012-05-19 7:33 ` [PATCH v2 " Eric Dumazet
@ 2012-05-19 8:03 ` David Miller
0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2012-05-19 8:03 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev, mcarlson, mchan
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sat, 19 May 2012 09:33:39 +0200
> From: Eric Dumazet <edumazet@google.com>
>
> Update our reference driver to use netdev_alloc_frag() API instead of
> the temporary custom allocator I introduced in commit 8d4057a938
> (tg3: provide frags as skb head)
>
> This removes the memory leak we had, since we could leak one page at
> device dismantle.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Applied.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] tg3: use netdev_alloc_frag() API
2012-05-19 8:01 ` David Miller
@ 2012-05-19 8:17 ` Eric Dumazet
0 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2012-05-19 8:17 UTC (permalink / raw)
To: David Miller; +Cc: netdev, mcarlson, mchan
On Sat, 2012-05-19 at 04:01 -0400, David Miller wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Sat, 19 May 2012 09:31:41 +0200
>
> > Indeed, there is an extra space at the end of one line in my tree... ???
> >
> > atomic_add((PAGE_SIZE / TG3_FRAGSIZE) - 1, &page->_count); <HERE>
>
> I silently fix trailing whitespace errors in your patches.
OK, good to know ;)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-19 8:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-19 7:15 [PATCH net-next] tg3: use netdev_alloc_frag() API Eric Dumazet
2012-05-19 7:19 ` David Miller
2012-05-19 7:31 ` Eric Dumazet
2012-05-19 8:01 ` David Miller
2012-05-19 8:17 ` Eric Dumazet
2012-05-19 7:33 ` [PATCH v2 " Eric Dumazet
2012-05-19 8:03 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).