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

mm/vmalloc: add a helper to optimize vmalloc allocation gfps

vm_area_alloc_pages() attempts to use different gfp flags as a way to
optimize allocations. This has been done inline which makes things harder
to read.

Add a helper function to make the code more readable.

Link: https://lkml.kernel.org/r/20251121094405.40628-3-vishal.moola@gmail.com
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Acked-by: SeongJae Park <sj@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Vishal Moola (Oracle) and committed by
Andrew Morton
bb4d3c76 07003531

+14 -3
+14 -3
mm/vmalloc.c
··· 3614 3614 EXPORT_SYMBOL_GPL(vmap_pfn); 3615 3615 #endif /* CONFIG_VMAP_PFN */ 3616 3616 3617 + /* 3618 + * Helper for vmalloc to adjust the gfp flags for certain allocations. 3619 + */ 3620 + static inline gfp_t vmalloc_gfp_adjust(gfp_t flags, const bool large) 3621 + { 3622 + flags |= __GFP_NOWARN; 3623 + if (large) 3624 + flags &= ~__GFP_NOFAIL; 3625 + return flags; 3626 + } 3627 + 3617 3628 static inline unsigned int 3618 3629 vm_area_alloc_pages(gfp_t gfp, int nid, 3619 3630 unsigned int order, unsigned int nr_pages, struct page **pages) ··· 3863 3852 * Please note, the __vmalloc_node_range_noprof() falls-back 3864 3853 * to order-0 pages if high-order attempt is unsuccessful. 3865 3854 */ 3866 - area->nr_pages = vm_area_alloc_pages((page_order ? 3867 - gfp_mask & ~__GFP_NOFAIL : gfp_mask) | __GFP_NOWARN, 3868 - node, page_order, nr_small_pages, area->pages); 3855 + area->nr_pages = vm_area_alloc_pages( 3856 + vmalloc_gfp_adjust(gfp_mask, page_order), node, 3857 + page_order, nr_small_pages, area->pages); 3869 3858 3870 3859 atomic_long_add(area->nr_pages, &nr_vmalloc_pages); 3871 3860 /* All pages of vm should be charged to same memcg, so use first one. */