Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument

napi_alloc_frag_align() and netdev_alloc_frag_align() accept
align as an argument, and they are thin wrappers around the
__napi_alloc_frag_align() and __netdev_alloc_frag_align() APIs
doing the alignment checking and align mask conversion, in order
to call page_frag_alloc_align() directly. The intention here is
to keep the alignment checking and the alignmask conversion in
in-line wrapper to avoid those kind of operations during execution
time since it can usually be handled during compile time.

We are going to use page_frag_alloc_align() in vhost_net.c, it
need the same kind of alignment checking and alignmask conversion,
so split up page_frag_alloc_align into an inline wrapper doing the
above operation, and add __page_frag_alloc_align() which is passed
with the align mask the original function expected as suggested by
Alexander.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
CC: Alexander Duyck <alexander.duyck@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Yunsheng Lin and committed by
Paolo Abeni
411c5f36 0e71862a

+21 -11
+11 -4
include/linux/gfp.h
··· 312 312 313 313 struct page_frag_cache; 314 314 extern void __page_frag_cache_drain(struct page *page, unsigned int count); 315 - extern void *page_frag_alloc_align(struct page_frag_cache *nc, 316 - unsigned int fragsz, gfp_t gfp_mask, 317 - unsigned int align_mask); 315 + void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, 316 + gfp_t gfp_mask, unsigned int align_mask); 317 + 318 + static inline void *page_frag_alloc_align(struct page_frag_cache *nc, 319 + unsigned int fragsz, gfp_t gfp_mask, 320 + unsigned int align) 321 + { 322 + WARN_ON_ONCE(!is_power_of_2(align)); 323 + return __page_frag_alloc_align(nc, fragsz, gfp_mask, -align); 324 + } 318 325 319 326 static inline void *page_frag_alloc(struct page_frag_cache *nc, 320 327 unsigned int fragsz, gfp_t gfp_mask) 321 328 { 322 - return page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); 329 + return __page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); 323 330 } 324 331 325 332 extern void page_frag_free(void *addr);
+4 -4
mm/page_alloc.c
··· 4708 4708 } 4709 4709 EXPORT_SYMBOL(__page_frag_cache_drain); 4710 4710 4711 - void *page_frag_alloc_align(struct page_frag_cache *nc, 4712 - unsigned int fragsz, gfp_t gfp_mask, 4713 - unsigned int align_mask) 4711 + void *__page_frag_alloc_align(struct page_frag_cache *nc, 4712 + unsigned int fragsz, gfp_t gfp_mask, 4713 + unsigned int align_mask) 4714 4714 { 4715 4715 unsigned int size = PAGE_SIZE; 4716 4716 struct page *page; ··· 4779 4779 4780 4780 return nc->va + offset; 4781 4781 } 4782 - EXPORT_SYMBOL(page_frag_alloc_align); 4782 + EXPORT_SYMBOL(__page_frag_alloc_align); 4783 4783 4784 4784 /* 4785 4785 * Frees a page fragment allocated out of either a compound or order 0 page.
+6 -3
net/core/skbuff.c
··· 315 315 316 316 fragsz = SKB_DATA_ALIGN(fragsz); 317 317 318 - return page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask); 318 + return __page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, 319 + align_mask); 319 320 } 320 321 EXPORT_SYMBOL(__napi_alloc_frag_align); 321 322 ··· 328 327 if (in_hardirq() || irqs_disabled()) { 329 328 struct page_frag_cache *nc = this_cpu_ptr(&netdev_alloc_cache); 330 329 331 - data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask); 330 + data = __page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, 331 + align_mask); 332 332 } else { 333 333 struct napi_alloc_cache *nc; 334 334 335 335 local_bh_disable(); 336 336 nc = this_cpu_ptr(&napi_alloc_cache); 337 - data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask); 337 + data = __page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, 338 + align_mask); 338 339 local_bh_enable(); 339 340 } 340 341 return data;