From patchwork Tue Oct 15 04:51:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Piccoli X-Patchwork-Id: 11189707 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 11BB3139A for ; Tue, 15 Oct 2019 04:52:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CEEDB21A49 for ; Tue, 15 Oct 2019 04:52:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CEEDB21A49 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 1DA0D8E0006; Tue, 15 Oct 2019 00:52:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 18C5F8E0001; Tue, 15 Oct 2019 00:52:18 -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 051A08E0006; Tue, 15 Oct 2019 00:52:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0175.hostedemail.com [216.40.44.175]) by kanga.kvack.org (Postfix) with ESMTP id D29A38E0001 for ; Tue, 15 Oct 2019 00:52:17 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 686DD8020B42 for ; Tue, 15 Oct 2019 04:52:17 +0000 (UTC) X-FDA: 76044797514.25.arch00_13ea4c603d438 X-Spam-Summary: 2,0,0,76b6ee070c3c0886,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:2:41:355:379:541:800:960:966:973:982:988:989:1260:1311:1314:1345:1437:1515:1535:1605:1606:1730:1747:1777:1792:1801:2196:2198:2199:2200:2393:2553:2559:2562:2731:3138:3139:3140:3141:3142:3865:3866:3867:3870:3871:3872:3874:4119:4250:4321:4385:4605:5007:6119:6261:7903:7974:8957:10004:10226:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13184:13229:13894:14394:21080:21325:21444:21451:21627:21796:21966: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: arch00_13ea4c603d438 X-Filterd-Recvd-Size: 8156 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Oct 2019 04:52:16 +0000 (UTC) Received: from mail-pf1-f199.google.com ([209.85.210.199]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iKEoh-0002uN-9N for linux-mm@kvack.org; Tue, 15 Oct 2019 04:52:15 +0000 Received: by mail-pf1-f199.google.com with SMTP id i28so15000882pfq.16 for ; Mon, 14 Oct 2019 21:52:15 -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=WQMobvz2HZDQGzhhbi3ppB5RzKsxgUB3nvRB102SsS8=; b=B5a/t5EgBPRsbcFgbP4zES0lmRPDZnUu5rzpEpUSdRztLw+/rBnGqlAwDGKy98kKtR Gdv/8pnSqSTb16dgwv/p4VLGV9xxVFsO5SO6Ta5qo48vVW9nliQlwwGmQYq2Mu6qixlG ONRp99Q7n4DLkk1m2d0dr4ebaTfObzcYq+adqrpO1xiir6IsKJj6hujfdud2+4sWKqrO rpxPAcauO8egh72beyOYcJ2mxsUSeigmvrS81PnHhinPIl8fbpE+6GMItNKSAlrYf0+9 /i1/EzAUnYufsBZNT7X0k4vW1L+U+TlIg4NcC6zuyBZJsY6kXk/Qm2vgpJkARbbmvBWJ W9kw== X-Gm-Message-State: APjAAAWWnI2p9QrPxp1Xy4KbObr4yMtIIPV4PaDv1DXDobAnpWzVOgRP O6I1eXrKSHlqHBQmOfgy7S0+b5OaCkxQ3yNx93wbBybz7vjHMKOKz+ugFc48UIVCKqyhf9VY1nO fzNNIQBxrd2R7EEg+fVcoWG/YL9Ft X-Received: by 2002:a62:e90d:: with SMTP id j13mr22903926pfh.237.1571115133373; Mon, 14 Oct 2019 21:52:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRnvSEwlddqeNb8FLTT8pchhPLd30L7P1E1zjw8HNEHB7GOQA2xa9U/odCorAcPojihGJF1w== X-Received: by 2002:a62:e90d:: with SMTP id j13mr22903906pfh.237.1571115133094; Mon, 14 Oct 2019 21:52:13 -0700 (PDT) Received: from localhost (201-92-249-168.dsl.telesp.net.br. [201.92.249.168]) by smtp.gmail.com with ESMTPSA id r18sm26476953pfc.3.2019.10.14.21.52.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Oct 2019 21:52:12 -0700 (PDT) From: "Guilherme G. Piccoli" To: linux-mm@kvack.org, mike.kravetz@oracle.com Cc: linux-kernel@vger.kernel.org, jay.vosburgh@canonical.com, gpiccoli@canonical.com, kernel@gpiccoli.net Subject: [PATCH V2] hugetlb: Add nohugepages parameter to prevent hugepages creation Date: Tue, 15 Oct 2019 01:51:58 -0300 Message-Id: <20191015045158.5297-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 --- .../admin-guide/kernel-parameters.txt | 4 +++ fs/hugetlbfs/inode.c | 5 ++-- include/linux/hugetlb.h | 7 ++++++ mm/hugetlb.c | 25 +++++++++++++------ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a84a83f8881e..061bec851114 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/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a478df035651..bbf8827ecccf 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1451,8 +1451,9 @@ static int __init init_hugetlbfs_fs(void) int error; int i; - if (!hugepages_supported()) { - pr_info("disabling because there are no supported hugepage sizes\n"); + if (!hugepages_enabled()) { + if (!hugetlb_disable_hugepages) + pr_info("disabling because there are no supported hugepage sizes\n"); return -ENOTSUPP; } diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 53fc34f930d0..91b3cc7ae891 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -549,6 +549,13 @@ static inline spinlock_t *huge_pte_lockptr(struct hstate *h, #define hugepages_supported() (HPAGE_SHIFT != 0) #endif +extern int hugetlb_disable_hugepages; + +static inline bool hugepages_enabled(void) +{ + return (hugepages_supported() && (!hugetlb_disable_hugepages)); +} + void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm); static inline void hugetlb_count_add(long l, struct mm_struct *mm) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ef37c85423a5..d0151454f13f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -43,6 +43,8 @@ int hugetlb_max_hstate __read_mostly; unsigned int default_hstate_idx; struct hstate hstates[HUGE_MAX_HSTATE]; +int hugetlb_disable_hugepages; + /* * Minimum page order among possible hugepage sizes, set to a proper value * at boot time. @@ -1604,7 +1606,7 @@ int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn) struct page *page; int rc = 0; - if (!hugepages_supported()) + if (!hugepages_enabled()) return rc; for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { @@ -2897,7 +2899,7 @@ static int __init hugetlb_init(void) { int i; - if (!hugepages_supported()) + if (!hugepages_enabled()) return 0; if (!size_to_hstate(default_hstate_size)) { @@ -3022,6 +3024,15 @@ static int __init hugetlb_default_setup(char *s) } __setup("default_hugepagesz=", hugetlb_default_setup); +static int __init nohugepages_setup(char *str) +{ + hugetlb_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; @@ -3042,7 +3053,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy, unsigned long tmp = h->max_huge_pages; int ret; - if (!hugepages_supported()) + if (!hugepages_enabled()) return -EOPNOTSUPP; table->data = &tmp; @@ -3083,7 +3094,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write, unsigned long tmp; int ret; - if (!hugepages_supported()) + if (!hugepages_enabled()) return -EOPNOTSUPP; tmp = h->nr_overcommit_huge_pages; @@ -3113,7 +3124,7 @@ void hugetlb_report_meminfo(struct seq_file *m) struct hstate *h; unsigned long total = 0; - if (!hugepages_supported()) + if (!hugepages_enabled()) return; for_each_hstate(h) { @@ -3141,7 +3152,7 @@ void hugetlb_report_meminfo(struct seq_file *m) int hugetlb_report_node_meminfo(int nid, char *buf) { struct hstate *h = &default_hstate; - if (!hugepages_supported()) + if (!hugepages_enabled()) return 0; return sprintf(buf, "Node %d HugePages_Total: %5u\n" @@ -3157,7 +3168,7 @@ void hugetlb_show_meminfo(void) struct hstate *h; int nid; - if (!hugepages_supported()) + if (!hugepages_enabled()) return; for_each_node_state(nid, N_MEMORY)