From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54109267B07 for ; Mon, 3 Aug 2026 14:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785768958; cv=none; b=MXdXPGPomBDbt4a9m5r7uWY0R6j3drgsj8E9IejcGXwYylOu30RaNOZPtjPkY2QfFbcWXemWrK91Tbnd+Z4lBgAGxeCid9LMAZ/JW10go6K1+iBi3b73LB2Zd+NUV/y8a4K1ir0ShPrykKoJD/RwZzaG1G9pfepxKVxvJA5+2J0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785768958; c=relaxed/simple; bh=Q/6K8yCeTd7oZM+hKi6x/9pftLmuOocXEhipPjytWTQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PC1dA5wPrMPZKPjrgUhUVRDdsJ2g/OtHEhRpHHr1u1e0cAHRLsx2xbMxCgwyLEzT2iaZIZdBlDWorsiDoLJIU/aQCPrurl/s6UqBuEIXC4h4DIw4Xv4fAJKDbkrxdCFykvg+RflzL6yj2vppaIJPmVvAtfW9xRMXzgbOJ8walso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=KDrd6JWA; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="KDrd6JWA" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-5276d598b96so16369041cf.3 for ; Mon, 03 Aug 2026 07:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1785768955; x=1786373755; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=peHvlhUw1Yu7SWf3hmHIsOYjE7R2xNdQVjGGTstXJYw=; b=KDrd6JWAPI5rjCrormGKj08L7guJbtTmTSFRg2M4Ya96COe8LaLiQCKHxwtFbmDYB1 EColPKU0EGNSwLXvEBUnjAOz6P7/dkaA4pm2Q7YjbjN0eiU7Z0V5a4A2zj4J0MMbrNZB 7/Lf1HU6vFbbh++phIqhpEANw6wW+t8uAeAQwSJsB3MVoyaM63S8WpBnszzUgyVTdNNS SBsWEIAzjZAkH78JvE0OTyQh78N1Rx1crdGntbysWorS4TXGPnHU6i5qnkr2we71cyH6 hCipybi4AFlPu/d426+k12dzwOf6f9Ily6Y3BXn0J5ZZofbMuH1dp7scNYaKtHdrlQMm VmAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785768955; x=1786373755; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=peHvlhUw1Yu7SWf3hmHIsOYjE7R2xNdQVjGGTstXJYw=; b=HFy1nmXrZbDxllF9TWjuFvaz70An258ELeQqWxNZYsqXBegrlomnEJbzegDJGfg5CP jTFiaeEFsBHFUvlVYhkGhxIFumL7jufJCqz9r56bExXflg3QrDnKvcskpzmIwxDOTOWJ KBQqN0qFEZTtIjRX9mZHMFE9DIKuENA4qSIaPEm5W8rZs1TnnC/vooMH2Qcx3wpFf0xz Ky5wSaXPcK5ilRCykquWniKGBf4NMbkBb/xWM/fMvun4DcVE0NYtet9MF63s9K2cTpjK ahYvp3CYmk/KShHyOs5H3q/6bBnRHSKckBtDYfkqTabvdilUbM/Sc8yx61sHjbBmRH5g MxiQ== X-Forwarded-Encrypted: i=1; AHgh+RqO1yBMqurjZnuxHypwt8zecq0XUtV+OogFfWmrBvK1aszHMB1QmWYGmFd0AsimVV9/eM/qtmXq2hAxE1s=@vger.kernel.org X-Gm-Message-State: AOJu0YzH6K/mmG8H6MUnrBccEjTgiryhoA5FwcJNmn39szKMs5rDgatT RcDk2kU0G/g8h9CN0hUdhb6vGbCmTP/Bv5X2fcnyYMY4+unSq9ij13EdrELtOQNypCo= X-Gm-Gg: AR+sD10K9y+TKT+wW8tos5c27NWofr9x4XNzGpg3yuYZf1QjXO1XRVwfKePl6IN6aUq NmJrPmGdrvZV6yzEc3mT6YU2qCCjUWdyd3hoDBNfw0g05H166wYEOWaPKTNX2nmw7sDSXFDcG5w vpWiEAQyhndnPSxS6chb/LQA5x1Q5p3p2V904O61MaBLBnPXRK8KNr2NlbYGioSYun+SYV0SPTu /+3fs+Az2OA8GDLq6WL93IvJI1x5eRAsYuMvgwfA7TKTnUOSIE5+r9Bq5dMy4xiLqO5IcuWzeqY nhp/lKOe1zkFjtxvxEjiaTEpMo3aKEhfUUC50H0uo28X91lRJyMNq5iGD2mBfsIpdimlzFyhnOq W93repc+K1dbpyBdVEacfQROT463FFhEfNDufKJbx9Eu95EN5yPpHtiyUkT8kIJhzFGywe9LU4e 2L6myVon+vXsWTFPJQc59xeEtuQ82CB/rWrdqeEtYKI7ErLOm/cLnZjqTYfPM0FGVvVdgzgbn5t TqspLaxvRzXVJ8qFG2WhmEiqXQH7kbqoqn17PylzBz0 X-Received: by 2002:a05:620a:4e83:b0:916:14f5:8866 with SMTP id af79cd13be357-934a07a61d1mr1708987985a.16.1785768955096; Mon, 03 Aug 2026 07:55:55 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9349c206b00sm683232185a.46.2026.08.03.07.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 07:55:54 -0700 (PDT) Date: Mon, 3 Aug 2026 10:55:52 -0400 From: Gregory Price To: Ackerley Tng Cc: Alistair Popple , Andrew Morton , Byungchul Park , David Hildenbrand , Joshua Hahn , Matthew Brost , Muchun Song , Oscar Salvador , Rakie Kim , Ying Huang , Zi Yan , erdemaktas@google.com, fvdl@google.com, jiaqiyan@google.com, jthoughton@google.com, mhocko@kernel.org, michael.roth@amd.com, pasha.tatashin@soleen.com, pbonzini@redhat.com, peterx@redhat.com, pratyush@kernel.org, rick.p.edgecombe@intel.com, rientjes@google.com, roman.gushchin@linux.dev, seanjc@google.com, shakeel.butt@linux.dev, shivankg@amd.com, vannapurve@google.com, yan.y.zhao@intel.com, Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v5 2/3] mm: hugetlb: Move mpol interpretation out of alloc_buddy_hugetlb_folio_with_mpol() Message-ID: References: <20260803-hugetlb-mpol-interpretation-v5-0-af2b7089f8a9@google.com> <20260803-hugetlb-mpol-interpretation-v5-2-af2b7089f8a9@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260803-hugetlb-mpol-interpretation-v5-2-af2b7089f8a9@google.com> On Mon, Aug 03, 2026 at 06:37:59AM -0700, Ackerley Tng wrote: > Move memory policy interpretation out of > alloc_buddy_hugetlb_folio_with_mpol() and into alloc_hugetlb_folio() to > separate reading and interpretation of memory policy from actual > allocation. > > This will later allow memory policy to be interpreted outside of the > process of allocating a hugetlb folio entirely. This opens doors for other > callers of the HugeTLB folio allocation function, such as guest_memfd, > where memory may not always be mapped and hence may not have an associated > vma. > > Introduce struct mempolicy_interpreted to hold all the components of an > interpreted memory policy. > > Rename alloc_buddy_hugetlb_folio_with_mpol() to alloc_buddy_hugetlb_folio() > since the function no longer interprets memory policy. > > No functional change intended. > > Reviewed-by: James Houghton > Acked-by: Oscar Salvador > Signed-off-by: Ackerley Tng > --- > include/uapi/linux/mempolicy.h | 2 +- > mm/hugetlb.c | 54 ++++++++++++++++++++++++++++-------------- > 2 files changed, 37 insertions(+), 19 deletions(-) > > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1317,6 +1317,12 @@ static unsigned long available_huge_pages(struct hstate *h) > return h->free_huge_pages - h->resv_huge_pages; > } > > +struct mempolicy_interpreted { > + int nid; > + nodemask_t *nodemask; ^^ const please (mempolicy owns it, it should never change) > + enum mempolicy_mode mode; > +}; > + Is this intended to be an ephemeral struct that will eventually be removed? Because it feels like mempolicy.c should just be handling this directly instead of needing this cached structure. > static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, > struct vm_area_struct *vma, > unsigned long address) > @@ -2138,32 +2144,28 @@ static struct folio *alloc_migrate_hugetlb_folio(struct hstate *h, gfp_t gfp_mas > return folio; > } > ... snip ... > @@ -2926,8 +2928,24 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > folio = dequeue_hugetlb_folio_vma(h, vma, addr); > > if (!folio) { > + struct mempolicy_interpreted mpoli; > + struct mempolicy *mpol; > + nodemask_t *nodemask; > + int nid; > + > spin_unlock_irq(&hugetlb_lock); > - folio = alloc_buddy_hugetlb_folio_with_mpol(h, vma, addr); > + nid = huge_node(vma, addr, gfp, &mpol, &nodemask); > + mpoli = (struct mempolicy_interpreted){ > + .nid = nid, > +#ifdef CONFIG_NUMA > + .mode = mpol ? mpol->mode : MPOL_DEFAULT, > +#else > + .mode = MPOL_DEFAULT, > +#endif This is not great, and tells me this interaction should probably be sunk into mempolicy instead of pulling ifdef/else into hugetlb. > + .nodemask = nodemask, > + }; > + folio = alloc_buddy_hugetlb_folio(h, gfp, &mpoli); > + mpol_cond_put(mpol); > if (!folio) > goto out_uncharge_cgroup; > spin_lock_irq(&hugetlb_lock);