Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6209196pxb; Thu, 27 Jan 2022 08:42:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwm7gzvp2WzEM3UNXMmIKPewYM5J0f3eg71Sj806Dr3tbI1anj8qj1L391WkZSXyqg1RU7A X-Received: by 2002:a17:90b:249:: with SMTP id fz9mr14668350pjb.99.1643301752284; Thu, 27 Jan 2022 08:42:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643301752; cv=none; d=google.com; s=arc-20160816; b=jL9bXWl1yOYvZRdfyKqaVWVacHUk6CrYzwDkeCshf6xuzTgnizS4H1wLE2Rty0acgc R7qtwtdWMrAGBvuUMB1eKaWK/oHnZKGsxlyVAPxj8lpj58erWGnOIDMmvRiKUyhqilyb GVwh+zSNOL34mg41ZNB+zkTcOPqjOQHjx7cs/3tir0nQJdSCId+yqXSRV5n/OvuqeNE9 TpTGQ9FxM4M+itrsf0txG299RqFWFUJcWCxdFGrrkxj6J0Km5eJXHJKp7qejrcUvOcNJ dWH2tPG/MbCBl/YJZXk1uAyjew72KuN+ubdMKs9Yc+P05NFCerhPQd0kV23zoMC1KcxA BRBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=H9MfcJkPU7X+LxmFYI7/eugSPkPZI7hTVmmz4WErGb8=; b=YeZCX0b4ucwGYLZHKLBNZnU5WXCFmUc3VMtC9huzVOvdsVh6BjK+Ytv+xNbwbfkqv/ CFlHodB7BXg7u/mkGpLIYzfcNMkAAjndN4Knd8OmNHjvxmpxXoZoeJC8d6O8iMYO+dam F27Eupz6SjAUmldETiPeJOFkwyhyYzuD7Ibo2kWTlYKy6dim8KUL7S9DeYekPgIy/YD9 JBBIChu+BjvKUBjEjDJmgkrxGArjrYm/Bf6WQZUtud0ctrU0rYJmpR7mfK5IcCJW5fZV CcdvKW6NS4DWSwjd2RmZzRjm0aFmOdvzouBtzB1XJyKy1w2uLUxzQxc5tLFqXjUVneO1 4gCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si5695592pjh.81.2022.01.27.08.41.56; Thu, 27 Jan 2022 08:42:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238564AbiA0JcE (ORCPT + 99 others); Thu, 27 Jan 2022 04:32:04 -0500 Received: from mail.loongson.cn ([114.242.206.163]:35744 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229861AbiA0JcC (ORCPT ); Thu, 27 Jan 2022 04:32:02 -0500 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGuCHZvJhv+AEAA--.14616S2; Thu, 27 Jan 2022 17:31:52 +0800 (CST) From: Tiezhu Yang To: Baoquan He , Vivek Goyal , Dave Young , Jonathan Corbet , Andrew Morton Cc: Xuefeng Li , kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] kdump: Add support for crashkernel=auto Date: Thu, 27 Jan 2022 17:31:51 +0800 Message-Id: <1643275911-19489-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9AxGuCHZvJhv+AEAA--.14616S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXF43Gr4rJrWfGrWDtF48tFb_yoW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the reserved memory automatically for the crash kernel based on architecture. Most code of this patch come from: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-8/-/tree/c8s Signed-off-by: Tiezhu Yang --- Documentation/admin-guide/kdump/kdump.rst | 13 +++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 5 +++++ kernel/crash_core.c | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/Documentation/admin-guide/kdump/kdump.rst b/Documentation/admin-guide/kdump/kdump.rst index cb30ca3d..8f8a9cc 100644 --- a/Documentation/admin-guide/kdump/kdump.rst +++ b/Documentation/admin-guide/kdump/kdump.rst @@ -335,6 +335,19 @@ crashkernel syntax crashkernel=0,low +4) crashkernel=auto + + You can use crashkernel=auto if you have enough memory. The threshold + is 1G on x86_64 and s390x, 2G on arm64, ppc64 and ppc64le. If your system + memory is less than the threshold crashkernel=auto will not reserve memory. + + The automatically reserved memory size varies based on architecture. + The size changes according to system memory size like below: + x86_64: 1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M + s390x: 1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M + arm64: 2G-:448M + ppc64: 2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G + Boot into System Kernel ----------------------- 1) Update the boot loader (such as grub, yaboot, or lilo) configuration diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index f5a27f0..14f052d 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -783,6 +783,11 @@ Format: ,,,[,] + crashkernel=auto + [KNL] Set the reserved memory automatically for the crash kernel + based on architecture. + See Documentation/admin-guide/kdump/kdump.rst for further details. + crashkernel=size[KMG][@offset[KMG]] [KNL] Using kexec, Linux can switch to a 'crash kernel' upon panic. This parameter reserves the physical diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 256cf6d..32c51e2 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -252,6 +252,26 @@ static int __init __parse_crashkernel(char *cmdline, if (suffix) return parse_crashkernel_suffix(ck_cmdline, crash_size, suffix); + + if (strncmp(ck_cmdline, "auto", 4) == 0) { +#if defined(CONFIG_X86_64) || defined(CONFIG_S390) + ck_cmdline = "1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M"; +#elif defined(CONFIG_ARM64) + ck_cmdline = "2G-:448M"; +#elif defined(CONFIG_PPC64) + char *fadump_cmdline; + + fadump_cmdline = get_last_crashkernel(cmdline, "fadump=", NULL); + fadump_cmdline = fadump_cmdline ? + fadump_cmdline + strlen("fadump=") : NULL; + if (!fadump_cmdline || (strncmp(fadump_cmdline, "off", 3) == 0)) + ck_cmdline = "2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G"; + else + ck_cmdline = "4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G"; +#endif + pr_info("Using crashkernel=auto, the size chosen is a best effort estimation.\n"); + } + /* * if the commandline contains a ':', then that's the extended * syntax -- if not, it must be the classic syntax -- 2.1.0