From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (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 012DC30D3F0 for ; Tue, 7 Jul 2026 19:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783452844; cv=none; b=mnV+9ttQjp7kciYdbPz6sgabV5/CyoyNfN3dO5aOOTjI3qAHdjNi56k+lhrt15BaOtQUPYYnSyrIn+7UlZgKRsSoRCRSHqj6F4tEjRQDgSUgS90XSvqXKwik7lHjb4dlfYiG4kPVFAtmHiQBzlY99I0/ScWjXPp6e3VnxN7XV0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783452844; c=relaxed/simple; bh=aGPA05pR6bom7fxGJwW4sEe/V2+wFYSV9C5ihMpqhBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uAiotmhs9t6yh4rGKz4AmNASofAUYWoUtqoSorf7lwqeVldw9FphYLjEQBGcFIC4YudedTeJSx11TyXu1kT3s20BipJHcwi7HFmZqyZHC9N/ZywMYEItElQC/86XF/KlwzX3awzmEiwnW8AvLzhsjReBAWEM8vYE6SdpNRjze6w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JDDvOPFb; arc=none smtp.client-ip=209.85.160.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JDDvOPFb" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-448df16ab34so1740919fac.1 for ; Tue, 07 Jul 2026 12:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783452842; x=1784057642; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yV5ncxbkCYl4acpcVXgqqMbkDn7uQGkSDLvd/JcyFLc=; b=JDDvOPFbBBWp32nLsYdwPZEQJM3dbi0X3/nmbI9h+o7OvK68CAW9K+K2/NZcv1u3X/ gH9+TS84FVv1IWp4NMzIAWPTLIgWGs1a0MyPqQGCV4ZMYu8FKqfKD7broDofcHazX61+ sAMPMlmstahnR7Eye+Zfo5QCWMXNl96hrpVfwpRLFD7qpuMqSeWDLI6uL7q54Df2CYw9 U6zqH7+TecimMwKPU1gaz6KODwU+fvjEsvYSquxOdw+A2L/64UYgB9RmUOjkGHJ2n5MV 8X9XpSEsfUT5trQpQoBJAC2/10Bh2NtugCr3nFN45gxt1L3iUEkzsk9K0TZt9TgCMEoi bPfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783452842; x=1784057642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yV5ncxbkCYl4acpcVXgqqMbkDn7uQGkSDLvd/JcyFLc=; b=DHBtkE6TEQE4jqbxrIXOr7BIjZMMt1l2FxC3FIEpxeu3OzcnF26wBBW1dfCPzAzxaV ULwoYN7E8PbGrbvWcMLA605Y+7k4AojX8BbldCvBfXzet4CzDAAxNUdiY5Iq7sFKU7Qn ZlFX9+JK/jp03XwLDAbMvaXTnWoqEG+SfaMUYKbHaoKwRD1qTl/MQks427mO+mI99rft fMyP/MDvqnZWM0TyPEV2mzSM96NL9/H+xhwpw/fcn406o4kraNDQWcWMJ7lrm4KqEAfl VUi/Gc8b9FSLOxzgZkKuwJ2zfm2D7ugnhUR4wyn4LFlOdLonyzLFVojWYNMznVxQRTHi eiLQ== X-Forwarded-Encrypted: i=1; AFNElJ+Z+VxI+D3/8cXKIMrZjCR5gQz+VXAEJPxnygelu1fkIRMF/G6HBISZ5bovFsu+bTd0vcxn042eYXeGFP4=@vger.kernel.org X-Gm-Message-State: AOJu0YxFqtJIkHTbX6g/i+4dezgoclFzDqCOeC5LD0uFJ3wbSgA8ttV8 k49OOBqcMXfOsJ1K1cdPzKQkxveb3n6BEqdFoae1242mpRMfnWFtm/O7 X-Gm-Gg: AfdE7ckkDlaAa2ppRbSlmiE3PGFWRmmop0QWu8DK37fuJ5LtLx2rKXezPH79+triBGD 46Be1SvF7YDyeBKPFk1JppwBXmqgEmSnPqNADfeor5+uczoACRK8+fepd08kvY2+3UhL1S1RdWT dvPft4Xh/2Y4RzvFuohUefHbInd11mhetYyph04YO1jc+n3AWXH1uPNLp6yT5jtXW03jw1C3/A7 cZT8XuUvkagGeRhEEroW1/8DMcjYeQFridAVFeqSS/hdCFnQiFfutWGxLSVjxAnXMM3Q03ZFKGq lMVdPhKp9p0SplSsVzTIW/wXqF8LoC2FSpvELd+zNi0KoKK6Sncfh6d36KwSwc1wzCwse+Gfbqy KOPicPm8wVLNFn6J9+1Uj2jdCO5pLvFnM++rOX1IJIh6kx2Lf/6nkhEZ4UIalQQ3I4avR4jnrqs VSCGo5dtLmcaUlBS6P9nSBmn5xopMoW2n/6qFmbB2zzGH01KA+EOFICg== X-Received: by 2002:a05:6808:2205:b0:497:e0bc:afe2 with SMTP id 5614622812f47-49fdba4150amr4147933b6e.4.1783452840534; Tue, 07 Jul 2026 12:34:00 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:49::]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4a1adca6bedsm181768b6e.8.2026.07.07.12.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 12:34:00 -0700 (PDT) From: Joshua Hahn To: Charles Haithcock Cc: muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org, david@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, arozansk@redhat.com Subject: Re: [PATCH 1/2] mm/hugetlb: Prefer mempolicy nodes for calcuating surplus hugepage reservation Date: Tue, 7 Jul 2026 12:33:57 -0700 Message-ID: <20260707193358.3434034-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260707182900.483757-2-chaithco@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, 7 Jul 2026 12:28:55 -0600 Charles Haithcock wrote: > Currently, reserving surplus hugetlb pages in a mempolicy still use > global counters for calculating how many hugetlb pages to reserve. > Modify this to consider the nodes in the mempolicy first but fall back > to all possible nodes. Hi Charles, thank you for the patch, this looks good to me! Personally I like the description of the commit in the cover letter because it provides a bit more context. Do other reviewers have thoughts on this? In any case, the code LGTM : -) Reviewed-by: Joshua Hahn BTW this is a little strange but Sashiko seems to have failed to apply this patch [1] which is strange because when applying on the exact same commit db6ed2a3d3106 "mm/swap, PM: hibernate: atomically replace hibernation pin" as Sashiko tried, it worked & compiled for me with no errors at all... [1] https://sashiko.dev/#/patchset/20260707182900.483757-1-chaithco%40redhat.com Sashiko's error log: Trying baseline: mm/mm-new (db6ed2a3d31068ca5577466591b2521dee0508ca) Patch 41962/2 (ID: 108031) failed to apply. Application failed. > Suggested-by: Joshua Hahn > Signed-off-by: Charles Haithcock > --- > > - v1: Modified `needed` calculation to use `allowed_mems_nr(h)` in order > to consider free hugetlb pages in our mempolicy. > - v2: Folded in Joshua Hahn's recommendation [1] to further modify > `needed` calculation to take the max of either the available hugetlb > pages in the mempolicy or the globally available hugetlb pages. Allows > allocations to prioritize nodes in the mempolicy but can still fall > back to offnode allocations. Also added selftests to check only for > the edgecase which caused this to initially be reported and sanity > checks. > - v3: Split the change and tests into separate patches and clean up code > to better align with kernel style guidelines. Likewise, fold in Usama > Arif's correction [2]. > > [1] https://lore.kernel.org/all/20260602152022.2673803-1-joshua.hahnjy@gmail.com/ > [2] https://lore.kernel.org/linux-mm/20260624144600.8159-1-usama.arif@linux.dev/ > > mm/hugetlb.c | 42 ++++++++++++++++++++++-------------------- > 1 file changed, 22 insertions(+), 20 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index f24bf49be0..f5e678e997 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2255,6 +2255,23 @@ static nodemask_t *policy_mbind_nodemask(gfp_t gfp) > return NULL; > } > > +static unsigned int allowed_mems_nr(struct hstate *h) > +{ > + int node; > + unsigned int nr = 0; > + nodemask_t *mbind_nodemask; > + unsigned int *array = h->free_huge_pages_node; > + gfp_t gfp_mask = htlb_alloc_mask(h); > + > + mbind_nodemask = policy_mbind_nodemask(gfp_mask); > + for_each_node_mask(node, cpuset_current_mems_allowed) { > + if (!mbind_nodemask || node_isset(node, *mbind_nodemask)) > + nr += array[node]; > + } > + > + return nr; > +} > + > /* > * Increase the hugetlb pool such that it can accommodate a reservation > * of size 'delta'. > @@ -2277,7 +2294,8 @@ static int gather_surplus_pages(struct hstate *h, long delta) > alloc_nodemask = cpuset_current_mems_allowed; > > lockdep_assert_held(&hugetlb_lock); > - needed = (h->resv_huge_pages + delta) - h->free_huge_pages; > + needed = max_t(long, (delta - allowed_mems_nr(h)), > + ((h->resv_huge_pages + delta) - h->free_huge_pages)); > if (needed <= 0) { > h->resv_huge_pages += delta; > return 0; > @@ -2311,8 +2329,9 @@ static int gather_surplus_pages(struct hstate *h, long delta) > * because either resv_huge_pages or free_huge_pages may have changed. > */ > spin_lock_irq(&hugetlb_lock); > - needed = (h->resv_huge_pages + delta) - > - (h->free_huge_pages + allocated); > + needed = max_t(long, ((delta - allowed_mems_nr(h)) - allocated), > + ((h->resv_huge_pages + delta) - > + (h->free_huge_pages + allocated))); > if (needed > 0) { > if (alloc_ok) > goto retry; > @@ -4513,23 +4532,6 @@ static int __init hugepage_alloc_threads_setup(char *s) > } > __setup("hugepage_alloc_threads=", hugepage_alloc_threads_setup); > > -static unsigned int allowed_mems_nr(struct hstate *h) > -{ > - int node; > - unsigned int nr = 0; > - nodemask_t *mbind_nodemask; > - unsigned int *array = h->free_huge_pages_node; > - gfp_t gfp_mask = htlb_alloc_mask(h); > - > - mbind_nodemask = policy_mbind_nodemask(gfp_mask); > - for_each_node_mask(node, cpuset_current_mems_allowed) { > - if (!mbind_nodemask || node_isset(node, *mbind_nodemask)) > - nr += array[node]; > - } > - > - return nr; > -} > - > void hugetlb_report_meminfo(struct seq_file *m) > { > struct hstate *h; > -- > 2.55.0