From patchwork Thu Nov 15 05:50:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 10683541 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5000A17F3 for ; Thu, 15 Nov 2018 05:54:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DCFC2C158 for ; Thu, 15 Nov 2018 05:54:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 329E82C20F; Thu, 15 Nov 2018 05:54:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59CFF2C158 for ; Thu, 15 Nov 2018 05:54:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbeKOQBJ (ORCPT ); Thu, 15 Nov 2018 11:01:09 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34506 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbeKOQBJ (ORCPT ); Thu, 15 Nov 2018 11:01:09 -0500 Received: by mail-pl1-f195.google.com with SMTP id f12-v6so8968449plo.1 for ; Wed, 14 Nov 2018 21:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uLFZE9ZIYhbq/RZKB79BO43XBOr7i2S2rpk1LvaDfyo=; b=C7GRytjZqfoNPWXhaK7E/hR3GJd3PvGUDNZi0GtARWffJMEwlO6i0GZD5L20IhgdSX oBxGz1nfGyTSmlh5Q33LV/jl5GBsbGDyOt9CwDUREJkMh8DJc5bCVOaivWFvHRhlg30j UCoirQP34R2zNHViK8YxerwOtaykGzee+gf7e0jnS+XTwI5R4XshAeQvLcWA8chgSLvu Ab5QLj6aVzJSuviXmk+PEAg2X95KVM77imABNv3RLq7DxM0OhCnEUqROE4RflG8DnNF3 YK+UYjVvx1+Vv/vKQfNyMD/7juQbkHZ10EP+P18R8moCipMcNq7bJ69ipfOLev7B8HgP uH7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uLFZE9ZIYhbq/RZKB79BO43XBOr7i2S2rpk1LvaDfyo=; b=qkqcyYBoCtiDBLfDMeR+1GWRRyy4eGtleMVReocOXUESc81zqZsSncT01PuwvinYgO Mw8RIrPJXnWQ/OCacU7vWDgXLIVyhjU9PfQQcfuQC7jqUhxOjdy2vvjsMCoVD1NAeikT y2ZFK9RaM3z1KPOtbdyrzXaKDPXt1IOdIgVhSbk4ELkqiYPvhgeP+y6+ZWthtlBQ11FW EXjDQXXTm9RSBMtIKeocqbHa0TuP+o/ygVW605bVD+COtJpylUJzNKEue1MYSuj+v4gH 30D3P9CYqmlxrHvH+94VucAKtfz+zyBcgBU/qXoPSVl9aw+b48WjOnyNtrZ8cMh3Iibd LcWA== X-Gm-Message-State: AGRZ1gIF+DdYbKUcoNxI/M3QO9la0DNSc3Y7g9Par10vKQg+aWmgO2vQ 8qTXTxxLvrerIcgjjOGhjmA= X-Google-Smtp-Source: AJdET5ckTBdo9DTdSNvxvd7tnPxoaVsurVDtMZbKqaXWInwjG/ZDL+4pT3SIcZa2Js0ocGgSHKLmJg== X-Received: by 2002:a17:902:6948:: with SMTP id k8mr784741plt.2.1542261283260; Wed, 14 Nov 2018 21:54:43 -0800 (PST) Received: from software.domain.org ([222.92.8.142]) by smtp.gmail.com with ESMTPSA id o1sm34882306pgn.63.2018.11.14.21.54.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Nov 2018 21:54:42 -0800 (PST) From: Huacai Chen To: Jean Delvare Cc: Guenter Roeck , linux-hwmon@vger.kernel.org, Fuxin Zhang , Huacai Chen Subject: [PATCH V5 6/8] MIPS: Reserve extra memory for crash dump Date: Thu, 15 Nov 2018 13:50:55 +0800 Message-Id: <1542261057-6019-7-git-send-email-chenhc@lemote.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1542261057-6019-1-git-send-email-chenhc@lemote.com> References: <1542261057-6019-1-git-send-email-chenhc@lemote.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Traditionally, MIPS's contiguous low memory can be as less as 256M, so crashkernel=X@Y may be unable to large enough in some cases. Moreover, for the "multi numa node + sparse memory model" case, it is attempt to allocate section_mem_maps on every node. Thus, if the total memory of a node is more than 1GB, we reserve the top 128MB for the crash kernel. Signed-off-by: Huacai Chen --- arch/mips/kernel/setup.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index ea09ed6..070234b 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -756,6 +757,48 @@ static void __init request_crashkernel(struct resource *res) #define BUILTIN_EXTEND_WITH_PROM \ IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND) +/* Traditionally, MIPS's contiguous low memory is 256M, so crashkernel=X@Y is + * unable to be large enough in some cases. Thus, if the total memory of a node + * is more than 1GB, we reserve the top 128MB for the crash kernel */ +static void reserve_crashm_region(int node, unsigned long s0, unsigned long e0) +{ +#ifdef CONFIG_KEXEC + if (crashk_res.start == crashk_res.end) + return; + + if ((e0 - s0) <= (SZ_1G >> PAGE_SHIFT)) + return; + + s0 = e0 - (SZ_128M >> PAGE_SHIFT); + + memblock_reserve(PFN_PHYS(s0), (e0 - s0) << PAGE_SHIFT); +#endif +} + +static void reserve_oldmem_region(int node, unsigned long s0, unsigned long e0) +{ +#ifdef CONFIG_CRASH_DUMP + unsigned long s1, e1; + + if (!is_kdump_kernel()) + return; + + if ((e0 - s0) > (SZ_1G >> PAGE_SHIFT)) + e0 = e0 - (SZ_128M >> PAGE_SHIFT); + + /* boot_mem_map.map[0] is crashk_res reserved by primary kernel */ + s1 = PFN_UP(boot_mem_map.map[0].addr); + e1 = PFN_DOWN(boot_mem_map.map[0].addr + boot_mem_map.map[0].size); + + if (node == 0) { + memblock_reserve(PFN_PHYS(s0), (s1 - s0) << PAGE_SHIFT); + memblock_reserve(PFN_PHYS(e1), (e0 - e1) << PAGE_SHIFT); + } else { + memblock_reserve(PFN_PHYS(s0), (e0 - s0) << PAGE_SHIFT); + } +#endif +} + /* * arch_mem_init - initialize memory management subsystem * @@ -780,6 +823,8 @@ static void __init request_crashkernel(struct resource *res) */ static void __init arch_mem_init(char **cmdline_p) { + unsigned int node; + unsigned long start_pfn, end_pfn; struct memblock_region *reg; extern void plat_mem_setup(void); @@ -877,6 +922,12 @@ static void __init arch_mem_init(char **cmdline_p) memblock_reserve(crashk_res.start, crashk_res.end - crashk_res.start + 1); #endif + for_each_online_node(node) { + get_pfn_range_for_nid(node, &start_pfn, &end_pfn); + reserve_crashm_region(node, start_pfn, end_pfn); + reserve_oldmem_region(node, start_pfn, end_pfn); + } + device_tree_init(); sparse_init(); plat_swiotlb_setup();