From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 1FEA61A267 for ; Tue, 12 May 2026 12:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778590615; cv=none; b=R7L/HLzdPy2pBUFUaiFh4l/v2h8t71zAbS58pwPtulvqDO0QhACMsLjI+UOfu4123cvTMWgrVPqyvKe2jivd4glTAIianQe3EkMvPpag6Htvdc4JwwqXaBDEwAI5o3KvCBYWP0KLXqgg2vcxqBxaOtgPUDUzcmZyElTT+mWOXAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778590615; c=relaxed/simple; bh=RUONYCAdsNXeLhqmZsMzBif/xqgcg35B3nXuoM1rWp4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bmRhXcrok24FWgp3ZNQIt04s6tatpXKt/o6pW1rLzW4IfHOibCojpV9W87WljW5wEs7fUf4ZYQq3c49vdnazjUT6oc2WcerXEGCjEAY1B143kkxtuYl0ynIhBq4tCvt5uw0uFO+I/z6qV0PCckU933k8Ttu/B7Fn08Fh5PfGz24= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ejVJkCEe; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=p3uD812k; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=ejVJkCEe; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=p3uD812k; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ejVJkCEe"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="p3uD812k"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ejVJkCEe"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="p3uD812k" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6FC236C21F; Tue, 12 May 2026 12:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1778590612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f6CUZWjX8Zu6dMxEEaiGDxiAJZZDLVMaxZk+TLPcyno=; b=ejVJkCEeU3IaWbLmz31hGsIMN1fSkj9qqRXQAYJf39chia9i8KmJTqbeGnI15K2lYyOCzs 7Av4ibeZi264HTwkpq+64/H+v8Wtt9UJGgJUbFY0Z/LsnbjTVO8f0CpaYNm2rUhsCOrICG z3WPhuWJWBRPIEMjDUIN6JZGZHKPHac= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1778590612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f6CUZWjX8Zu6dMxEEaiGDxiAJZZDLVMaxZk+TLPcyno=; b=p3uD812kXuYIxYxvw+BQJcHF1r5EU3vdegqaKdxy7uHfNRhDj4gg7TFuk5aorKQgSzwlnZ YneEZJlgJELMiDDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1778590612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f6CUZWjX8Zu6dMxEEaiGDxiAJZZDLVMaxZk+TLPcyno=; b=ejVJkCEeU3IaWbLmz31hGsIMN1fSkj9qqRXQAYJf39chia9i8KmJTqbeGnI15K2lYyOCzs 7Av4ibeZi264HTwkpq+64/H+v8Wtt9UJGgJUbFY0Z/LsnbjTVO8f0CpaYNm2rUhsCOrICG z3WPhuWJWBRPIEMjDUIN6JZGZHKPHac= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1778590612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f6CUZWjX8Zu6dMxEEaiGDxiAJZZDLVMaxZk+TLPcyno=; b=p3uD812kXuYIxYxvw+BQJcHF1r5EU3vdegqaKdxy7uHfNRhDj4gg7TFuk5aorKQgSzwlnZ YneEZJlgJELMiDDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 69EB9593A9; Tue, 12 May 2026 12:56:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id w2HJF5MjA2oSNQAAD6G6ig (envelope-from ); Tue, 12 May 2026 12:56:51 +0000 Date: Tue, 12 May 2026 14:56:45 +0200 From: Oscar Salvador To: ackerleytng@google.com Cc: Muchun Song , David Hildenbrand , Andrew Morton , fvdl@google.com, jiaqiyan@google.com, joshua.hahnjy@gmail.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, Dan Williams , Jason Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/6] mm: hugetlb: Move mpol interpretation out of dequeue_hugetlb_folio_vma() Message-ID: References: <20260506-hugetlb-open-up-v2-0-826a0c5f28fc@google.com> <20260506-hugetlb-open-up-v2-3-826a0c5f28fc@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: <20260506-hugetlb-open-up-v2-3-826a0c5f28fc@google.com> X-Spam-Flag: NO X-Spam-Score: -2.80 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_TWELVE(0.00)[26]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; MISSING_XM_UA(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; R_RATELIMIT(0.00)[to_ip_from(RLa1jia3o8a9x8abp87x6pc54n)]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[linux.dev,kernel.org,linux-foundation.org,google.com,gmail.com,amd.com,soleen.com,redhat.com,intel.com,ziepe.ca,kvack.org,vger.kernel.org]; RCVD_TLS_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; URIBL_BLOCKED(0.00)[imap1.dmz-prg2.suse.org:helo,localhost.localdomain:mid]; RCVD_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,localhost.localdomain:mid] X-Spam-Level: On Wed, May 06, 2026 at 08:54:39AM -0700, Ackerley Tng via B4 Relay wrote: > From: Ackerley Tng > > Move memory policy interpretation out of dequeue_hugetlb_folio_vma() and > into alloc_hugetlb_folio() to separate reading and interpretation of memory > policy from actual allocation. > > Also rename dequeue_hugetlb_folio_vma() to > dequeue_hugetlb_folio_with_mpol() to remove association with vma and to > align with alloc_buddy_hugetlb_folio_with_mpol(). > > 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. > > No functional change intended. > > Signed-off-by: Ackerley Tng > Reviewed-by: James Houghton > --- > mm/hugetlb.c | 34 +++++++++++++++------------------- > 1 file changed, 15 insertions(+), 19 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index ea3bc405b3162..3395de4d0999a 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1334,18 +1334,11 @@ static unsigned long available_huge_pages(struct hstate *h) > return h->free_huge_pages - h->resv_huge_pages; > } > > -static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, > - struct vm_area_struct *vma, > - unsigned long address) > +static struct folio *dequeue_hugetlb_folio_with_mpol(struct hstate *h, > + struct mempolicy *mpol, int nid, nodemask_t *nodemask) > { > struct folio *folio = NULL; > - struct mempolicy *mpol; > - gfp_t gfp_mask; > - nodemask_t *nodemask; > - int nid; > - > - gfp_mask = htlb_alloc_mask(h); > - nid = huge_node(vma, address, gfp_mask, &mpol, &nodemask); > + gfp_t gfp_mask = htlb_alloc_mask(h); Same thing here, you already have the mask from the caller. > @@ -2866,6 +2858,9 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > int ret, idx; > struct hugetlb_cgroup *h_cg = NULL; > gfp_t gfp = htlb_alloc_mask(h); > + struct mempolicy *mpol; > + nodemask_t *nodemask; > + int nid; > > idx = hstate_index(h); > > @@ -2926,6 +2921,9 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, > > spin_lock_irq(&hugetlb_lock); > > + /* Takes reference on mpol. */ > + nid = huge_node(vma, addr, gfp, &mpol, &nodemask); I know that before the refactoring we called huge_node() with the lock taken, but I think that was just because dequeue_hugetlb_folio_vma() needed that. Now, I think we can just have it out of the lock. Bottom line is we should really make crystal clear what needs to go with or without the lock, because we have some history in hugetlb land about know fully knowning what protects what and why. If you think we still need to call it under the lock, I would state why, but I do not think we do. -- Oscar Salvador SUSE Labs