From nobody Tue Feb 10 00:22:27 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 B74A91F63F9 for ; Mon, 27 Jan 2025 23:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738020188; cv=none; b=VG0umLlBA2Qz1X8qduyNbgOGq4BeE7J1tx4B/tUQ2WTrIabUjNG5SnQHRK+fbflZ8x2XKqmuD9Q+8LiWvlzTHjqggBrzUExxV/uk4I+zQhHb4whN3nvIBu/i4RGufNixMP8BBiP8S3jDNLjiLEFVaYiM25yQvdA9zelA9eX6G0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738020188; c=relaxed/simple; bh=b8PC/zOeEnrwcsPy2mCUwc4hMFA8w9oISmzSYUjxhUc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Nl1uWqfbVErhjE9Mjo9x79bMYxoQ+zMcmJ3O9fC3RJX7bIXBJ8CZphNJRQvHKErQ3WO7CmjVWvkE/+KkgEnbOQsQef+h3+JrKP1Xh82YERfI7NGNxe+LCN/+NjtSUaAIwyZHCj0M2PYzeFzD9S8ck3L8Pdh79OL2U84QpLrgXhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--fvdl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sMrUZOca; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--fvdl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sMrUZOca" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef9864e006so14698992a91.2 for ; Mon, 27 Jan 2025 15:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738020185; x=1738624985; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EKeeHmURdM6aNKIslC9cbG8uxcWG/M1qKwEQEge7FZ4=; b=sMrUZOcaGTvcztZEmVJFP+cCU1SRgs3QHGFW+k1YQH0a5XW9nyrcwYoKIB5oW5SOGM CJ1U6pMlNc3chrMFjd6skGK3uA2BM6ixZXByut8AQpOjNa45NDVwOPsjE4Y0bUGvQ79y Leo448hzktef0eXEsAwcPx8lRNrDzQwu3oIQFQJHFxJcJNLY0hNhojlEczH3LShhZKHs JRpOH097o7V2Ht3uDZTznA1NtusHQ3sNVDry8HlfTEv2Kt3TZs/btWEZhXHESu8jQIkA 4WzgeGvm0S1ilPYfceF8V91uVJ7lUfsHvob/yU3o+8UuVf15WTRLMTqJnyyHBwYepr46 NzLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738020185; x=1738624985; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EKeeHmURdM6aNKIslC9cbG8uxcWG/M1qKwEQEge7FZ4=; b=SEbXbOhWajFVh/ZS1H/UuE/gHMPjuw/5t/HoS7kuNYk9TAmjsClp1D2b4+j/z9FJ5q 6/RFAV0RixDU2i/bVLBfFdgCqPPmW8MRf5urUqTbJwOc0hl2yLwYlFWPuF4/rOeowpK7 AriZU1GUELdu2Oc38IRB1rgjqcck0Uk6ABZKAWc8J+RVwWma5dHFhEQmGkVAfCUy8wis C/aCzPkmG+RYJUw4gLGhgqgZ6D7Id/KCRrrsU26xd722/EzKRVz5qWFE0KvMvDR/b2en T1tOfK6C6RKTX8inmSIpicqPOvVf3DB6Viqz7wgrlc0O+Xunnk4cQ8HJpTohgqLmEdAe bLAw== X-Forwarded-Encrypted: i=1; AJvYcCVncRIfo3TArqAGagjJ4Z+hp7rVHzUn5Q19SAs+uKx9dRmgSQz3jrf/q5kF2ejDDI90Y6p0RhYpvH9mows=@vger.kernel.org X-Gm-Message-State: AOJu0YwiTEFPCEWcAldK+xHmmxT7ihiFeVGug57rGtE2bCk9SwSKjWOw LAxAm7LE4iwmOl0KaXzebwHZPJv6TdEq2uahqJMKjpvHd6z0Pod15O53hZdeUVJXhZXq2Q== X-Google-Smtp-Source: AGHT+IHgFhdTPrw6WGsfRcFM8FTm7PmxtxhzLyvV3ymhkxmbus+woNireOpmJQGtxSxQ613Ma5NUaJJJ X-Received: from pfbbd10.prod.google.com ([2002:a05:6a00:278a:b0:728:e945:d2c2]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d88:b0:1e1:aab8:386a with SMTP id adf61e73a8af0-1eb2148ebd2mr76997102637.18.1738020184991; Mon, 27 Jan 2025 15:23:04 -0800 (PST) Date: Mon, 27 Jan 2025 23:22:06 +0000 In-Reply-To: <20250127232207.3888640-1-fvdl@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250127232207.3888640-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127232207.3888640-27-fvdl@google.com> Subject: [PATCH 26/27] mm/hugetlb: add hugetlb_cma_only cmdline option From: Frank van der Linden To: akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: yuzhao@google.com, usama.arif@bytedance.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an option to force hugetlb gigantic pages to be allocated using CMA only (if hugetlb_cma is enabled). This avoids a fallback to allocation from the rest of system memory if the CMA allocation fails. This makes the size of hugetlb_cma a hard upper boundary for gigantic hugetlb page allocations. This is useful because, with a large CMA area, the kernel's unmovable allocations will have less room to work with and it is undesirable for new hugetlb gigantic page allocations to be done from that remaining area. It will eat in to the space available for unmovable allocations, leading to unwanted system behavior (OOMs because the kernel fails to do unmovable allocations). So, with this enabled, an administrator can force a hard upper bound for runtime gigantic page allocations, and have more predictable system behavior. Signed-off-by: Frank van der Linden --- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ mm/hugetlb.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index d0f6c055dfcc..6a164466ec33 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1892,6 +1892,13 @@ hugepages using the CMA allocator. If enabled, the boot-time allocation of gigantic hugepages is skipped. =20 + hugetlb_cma_only=3D + [HW,CMA,EARLY] When allocating new HugeTLB pages, only + try to allocate from the CMA areas. + + This option does nothing if hugetlb_cma=3D is not also + specified. + hugetlb_free_vmemmap=3D [KNL] Requires CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP enabled. diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 28653214f23d..32ebde9039e2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -60,6 +60,7 @@ struct hstate hstates[HUGE_MAX_HSTATE]; static struct cma *hugetlb_cma[MAX_NUMNODES]; static unsigned long hugetlb_cma_size_in_node[MAX_NUMNODES] __initdata; #endif +static bool hugetlb_cma_only; static unsigned long hugetlb_cma_size __initdata; =20 __initdata struct list_head huge_boot_pages[MAX_NUMNODES]; @@ -1511,6 +1512,9 @@ static struct folio *alloc_gigantic_folio(struct hsta= te *h, gfp_t gfp_mask, } #endif if (!folio) { + if (hugetlb_cma_size && hugetlb_cma_only) + return NULL; + folio =3D folio_alloc_gigantic(order, gfp_mask, nid, nodemask); if (!folio) return NULL; @@ -7844,6 +7848,13 @@ static int __init cmdline_parse_hugetlb_cma(char *p) =20 early_param("hugetlb_cma", cmdline_parse_hugetlb_cma); =20 +static int __init cmdline_parse_hugetlb_cma_only(char *p) +{ + return kstrtobool(p, &hugetlb_cma_only); +} + +early_param("hugetlb_cma_only", cmdline_parse_hugetlb_cma_only); + void __init hugetlb_cma_reserve(int order) { unsigned long size, reserved, per_node; --=20 2.48.1.262.g85cc9f2d1e-goog