[PATCH 1/2] net: Export __netdev_alloc_frag() to allow gfp_mask flags

2015-07-29 Thread WingMan Kwok
This patch makes the function __netdev_alloc_frag() non-static and
exports it so that drivers that need to specify additional flags,
such as __GFP_DMA, can use it. The currently exported function,
netdev_alloc_frag() doesn't allow passing in gfp_mask flags.

Signed-off-by: WingMan Kwok 
Signed-off-by: Reece R. Pollack 
---
 include/linux/skbuff.h |1 +
 net/core/skbuff.c  |3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index d6cdd6e..596deb3 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2139,6 +2139,7 @@ static inline void __skb_queue_purge(struct sk_buff_head 
*list)
kfree_skb(skb);
 }
 
+void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask);
 void *netdev_alloc_frag(unsigned int fragsz);
 
 struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int length,
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index b6a19ca..6f3451f 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -350,7 +350,7 @@ EXPORT_SYMBOL(build_skb);
 static DEFINE_PER_CPU(struct page_frag_cache, netdev_alloc_cache);
 static DEFINE_PER_CPU(struct page_frag_cache, napi_alloc_cache);
 
-static void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
+void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
 {
struct page_frag_cache *nc;
unsigned long flags;
@@ -362,6 +362,7 @@ static void *__netdev_alloc_frag(unsigned int fragsz, gfp_t 
gfp_mask)
local_irq_restore(flags);
return data;
 }
+EXPORT_SYMBOL(__netdev_alloc_frag);
 
 /**
  * netdev_alloc_frag - allocate a page fragment
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] net: Export __netdev_alloc_frag() to allow gfp_mask flags

2015-07-29 Thread Eric Dumazet
On Wed, 2015-07-29 at 11:10 -0400, WingMan Kwok wrote:
> This patch makes the function __netdev_alloc_frag() non-static and
> exports it so that drivers that need to specify additional flags,
> such as __GFP_DMA, can use it. The currently exported function,
> netdev_alloc_frag() doesn't allow passing in gfp_mask flags.
> 
> Signed-off-by: WingMan Kwok 
> Signed-off-by: Reece R. Pollack 
> ---
>  include/linux/skbuff.h |1 +
>  net/core/skbuff.c  |3 ++-
>  2 files changed, 3 insertions(+), 1 deletion(-)

You can not do this.

__napi_alloc_frag() uses __alloc_page_frag() using a per cpu reserve.

This per cpu reserve would be shared by regular GFP_ATOMIC and your
__GFP_DMA allocations.



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] net: Export __netdev_alloc_frag() to allow gfp_mask flags

2015-07-29 Thread Murali Karicheri

Eric,

On 07/29/2015 12:31 PM, Eric Dumazet wrote:

On Wed, 2015-07-29 at 11:10 -0400, WingMan Kwok wrote:

This patch makes the function __netdev_alloc_frag() non-static and
exports it so that drivers that need to specify additional flags,
such as __GFP_DMA, can use it. The currently exported function,
netdev_alloc_frag() doesn't allow passing in gfp_mask flags.

Signed-off-by: WingMan Kwok 
Signed-off-by: Reece R. Pollack 
---
  include/linux/skbuff.h |1 +
  net/core/skbuff.c  |3 ++-
  2 files changed, 3 insertions(+), 1 deletion(-)


You can not do this.

__napi_alloc_frag() uses __alloc_page_frag() using a per cpu reserve.


Thanks for your response.

I assume you mean to say __netdev_alloc_frag() which is what the patch 
affects. Right?



This per cpu reserve would be shared by regular GFP_ATOMIC and your
__GFP_DMA allocations.


I am trying to understand the issue here. Is there any issue in sharing 
this per CPU reserve between DMA and ATOMIC allocations. Without this 
flag, the assumption is this function can return memory which is not 
DMA-able and this flag assures it is allocated from DMA zone.


Murali









--
Murali Karicheri
Linux Kernel, Keystone
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] net: Export __netdev_alloc_frag() to allow gfp_mask flags

2015-07-29 Thread Eric Dumazet
On Wed, 2015-07-29 at 16:22 -0400, Murali Karicheri wrote:
> Eric,
> 
> On 07/29/2015 12:31 PM, Eric Dumazet wrote:
> > On Wed, 2015-07-29 at 11:10 -0400, WingMan Kwok wrote:
> >> This patch makes the function __netdev_alloc_frag() non-static and
> >> exports it so that drivers that need to specify additional flags,
> >> such as __GFP_DMA, can use it. The currently exported function,
> >> netdev_alloc_frag() doesn't allow passing in gfp_mask flags.
> >>
> >> Signed-off-by: WingMan Kwok 
> >> Signed-off-by: Reece R. Pollack 
> >> ---
> >>   include/linux/skbuff.h |1 +
> >>   net/core/skbuff.c  |3 ++-
> >>   2 files changed, 3 insertions(+), 1 deletion(-)
> >
> > You can not do this.
> >
> > __napi_alloc_frag() uses __alloc_page_frag() using a per cpu reserve.
> >
> Thanks for your response.
> 
> I assume you mean to say __netdev_alloc_frag() which is what the patch 
> affects. Right?
> 
> > This per cpu reserve would be shared by regular GFP_ATOMIC and your
> > __GFP_DMA allocations.
> 
> I am trying to understand the issue here. Is there any issue in sharing 
> this per CPU reserve between DMA and ATOMIC allocations. Without this 
> flag, the assumption is this function can return memory which is not 
> DMA-able and this flag assures it is allocated from DMA zone.

First caller __netdev_alloc_frag() uses GFP_ATOMIC.

A big page (32 KB) is allocated and stored into cache. Part of it given
to caller. (like 1536 bytes or so)

Then your driver calls with __GFP_DMA.

We find a prior page on percpu cache with enough room in it to allocate
a fragment.

Your driver getd a fragment from the prior GFP_ATOMIC allocation, with
no DMA guarantee.

Therefore, your patch is not working in all cases.


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html