From patchwork Wed Jan 29 22:41:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 13954223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EB06C02193 for ; Wed, 29 Jan 2025 22:43:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6ED7280272; Wed, 29 Jan 2025 17:43:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C1D0D28026C; Wed, 29 Jan 2025 17:43:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A977A280272; Wed, 29 Jan 2025 17:43:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8586928026C for ; Wed, 29 Jan 2025 17:43:00 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 419F2AED03 for ; Wed, 29 Jan 2025 22:43:00 +0000 (UTC) X-FDA: 83061966120.25.50C6FC5 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf03.hostedemail.com (Postfix) with ESMTP id 6DBBB20007 for ; Wed, 29 Jan 2025 22:42:58 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=P6Dwerhn; spf=pass (imf03.hostedemail.com: domain of 38a6aZwQKCPwjzhpksskpi.gsqpmry1-qqozego.svk@flex--fvdl.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=38a6aZwQKCPwjzhpksskpi.gsqpmry1-qqozego.svk@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738190578; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Nz/2tKPy0YCm5EodMQQ+b1Mhej+Q9ynW9kEvQcn7esU=; b=sLn1lTZN1ZnxO0Y0Q/nUfaO/Eq7TZvJ3PyOrEZRkAmMr0fafoT6zQBtiXiExyTogKwu3Sd o7SuAzZTxVO489F1a7+0r6oPwkWODKOIQVtyFra+xD0E9elEA7e1PyOQ7Kh0HeObRh6us+ plphyJi9j4tIO4FtHNIc5k4/I7o5AoU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738190578; a=rsa-sha256; cv=none; b=Wq3U7V6A/4OOIJmdon8siJIzFdF1JeKabp1UZVbzsq2EzV1SL0Zns/7Ml1Vr78eOvS2NM3 3v8boipP4u35uv4RPRxO4GrtmmSHjBUyMYJ1uuM6oukWNLOgOnpDLh2RNYRJqlglsaL9A0 eWRrM67zYfg2CwahCRQS7d3llVvdg1M= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=P6Dwerhn; spf=pass (imf03.hostedemail.com: domain of 38a6aZwQKCPwjzhpksskpi.gsqpmry1-qqozego.svk@flex--fvdl.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=38a6aZwQKCPwjzhpksskpi.gsqpmry1-qqozego.svk@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef9dbeb848so254410a91.0 for ; Wed, 29 Jan 2025 14:42:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738190577; x=1738795377; darn=kvack.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=Nz/2tKPy0YCm5EodMQQ+b1Mhej+Q9ynW9kEvQcn7esU=; b=P6Dwerhn/afJcl9b2Vx20npza70p2QOYkAuLTyhc6VqZz8++eOI0M1gecrBY73adPD 24jnViLyY02uRwysGOwMtRo55GEoqpPMDQMLtSYcm5gsIzlxdLRrhqpmhP7WZWjV1xl5 Eub6dPWZmoHtVFr/9VlcZc4db/AoGorhnolJ8V8pmP1OCHjmq+r1T40etGteBklrkcFy xD82Q6TZ2hnGOhAUKLAGkjyt8gKO6c1OcsV/PGtNyu8jli3xp6DGYKNjJkQWtCM/IQka 7ovvf37z8XLqvGVtKWBo9jnXJXsFPslbu/eUksV2VGqapEjOkhX+kiM8kjqOolmrcr8s /X0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738190577; x=1738795377; 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=Nz/2tKPy0YCm5EodMQQ+b1Mhej+Q9ynW9kEvQcn7esU=; b=fE+J+eSOFwaRTdCeXM5rlc74zsml9Gif3jU+dB5V7uIekTGiOADkMuy6mkYANtmJew wxpAcwlKqbKhKQQhbyZrkJeqqb3htjGmfnvPqRv4Cz3Ub1gAeeEzlDKLnsGdvgJ3WypQ nJz7//77JEnd/FZJEvhMxFg93WQhPcypRaY1vLTiSwn6WSxifrCrPjBYhLKLpAC+WBq/ onP0ANqPkpWGYnK9VC7HQLDze+HuDvg7F5Fr+U25esE0u/bjrQoY3bHD+T/PXljhru7+ khbKLa8GvDz0D+j/ObIcwThL0gtsWNe5BHl+M/iyYhaUFvnWrZpeuvVDKI/vfpnBzF5b v/pg== X-Forwarded-Encrypted: i=1; AJvYcCXs9+/f2/IVvM3tV8vmCKTLO3FtNiNwNn5iJMQ6poSPjHPaCl/99ZBfN9HofAOXPmSk60rYHVY4Gw==@kvack.org X-Gm-Message-State: AOJu0YxpAxgVtprT8fw0cI4zydfD7lCARufB4w3Rkre0WYg6adLIDF9J d21ttIn9/M08iU+DG8ELuyLkMxN5FZDew2rXWmxNQazBFd3ce8TDWSS4yDyEplLNnixYKg== X-Google-Smtp-Source: AGHT+IGXUZD7q/hJ2fVVwgnyF88t+mgr40dGpUsg8S5E9Rm1s3dTi62LjPOI+SAicO9GvtyTUPW1WmMG X-Received: from pfbcw17.prod.google.com ([2002:a05:6a00:4511:b0:725:cd3b:3256]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:b8b:b0:72d:35ed:214b with SMTP id d2e1a72fcca58-72fd0c8bfb4mr7028832b3a.24.1738190577253; Wed, 29 Jan 2025 14:42:57 -0800 (PST) Date: Wed, 29 Jan 2025 22:41:55 +0000 In-Reply-To: <20250129224157.2046079-1-fvdl@google.com> Mime-Version: 1.0 References: <20250129224157.2046079-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250129224157.2046079-27-fvdl@google.com> Subject: [PATCH v2 26/28] 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, usamaarif642@gmail.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden X-Rspamd-Queue-Id: 6DBBB20007 X-Stat-Signature: 4uu8okf3buez9utfde53a9pbf8urwhkg X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1738190578-980916 X-HE-Meta: U2FsdGVkX1/utEUg48STxb1W1Uvi9aK2hohnbMu0XCaJVv0V329PhWhL6LY1u1MFGOnKCNFthPa+0PsHlFMooPZ9lMlNtV3jG1BljDh7Hz63DPx46GL33lCIkssgZFFzP/g6nnR1uPke9bb4FFSlG0kRy89kserKIxArMTr+FMBHz6BGaslwujOy41BAo1++Qswvd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lYiZ+CGn/WrL8ovF9GPwKGjl8DcZOiLuBTOjwxqNghtYJWpMuyOtc+dmrdVb+GSRktCEMfbW93d+at0BHuuM8IesN92N7OkJRS9wY8HD9UrMCUVlpvGz6q93T3NiF8cORvsZBOpetxmRY4Kwu7qhmg+K+dPzHziNUpHhaZZf+5PQ3PlJycOM3pAd6zCu7wNBv+09RkuaG5NI92lWT76tloTMA/ZUeyjtVgouqTn59jcRW3FldOvGxfU9CnMBfRZrF9n037aYAwQzP6meB/z06Uij9vDEzjMTLcHAL58cm6qKsY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index fb8752b42ec8..eb56b251ce10 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. + hugetlb_cma_only= + [HW,CMA,EARLY] When allocating new HugeTLB pages, only + try to allocate from the CMA areas. + + This option does nothing if hugetlb_cma= is not also + specified. + hugetlb_free_vmemmap= [KNL] Requires CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP enabled. diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5af544960052..c227d0b9cf1e 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; __initdata struct list_head huge_boot_pages[MAX_NUMNODES]; @@ -1511,6 +1512,9 @@ static struct folio *alloc_gigantic_folio(struct hstate *h, gfp_t gfp_mask, } #endif if (!folio) { + if (hugetlb_cma_only) + return NULL; + folio = folio_alloc_gigantic(order, gfp_mask, nid, nodemask); if (!folio) return NULL; @@ -4732,6 +4736,9 @@ static __init void hugetlb_parse_params(void) hcp->setup(hcp->val); } + + if (!hugetlb_cma_size) + hugetlb_cma_only = false; } /* @@ -7844,6 +7851,13 @@ static int __init cmdline_parse_hugetlb_cma(char *p) early_param("hugetlb_cma", cmdline_parse_hugetlb_cma); +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;