Re: [PATCH v2 2/4] mm: replace exec_folio_order() with generic preferred_exec_order()

Kiryl Shutsemau
2026-03-20T14:41:43Z

On Fri, Mar 20, 2026 at 06:58:52AM -0700, Usama Arif wrote:
> + * allocations when memory is tight.
> + */
> +static unsigned int preferred_exec_order(struct vm_area_struct *vma)
> +{
> + int order;
> + unsigned long vma_len = vma_pages(vma);
> + struct zone *zone;
> + gfp_t gfp;
> +
> + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
> + return 0;
> +
> + /* Cap at min(PMD_ORDER, 2M) */
> + order = min(HPAGE_PMD_ORDER, ilog2(SZ_2M >> PAGE_SHIFT));
> +
> + /* Don't request folios larger than the VMA */
> + order = min(order, ilog2(vma_len));
> +
> + /* Step down under memory pressure */
> + gfp = mapping_gfp_mask(vma->vm_file->f_mapping);
> + zone = first_zones_zonelist(node_zonelist(numa_node_id(), gfp),
> + gfp_zone(gfp), NULL)->zone;
> + if (zone) {
> + while (order > 0 &&
> + !zone_watermark_ok(zone, order,
> + high_wmark_pages(zone), 0, 0))
> + order--;
> + }

Eww. That's overkill and layering violation.

If we need something like this, it has to be do within page allocator:
an allocation interface that takes a range (or mask) of acceptable
order.

--
Kiryl Shutsemau / Kirill A. Shutemov