Skip to content

Commit 0614002

Browse files
Mel Gormantorvalds
authored andcommitted
netvm: propagate page->pfmemalloc from skb_alloc_page to skb
The skb->pfmemalloc flag gets set to true iff during the slab allocation of data in __alloc_skb that the the PFMEMALLOC reserves were used. If page splitting is used, it is possible that pages will be allocated from the PFMEMALLOC reserve without propagating this information to the skb. This patch propagates page->pfmemalloc from pages allocated for fragments to the skb. It works by reintroducing and expanding the skb_alloc_page() API to take an skb. If the page was allocated from pfmemalloc reserves, it is automatically copied. If the driver allocates the page before the skb, it should call skb_propagate_pfmemalloc() after the skb is allocated to ensure the flag is copied properly. Failure to do so is not critical. The resulting driver may perform slower if it is used for swap-over-NBD or swap-over-NFS but it should not result in failure. [davem@davemloft.net: API rename and consistency] 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>
1 parent c48a11c commit 0614002

File tree

8 files changed

+62
-8
lines changed

8 files changed

+62
-8
lines changed

drivers/net/ethernet/chelsio/cxgb4/sge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ static unsigned int refill_fl(struct adapter *adap, struct sge_fl *q, int n,
528528
#endif
529529

530530
while (n--) {
531-
pg = alloc_page(gfp);
531+
pg = __skb_alloc_page(gfp, NULL);
532532
if (unlikely(!pg)) {
533533
q->alloc_failed++;
534534
break;

drivers/net/ethernet/chelsio/cxgb4vf/sge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl,
653653

654654
alloc_small_pages:
655655
while (n--) {
656-
page = alloc_page(gfp | __GFP_NOWARN | __GFP_COLD);
656+
page = __skb_alloc_page(gfp | __GFP_NOWARN, NULL);
657657
if (unlikely(!page)) {
658658
fl->alloc_failed++;
659659
break;

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6235,7 +6235,7 @@ static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
62356235
return true;
62366236

62376237
if (!page) {
6238-
page = alloc_page(GFP_ATOMIC | __GFP_COLD);
6238+
page = __skb_alloc_page(GFP_ATOMIC, bi->skb);
62396239
bi->page = page;
62406240
if (unlikely(!page)) {
62416241
rx_ring->rx_stats.alloc_failed++;

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,8 @@ static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
11411141

11421142
/* alloc new page for storage */
11431143
if (likely(!page)) {
1144-
page = alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1145-
ixgbe_rx_pg_order(rx_ring));
1144+
page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1145+
bi->skb, ixgbe_rx_pg_order(rx_ring));
11461146
if (unlikely(!page)) {
11471147
rx_ring->rx_stats.alloc_rx_page_failed++;
11481148
return false;

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter,
352352
adapter->alloc_rx_buff_failed++;
353353
goto no_buffers;
354354
}
355-
356355
bi->skb = skb;
357356
}
358357
if (!bi->dma) {

drivers/net/usb/cdc-phonet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static int rx_submit(struct usbpn_dev *pnd, struct urb *req, gfp_t gfp_flags)
130130
struct page *page;
131131
int err;
132132

133-
page = alloc_page(gfp_flags);
133+
page = __skb_alloc_page(gfp_flags | __GFP_NOMEMALLOC, NULL);
134134
if (!page)
135135
return -ENOMEM;
136136

drivers/usb/gadget/f_phonet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pn_rx_submit(struct f_phonet *fp, struct usb_request *req, gfp_t gfp_flags)
301301
struct page *page;
302302
int err;
303303

304-
page = alloc_page(gfp_flags);
304+
page = __skb_alloc_page(gfp_flags | __GFP_NOMEMALLOC, NULL);
305305
if (!page)
306306
return -ENOMEM;
307307

include/linux/skbuff.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,61 @@ static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev,
17741774
return __netdev_alloc_skb_ip_align(dev, length, GFP_ATOMIC);
17751775
}
17761776

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+
17771832
/**
17781833
* skb_frag_page - retrieve the page refered to by a paged fragment
17791834
* @frag: the paged fragment

0 commit comments

Comments
 (0)