diff options
Diffstat (limited to 'include/linux/skbuff.h')
-rw-r--r-- | include/linux/skbuff.h | 80 |
1 files changed, 78 insertions, 2 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index d205c4be7f5b..7632c87da2c9 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 */ | ||
510 | static 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 | ||
567 | extern struct sk_buff *__alloc_skb(unsigned int size, | 577 | extern struct sk_buff *__alloc_skb(unsigned int size, |
568 | gfp_t priority, int fclone, int node); | 578 | gfp_t priority, int flags, int node); |
569 | extern struct sk_buff *build_skb(void *data, unsigned int frag_size); | 579 | extern struct sk_buff *build_skb(void *data, unsigned int frag_size); |
570 | static inline struct sk_buff *alloc_skb(unsigned int size, | 580 | static 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, | |||
576 | static inline struct sk_buff *alloc_skb_fclone(unsigned int size, | 586 | static 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 | ||
582 | extern void skb_recycle(struct sk_buff *skb); | 592 | extern void skb_recycle(struct sk_buff *skb); |
@@ -1237,6 +1247,17 @@ static inline void __skb_fill_page_desc(struct sk_buff *skb, int i, | |||
1237 | { | 1247 | { |
1238 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | 1248 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
1239 | 1249 | ||
1250 | /* | ||
1251 | * Propagate page->pfmemalloc to the skb if we can. The problem is | ||
1252 | * that not all callers have unique ownership of the page. If | ||
1253 | * pfmemalloc is set, we check the mapping as a mapping implies | ||
1254 | * page->index is set (index and pfmemalloc share space). | ||
1255 | * If it's a valid mapping, we cannot use page->pfmemalloc but we | ||
1256 | * do not lose pfmemalloc information as the pages would not be | ||
1257 | * allocated using __GFP_MEMALLOC. | ||
1258 | */ | ||
1259 | if (page->pfmemalloc && !page->mapping) | ||
1260 | skb->pfmemalloc = true; | ||
1240 | frag->page.p = page; | 1261 | frag->page.p = page; |
1241 | frag->page_offset = off; | 1262 | frag->page_offset = off; |
1242 | skb_frag_size_set(frag, size); | 1263 | skb_frag_size_set(frag, size); |
@@ -1753,6 +1774,61 @@ static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, | |||
1753 | return __netdev_alloc_skb_ip_align(dev, length, GFP_ATOMIC); | 1774 | return __netdev_alloc_skb_ip_align(dev, length, GFP_ATOMIC); |
1754 | } | 1775 | } |
1755 | 1776 | ||
1777 | /* | ||
1778 | * __skb_alloc_page - allocate pages for ps-rx on a skb and preserve pfmemalloc data | ||
1779 | * @gfp_mask: alloc_pages_node mask. Set __GFP_NOMEMALLOC if not for network packet RX | ||
1780 | * @skb: skb to set pfmemalloc on if __GFP_MEMALLOC is used | ||
1781 | * @order: size of the allocation | ||
1782 | * | ||
1783 | * Allocate a new page. | ||
1784 | * | ||
1785 | * %NULL is returned if there is no free memory. | ||
1786 | */ | ||
1787 | static inline struct page *__skb_alloc_pages(gfp_t gfp_mask, | ||
1788 | struct sk_buff *skb, | ||
1789 | unsigned int order) | ||
1790 | { | ||
1791 | struct page *page; | ||
1792 | |||
1793 | gfp_mask |= __GFP_COLD; | ||
1794 | |||
1795 | if (!(gfp_mask & __GFP_NOMEMALLOC)) | ||
1796 | gfp_mask |= __GFP_MEMALLOC; | ||
1797 | |||
1798 | page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, order); | ||
1799 | if (skb && page && page->pfmemalloc) | ||
1800 | skb->pfmemalloc = true; | ||
1801 | |||
1802 | return page; | ||
1803 | } | ||
1804 | |||
1805 | /** | ||
1806 | * __skb_alloc_page - allocate a page for ps-rx for a given skb and preserve pfmemalloc data | ||
1807 | * @gfp_mask: alloc_pages_node mask. Set __GFP_NOMEMALLOC if not for network packet RX | ||
1808 | * @skb: skb to set pfmemalloc on if __GFP_MEMALLOC is used | ||
1809 | * | ||
1810 | * Allocate a new page. | ||
1811 | * | ||
1812 | * %NULL is returned if there is no free memory. | ||
1813 | */ | ||
1814 | static inline struct page *__skb_alloc_page(gfp_t gfp_mask, | ||
1815 | struct sk_buff *skb) | ||
1816 | { | ||
1817 | return __skb_alloc_pages(gfp_mask, skb, 0); | ||
1818 | } | ||
1819 | |||
1820 | /** | ||
1821 | * skb_propagate_pfmemalloc - Propagate pfmemalloc if skb is allocated after RX page | ||
1822 | * @page: The page that was allocated from skb_alloc_page | ||
1823 | * @skb: The skb that may need pfmemalloc set | ||
1824 | */ | ||
1825 | static inline void skb_propagate_pfmemalloc(struct page *page, | ||
1826 | struct sk_buff *skb) | ||
1827 | { | ||
1828 | if (page && page->pfmemalloc) | ||
1829 | skb->pfmemalloc = true; | ||
1830 | } | ||
1831 | |||
1756 | /** | 1832 | /** |
1757 | * skb_frag_page - retrieve the page refered to by a paged fragment | 1833 | * skb_frag_page - retrieve the page refered to by a paged fragment |
1758 | * @frag: the paged fragment | 1834 | * @frag: the paged fragment |