aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMel Gorman <mgorman@suse.de>2012-07-31 19:44:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-31 21:42:46 -0400
commitc93bdd0e03e848555d144eb44a1f275b871a8dd5 (patch)
tree8aff3bc2b9ff9f32e51040a7652bfb31257db626 /include
parent7cb0240492caea2f6467f827313478f41877e6ef (diff)
netvm: allow skb allocation to use PFMEMALLOC reserves
Change the skb allocation API to indicate RX usage and use this to fall back to the PFMEMALLOC reserve when needed. SKBs allocated from the reserve are tagged in skb->pfmemalloc. If an SKB is allocated from the reserve and the socket is later found to be unrelated to page reclaim, the packet is dropped so that the memory remains available for page reclaim. Network protocols are expected to recover from this packet loss. [a.p.zijlstra@chello.nl: Ideas taken from various patches] [davem@davemloft.net: Use static branches, coding style corrections] [sebastian@breakpoint.cc: Avoid unnecessary cast, fix !CONFIG_NET build] Signed-off-by: Mel Gorman <mgorman@suse.de> Acked-by: David S. Miller <davem@davemloft.net> Cc: Neil Brown <neilb@suse.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Christie <michaelc@cs.wisc.edu> Cc: Eric B Munson <emunson@mgebm.net> Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> Cc: Mel Gorman <mgorman@suse.de> Cc: Christoph Lameter <cl@linux.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/gfp.h3
-rw-r--r--include/linux/skbuff.h14
-rw-r--r--include/net/sock.h15
3 files changed, 30 insertions, 2 deletions
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index cbd7400e5862..4883f393f50a 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -385,6 +385,9 @@ void drain_local_pages(void *dummy);
385 */ 385 */
386extern gfp_t gfp_allowed_mask; 386extern gfp_t gfp_allowed_mask;
387 387
388/* Returns true if the gfp_mask allows use of ALLOC_NO_WATERMARK */
389bool gfp_pfmemalloc_allowed(gfp_t gfp_mask);
390
388extern void pm_restrict_gfp_mask(void); 391extern void pm_restrict_gfp_mask(void);
389extern void pm_restore_gfp_mask(void); 392extern void pm_restore_gfp_mask(void);
390 393
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index d205c4be7f5b..0336f02e3667 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -462,6 +462,7 @@ struct sk_buff {
462#ifdef CONFIG_IPV6_NDISC_NODETYPE 462#ifdef CONFIG_IPV6_NDISC_NODETYPE
463 __u8 ndisc_nodetype:2; 463 __u8 ndisc_nodetype:2;
464#endif 464#endif
465 __u8 pfmemalloc:1;
465 __u8 ooo_okay:1; 466 __u8 ooo_okay:1;
466 __u8 l4_rxhash:1; 467 __u8 l4_rxhash:1;
467 __u8 wifi_acked_valid:1; 468 __u8 wifi_acked_valid:1;
@@ -502,6 +503,15 @@ struct sk_buff {
502#include <linux/slab.h> 503#include <linux/slab.h>
503 504
504 505
506#define SKB_ALLOC_FCLONE 0x01
507#define SKB_ALLOC_RX 0x02
508
509/* Returns true if the skb was allocated from PFMEMALLOC reserves */
510static inline bool skb_pfmemalloc(const struct sk_buff *skb)
511{
512 return unlikely(skb->pfmemalloc);
513}
514
505/* 515/*
506 * skb might have a dst pointer attached, refcounted or not. 516 * skb might have a dst pointer attached, refcounted or not.
507 * _skb_refdst low order bit is set if refcount was _not_ taken 517 * _skb_refdst low order bit is set if refcount was _not_ taken
@@ -565,7 +575,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
565 bool *fragstolen, int *delta_truesize); 575 bool *fragstolen, int *delta_truesize);
566 576
567extern struct sk_buff *__alloc_skb(unsigned int size, 577extern struct sk_buff *__alloc_skb(unsigned int size,
568 gfp_t priority, int fclone, int node); 578 gfp_t priority, int flags, int node);
569extern struct sk_buff *build_skb(void *data, unsigned int frag_size); 579extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
570static inline struct sk_buff *alloc_skb(unsigned int size, 580static inline struct sk_buff *alloc_skb(unsigned int size,
571 gfp_t priority) 581 gfp_t priority)
@@ -576,7 +586,7 @@ static inline struct sk_buff *alloc_skb(unsigned int size,
576static inline struct sk_buff *alloc_skb_fclone(unsigned int size, 586static inline struct sk_buff *alloc_skb_fclone(unsigned int size,
577 gfp_t priority) 587 gfp_t priority)
578{ 588{
579 return __alloc_skb(size, priority, 1, NUMA_NO_NODE); 589 return __alloc_skb(size, priority, SKB_ALLOC_FCLONE, NUMA_NO_NODE);
580} 590}
581 591
582extern void skb_recycle(struct sk_buff *skb); 592extern void skb_recycle(struct sk_buff *skb);
diff --git a/include/net/sock.h b/include/net/sock.h
index bfa7d20e6646..81198632ac2a 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -659,6 +659,21 @@ static inline bool sock_flag(const struct sock *sk, enum sock_flags flag)
659 return test_bit(flag, &sk->sk_flags); 659 return test_bit(flag, &sk->sk_flags);
660} 660}
661 661
662#ifdef CONFIG_NET
663extern struct static_key memalloc_socks;
664static inline int sk_memalloc_socks(void)
665{
666 return static_key_false(&memalloc_socks);
667}
668#else
669
670static inline int sk_memalloc_socks(void)
671{
672 return 0;
673}
674
675#endif
676
662static inline gfp_t sk_gfp_atomic(struct sock *sk, gfp_t gfp_mask) 677static inline gfp_t sk_gfp_atomic(struct sock *sk, gfp_t gfp_mask)
663{ 678{
664 return GFP_ATOMIC | (sk->sk_allocation & __GFP_MEMALLOC); 679 return GFP_ATOMIC | (sk->sk_allocation & __GFP_MEMALLOC);