From patchwork Mon Jan 27 23:22:06 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: 13951867 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 688AAC02188 for ; Mon, 27 Jan 2025 23:23:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7771B2801DC; Mon, 27 Jan 2025 18:23:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AC0F2801D9; Mon, 27 Jan 2025 18:23:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 573B72801DC; Mon, 27 Jan 2025 18:23:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 338872801D9 for ; Mon, 27 Jan 2025 18:23:08 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EBB45C082C for ; Mon, 27 Jan 2025 23:23:07 +0000 (UTC) X-FDA: 83054809614.26.3263540 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf06.hostedemail.com (Postfix) with ESMTP id 2583F180002 for ; Mon, 27 Jan 2025 23:23:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=GkRXI0B4; spf=pass (imf06.hostedemail.com: domain of 3WBWYZwQKCCcIYGOJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--fvdl.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3WBWYZwQKCCcIYGOJRRJOH.FRPOLQXa-PPNYDFN.RUJ@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=1738020186; 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=EKeeHmURdM6aNKIslC9cbG8uxcWG/M1qKwEQEge7FZ4=; b=qyPOnJZBwOUOuondaaX6BwsP298Vl4cWF5hyCliXtAvX2FxUm7p8uJw4zGtGGN5DlVfVu8 oM35vQUYX3bYJRvj3aPTyey6BYz43H86ONEHFYQ3R4uTXOKHW1AsTkjnhqgBPQeN/clJZv RpLNzLmotqh3gJk3wzWf6sxSMpn6gE8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=GkRXI0B4; spf=pass (imf06.hostedemail.com: domain of 3WBWYZwQKCCcIYGOJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--fvdl.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3WBWYZwQKCCcIYGOJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738020186; a=rsa-sha256; cv=none; b=NzgL1z37DSpAYGP8Nz3FNjtfDCqxv2xtPAAHFkaE8acCK6KOpetojFm1aB62lWtAtUtOPT vGVb3R5iAkAUOmpsIAQQ9luHIPzcoZcdZ2Gk9V2KnxFMuGndTvAL5Wmo1Eq4QPJXThBJpW hbLTP88f3gENmPE2KRaKhoJgn9NBR2o= Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so14694484a91.3 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=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=EKeeHmURdM6aNKIslC9cbG8uxcWG/M1qKwEQEge7FZ4=; b=GkRXI0B46IuLbP5ZKos1fLcjVFDx+fRs1uo6brR4Xvairf1KwjDN9W1C7BXc7O0SSa gGizmvzXwglTD9gnuEftjFTiplkjpkkmWFyndTpikZkkJry+dhclr1rWVpd1KPFa1QMJ SNkkxLER7p7kmwInnEPrCmaVLPYjwPfvybzfnKaejrkh0EIeaBiYwezyGNtizI3hd3NA Obli3guw+gwz/o+EcdEW+RaNa0jDD2Qrjv67rEENLi2TmfQWN+7bgZ515WCuvblfFDgO FFlWicmwDdI7lq39MHEUJbYzl9mrryNOC3ufvtf1xOOMtmIVon4rWW93/2koHSvIQf47 oIfg== 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=DfjL7K6jgaXS/+Lbax3DG6oCa3WYR5oyIplXMF2prpzQql4em6wCS1wcwDOGb6uxRn TMf32sYttKPBm2nyAzilE26aCLzIQJDyuyMpsWE0kZ8OdfYFJo8Q7K7UxtFinlZD8ucS BEoC7uXNNKNmwerXw3xLeMSToq/epMzJpw4T7JKbA4/xc8h2UscvFqs3XMHmNK0roSz6 0aSdKSJMfMzJkmNMlWIvSN7KD0uRPxDnujST2DCCu6RKku2/eJjAEEOTyfIbbj/WermE 0nPCi4Hedm6up2AQZjVvfAvxNYekeY6JVdB/I0dljmpO6KgpSnJTnsXWpQqALWYnG0/A XQvw== X-Forwarded-Encrypted: i=1; AJvYcCUgpeHgq0hS+Xrxza/CPM2Hf35Oihc+2D/t05v/mr0Hms4ZDtIbNxda+z4FI5LUun4KueArfIL8ZA==@kvack.org X-Gm-Message-State: AOJu0YwFWNQrRVXCQ1EyKGY8aBmrxmo9ND71a8fF1nrwui72ubcGEjsK 8Poj5oVz1GnCn6Kgv1F9oLOjOA4MUB0qeVlxrgFNvE+gV47nX2C4Np7FtOsrWjWirUsyAg== 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> 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 X-Rspamd-Queue-Id: 2583F180002 X-Stat-Signature: oxn887mf3zngrqkztw7d9m9rkm7u7hmb X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1738020185-201199 X-HE-Meta: U2FsdGVkX1929ohjYIOaX7R2sXRUPO6eKvg6fIIE6l/PXlMv9YVB9Vlti62Qk2QPV7ISXeOa6K1kqTKU/R2JT7DA3UMxCf9grdFbfVOI3SifK9OOIZokC6QNolHdcGD/leJ792DAZ4nxmcPwmz3J1ICgJUphUohMnKNyNe0e6X/XY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Nz4C5kuHXTEKAAWx80uOANaLgTlkVZvr4Uj5b/Pgfu0ob3npDTm1IGCxphzqelZ8sB/t12jYltDXqz2qVdVves4gyUPqaW8+69xBLMo2wrpylyjmF6XSnAVQuzcGpxRgnu7wsU2dFAaNiFUc9x1UkGYaz0f+EK5YRTxovP1GBRwsgHL69Zc4Ine54Kz+L/APi5gVR7IZCbOoqQ0JojDdsRrr9UgVIdMo8/nSkO1UauS1xIJ65eawXwryuq0TbF9sqJPMeX6LXTvJotLL65MfWccwfRhCYeoUYSo4Z44VcvXWhoPBpkvQ4rUktj2hLvls9ICQ87U= 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 | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/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. + 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 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; __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_size && hugetlb_cma_only) + return NULL; + folio = 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) 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;