Received: by 10.223.185.116 with SMTP id b49csp2827999wrg; Mon, 12 Feb 2018 16:26:26 -0800 (PST) X-Google-Smtp-Source: AH8x227BzS5MrILXtXtM9WY5NNyS1SiR3D/IH+es8Y3YXKIALxm4i111pnsL0CJ3K8YrW/coqKbB X-Received: by 10.98.150.14 with SMTP id c14mr13223246pfe.210.1518481586222; Mon, 12 Feb 2018 16:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518481586; cv=none; d=google.com; s=arc-20160816; b=WGlB6QnFEqWb2MnrU9O3DSbtwyLYbitDng307hHeOofVMEvnacR9mJ94QK3lI1BGkL LiHyfwP/jtgWFjwuYk3CRjG3nXzg+OgrQXlDOG3+MV34DNXCpL5oL0fiRBlB3nSuzC/Y uYBoNLPUYqkp6MDNotWk3M9K0PsVA0oNVxCdlGdZJ3ieqbEI05dCT1vP6tSFtO0kDdRS 22mPy8NBuM6Ib/GUjrBjbYm3QXkNIsNrqynZuaw4rS7QaD+EUq9bN65bG+O1BFwb8yFZ XFqMR73rbpnNvgNlVptN/6YDh82ZsUZLcho10qlD/JV3MuW+/2NuzK9f6BTuD7V+oZgV Pn2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=Da0qI7JYf/adkWh0QxU0VAEaE8vtVc6Cg0L2TFbPLMY=; b=q0LUohM38CPwYI7UjRpKZmFJ5CwHPArSU0HcRotzWWvknahG5SyDenzcg+AHysNeqm jI9gIKQhFVG4UEpZeVHhm74/KVL4/TLybC4tAtotmiQsUcaN+vCGfmAwJocPnwMgXVRo 01NjdSXJk7O/SBpAcSwpB1CxsA0FZRv+uvdFc1bBf7/J2C4lNxc6y2fDZ+q+7FtaDTIR 2jCK1vWKfwPaQPNd6+jfiG1p/EoFFixU1tq62pr3g9epZMK/j7+ORM8tQ+T48Ipn8wL8 0QsNvljdMRurZiAAadoaxwXPHB7djp6OOF+hAsUlNbUndSTVT7GkM6C6Sv32kE9DtQdo 2xBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J3K4kcVG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j63si346799pgc.591.2018.02.12.16.26.11; Mon, 12 Feb 2018 16:26:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J3K4kcVG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932957AbeBMAYa (ORCPT + 99 others); Mon, 12 Feb 2018 19:24:30 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:55655 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932743AbeBMAY2 (ORCPT ); Mon, 12 Feb 2018 19:24:28 -0500 Received: by mail-it0-f66.google.com with SMTP id b66so9024266itd.5 for ; Mon, 12 Feb 2018 16:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=Da0qI7JYf/adkWh0QxU0VAEaE8vtVc6Cg0L2TFbPLMY=; b=J3K4kcVG8mgNeFloktkh8nM20y/DeknYgSDuxjoYk178wKyN4JZtQfXXPcAfTA5nj3 YJOD5JNMWmZZRU2ufN+xkkFzKQkHbb0HsnLbapZCaV8ZzG0+fm2OULGv2945zzT2x2iV kTdC85p8/eTZ3Cm6LoutJWTTsAyPdB6nO0ap3xX6lIEFGD66zXTE+7INVdm94bhg9gAF t1NlILSVfrenxNc0N92ci03ztvYJGoaJlmpHRSv7Ars03Toc/Rk3s3SdaSQcwAIXQhXQ 6bUzJHALyp3rwwnLt5tRPPemVluNDGmbo4N23glRml/E1fo3oOJwSjrnsGmoqgmWc77f t4Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=Da0qI7JYf/adkWh0QxU0VAEaE8vtVc6Cg0L2TFbPLMY=; b=qKYlx0Xt6b3OVvAVXxB28EwLsAvUshoqHnBNku96+mlZNftaPh2wRWIWFgYNp/myMU NTtSVQ38qDNLYxgYXqQ7N8rz1rkQEKWTQ9pE/HGVvK7mS1E+7B87GdI1njJkz28T7/Gw dagCwGt6Oo/uPxBMF527Yed6AbDoeuXh0avdyHNQ/JxS2NdIpuIb5RaDE2VPQoEsCExn 2Yrb73xSEtq7ndBh5HXPeISs4kMZt6x+m7kU6dzaBHy+NgWdbAFgLl4oqLEd4gMcatpd JZVqs+gKx/zA8xx0Prb0NOwvjiAsXtmffc6/2nxzrh7XmFsnCy/0HC2f0+rDGb/yb/Vt U1jA== X-Gm-Message-State: APf1xPB6epIdV1g1eL1PVg4++r07zfUz1wo4gApoFoGLeCLM6sKYRSGc McKqHddYJxlBRe+Vay3WxgWssg== X-Received: by 10.36.105.138 with SMTP id e132mr338290itc.137.1518481467593; Mon, 12 Feb 2018 16:24:27 -0800 (PST) Received: from [2620:15c:17:3:8446:18ef:ea2c:aecf] ([2620:15c:17:3:8446:18ef:ea2c:aecf]) by smtp.gmail.com with ESMTPSA id o193sm5315834itg.43.2018.02.12.16.24.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Feb 2018 16:24:26 -0800 (PST) Date: Mon, 12 Feb 2018 16:24:25 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton cc: Jonathan Corbet , Vlastimil Babka , Mel Gorman , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org Subject: [patch 1/2] mm, page_alloc: extend kernelcore and movablecore for percent Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both kernelcore= and movablecore= can be used to define the amount of ZONE_NORMAL and ZONE_MOVABLE on a system, respectively. This requires the system memory capacity to be known when specifying the command line, however. This introduces the ability to define both kernelcore= and movablecore= as a percentage of total system memory. This is convenient for systems software that wants to define the amount of ZONE_MOVABLE, for example, as a proportion of a system's memory rather than a hardcoded byte value. To define the percentage, the final character of the parameter should be a '%'. Signed-off-by: David Rientjes --- Documentation/admin-guide/kernel-parameters.txt | 44 ++++++++++++------------- mm/page_alloc.c | 43 +++++++++++++++++++----- 2 files changed, 57 insertions(+), 30 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1825,30 +1825,30 @@ keepinitrd [HW,ARM] kernelcore= [KNL,X86,IA-64,PPC] - Format: nn[KMGTPE] | "mirror" - This parameter - specifies the amount of memory usable by the kernel - for non-movable allocations. The requested amount is - spread evenly throughout all nodes in the system. The - remaining memory in each node is used for Movable - pages. In the event, a node is too small to have both - kernelcore and Movable pages, kernelcore pages will - take priority and other nodes will have a larger number - of Movable pages. The Movable zone is used for the - allocation of pages that may be reclaimed or moved - by the page migration subsystem. This means that - HugeTLB pages may not be allocated from this zone. - Note that allocations like PTEs-from-HighMem still - use the HighMem zone if it exists, and the Normal - zone if it does not. - - Instead of specifying the amount of memory (nn[KMGTPE]), - you can specify "mirror" option. In case "mirror" + Format: nn[KMGTPE] | nn% | "mirror" + This parameter specifies the amount of memory usable by + the kernel for non-movable allocations. The requested + amount is spread evenly throughout all nodes in the + system as ZONE_NORMAL. The remaining memory is used for + movable memory in its own zone, ZONE_MOVABLE. In the + event, a node is too small to have both ZONE_NORMAL and + ZONE_MOVABLE, kernelcore memory will take priority and + other nodes will have a larger ZONE_MOVABLE. + + ZONE_MOVABLE is used for the allocation of pages that + may be reclaimed or moved by the page migration + subsystem. This means that HugeTLB pages may not be + allocated from this zone. Note that allocations like + PTEs-from-HighMem still use the HighMem zone if it + exists, and the Normal zone if it does not. + + It is possible to specify the exact amount of memory in + the form of "nn[KMGTPE]", a percentage of total system + memory in the form of "nn%", or "mirror". If "mirror" option is specified, mirrored (reliable) memory is used for non-movable allocations and remaining memory is used - for Movable pages. nn[KMGTPE] and "mirror" are exclusive, - so you can NOT specify nn[KMGTPE] and "mirror" at the same - time. + for Movable pages. "nn[KMGTPE]", "nn%", and "mirror" + are exclusive, so you cannot specify multiple forms. kgdbdbgp= [KGDB,HW] kgdb over EHCI usb debug port. Format: [,poll interval] diff --git a/mm/page_alloc.c b/mm/page_alloc.c --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -272,7 +272,9 @@ static unsigned long __meminitdata dma_reserve; static unsigned long __meminitdata arch_zone_lowest_possible_pfn[MAX_NR_ZONES]; static unsigned long __meminitdata arch_zone_highest_possible_pfn[MAX_NR_ZONES]; static unsigned long __initdata required_kernelcore; +static unsigned long required_kernelcore_percent __initdata; static unsigned long __initdata required_movablecore; +static unsigned long required_movablecore_percent __initdata; static unsigned long __meminitdata zone_movable_pfn[MAX_NUMNODES]; static bool mirrored_kernelcore; @@ -6477,7 +6479,18 @@ static void __init find_zone_movable_pfns_for_nodes(void) } /* - * If movablecore=nn[KMG] was specified, calculate what size of + * If kernelcore=nn% or movablecore=nn% was specified, calculate the + * amount of necessary memory. + */ + if (required_kernelcore_percent) + required_kernelcore = (totalpages * 100 * required_kernelcore_percent) / + 10000UL; + if (required_movablecore_percent) + required_movablecore = (totalpages * 100 * required_movablecore_percent) / + 10000UL; + + /* + * If movablecore= was specified, calculate what size of * kernelcore that corresponds so that memory usable for * any allocation type is evenly spread. If both kernelcore * and movablecore are specified, then the value of kernelcore @@ -6717,18 +6730,30 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn) zero_resv_unavail(); } -static int __init cmdline_parse_core(char *p, unsigned long *core) +static int __init cmdline_parse_core(char *p, unsigned long *core, + unsigned long *percent) { unsigned long long coremem; + char *endptr; + if (!p) return -EINVAL; - coremem = memparse(p, &p); - *core = coremem >> PAGE_SHIFT; + /* Value may be a percentage of total memory, otherwise bytes */ + coremem = simple_strtoull(p, &endptr, 0); + if (*endptr == '%') { + /* Paranoid check for percent values greater than 100 */ + WARN_ON(coremem > 100); - /* Paranoid check that UL is enough for the coremem value */ - WARN_ON((coremem >> PAGE_SHIFT) > ULONG_MAX); + *percent = coremem; + } else { + coremem = memparse(p, &p); + /* Paranoid check that UL is enough for the coremem value */ + WARN_ON((coremem >> PAGE_SHIFT) > ULONG_MAX); + *core = coremem >> PAGE_SHIFT; + *percent = 0UL; + } return 0; } @@ -6744,7 +6769,8 @@ static int __init cmdline_parse_kernelcore(char *p) return 0; } - return cmdline_parse_core(p, &required_kernelcore); + return cmdline_parse_core(p, &required_kernelcore, + &required_kernelcore_percent); } /* @@ -6753,7 +6779,8 @@ static int __init cmdline_parse_kernelcore(char *p) */ static int __init cmdline_parse_movablecore(char *p) { - return cmdline_parse_core(p, &required_movablecore); + return cmdline_parse_core(p, &required_movablecore, + &required_movablecore_percent); } early_param("kernelcore", cmdline_parse_kernelcore);