Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751169AbdCQK5Q (ORCPT ); Fri, 17 Mar 2017 06:57:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55344 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbdCQK5P (ORCPT ); Fri, 17 Mar 2017 06:57:15 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BE78E445DE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=xlpang@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BE78E445DE From: Xunlei Pang To: linux-kernel@vger.kernel.org, kexec@lists.infradead.org Cc: akpm@linux-foundation.org, Eric Biederman , Dave Young , Baoquan He , "H. Peter Anvin" , Ingo Molnar , x86@kernel.org, Xunlei Pang Subject: [PATCH] x86_64, kexec: Avoid unnecessary identity mappings for kdump Date: Fri, 17 Mar 2017 18:22:30 +0800 Message-Id: <1489746150-28364-1-git-send-email-xlpang@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 17 Mar 2017 10:20:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2297 Lines: 70 kexec setups identity mappings for all the memory mapped in 1st kernel, this is not necessary for the kdump case. Actually it can cause extra memory consumption for paging structures, which is quite considerable on modern machines with huge memory. E.g. On our 24TB machine, it will waste around 96MB (around 4MB/TB) from the reserved memory range if setting all the identity mappings. It also causes some trouble for distributions that use an intelligent policy to evaluate the proper "crashkernel=X" for users. To solve it, in case of kdump, we only setup identity mappings for the crash memory and the ISA memory(may be needed by purgatory/kdump boot). Signed-off-by: Xunlei Pang --- arch/x86/kernel/machine_kexec_64.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 857cdbd..db77a76 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -112,14 +112,40 @@ static int init_pgtable(struct kimage *image, unsigned long start_pgtable) level4p = (pgd_t *)__va(start_pgtable); clear_page(level4p); - for (i = 0; i < nr_pfn_mapped; i++) { - mstart = pfn_mapped[i].start << PAGE_SHIFT; - mend = pfn_mapped[i].end << PAGE_SHIFT; + if (image->type == KEXEC_TYPE_CRASH) { + /* Always map the ISA range */ result = kernel_ident_mapping_init(&info, - level4p, mstart, mend); + level4p, 0, ISA_END_ADDRESS); if (result) return result; + + /* crashk_low_res may not be initialized when reaching here */ + if (crashk_low_res.end) { + mstart = crashk_low_res.start; + mend = crashk_low_res.end + 1; + result = kernel_ident_mapping_init(&info, + level4p, mstart, mend); + if (result) + return result; + } + + mstart = crashk_res.start; + mend = crashk_res.end + 1; + result = kernel_ident_mapping_init(&info, + level4p, mstart, mend); + if (result) + return result; + } else { + for (i = 0; i < nr_pfn_mapped; i++) { + mstart = pfn_mapped[i].start << PAGE_SHIFT; + mend = pfn_mapped[i].end << PAGE_SHIFT; + + result = kernel_ident_mapping_init(&info, + level4p, mstart, mend); + if (result) + return result; + } } /* -- 1.8.3.1