page_pool.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * page_pool.c
  4. * Author: Jesper Dangaard Brouer <netoptimizer@brouer.com>
  5. * Copyright (C) 2016 Red Hat, Inc.
  6. */
  7. #include <linux/error-injection.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include <linux/device.h>
  12. #include <net/netdev_rx_queue.h>
  13. #include <net/page_pool/helpers.h>
  14. #include <net/xdp.h>
  15. #include <linux/dma-direction.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/page-flags.h>
  18. #include <linux/mm.h> /* for put_page() */
  19. #include <linux/poison.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/netdevice.h>
  22. #include <trace/events/page_pool.h>
  23. #include "dev.h"
  24. #include "mp_dmabuf_devmem.h"
  25. #include "netmem_priv.h"
  26. #include "page_pool_priv.h"
  27. DEFINE_STATIC_KEY_FALSE(page_pool_mem_providers);
  28. #define DEFER_TIME (msecs_to_jiffies(1000))
  29. #define DEFER_WARN_INTERVAL (60 * HZ)
  30. #define BIAS_MAX (LONG_MAX >> 1)
  31. #ifdef CONFIG_PAGE_POOL_STATS
  32. static DEFINE_PER_CPU(struct page_pool_recycle_stats, pp_system_recycle_stats);
  33. /* alloc_stat_inc is intended to be used in softirq context */
  34. #define alloc_stat_inc(pool, __stat) (pool->alloc_stats.__stat++)
  35. /* recycle_stat_inc is safe to use when preemption is possible. */
  36. #define recycle_stat_inc(pool, __stat) \
  37. do { \
  38. struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \
  39. this_cpu_inc(s->__stat); \
  40. } while (0)
  41. #define recycle_stat_add(pool, __stat, val) \
  42. do { \
  43. struct page_pool_recycle_stats __percpu *s = pool->recycle_stats; \
  44. this_cpu_add(s->__stat, val); \
  45. } while (0)
  46. static const char pp_stats[][ETH_GSTRING_LEN] = {
  47. "rx_pp_alloc_fast",
  48. "rx_pp_alloc_slow",
  49. "rx_pp_alloc_slow_ho",
  50. "rx_pp_alloc_empty",
  51. "rx_pp_alloc_refill",
  52. "rx_pp_alloc_waive",
  53. "rx_pp_recycle_cached",
  54. "rx_pp_recycle_cache_full",
  55. "rx_pp_recycle_ring",
  56. "rx_pp_recycle_ring_full",
  57. "rx_pp_recycle_released_ref",
  58. };
  59. /**
  60. * page_pool_get_stats() - fetch page pool stats
  61. * @pool: pool from which page was allocated
  62. * @stats: struct page_pool_stats to fill in
  63. *
  64. * Retrieve statistics about the page_pool. This API is only available
  65. * if the kernel has been configured with ``CONFIG_PAGE_POOL_STATS=y``.
  66. * A pointer to a caller allocated struct page_pool_stats structure
  67. * is passed to this API which is filled in. The caller can then report
  68. * those stats to the user (perhaps via ethtool, debugfs, etc.).
  69. */
  70. bool page_pool_get_stats(const struct page_pool *pool,
  71. struct page_pool_stats *stats)
  72. {
  73. int cpu = 0;
  74. if (!stats)
  75. return false;
  76. /* The caller is responsible to initialize stats. */
  77. stats->alloc_stats.fast += pool->alloc_stats.fast;
  78. stats->alloc_stats.slow += pool->alloc_stats.slow;
  79. stats->alloc_stats.slow_high_order += pool->alloc_stats.slow_high_order;
  80. stats->alloc_stats.empty += pool->alloc_stats.empty;
  81. stats->alloc_stats.refill += pool->alloc_stats.refill;
  82. stats->alloc_stats.waive += pool->alloc_stats.waive;
  83. for_each_possible_cpu(cpu) {
  84. const struct page_pool_recycle_stats *pcpu =
  85. per_cpu_ptr(pool->recycle_stats, cpu);
  86. stats->recycle_stats.cached += pcpu->cached;
  87. stats->recycle_stats.cache_full += pcpu->cache_full;
  88. stats->recycle_stats.ring += pcpu->ring;
  89. stats->recycle_stats.ring_full += pcpu->ring_full;
  90. stats->recycle_stats.released_refcnt += pcpu->released_refcnt;
  91. }
  92. return true;
  93. }
  94. EXPORT_SYMBOL(page_pool_get_stats);
  95. u8 *page_pool_ethtool_stats_get_strings(u8 *data)
  96. {
  97. int i;
  98. for (i = 0; i < ARRAY_SIZE(pp_stats); i++) {
  99. memcpy(data, pp_stats[i], ETH_GSTRING_LEN);
  100. data += ETH_GSTRING_LEN;
  101. }
  102. return data;
  103. }
  104. EXPORT_SYMBOL(page_pool_ethtool_stats_get_strings);
  105. int page_pool_ethtool_stats_get_count(void)
  106. {
  107. return ARRAY_SIZE(pp_stats);
  108. }
  109. EXPORT_SYMBOL(page_pool_ethtool_stats_get_count);
  110. u64 *page_pool_ethtool_stats_get(u64 *data, const void *stats)
  111. {
  112. const struct page_pool_stats *pool_stats = stats;
  113. *data++ = pool_stats->alloc_stats.fast;
  114. *data++ = pool_stats->alloc_stats.slow;
  115. *data++ = pool_stats->alloc_stats.slow_high_order;
  116. *data++ = pool_stats->alloc_stats.empty;
  117. *data++ = pool_stats->alloc_stats.refill;
  118. *data++ = pool_stats->alloc_stats.waive;
  119. *data++ = pool_stats->recycle_stats.cached;
  120. *data++ = pool_stats->recycle_stats.cache_full;
  121. *data++ = pool_stats->recycle_stats.ring;
  122. *data++ = pool_stats->recycle_stats.ring_full;
  123. *data++ = pool_stats->recycle_stats.released_refcnt;
  124. return data;
  125. }
  126. EXPORT_SYMBOL(page_pool_ethtool_stats_get);
  127. #else
  128. #define alloc_stat_inc(...) do { } while (0)
  129. #define recycle_stat_inc(...) do { } while (0)
  130. #define recycle_stat_add(...) do { } while (0)
  131. #endif
  132. static bool page_pool_producer_lock(struct page_pool *pool)
  133. __acquires(&pool->ring.producer_lock)
  134. {
  135. bool in_softirq = in_softirq();
  136. if (in_softirq)
  137. spin_lock(&pool->ring.producer_lock);
  138. else
  139. spin_lock_bh(&pool->ring.producer_lock);
  140. return in_softirq;
  141. }
  142. static void page_pool_producer_unlock(struct page_pool *pool,
  143. bool in_softirq)
  144. __releases(&pool->ring.producer_lock)
  145. {
  146. if (in_softirq)
  147. spin_unlock(&pool->ring.producer_lock);
  148. else
  149. spin_unlock_bh(&pool->ring.producer_lock);
  150. }
  151. static void page_pool_struct_check(void)
  152. {
  153. CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_users);
  154. CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_page);
  155. CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_offset);
  156. CACHELINE_ASSERT_GROUP_SIZE(struct page_pool, frag,
  157. PAGE_POOL_FRAG_GROUP_ALIGN);
  158. }
  159. static int page_pool_init(struct page_pool *pool,
  160. const struct page_pool_params *params,
  161. int cpuid)
  162. {
  163. unsigned int ring_qsize = 1024; /* Default */
  164. struct netdev_rx_queue *rxq;
  165. int err;
  166. page_pool_struct_check();
  167. memcpy(&pool->p, &params->fast, sizeof(pool->p));
  168. memcpy(&pool->slow, &params->slow, sizeof(pool->slow));
  169. pool->cpuid = cpuid;
  170. /* Validate only known flags were used */
  171. if (pool->slow.flags & ~PP_FLAG_ALL)
  172. return -EINVAL;
  173. if (pool->p.pool_size)
  174. ring_qsize = pool->p.pool_size;
  175. /* Sanity limit mem that can be pinned down */
  176. if (ring_qsize > 32768)
  177. return -E2BIG;
  178. /* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL.
  179. * DMA_BIDIRECTIONAL is for allowing page used for DMA sending,
  180. * which is the XDP_TX use-case.
  181. */
  182. if (pool->slow.flags & PP_FLAG_DMA_MAP) {
  183. if ((pool->p.dma_dir != DMA_FROM_DEVICE) &&
  184. (pool->p.dma_dir != DMA_BIDIRECTIONAL))
  185. return -EINVAL;
  186. pool->dma_map = true;
  187. }
  188. if (pool->slow.flags & PP_FLAG_DMA_SYNC_DEV) {
  189. /* In order to request DMA-sync-for-device the page
  190. * needs to be mapped
  191. */
  192. if (!(pool->slow.flags & PP_FLAG_DMA_MAP))
  193. return -EINVAL;
  194. if (!pool->p.max_len)
  195. return -EINVAL;
  196. pool->dma_sync = true;
  197. /* pool->p.offset has to be set according to the address
  198. * offset used by the DMA engine to start copying rx data
  199. */
  200. }
  201. pool->has_init_callback = !!pool->slow.init_callback;
  202. #ifdef CONFIG_PAGE_POOL_STATS
  203. if (!(pool->slow.flags & PP_FLAG_SYSTEM_POOL)) {
  204. pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats);
  205. if (!pool->recycle_stats)
  206. return -ENOMEM;
  207. } else {
  208. /* For system page pool instance we use a singular stats object
  209. * instead of allocating a separate percpu variable for each
  210. * (also percpu) page pool instance.
  211. */
  212. pool->recycle_stats = &pp_system_recycle_stats;
  213. pool->system = true;
  214. }
  215. #endif
  216. if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
  217. #ifdef CONFIG_PAGE_POOL_STATS
  218. if (!pool->system)
  219. free_percpu(pool->recycle_stats);
  220. #endif
  221. return -ENOMEM;
  222. }
  223. atomic_set(&pool->pages_state_release_cnt, 0);
  224. /* Driver calling page_pool_create() also call page_pool_destroy() */
  225. refcount_set(&pool->user_cnt, 1);
  226. xa_init_flags(&pool->dma_mapped, XA_FLAGS_ALLOC1);
  227. if (pool->slow.flags & PP_FLAG_ALLOW_UNREADABLE_NETMEM) {
  228. /* We rely on rtnl_lock()ing to make sure netdev_rx_queue
  229. * configuration doesn't change while we're initializing
  230. * the page_pool.
  231. */
  232. ASSERT_RTNL();
  233. rxq = __netif_get_rx_queue(pool->slow.netdev,
  234. pool->slow.queue_idx);
  235. pool->mp_priv = rxq->mp_params.mp_priv;
  236. }
  237. if (pool->mp_priv) {
  238. err = mp_dmabuf_devmem_init(pool);
  239. if (err) {
  240. pr_warn("%s() mem-provider init failed %d\n", __func__,
  241. err);
  242. goto free_ptr_ring;
  243. }
  244. static_branch_inc(&page_pool_mem_providers);
  245. }
  246. return 0;
  247. free_ptr_ring:
  248. ptr_ring_cleanup(&pool->ring, NULL);
  249. #ifdef CONFIG_PAGE_POOL_STATS
  250. if (!pool->system)
  251. free_percpu(pool->recycle_stats);
  252. #endif
  253. return err;
  254. }
  255. static void page_pool_uninit(struct page_pool *pool)
  256. {
  257. ptr_ring_cleanup(&pool->ring, NULL);
  258. xa_destroy(&pool->dma_mapped);
  259. #ifdef CONFIG_PAGE_POOL_STATS
  260. if (!pool->system)
  261. free_percpu(pool->recycle_stats);
  262. #endif
  263. }
  264. /**
  265. * page_pool_create_percpu() - create a page pool for a given cpu.
  266. * @params: parameters, see struct page_pool_params
  267. * @cpuid: cpu identifier
  268. */
  269. struct page_pool *
  270. page_pool_create_percpu(const struct page_pool_params *params, int cpuid)
  271. {
  272. struct page_pool *pool;
  273. int err;
  274. pool = kzalloc_node(sizeof(*pool), GFP_KERNEL, params->nid);
  275. if (!pool)
  276. return ERR_PTR(-ENOMEM);
  277. err = page_pool_init(pool, params, cpuid);
  278. if (err < 0)
  279. goto err_free;
  280. err = page_pool_list(pool);
  281. if (err)
  282. goto err_uninit;
  283. return pool;
  284. err_uninit:
  285. page_pool_uninit(pool);
  286. err_free:
  287. pr_warn("%s() gave up with errno %d\n", __func__, err);
  288. kfree(pool);
  289. return ERR_PTR(err);
  290. }
  291. EXPORT_SYMBOL(page_pool_create_percpu);
  292. /**
  293. * page_pool_create() - create a page pool
  294. * @params: parameters, see struct page_pool_params
  295. */
  296. struct page_pool *page_pool_create(const struct page_pool_params *params)
  297. {
  298. return page_pool_create_percpu(params, -1);
  299. }
  300. EXPORT_SYMBOL(page_pool_create);
  301. static void page_pool_return_page(struct page_pool *pool, netmem_ref netmem);
  302. static noinline netmem_ref page_pool_refill_alloc_cache(struct page_pool *pool)
  303. {
  304. struct ptr_ring *r = &pool->ring;
  305. netmem_ref netmem;
  306. int pref_nid; /* preferred NUMA node */
  307. /* Quicker fallback, avoid locks when ring is empty */
  308. if (__ptr_ring_empty(r)) {
  309. alloc_stat_inc(pool, empty);
  310. return 0;
  311. }
  312. /* Softirq guarantee CPU and thus NUMA node is stable. This,
  313. * assumes CPU refilling driver RX-ring will also run RX-NAPI.
  314. */
  315. #ifdef CONFIG_NUMA
  316. pref_nid = (pool->p.nid == NUMA_NO_NODE) ? numa_mem_id() : pool->p.nid;
  317. #else
  318. /* Ignore pool->p.nid setting if !CONFIG_NUMA, helps compiler */
  319. pref_nid = numa_mem_id(); /* will be zero like page_to_nid() */
  320. #endif
  321. /* Refill alloc array, but only if NUMA match */
  322. do {
  323. netmem = (__force netmem_ref)__ptr_ring_consume(r);
  324. if (unlikely(!netmem))
  325. break;
  326. if (likely(netmem_is_pref_nid(netmem, pref_nid))) {
  327. pool->alloc.cache[pool->alloc.count++] = netmem;
  328. } else {
  329. /* NUMA mismatch;
  330. * (1) release 1 page to page-allocator and
  331. * (2) break out to fallthrough to alloc_pages_node.
  332. * This limit stress on page buddy alloactor.
  333. */
  334. page_pool_return_page(pool, netmem);
  335. alloc_stat_inc(pool, waive);
  336. netmem = 0;
  337. break;
  338. }
  339. } while (pool->alloc.count < PP_ALLOC_CACHE_REFILL);
  340. /* Return last page */
  341. if (likely(pool->alloc.count > 0)) {
  342. netmem = pool->alloc.cache[--pool->alloc.count];
  343. alloc_stat_inc(pool, refill);
  344. }
  345. return netmem;
  346. }
  347. /* fast path */
  348. static netmem_ref __page_pool_get_cached(struct page_pool *pool)
  349. {
  350. netmem_ref netmem;
  351. /* Caller MUST guarantee safe non-concurrent access, e.g. softirq */
  352. if (likely(pool->alloc.count)) {
  353. /* Fast-path */
  354. netmem = pool->alloc.cache[--pool->alloc.count];
  355. alloc_stat_inc(pool, fast);
  356. } else {
  357. netmem = page_pool_refill_alloc_cache(pool);
  358. }
  359. return netmem;
  360. }
  361. static void __page_pool_dma_sync_for_device(const struct page_pool *pool,
  362. netmem_ref netmem,
  363. u32 dma_sync_size)
  364. {
  365. #if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC)
  366. dma_addr_t dma_addr = page_pool_get_dma_addr_netmem(netmem);
  367. dma_sync_size = min(dma_sync_size, pool->p.max_len);
  368. __dma_sync_single_for_device(pool->p.dev, dma_addr + pool->p.offset,
  369. dma_sync_size, pool->p.dma_dir);
  370. #endif
  371. }
  372. static __always_inline void
  373. page_pool_dma_sync_for_device(const struct page_pool *pool,
  374. netmem_ref netmem,
  375. u32 dma_sync_size)
  376. {
  377. if (pool->dma_sync && dma_dev_need_sync(pool->p.dev)) {
  378. rcu_read_lock();
  379. /* re-check under rcu_read_lock() to sync with page_pool_scrub() */
  380. if (pool->dma_sync)
  381. __page_pool_dma_sync_for_device(pool, netmem,
  382. dma_sync_size);
  383. rcu_read_unlock();
  384. }
  385. }
  386. static int page_pool_register_dma_index(struct page_pool *pool,
  387. netmem_ref netmem, gfp_t gfp)
  388. {
  389. int err = 0;
  390. u32 id;
  391. if (unlikely(!PP_DMA_INDEX_BITS))
  392. goto out;
  393. if (in_softirq())
  394. err = xa_alloc(&pool->dma_mapped, &id, netmem_to_page(netmem),
  395. PP_DMA_INDEX_LIMIT, gfp);
  396. else
  397. err = xa_alloc_bh(&pool->dma_mapped, &id, netmem_to_page(netmem),
  398. PP_DMA_INDEX_LIMIT, gfp);
  399. if (err) {
  400. WARN_ONCE(err != -ENOMEM, "couldn't track DMA mapping, please report to netdev@");
  401. goto out;
  402. }
  403. netmem_set_dma_index(netmem, id);
  404. out:
  405. return err;
  406. }
  407. static int page_pool_release_dma_index(struct page_pool *pool,
  408. netmem_ref netmem)
  409. {
  410. struct page *old, *page = netmem_to_page(netmem);
  411. unsigned long id;
  412. if (unlikely(!PP_DMA_INDEX_BITS))
  413. return 0;
  414. id = netmem_get_dma_index(netmem);
  415. if (!id)
  416. return -1;
  417. if (in_softirq())
  418. old = xa_cmpxchg(&pool->dma_mapped, id, page, NULL, 0);
  419. else
  420. old = xa_cmpxchg_bh(&pool->dma_mapped, id, page, NULL, 0);
  421. if (old != page)
  422. return -1;
  423. netmem_set_dma_index(netmem, 0);
  424. return 0;
  425. }
  426. static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem, gfp_t gfp)
  427. {
  428. dma_addr_t dma;
  429. int err;
  430. /* Setup DMA mapping: use 'struct page' area for storing DMA-addr
  431. * since dma_addr_t can be either 32 or 64 bits and does not always fit
  432. * into page private data (i.e 32bit cpu with 64bit DMA caps)
  433. * This mapping is kept for lifetime of page, until leaving pool.
  434. */
  435. dma = dma_map_page_attrs(pool->p.dev, netmem_to_page(netmem), 0,
  436. (PAGE_SIZE << pool->p.order), pool->p.dma_dir,
  437. DMA_ATTR_SKIP_CPU_SYNC |
  438. DMA_ATTR_WEAK_ORDERING);
  439. if (dma_mapping_error(pool->p.dev, dma))
  440. return false;
  441. if (page_pool_set_dma_addr_netmem(netmem, dma)) {
  442. WARN_ONCE(1, "unexpected DMA address, please report to netdev@");
  443. goto unmap_failed;
  444. }
  445. err = page_pool_register_dma_index(pool, netmem, gfp);
  446. if (err)
  447. goto unset_failed;
  448. page_pool_dma_sync_for_device(pool, netmem, pool->p.max_len);
  449. return true;
  450. unset_failed:
  451. page_pool_set_dma_addr_netmem(netmem, 0);
  452. unmap_failed:
  453. dma_unmap_page_attrs(pool->p.dev, dma,
  454. PAGE_SIZE << pool->p.order, pool->p.dma_dir,
  455. DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
  456. return false;
  457. }
  458. static struct page *__page_pool_alloc_page_order(struct page_pool *pool,
  459. gfp_t gfp)
  460. {
  461. struct page *page;
  462. gfp |= __GFP_COMP;
  463. page = alloc_pages_node(pool->p.nid, gfp, pool->p.order);
  464. if (unlikely(!page))
  465. return NULL;
  466. if (pool->dma_map && unlikely(!page_pool_dma_map(pool, page_to_netmem(page), gfp))) {
  467. put_page(page);
  468. return NULL;
  469. }
  470. alloc_stat_inc(pool, slow_high_order);
  471. page_pool_set_pp_info(pool, page_to_netmem(page));
  472. /* Track how many pages are held 'in-flight' */
  473. pool->pages_state_hold_cnt++;
  474. trace_page_pool_state_hold(pool, page_to_netmem(page),
  475. pool->pages_state_hold_cnt);
  476. return page;
  477. }
  478. /* slow path */
  479. static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,
  480. gfp_t gfp)
  481. {
  482. const int bulk = PP_ALLOC_CACHE_REFILL;
  483. unsigned int pp_order = pool->p.order;
  484. bool dma_map = pool->dma_map;
  485. netmem_ref netmem;
  486. int i, nr_pages;
  487. /* Don't support bulk alloc for high-order pages */
  488. if (unlikely(pp_order))
  489. return page_to_netmem(__page_pool_alloc_page_order(pool, gfp));
  490. /* Unnecessary as alloc cache is empty, but guarantees zero count */
  491. if (unlikely(pool->alloc.count > 0))
  492. return pool->alloc.cache[--pool->alloc.count];
  493. /* Mark empty alloc.cache slots "empty" for alloc_pages_bulk_array */
  494. memset(&pool->alloc.cache, 0, sizeof(void *) * bulk);
  495. nr_pages = alloc_pages_bulk_array_node(gfp,
  496. pool->p.nid, bulk,
  497. (struct page **)pool->alloc.cache);
  498. if (unlikely(!nr_pages))
  499. return 0;
  500. /* Pages have been filled into alloc.cache array, but count is zero and
  501. * page element have not been (possibly) DMA mapped.
  502. */
  503. for (i = 0; i < nr_pages; i++) {
  504. netmem = pool->alloc.cache[i];
  505. if (dma_map && unlikely(!page_pool_dma_map(pool, netmem, gfp))) {
  506. put_page(netmem_to_page(netmem));
  507. continue;
  508. }
  509. page_pool_set_pp_info(pool, netmem);
  510. pool->alloc.cache[pool->alloc.count++] = netmem;
  511. /* Track how many pages are held 'in-flight' */
  512. pool->pages_state_hold_cnt++;
  513. trace_page_pool_state_hold(pool, netmem,
  514. pool->pages_state_hold_cnt);
  515. }
  516. /* Return last page */
  517. if (likely(pool->alloc.count > 0)) {
  518. netmem = pool->alloc.cache[--pool->alloc.count];
  519. alloc_stat_inc(pool, slow);
  520. } else {
  521. netmem = 0;
  522. }
  523. /* When page just alloc'ed is should/must have refcnt 1. */
  524. return netmem;
  525. }
  526. /* For using page_pool replace: alloc_pages() API calls, but provide
  527. * synchronization guarantee for allocation side.
  528. */
  529. netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp)
  530. {
  531. netmem_ref netmem;
  532. /* Fast-path: Get a page from cache */
  533. netmem = __page_pool_get_cached(pool);
  534. if (netmem)
  535. return netmem;
  536. /* Slow-path: cache empty, do real allocation */
  537. if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv)
  538. netmem = mp_dmabuf_devmem_alloc_netmems(pool, gfp);
  539. else
  540. netmem = __page_pool_alloc_pages_slow(pool, gfp);
  541. return netmem;
  542. }
  543. EXPORT_SYMBOL(page_pool_alloc_netmem);
  544. struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp)
  545. {
  546. return netmem_to_page(page_pool_alloc_netmem(pool, gfp));
  547. }
  548. EXPORT_SYMBOL(page_pool_alloc_pages);
  549. ALLOW_ERROR_INJECTION(page_pool_alloc_pages, NULL);
  550. /* Calculate distance between two u32 values, valid if distance is below 2^(31)
  551. * https://en.wikipedia.org/wiki/Serial_number_arithmetic#General_Solution
  552. */
  553. #define _distance(a, b) (s32)((a) - (b))
  554. s32 page_pool_inflight(const struct page_pool *pool, bool strict)
  555. {
  556. u32 release_cnt = atomic_read(&pool->pages_state_release_cnt);
  557. u32 hold_cnt = READ_ONCE(pool->pages_state_hold_cnt);
  558. s32 inflight;
  559. inflight = _distance(hold_cnt, release_cnt);
  560. if (strict) {
  561. trace_page_pool_release(pool, inflight, hold_cnt, release_cnt);
  562. WARN(inflight < 0, "Negative(%d) inflight packet-pages",
  563. inflight);
  564. } else {
  565. inflight = max(0, inflight);
  566. }
  567. return inflight;
  568. }
  569. void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem)
  570. {
  571. netmem_set_pp(netmem, pool);
  572. netmem_or_pp_magic(netmem, PP_SIGNATURE);
  573. /* Ensuring all pages have been split into one fragment initially:
  574. * page_pool_set_pp_info() is only called once for every page when it
  575. * is allocated from the page allocator and page_pool_fragment_page()
  576. * is dirtying the same cache line as the page->pp_magic above, so
  577. * the overhead is negligible.
  578. */
  579. page_pool_fragment_netmem(netmem, 1);
  580. if (pool->has_init_callback)
  581. pool->slow.init_callback(netmem, pool->slow.init_arg);
  582. }
  583. void page_pool_clear_pp_info(netmem_ref netmem)
  584. {
  585. netmem_clear_pp_magic(netmem);
  586. netmem_set_pp(netmem, NULL);
  587. }
  588. static __always_inline void __page_pool_release_page_dma(struct page_pool *pool,
  589. netmem_ref netmem)
  590. {
  591. dma_addr_t dma;
  592. if (!pool->dma_map)
  593. /* Always account for inflight pages, even if we didn't
  594. * map them
  595. */
  596. return;
  597. if (page_pool_release_dma_index(pool, netmem))
  598. return;
  599. dma = page_pool_get_dma_addr_netmem(netmem);
  600. /* When page is unmapped, it cannot be returned to our pool */
  601. dma_unmap_page_attrs(pool->p.dev, dma,
  602. PAGE_SIZE << pool->p.order, pool->p.dma_dir,
  603. DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
  604. page_pool_set_dma_addr_netmem(netmem, 0);
  605. }
  606. /* Disconnects a page (from a page_pool). API users can have a need
  607. * to disconnect a page (from a page_pool), to allow it to be used as
  608. * a regular page (that will eventually be returned to the normal
  609. * page-allocator via put_page).
  610. */
  611. void page_pool_return_page(struct page_pool *pool, netmem_ref netmem)
  612. {
  613. int count;
  614. bool put;
  615. put = true;
  616. if (static_branch_unlikely(&page_pool_mem_providers) && pool->mp_priv)
  617. put = mp_dmabuf_devmem_release_page(pool, netmem);
  618. else
  619. __page_pool_release_page_dma(pool, netmem);
  620. /* This may be the last page returned, releasing the pool, so
  621. * it is not safe to reference pool afterwards.
  622. */
  623. count = atomic_inc_return_relaxed(&pool->pages_state_release_cnt);
  624. trace_page_pool_state_release(pool, netmem, count);
  625. if (put) {
  626. page_pool_clear_pp_info(netmem);
  627. put_page(netmem_to_page(netmem));
  628. }
  629. /* An optimization would be to call __free_pages(page, pool->p.order)
  630. * knowing page is not part of page-cache (thus avoiding a
  631. * __page_cache_release() call).
  632. */
  633. }
  634. static bool page_pool_recycle_in_ring(struct page_pool *pool, netmem_ref netmem)
  635. {
  636. bool in_softirq, ret;
  637. /* BH protection not needed if current is softirq */
  638. in_softirq = page_pool_producer_lock(pool);
  639. ret = !__ptr_ring_produce(&pool->ring, (__force void *)netmem);
  640. if (ret)
  641. recycle_stat_inc(pool, ring);
  642. page_pool_producer_unlock(pool, in_softirq);
  643. return ret;
  644. }
  645. /* Only allow direct recycling in special circumstances, into the
  646. * alloc side cache. E.g. during RX-NAPI processing for XDP_DROP use-case.
  647. *
  648. * Caller must provide appropriate safe context.
  649. */
  650. static bool page_pool_recycle_in_cache(netmem_ref netmem,
  651. struct page_pool *pool)
  652. {
  653. if (unlikely(pool->alloc.count == PP_ALLOC_CACHE_SIZE)) {
  654. recycle_stat_inc(pool, cache_full);
  655. return false;
  656. }
  657. /* Caller MUST have verified/know (page_ref_count(page) == 1) */
  658. pool->alloc.cache[pool->alloc.count++] = netmem;
  659. recycle_stat_inc(pool, cached);
  660. return true;
  661. }
  662. static bool __page_pool_page_can_be_recycled(netmem_ref netmem)
  663. {
  664. return netmem_is_net_iov(netmem) ||
  665. (page_ref_count(netmem_to_page(netmem)) == 1 &&
  666. !page_is_pfmemalloc(netmem_to_page(netmem)));
  667. }
  668. /* If the page refcnt == 1, this will try to recycle the page.
  669. * If pool->dma_sync is set, we'll try to sync the DMA area for
  670. * the configured size min(dma_sync_size, pool->max_len).
  671. * If the page refcnt != 1, then the page will be returned to memory
  672. * subsystem.
  673. */
  674. static __always_inline netmem_ref
  675. __page_pool_put_page(struct page_pool *pool, netmem_ref netmem,
  676. unsigned int dma_sync_size, bool allow_direct)
  677. {
  678. lockdep_assert_no_hardirq();
  679. /* This allocator is optimized for the XDP mode that uses
  680. * one-frame-per-page, but have fallbacks that act like the
  681. * regular page allocator APIs.
  682. *
  683. * refcnt == 1 means page_pool owns page, and can recycle it.
  684. *
  685. * page is NOT reusable when allocated when system is under
  686. * some pressure. (page_is_pfmemalloc)
  687. */
  688. if (likely(__page_pool_page_can_be_recycled(netmem))) {
  689. /* Read barrier done in page_ref_count / READ_ONCE */
  690. page_pool_dma_sync_for_device(pool, netmem, dma_sync_size);
  691. if (allow_direct && page_pool_recycle_in_cache(netmem, pool))
  692. return 0;
  693. /* Page found as candidate for recycling */
  694. return netmem;
  695. }
  696. /* Fallback/non-XDP mode: API user have elevated refcnt.
  697. *
  698. * Many drivers split up the page into fragments, and some
  699. * want to keep doing this to save memory and do refcnt based
  700. * recycling. Support this use case too, to ease drivers
  701. * switching between XDP/non-XDP.
  702. *
  703. * In-case page_pool maintains the DMA mapping, API user must
  704. * call page_pool_put_page once. In this elevated refcnt
  705. * case, the DMA is unmapped/released, as driver is likely
  706. * doing refcnt based recycle tricks, meaning another process
  707. * will be invoking put_page.
  708. */
  709. recycle_stat_inc(pool, released_refcnt);
  710. page_pool_return_page(pool, netmem);
  711. return 0;
  712. }
  713. static bool page_pool_napi_local(const struct page_pool *pool)
  714. {
  715. const struct napi_struct *napi;
  716. u32 cpuid;
  717. /* On PREEMPT_RT the softirq can be preempted by the consumer */
  718. if (IS_ENABLED(CONFIG_PREEMPT_RT))
  719. return false;
  720. if (unlikely(!in_softirq()))
  721. return false;
  722. /* Allow direct recycle if we have reasons to believe that we are
  723. * in the same context as the consumer would run, so there's
  724. * no possible race.
  725. * __page_pool_put_page() makes sure we're not in hardirq context
  726. * and interrupts are enabled prior to accessing the cache.
  727. */
  728. cpuid = smp_processor_id();
  729. if (READ_ONCE(pool->cpuid) == cpuid)
  730. return true;
  731. napi = READ_ONCE(pool->p.napi);
  732. return napi && READ_ONCE(napi->list_owner) == cpuid;
  733. }
  734. void page_pool_put_unrefed_netmem(struct page_pool *pool, netmem_ref netmem,
  735. unsigned int dma_sync_size, bool allow_direct)
  736. {
  737. if (!allow_direct)
  738. allow_direct = page_pool_napi_local(pool);
  739. netmem =
  740. __page_pool_put_page(pool, netmem, dma_sync_size, allow_direct);
  741. if (netmem && !page_pool_recycle_in_ring(pool, netmem)) {
  742. /* Cache full, fallback to free pages */
  743. recycle_stat_inc(pool, ring_full);
  744. page_pool_return_page(pool, netmem);
  745. }
  746. }
  747. EXPORT_SYMBOL(page_pool_put_unrefed_netmem);
  748. void page_pool_put_unrefed_page(struct page_pool *pool, struct page *page,
  749. unsigned int dma_sync_size, bool allow_direct)
  750. {
  751. page_pool_put_unrefed_netmem(pool, page_to_netmem(page), dma_sync_size,
  752. allow_direct);
  753. }
  754. EXPORT_SYMBOL(page_pool_put_unrefed_page);
  755. /**
  756. * page_pool_put_page_bulk() - release references on multiple pages
  757. * @pool: pool from which pages were allocated
  758. * @data: array holding page pointers
  759. * @count: number of pages in @data
  760. *
  761. * Tries to refill a number of pages into the ptr_ring cache holding ptr_ring
  762. * producer lock. If the ptr_ring is full, page_pool_put_page_bulk()
  763. * will release leftover pages to the page allocator.
  764. * page_pool_put_page_bulk() is suitable to be run inside the driver NAPI tx
  765. * completion loop for the XDP_REDIRECT use case.
  766. *
  767. * Please note the caller must not use data area after running
  768. * page_pool_put_page_bulk(), as this function overwrites it.
  769. */
  770. void page_pool_put_page_bulk(struct page_pool *pool, void **data,
  771. int count)
  772. {
  773. int i, bulk_len = 0;
  774. bool allow_direct;
  775. bool in_softirq;
  776. allow_direct = page_pool_napi_local(pool);
  777. for (i = 0; i < count; i++) {
  778. netmem_ref netmem = page_to_netmem(virt_to_head_page(data[i]));
  779. /* It is not the last user for the page frag case */
  780. if (!page_pool_is_last_ref(netmem))
  781. continue;
  782. netmem = __page_pool_put_page(pool, netmem, -1, allow_direct);
  783. /* Approved for bulk recycling in ptr_ring cache */
  784. if (netmem)
  785. data[bulk_len++] = (__force void *)netmem;
  786. }
  787. if (!bulk_len)
  788. return;
  789. /* Bulk producer into ptr_ring page_pool cache */
  790. in_softirq = page_pool_producer_lock(pool);
  791. for (i = 0; i < bulk_len; i++) {
  792. if (__ptr_ring_produce(&pool->ring, data[i])) {
  793. /* ring full */
  794. recycle_stat_inc(pool, ring_full);
  795. break;
  796. }
  797. }
  798. recycle_stat_add(pool, ring, i);
  799. page_pool_producer_unlock(pool, in_softirq);
  800. /* Hopefully all pages was return into ptr_ring */
  801. if (likely(i == bulk_len))
  802. return;
  803. /* ptr_ring cache full, free remaining pages outside producer lock
  804. * since put_page() with refcnt == 1 can be an expensive operation
  805. */
  806. for (; i < bulk_len; i++)
  807. page_pool_return_page(pool, (__force netmem_ref)data[i]);
  808. }
  809. EXPORT_SYMBOL(page_pool_put_page_bulk);
  810. static netmem_ref page_pool_drain_frag(struct page_pool *pool,
  811. netmem_ref netmem)
  812. {
  813. long drain_count = BIAS_MAX - pool->frag_users;
  814. /* Some user is still using the page frag */
  815. if (likely(page_pool_unref_netmem(netmem, drain_count)))
  816. return 0;
  817. if (__page_pool_page_can_be_recycled(netmem)) {
  818. page_pool_dma_sync_for_device(pool, netmem, -1);
  819. return netmem;
  820. }
  821. page_pool_return_page(pool, netmem);
  822. return 0;
  823. }
  824. static void page_pool_free_frag(struct page_pool *pool)
  825. {
  826. long drain_count = BIAS_MAX - pool->frag_users;
  827. netmem_ref netmem = pool->frag_page;
  828. pool->frag_page = 0;
  829. if (!netmem || page_pool_unref_netmem(netmem, drain_count))
  830. return;
  831. page_pool_return_page(pool, netmem);
  832. }
  833. netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool,
  834. unsigned int *offset, unsigned int size,
  835. gfp_t gfp)
  836. {
  837. unsigned int max_size = PAGE_SIZE << pool->p.order;
  838. netmem_ref netmem = pool->frag_page;
  839. if (WARN_ON(size > max_size))
  840. return 0;
  841. size = ALIGN(size, dma_get_cache_alignment());
  842. *offset = pool->frag_offset;
  843. if (netmem && *offset + size > max_size) {
  844. netmem = page_pool_drain_frag(pool, netmem);
  845. if (netmem) {
  846. alloc_stat_inc(pool, fast);
  847. goto frag_reset;
  848. }
  849. }
  850. if (!netmem) {
  851. netmem = page_pool_alloc_netmem(pool, gfp);
  852. if (unlikely(!netmem)) {
  853. pool->frag_page = 0;
  854. return 0;
  855. }
  856. pool->frag_page = netmem;
  857. frag_reset:
  858. pool->frag_users = 1;
  859. *offset = 0;
  860. pool->frag_offset = size;
  861. page_pool_fragment_netmem(netmem, BIAS_MAX);
  862. return netmem;
  863. }
  864. pool->frag_users++;
  865. pool->frag_offset = *offset + size;
  866. alloc_stat_inc(pool, fast);
  867. return netmem;
  868. }
  869. EXPORT_SYMBOL(page_pool_alloc_frag_netmem);
  870. struct page *page_pool_alloc_frag(struct page_pool *pool, unsigned int *offset,
  871. unsigned int size, gfp_t gfp)
  872. {
  873. return netmem_to_page(page_pool_alloc_frag_netmem(pool, offset, size,
  874. gfp));
  875. }
  876. EXPORT_SYMBOL(page_pool_alloc_frag);
  877. static void page_pool_empty_ring(struct page_pool *pool)
  878. {
  879. netmem_ref netmem;
  880. /* Empty recycle ring */
  881. while ((netmem = (__force netmem_ref)ptr_ring_consume_bh(&pool->ring))) {
  882. /* Verify the refcnt invariant of cached pages */
  883. if (!(netmem_ref_count(netmem) == 1))
  884. pr_crit("%s() page_pool refcnt %d violation\n",
  885. __func__, netmem_ref_count(netmem));
  886. page_pool_return_page(pool, netmem);
  887. }
  888. }
  889. static void __page_pool_destroy(struct page_pool *pool)
  890. {
  891. if (pool->disconnect)
  892. pool->disconnect(pool);
  893. page_pool_unlist(pool);
  894. page_pool_uninit(pool);
  895. if (pool->mp_priv) {
  896. mp_dmabuf_devmem_destroy(pool);
  897. static_branch_dec(&page_pool_mem_providers);
  898. }
  899. kfree(pool);
  900. }
  901. static void page_pool_empty_alloc_cache_once(struct page_pool *pool)
  902. {
  903. netmem_ref netmem;
  904. if (pool->destroy_cnt)
  905. return;
  906. /* Empty alloc cache, assume caller made sure this is
  907. * no-longer in use, and page_pool_alloc_pages() cannot be
  908. * call concurrently.
  909. */
  910. while (pool->alloc.count) {
  911. netmem = pool->alloc.cache[--pool->alloc.count];
  912. page_pool_return_page(pool, netmem);
  913. }
  914. }
  915. static void page_pool_scrub(struct page_pool *pool)
  916. {
  917. unsigned long id;
  918. void *ptr;
  919. page_pool_empty_alloc_cache_once(pool);
  920. if (!pool->destroy_cnt++ && pool->dma_map) {
  921. if (pool->dma_sync) {
  922. /* Disable page_pool_dma_sync_for_device() */
  923. pool->dma_sync = false;
  924. /* Make sure all concurrent returns that may see the old
  925. * value of dma_sync (and thus perform a sync) have
  926. * finished before doing the unmapping below. Skip the
  927. * wait if the device doesn't actually need syncing, or
  928. * if there are no outstanding mapped pages.
  929. */
  930. if (dma_dev_need_sync(pool->p.dev) &&
  931. !xa_empty(&pool->dma_mapped))
  932. synchronize_net();
  933. }
  934. xa_for_each(&pool->dma_mapped, id, ptr)
  935. __page_pool_release_page_dma(pool, page_to_netmem(ptr));
  936. }
  937. /* No more consumers should exist, but producers could still
  938. * be in-flight.
  939. */
  940. page_pool_empty_ring(pool);
  941. }
  942. static int page_pool_release(struct page_pool *pool)
  943. {
  944. bool in_softirq;
  945. int inflight;
  946. page_pool_scrub(pool);
  947. inflight = page_pool_inflight(pool, true);
  948. /* Acquire producer lock to make sure producers have exited. */
  949. in_softirq = page_pool_producer_lock(pool);
  950. page_pool_producer_unlock(pool, in_softirq);
  951. if (!inflight)
  952. __page_pool_destroy(pool);
  953. return inflight;
  954. }
  955. static void page_pool_release_retry(struct work_struct *wq)
  956. {
  957. struct delayed_work *dwq = to_delayed_work(wq);
  958. struct page_pool *pool = container_of(dwq, typeof(*pool), release_dw);
  959. void *netdev;
  960. int inflight;
  961. inflight = page_pool_release(pool);
  962. /* In rare cases, a driver bug may cause inflight to go negative.
  963. * Don't reschedule release if inflight is 0 or negative.
  964. * - If 0, the page_pool has been destroyed
  965. * - if negative, we will never recover
  966. * in both cases no reschedule is necessary.
  967. */
  968. if (inflight <= 0)
  969. return;
  970. /* Periodic warning for page pools the user can't see */
  971. netdev = READ_ONCE(pool->slow.netdev);
  972. if (time_after_eq(jiffies, pool->defer_warn) &&
  973. (!netdev || netdev == NET_PTR_POISON)) {
  974. int sec = (s32)((u32)jiffies - (u32)pool->defer_start) / HZ;
  975. pr_warn("%s() stalled pool shutdown: id %u, %d inflight %d sec\n",
  976. __func__, pool->user.id, inflight, sec);
  977. pool->defer_warn = jiffies + DEFER_WARN_INTERVAL;
  978. }
  979. /* Still not ready to be disconnected, retry later */
  980. schedule_delayed_work(&pool->release_dw, DEFER_TIME);
  981. }
  982. void page_pool_use_xdp_mem(struct page_pool *pool, void (*disconnect)(void *),
  983. const struct xdp_mem_info *mem)
  984. {
  985. refcount_inc(&pool->user_cnt);
  986. pool->disconnect = disconnect;
  987. pool->xdp_mem_id = mem->id;
  988. }
  989. void page_pool_disable_direct_recycling(struct page_pool *pool)
  990. {
  991. /* Disable direct recycling based on pool->cpuid.
  992. * Paired with READ_ONCE() in page_pool_napi_local().
  993. */
  994. WRITE_ONCE(pool->cpuid, -1);
  995. if (!pool->p.napi)
  996. return;
  997. napi_assert_will_not_race(pool->p.napi);
  998. WRITE_ONCE(pool->p.napi, NULL);
  999. }
  1000. EXPORT_SYMBOL(page_pool_disable_direct_recycling);
  1001. void page_pool_destroy(struct page_pool *pool)
  1002. {
  1003. if (!pool)
  1004. return;
  1005. if (!page_pool_put(pool))
  1006. return;
  1007. page_pool_disable_direct_recycling(pool);
  1008. page_pool_free_frag(pool);
  1009. if (!page_pool_release(pool))
  1010. return;
  1011. page_pool_detached(pool);
  1012. pool->defer_start = jiffies;
  1013. pool->defer_warn = jiffies + DEFER_WARN_INTERVAL;
  1014. INIT_DELAYED_WORK(&pool->release_dw, page_pool_release_retry);
  1015. schedule_delayed_work(&pool->release_dw, DEFER_TIME);
  1016. }
  1017. EXPORT_SYMBOL(page_pool_destroy);
  1018. /* Caller must provide appropriate safe context, e.g. NAPI. */
  1019. void page_pool_update_nid(struct page_pool *pool, int new_nid)
  1020. {
  1021. netmem_ref netmem;
  1022. trace_page_pool_update_nid(pool, new_nid);
  1023. pool->p.nid = new_nid;
  1024. /* Flush pool alloc cache, as refill will check NUMA node */
  1025. while (pool->alloc.count) {
  1026. netmem = pool->alloc.cache[--pool->alloc.count];
  1027. page_pool_return_page(pool, netmem);
  1028. }
  1029. }
  1030. EXPORT_SYMBOL(page_pool_update_nid);