Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp734618rwd; Sat, 27 May 2023 05:48:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4opOtmLVykCKve9OzS+IRHyeyf4TARvx+j6SlfSakgtjaRl9AioyQUlHz+FRmOVTo9OBd7 X-Received: by 2002:a05:6a00:23ca:b0:63d:6744:8cae with SMTP id g10-20020a056a0023ca00b0063d67448caemr2781058pfc.2.1685191692558; Sat, 27 May 2023 05:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685191692; cv=none; d=google.com; s=arc-20160816; b=wYwO6J9qqDFZMUE+766JAa+0oMxB3yfthj9WXPqCGCmF4Ca3jiGzeGNp1MFal66Pl9 /jpbfFpNnNipQQBjc80ct4yJsiXwGtErQfFokyfZGbwq+vL9ztUPxLfb7ap3fwM4XL7B aW+1OmMpnhzKt3qb+kP2Ln+XFYzFkMIq3lfzMSREg6BT6YdIpIEp+39yYh98BBQ+JPtE EpjTteXlnyHMY2cHoL6lBUf7wa9k3TJtS6tpvibPhbOC+h58oJsntwWM42GAld49GxK4 +S9vpmfHJUyIcXErxbehKKYB2YtiIpL/QU+Pqna17oX4jAU9VhYt0+ZP19zwn+dvq/5l 8JrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=OOcY+sHm9fJ0kffIKHkwCH9dlshasPXkz2f2nY5cM78=; b=uDU3qxF4xI7gBjTxssyVLwipwzCqsGQsWXLSGNbe870uQxOmI5uJHG/w8s1ImcrILF JA41wq/E/zreq0KrGJ3Vcyl1uwDkmQAipcR7rF1+wZOXuXQ4EWLDsn21o93icUXLdtkz uYjcEmZBkNtM9GCkAtB2aNkSX7oN3Nk8nKpTw69k9OXqx0mBUANoLrLnJvNSmZbgrS/i Dna6y0MiCdD9DkuDT2zSQ/mETwE78Z1tOFfgpsrLvzCOI5WSBTdIlgReq374y7GIsji9 +jjWwEe18KUDSWxK3aUty8Hxn3YH+WOBOmjlC/Nc+LSkZelrt1/D9F3U+lpHLORGwpLZ ifsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q15-20020aa7842f000000b0064f6a531c88si6354892pfn.323.2023.05.27.05.47.58; Sat, 27 May 2023 05:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232532AbjE0MgM (ORCPT + 99 others); Sat, 27 May 2023 08:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232538AbjE0MgL (ORCPT ); Sat, 27 May 2023 08:36:11 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2FB135 for ; Sat, 27 May 2023 05:35:49 -0700 (PDT) Received: from dggpemm500006.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QT1SR3mYTzLm9y; Sat, 27 May 2023 20:34:15 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sat, 27 May 2023 20:35:46 +0800 From: Zhen Lei To: Eric Biederman , Baoquan He , , CC: Zhen Lei , Michael Holzheu , Andrew Morton , Amerigo Wang Subject: [PATCH 0/6] kexec: enable kexec_crash_size to support two crash kernel regions Date: Sat, 27 May 2023 20:34:33 +0800 Message-ID: <20230527123439.772-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When crashkernel=X fails to reserve region under 4G, it will fall back to reserve region above 4G and a region of the default size will also be reserved under 4G. Unfortunately, /sys/kernel/kexec_crash_size only supports one crash kernel region now, the user cannot sense the low memory reserved by reading /sys/kernel/kexec_crash_size. Also, low memory cannot be freed by writing this file. For example: resource_size(crashk_res) = 512M resource_size(crashk_low_res) = 256M The result of 'cat /sys/kernel/kexec_crash_size' is 512M, but it should be 768M. When we execute 'echo 0 > /sys/kernel/kexec_crash_size', the size of crashk_res becomes 0 and resource_size(crashk_low_res) is still 256 MB, which is incorrect. Since crashk_res manages the memory with high address and crashk_low_res manages the memory with low address, crashk_low_res is shrunken only when all crashk_res is shrunken. And because when there is only one crash kernel region, crashk_res is always used. Therefore, if all crashk_res is shrunken and crashk_low_res still exists, swap them. Zhen Lei (6): kexec: fix a memory leak in crash_shrink_memory() kexec: delete a useless check in crash_shrink_memory() kexec: clear crashk_res if all its memory has been released kexec: improve the readability of crash_shrink_memory() kexec: add helper __crash_shrink_memory() kexec: enable kexec_crash_size to support two crash kernel regions kernel/kexec_core.c | 92 +++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 28 deletions(-) -- 2.25.1