Lines Matching refs:page

11  * The page_pool allocator is optimized for recycling page or page fragment used
15 * which allocate memory with or without page splitting depending on the
19 * always smaller than half a page, it can use one of the more specific API
22 * 1. page_pool_alloc_pages(): allocate memory without page splitting when
23 * driver knows that the memory it need is always bigger than half of the page
24 * allocated from page pool. There is no cache line dirtying for 'struct page'
25 * when a page is recycled back to the page pool.
27 * 2. page_pool_alloc_frag(): allocate memory with page splitting when driver
29 * page allocated from page pool. Page splitting enables memory saving and thus
31 * implement page splitting, mainly some cache line dirtying/bouncing for
32 * 'struct page' and atomic operation for page->pp_ref_count.
40 * page_pool_put_page() may be called multiple times on the same page if a page
42 * recycle the page, or in case of page->_refcount > 1, it will release the DMA
48 * the same page when a page is split. The API user must setup pool->p.max_len
83 * page_pool_dev_alloc_pages() - allocate a page.
86 * Get a page from the page allocator or page_pool caches.
88 static inline struct page *page_pool_dev_alloc_pages(struct page_pool *pool)
96 * page_pool_dev_alloc_frag() - allocate a page fragment.
98 * @offset: offset to the allocated page
101 * Get a page fragment from the page allocator or page_pool caches.
104 * Return allocated page fragment, otherwise return NULL.
106 static inline struct page *page_pool_dev_alloc_frag(struct page_pool *pool,
115 static inline struct page *page_pool_alloc(struct page_pool *pool,
120 struct page *page;
128 page = page_pool_alloc_frag(pool, offset, *size, gfp);
129 if (unlikely(!page))
141 return page;
145 * page_pool_dev_alloc() - allocate a page or a page fragment.
147 * @offset: offset to the allocated page
150 * Get a page or a page fragment from the page allocator or page_pool caches
155 * Return allocated page or page fragment, otherwise return NULL.
157 static inline struct page *page_pool_dev_alloc(struct page_pool *pool,
170 struct page *page;
173 page = page_pool_alloc(pool, &offset, size, gfp & ~__GFP_HIGHMEM);
174 if (unlikely(!page))
177 return page_address(page) + offset;
181 * page_pool_dev_alloc_va() - allocate a page or a page fragment and return its
187 * it returns va of the allocated page or page fragment.
190 * Return the va for the allocated page or page fragment, otherwise return NULL.
202 * @pool: pool from which page was allocated
214 * page_pool_fragment_page() - split a fresh page into fragments
215 * @page: page to split
218 * pp_ref_count represents the number of outstanding references to the page,
219 * which will be freed using page_pool APIs (rather than page allocator APIs
221 * objects like skbs marked for page pool recycling.
224 * freshly allocated page. The page must be freshly allocated (have a
231 static inline void page_pool_fragment_page(struct page *page, long nr)
233 atomic_long_set(&page->pp_ref_count, nr);
236 static inline long page_pool_unref_page(struct page *page, long nr)
241 * references to the page:
248 * an atomic update, especially when dealing with a page that may be
251 * initially, and only overwrite it when the page is partitioned into
254 if (atomic_long_read(&page->pp_ref_count) == nr) {
261 atomic_long_set(&page->pp_ref_count, 1);
266 ret = atomic_long_sub_return(nr, &page->pp_ref_count);
275 atomic_long_set(&page->pp_ref_count, 1);
280 static inline void page_pool_ref_page(struct page *page)
282 atomic_long_inc(&page->pp_ref_count);
285 static inline bool page_pool_is_last_ref(struct page *page)
288 return page_pool_unref_page(page, 1) == 0;
292 * page_pool_put_page() - release a reference to a page pool page
293 * @pool: pool from which page was allocated
294 * @page: page to release a reference on
295 * @dma_sync_size: how much of the page may have been touched by the device
298 * The outcome of this depends on the page refcnt. If the driver bumps
299 * the refcnt > 1 this will unmap the page. If the page refcnt is 1
300 * the allocator owns the page and will try to recycle it in one of the pool
301 * caches. If PP_FLAG_DMA_SYNC_DEV is set, the page will be synced for_device
305 struct page *page,
313 if (!page_pool_is_last_ref(page))
316 page_pool_put_unrefed_page(pool, page, dma_sync_size, allow_direct);
321 * page_pool_put_full_page() - release a reference on a page pool page
322 * @pool: pool from which page was allocated
323 * @page: page to release a reference on
330 struct page *page, bool allow_direct)
332 page_pool_put_page(pool, page, -1, allow_direct);
336 * page_pool_recycle_direct() - release a reference on a page pool page
337 * @pool: pool from which page was allocated
338 * @page: page to release a reference on
341 * (e.g NAPI), since it will recycle the page directly into the pool fast cache.
344 struct page *page)
346 page_pool_put_full_page(pool, page, true);
368 * @page: page allocated from a page pool
370 * Fetch the DMA address of the page. The page pool to which the page belongs
373 static inline dma_addr_t page_pool_get_dma_addr(struct page *page)
375 dma_addr_t ret = page->dma_addr;
383 static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
386 page->dma_addr = addr >> PAGE_SHIFT;
388 /* We assume page alignment to shave off bottom bits,
391 return addr != (dma_addr_t)page->dma_addr << PAGE_SHIFT;
394 page->dma_addr = addr;