From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6159143DA28 for ; Tue, 7 Jul 2026 18:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783448957; cv=none; b=VdvZsg/9zmDOBlGAAtkST1E8H7d5Yy8PzEW9Lb7iwVN0DdPPZuKVwZX13pSO+vI/IKwd8p1Z/J6k5cRa0dhh8mDdblrVaTR/zRou28dtMsJPbHjsu8Enhez2zkuMny0Cls2kEh/siYNvxtm5KcPAxcgeVrLkEbXRjo40xKHsmEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783448957; c=relaxed/simple; bh=irN9YWxXUSSsXZPLSzDjiTii3pfODdHonWjGvFP/dYI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FQdzKJJ9EYBy4hbipQMMyqkthUK/jz1UoeNMbpisMLVxMNiz7HrmTG6QpoeF3kmy28gFcgopwdOgtwuilNEscGx2ppxDFzIzKi/UXUKpyNw5nFJOcmyaXxngWGobtxVtXest4KcHO65TLnh5p1X4x/YAduywoRovtODT/mDOWfQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c0X67km9; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hpo4xL9y; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c0X67km9"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hpo4xL9y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783448955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=JQByjrZEnlfvBUgq55yU0uevWZpdlhSt/rPl0iueosA=; b=c0X67km9acV+tejp9wqr1tKLqMw38uELSCb4my+h7HpA8e8OC9lgi0CZztkRgGCGPeJRtr Hk16B2zqzAd0zUZUvxXLR/lIXLoPYSoxIkMMubcQztOFn/wDo+gqVi1eM10MW70/BG5+ty NV9uKlaes9gEtQ9YwDqOyk/ByL8rP+A= Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-aCc26NdSMymUoEQg57SQXA-1; Tue, 07 Jul 2026 14:29:13 -0400 X-MC-Unique: aCc26NdSMymUoEQg57SQXA-1 X-Mimecast-MFC-AGG-ID: aCc26NdSMymUoEQg57SQXA_1783448953 Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-44a06794b48so2706393fac.0 for ; Tue, 07 Jul 2026 11:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1783448953; x=1784053753; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JQByjrZEnlfvBUgq55yU0uevWZpdlhSt/rPl0iueosA=; b=Hpo4xL9yIWbq9/jOYMmKvrPmG/Kj3BRx++ikzMw6Y9NNUNU866SCkMWLzN2R9UQdRD Ilz92kaEJrD8ahP92x7sg9j5cN22bfUYOQnQEyH31pBz28vkMiKr/qAOsU+wj45M1dfK 3+Qo+XdIAX0UM+l5wOr/BLYK3ok2rA6pV8WNUYUS+BpjhCcoNYEaKrStj/yo81V48ATD 6rFRLhBVL1ADKyvae+9koWoN6+2xNM5FxTfPl0wpDbTNftmBUj4OnYgMrxZSdJocoY3a ojERg/wwcLOKndHfGrndWjjCi93BnaFHPKmI9nhwpaFQxW0QjPfEWEtZz3Rdpjb3nAYU mUoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783448953; x=1784053753; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JQByjrZEnlfvBUgq55yU0uevWZpdlhSt/rPl0iueosA=; b=R2SQmtQXxvneVVECW/I9HaaNlWVSzlgmV2c/pDXAMNxWnP36PEcgNhhKf+lqmxG2+D fzPSJxswvYI6lkYEyNRkxdSDC+wFJkvozN50+b9z5E0ghhr4s/lguYUlviHahP39p5Yr Rsdf4slD28KnBKvOZBNA0Wq2OJdMu4ecc6sG0Ca4ArxzDy93MgogrGvRzlehMKOnoA5x jSnShp98wsLyGZLCE4X4xrCLceWSG6RipLMdosMeHTwFi+C1ncRVd0rEPOvZ9FM3VcIq 2HNCqvrLV+y5cMTMcjSxR+G4289E3EduwLTEwTUxRwibddpM2eLZU12WL1ZPf9N/74qH p9pg== X-Forwarded-Encrypted: i=1; AHgh+RqTemIbdkYdcgiZonPClkKBBJVCFPeKkwqyi2ooZkg0gZZmJ++LFBw0GuiMoRIhiEfQTHnprcsRJuVtEzs=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/CmawDyQWbIBcW17E1JebazqbfPo+wO0BYIjjijD2XhIA465A icIBgfNAfB+YQs76f+0Xy5opX+2OCbTRIYDeyjjsSESlLo8gMEpqIArzCNY94EiKcW0oGLzrnfF Ad9tzsYbOQiioW2vco49Alo8VlmhmVYcb+8jj9RVQYbr+5XjAEYU6xgxuzPjDyQtuLg== X-Gm-Gg: AfdE7ckrsJMcgdIwBX5Lga++wp3p+N12cjyH2dh+0TYX0iosQwy5paRI8vManFqyMnH X6lP5DkCCShEhHntIsaHd8Ld+t4NbrJ2co5TjZR39x9RCPoVhFLn1ssDXpdSi8j/UGXeFuJwnk7 EJmkIgy6qwDEVY3oLdpESGDw8YlQg2ClfKkO2k5l4N+FlbZxXaPsK4liFZOfPQG93NQ426CnfVt f6YW59T0VtwaLmNs4Av3RdCGR7Wkw7X1tgHsEN7vsbwG9KQzCvQiyxqVyX8mujHyPXATojOR32B cFbiLH+pvg/9dbvnUpTTHWW4k/U3taPEo1u54j8R97M0nPiBg3vk6kPIHHsjLosXSJXqMqBRjee 41KO58/4IZhHKuEm5RGhsHwvWTz3oAoQUgO+Lo/3bx1Cm2BeIWZ+vsKqCfmF1+1q3r4/zVemBIV azYhEcgQ== X-Received: by 2002:a05:6870:9d1a:b0:43c:2d3f:95f8 with SMTP id 586e51a60fabf-451059528d0mr3915355fac.0.1783448952952; Tue, 07 Jul 2026 11:29:12 -0700 (PDT) X-Received: by 2002:a05:6870:9d1a:b0:43c:2d3f:95f8 with SMTP id 586e51a60fabf-451059528d0mr3915329fac.0.1783448952487; Tue, 07 Jul 2026 11:29:12 -0700 (PDT) Received: from chaithco-thinkpadp16vgen1.rmtusco.csb.cloud (184-96-191-56.hlrn.qwest.net. [184.96.191.56]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-44cfb55907dsm13550509fac.11.2026.07.07.11.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 11:29:11 -0700 (PDT) From: Charles Haithcock To: muchun.song@linux.dev, osalvador@suse.de, akpm@linux-foundation.org Cc: Charles Haithcock , david@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, arozansk@redhat.com Subject: [PATCH 0/2] mm/hugetlb Try to respect mempolicy when calculating surplus huge pages Date: Tue, 7 Jul 2026 12:28:54 -0600 Message-ID: <20260707182900.483757-1-chaithco@redhat.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Presently, when calculating how many huge pages are needed when reserving surplus huge pages, the global count of free huge pages is used. When reserving with a mempolicy, the global count of free huge pages is used even if some/all of those free huge pages are on numa nodes outside of the mempolicy. Reserving surplus huge pages is ultimately best effort even without a mempolicy. Restrictions from cpusets and mempolicies further complicate calculating correct numbers of surplus huge pages to reserve and maintaining which nodes those reservations belong to (see the comment in `hugetlb_acct_memory`). However, we can do a little better when reserving surplus huge pages with a mempolicy. This patch changes how to calculate the necessary amount of surplus huge pages to reserve by considering the max of either the amount of free huge pages on nodes in the mempolicy or the global amount of free huge pages. We may still attempt to reserve huge pages outside the mempolicy, however, we end up being more likely to reserve from nodes in the mempolicy. - 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/ Charles Haithcock (2): mm/hugetlb: Prefer mempolicy nodes for calcuating surplus hugepage reservation selftests/mm: add surplus hugetlb mempolicy reservation tests mm/hugetlb.c | 42 +- tools/testing/selftests/mm/Makefile | 3 + .../selftests/mm/hugetlb_surplus_mempolicy.c | 491 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 1 + 4 files changed, 517 insertions(+), 20 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb_surplus_mempolicy.c -- 2.55.0