From patchwork Fri Oct 11 22:39:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Piccoli X-Patchwork-Id: 11186433 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E5511668 for ; Fri, 11 Oct 2019 22:40:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 10D1621E6F for ; Fri, 11 Oct 2019 22:40:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10D1621E6F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4EA8F6B0003; Fri, 11 Oct 2019 18:40:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 49B938E0005; Fri, 11 Oct 2019 18:40:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B1358E0001; Fri, 11 Oct 2019 18:40:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id 18C626B0003 for ; Fri, 11 Oct 2019 18:40:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id AF1B9180AD80E for ; Fri, 11 Oct 2019 22:40:14 +0000 (UTC) X-FDA: 76032973548.22.band21_5960a808b5936 X-Spam-Summary: 2,0,0,35295264eef575d8,d41d8cd98f00b204,gpiccoli@canonical.com,::mike.kravetz@oracle.com:linux-kernel@vger.kernel.org:jay.vosburgh@canonical.com:gpiccoli@canonical.com:kernel@gpiccoli.net,RULES_HIT:41:355:379:541:800:960:973:982:988:989:1260:1311:1314:1345:1437:1515:1535:1543:1711:1730:1747:1777:1792:1801:2110:2198:2199:2393:2553:2559:2562:2731:2911:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4117:4250:4321:4362:4425:4605:5007:6119:6261:7903:7974:9040:10004:10226:11026:11232:11473:11658:11914:12043:12297:12438:12517:12519:12555:12663:12895:13184:13229:13894:14040:14181:14394:14721:21063:21080:21324:21325:21444:21451:21627:21796:21966:30012:30036:30054:30062:30089:30090,0,RBL:91.189.89.112:@canonical.com:.lbl8.mailshell.net-62.8.15.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: band21_5960a808b5936 X-Filterd-Recvd-Size: 6219 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 11 Oct 2019 22:40:14 +0000 (UTC) Received: from mail-pf1-f198.google.com ([209.85.210.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iJ3a0-0005ja-Cg for linux-mm@kvack.org; Fri, 11 Oct 2019 22:40:12 +0000 Received: by mail-pf1-f198.google.com with SMTP id 194so8587921pfu.3 for ; Fri, 11 Oct 2019 15:40:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bFQOsU0Yw2SX6audeMgxRQZjWA+ky677CyE7FshJP3k=; b=bY8nbRRY7/cuMivRcmj21eGbUaoxaBzcCN6Q2CXC3TXpvIsFgGZb0pGYgfo89pnxc6 BppJcbUUlxK2SUVStEXgPfwcva2zTZeFX240ed4XHiV4NSeFxlfuPnuXQZUA3ezYtXF3 Id+7c0sGIMNPSM47t31QhvsUczeuJN+HmTAXgl4TEGvT1wZZbP8uoDNnhWN8aQZ6cQca gheJdiXYaIXWkGKUqhcEM7ABlKYv5kd/SHQFn49EPimBUEcF5jPhIsnaeEzp8GodRAAE mPjokJlqfF4dow10e5xzPVu/YLWUSxro6d7JmfQQTLihdGqagrQErsplQilzyuvH2Th9 M7RA== X-Gm-Message-State: APjAAAU00X7Yg62DQ5/LFkICBgQRDkC39/5lHbkGyGz3dxhh0WtamGYp QW1ViTUznerWKkC0ytKAz9SVhV3uqVKauS9YdfW2DPjSsg6o03/jN06qxe4EYcUzTd3ZyYTvoce MvY/ztzytqB0u49IyI+4lpPdZgLIi X-Received: by 2002:a17:90a:cb88:: with SMTP id a8mr20411310pju.85.1570833610432; Fri, 11 Oct 2019 15:40:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyooSuvk39320EB5pXd8iQc4RdUqGq6tYyCPa/eZWG8r9ggKLSkR6rfbGDRKVfzLQEAMCAGKw== X-Received: by 2002:a17:90a:cb88:: with SMTP id a8mr20411269pju.85.1570833610073; Fri, 11 Oct 2019 15:40:10 -0700 (PDT) Received: from localhost (201-92-249-168.dsl.telesp.net.br. [201.92.249.168]) by smtp.gmail.com with ESMTPSA id 7sm8656370pgj.35.2019.10.11.15.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Oct 2019 15:40:09 -0700 (PDT) From: "Guilherme G. Piccoli" To: linux-mm@kvack.org Cc: mike.kravetz@oracle.com, linux-kernel@vger.kernel.org, jay.vosburgh@canonical.com, gpiccoli@canonical.com, kernel@gpiccoli.net Subject: [PATCH] hugetlb: Add nohugepages parameter to prevent hugepages creation Date: Fri, 11 Oct 2019 19:39:55 -0300 Message-Id: <20191011223955.1435-1-gpiccoli@canonical.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 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: Currently there are 2 ways for setting HugeTLB hugepages in kernel; either users pass parameters on kernel command-line or they can write to sysfs files (which is effectively the sysctl way). Kdump kernels won't benefit from hugepages - in fact it's quite opposite, it may be the case hugepages on kdump kernel can lead to OOM if kernel gets unable to allocate demanded pages due to the fact the preallocated hugepages are consuming a lot of memory. This patch proposes a new kernel parameter to prevent the creation of HugeTLB hugepages - we currently don't have a way to do that. We can even have kdump scripts removing the kernel command-line options to set hugepages, but it's not straightforward to prevent sysctl/sysfs configuration, given it happens in later boot or anytime when the system is running. Signed-off-by: Guilherme G. Piccoli --- About some decisions took in this patch: * early_param() was used because I couldn't find a way to enforce parameters' ordering when using __setup(), and we need nohugepages processed before all other hugepages options. * The return when sysctl handler is prevented to progress due to nohugepages is -EINVAL, but could be changed; I've just followed present code there, but I'm OK changing that if we have suggestions. Thanks in advance for the review! Cheers, Guilherme Documentation/admin-guide/kernel-parameters.txt | 4 ++++ mm/hugetlb.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index c7ac2f3ac99f..eebe0e7b30cf 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2982,6 +2982,10 @@ nohugeiomap [KNL,x86,PPC] Disable kernel huge I/O mappings. + nohugepages [KNL] Disable HugeTLB hugepages completely, preventing + its setting either by kernel parameter or sysfs; + useful specially in kdump kernel. + nosmt [KNL,S390] Disable symmetric multithreading (SMT). Equivalent to smt=1. diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ef37c85423a5..a6c7a68152e5 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -43,6 +43,7 @@ int hugetlb_max_hstate __read_mostly; unsigned int default_hstate_idx; struct hstate hstates[HUGE_MAX_HSTATE]; +static int disable_hugepages; /* * Minimum page order among possible hugepage sizes, set to a proper value * at boot time. @@ -2550,6 +2551,9 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy, int err; nodemask_t nodes_allowed, *n_mask; + if (disable_hugepages) + return -EINVAL; + if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return -EINVAL; @@ -2978,6 +2982,9 @@ static int __init hugetlb_nrpages_setup(char *s) unsigned long *mhp; static unsigned long *last_mhp; + if (disable_hugepages) + return 1; + if (!parsed_valid_hugepagesz) { pr_warn("hugepages = %s preceded by " "an unsupported hugepagesz, ignoring\n", s); @@ -3022,6 +3029,15 @@ static int __init hugetlb_default_setup(char *s) } __setup("default_hugepagesz=", hugetlb_default_setup); +static int __init nohugepages_setup(char *str) +{ + disable_hugepages = 1; + pr_info("HugeTLB: hugepages disabled by kernel parameter\n"); + + return 0; +} +early_param("nohugepages", nohugepages_setup); + static unsigned int cpuset_mems_nr(unsigned int *array) { int node;