diff options
Diffstat (limited to 'net/core/skbuff.c')
-rw-r--r-- | net/core/skbuff.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d1967dab9cc6..3cfff2a3d651 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -280,13 +280,14 @@ nodata: | |||
280 | EXPORT_SYMBOL(__alloc_skb); | 280 | EXPORT_SYMBOL(__alloc_skb); |
281 | 281 | ||
282 | /** | 282 | /** |
283 | * build_skb - build a network buffer | 283 | * __build_skb - build a network buffer |
284 | * @data: data buffer provided by caller | 284 | * @data: data buffer provided by caller |
285 | * @frag_size: size of fragment, or 0 if head was kmalloced | 285 | * @frag_size: size of data, or 0 if head was kmalloced |
286 | * | 286 | * |
287 | * Allocate a new &sk_buff. Caller provides space holding head and | 287 | * Allocate a new &sk_buff. Caller provides space holding head and |
288 | * skb_shared_info. @data must have been allocated by kmalloc() only if | 288 | * skb_shared_info. @data must have been allocated by kmalloc() only if |
289 | * @frag_size is 0, otherwise data should come from the page allocator. | 289 | * @frag_size is 0, otherwise data should come from the page allocator |
290 | * or vmalloc() | ||
290 | * The return is the new skb buffer. | 291 | * The return is the new skb buffer. |
291 | * On a failure the return is %NULL, and @data is not freed. | 292 | * On a failure the return is %NULL, and @data is not freed. |
292 | * Notes : | 293 | * Notes : |
@@ -297,7 +298,7 @@ EXPORT_SYMBOL(__alloc_skb); | |||
297 | * before giving packet to stack. | 298 | * before giving packet to stack. |
298 | * RX rings only contains data buffers, not full skbs. | 299 | * RX rings only contains data buffers, not full skbs. |
299 | */ | 300 | */ |
300 | struct sk_buff *build_skb(void *data, unsigned int frag_size) | 301 | struct sk_buff *__build_skb(void *data, unsigned int frag_size) |
301 | { | 302 | { |
302 | struct skb_shared_info *shinfo; | 303 | struct skb_shared_info *shinfo; |
303 | struct sk_buff *skb; | 304 | struct sk_buff *skb; |
@@ -311,7 +312,6 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) | |||
311 | 312 | ||
312 | memset(skb, 0, offsetof(struct sk_buff, tail)); | 313 | memset(skb, 0, offsetof(struct sk_buff, tail)); |
313 | skb->truesize = SKB_TRUESIZE(size); | 314 | skb->truesize = SKB_TRUESIZE(size); |
314 | skb->head_frag = frag_size != 0; | ||
315 | atomic_set(&skb->users, 1); | 315 | atomic_set(&skb->users, 1); |
316 | skb->head = data; | 316 | skb->head = data; |
317 | skb->data = data; | 317 | skb->data = data; |
@@ -328,6 +328,23 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) | |||
328 | 328 | ||
329 | return skb; | 329 | return skb; |
330 | } | 330 | } |
331 | |||
332 | /* build_skb() is wrapper over __build_skb(), that specifically | ||
333 | * takes care of skb->head and skb->pfmemalloc | ||
334 | * This means that if @frag_size is not zero, then @data must be backed | ||
335 | * by a page fragment, not kmalloc() or vmalloc() | ||
336 | */ | ||
337 | struct sk_buff *build_skb(void *data, unsigned int frag_size) | ||
338 | { | ||
339 | struct sk_buff *skb = __build_skb(data, frag_size); | ||
340 | |||
341 | if (skb && frag_size) { | ||
342 | skb->head_frag = 1; | ||
343 | if (virt_to_head_page(data)->pfmemalloc) | ||
344 | skb->pfmemalloc = 1; | ||
345 | } | ||
346 | return skb; | ||
347 | } | ||
331 | EXPORT_SYMBOL(build_skb); | 348 | EXPORT_SYMBOL(build_skb); |
332 | 349 | ||
333 | struct netdev_alloc_cache { | 350 | struct netdev_alloc_cache { |
@@ -348,7 +365,8 @@ static struct page *__page_frag_refill(struct netdev_alloc_cache *nc, | |||
348 | gfp_t gfp = gfp_mask; | 365 | gfp_t gfp = gfp_mask; |
349 | 366 | ||
350 | if (order) { | 367 | if (order) { |
351 | gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY; | 368 | gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | |
369 | __GFP_NOMEMALLOC; | ||
352 | page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order); | 370 | page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order); |
353 | nc->frag.size = PAGE_SIZE << (page ? order : 0); | 371 | nc->frag.size = PAGE_SIZE << (page ? order : 0); |
354 | } | 372 | } |