From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1190DEB64DD for ; Sun, 30 Jul 2023 06:54:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16B0D8D0003; Sun, 30 Jul 2023 02:54:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 11BF98D0001; Sun, 30 Jul 2023 02:54:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 009F18D0003; Sun, 30 Jul 2023 02:54:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E0A808D0001 for ; Sun, 30 Jul 2023 02:54:35 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9DC7714086F for ; Sun, 30 Jul 2023 06:54:35 +0000 (UTC) X-FDA: 81067364910.25.705BBFC Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id E0B351C0009 for ; Sun, 30 Jul 2023 06:54:33 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XG5gPd+z; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690700074; a=rsa-sha256; cv=none; b=607hbkOSOLWFt84ey9tB66EZAHqYlvYZJUMdwhs0icru2bfhq/PCeRjTojEWSXlEHebRq4 nhS2QsYUEGfthp9oa8dhsMPaUIZ6Xc3zS/FqscBIKxmvIDRJjGrotKSXCPONFeYHVqLHk4 uZ5KFB8b8zqYy7bsAzfC7SORiinH+N8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XG5gPd+z; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690700074; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+K+F/EkzhzgEcDtCCx2/U7JERTjnaMTUEDqHiayBwSI=; b=nlv6yQFkbVyVGDv8q9DxAtDZL/XwKsMqfmaxlSMm7A2f9st3BifeWov8iRvrSu4LLZ+CI+ m9XZDohWywDyXcwPm2UOVyOiNWDPqQZdO2tQjtr8wpZCMqKmRJKMbGqcur62sMjV4wSYW/ 5V/vGx5cIBPboqh7W1UTNY2LVDpHENg= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D811860B68; Sun, 30 Jul 2023 06:54:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E5FFC433C8; Sun, 30 Jul 2023 06:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690700072; bh=RsD8d/vfrQpVJtmewGVDlM+4Khb7fzvS8k/vGcyrZdM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XG5gPd+z4nIAYhYanikh98tCwl/3yElC/ZMOWysCIv8vutL+74pyVp3z/toO8UpKF eGOe0SVBKKOG9bBKAZuEuldrcHdT6WB/1v2F68wvPNQbmonfPtAe8r75m8tZkE423r MN9hj764P/Tymz6PmC7nx+g60R2HxxxOfe7Cs1/myPTdRKQ05smvr60hG/RmQlxxdC svGIPokzPa8LUNlnCHc4MaiOPtUumDOPMDq9t18Rbf+Q+9kv4W0kiYBt5eRAhq13oV yU0GSHIZhtS2eo3ANa4IFrhBhNrj6iN78eoG62+bExYdwgvio3Zo0N3Jv62TDP+a0I JUtC5bWvK2JHA== Date: Sun, 30 Jul 2023 09:53:53 +0300 From: Mike Rapoport To: Kefeng Wang Cc: Wupeng Ma , akpm@linux-foundation.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: disable kernelcore=mirror when no mirror memory Message-ID: <20230730065353.GJ1901145@kernel.org> References: <20230728040124.4093229-1-mawupeng1@huawei.com> <20230729081218.GH1901145@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E0B351C0009 X-Stat-Signature: eurs9a9ws9sm3on3yizwnyhrmuhuyp4s X-HE-Tag: 1690700073-374565 X-HE-Meta: U2FsdGVkX19Jwb1ouEDASCt7ML4pfvHRhlk6TNobPRJhMqf8m9BUrCyHlFR+G7oUYkllGS7OydQRW0B/jlfbkuHNedWqvQ9/xC8YrJehGuKxF5VXuFB46pjEGY/lqtZ+DNNzsskPqEG4JUvidbIuiw1N49GTnqo54EBMt42nJUvTo/REcnUWfLXhATqXropMK/UiXrl62WjMVBSHaxGNlJMfsJsgKgZv2ejVsf7Ovbx8PxjZkpm20Z8SBSvMBKetEQNWIkgwrVvquBu5P8F7PKyWg5ONE4l+IC4gVa8Klz4CESORgicDg7kPyhwtFed0f4QzFCs0hjNW2dsYyS1QgLxZ3ms8mguOZyjrngMUnQRm68WQ2Sxpy5e1ARsRqqS6tfJOx8C7vcbRhiMAFzm+whuWQx0pDbNz6nyL1cCSx00r5duQIVEuXFpk9i1xlnOCJqHYWswqvPDGLqEvvRDuOdXJxACI5oQVImt6Y/zN/gndMD+HhMUp7qiknCV/b3KDGTPJSD1UeGmttK+onUwjwZ5YwpseKoGQu3Xy6URIRlyjPvZmJHm2+4WM4h4tqFPqFbCGbvv4BMX3TJDn77kXTtcPhT22ERl/fC0JmOf7NAUPjZXqze4mCxp5xmdyrgoKx1uFvVmXTLeNs9vZxVOVbGmKpOMVPU+xGJiN+uBZh9wpFgx4AHX56FyvBYN5KJbKgY2LPsa/8+2eStpyq6/M2bkdKrvdVq1nG/F9gvkIdh7k2P/qcVLtcpNRktmOQV10c0c2/9t0s9PYHl8yGMEGBnT2g/q8QCeMsIyxkoMeTdP0N0TkoF9xTgwmYOpMqIlPVByYeH21cpwx9HsgcvTZjIWl8PEzEscl/v0ngq/aUeVU9kMczrTySXk6wAhScqZnbjz98m+2HYnhNR2zZWOOd46qNvEyBrQa3tkksOkljU24GVrwV44+qJJoM7L4SkbUoKsbK0FjaxRNhUnVI15 Dbsz/mUY O0CG+eQtuKdf3pu8nDar2AzLHmIjh0xSAJlFiGnyTiuNIg9zvl9sZbtX3tAb2iIHfLo7Q/8yTuWEHFK7+SM9TYNRERphihh9AdeKL5b6KS9171+4TW8Z0vVnpYmh3vkki3LKc4wsOMaj5xreHoKfAlgW/yMVQ5E/gKAmUOvbkYGmFetuazkgql9WsjIDvFEEhsuzDq4mBCvEA+0hR7RGxs7k46LUUiQXESCYN5og+P4U1fxnunwAIh05dVqNgXxQrxs9e4ilkpXogaJD0OMDCfBlb6IThYZg3oC6Yp0sBoLwhVL+08/aFJcEcVQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, Jul 29, 2023 at 04:57:17PM +0800, Kefeng Wang wrote: > > > On 2023/7/29 16:12, Mike Rapoport wrote: > > On Fri, Jul 28, 2023 at 12:01:24PM +0800, Wupeng Ma wrote: > > > From: Ma Wupeng > > > > > > For system with kernelcore=mirror enabled while no mirrored memory is > > > reported by efi. This could lead to kernel OOM during startup since > > > all memory beside zone DMA are in the movable zone and this prevents > > > the kernel to use it. > > > > > > Zone DMA/DMA32 initialization is independent of mirrored memory and > > > their max pfn is set in zone_sizes_init(). Since kernel can fallback > > > to zone DMA/DMA32 if there is no memory in zone Normal, these zones > > > are seen as mirrored memory no mather their memory attributes are. > > > > Using kernelcore= and movablecore= always come with the risk there will be > > to little memory for the kernel to use. Even if EFI reports mirrored memory > > it's possible to have OOM with kernelcore=mirror because there could be > > just not enough mirrored memory. > > Yes, this is a big problem, could we add an option to move some > ZONE_MOVABLE pages into ZONE_NORMAL(MIGRATE_MOVABLE) when low free > memory?> > > > To solve this problem, disable kernelcore=mirror when there is no real > > > mirrored memory exists. > > > > > > Signed-off-by: Ma Wupeng > > > --- > > > mm/internal.h | 2 ++ > > > mm/memblock.c | 2 +- > > > mm/mm_init.c | 6 +++++- > > > 3 files changed, 8 insertions(+), 2 deletions(-) > > > > > > diff --git a/mm/internal.h b/mm/internal.h > > > index a7d9e980429a..98a03ac74ca7 100644 > > > --- a/mm/internal.h > > > +++ b/mm/internal.h > > > @@ -374,6 +374,8 @@ static inline void clear_zone_contiguous(struct zone *zone) > > > zone->contiguous = false; > > > } > > > +extern bool system_has_some_mirror; > > > + > > > extern int __isolate_free_page(struct page *page, unsigned int order); > > > extern void __putback_isolated_page(struct page *page, unsigned int order, > > > int mt); > > > diff --git a/mm/memblock.c b/mm/memblock.c > > > index f9e61e565a53..e7a7a65415fb 100644 > > > --- a/mm/memblock.c > > > +++ b/mm/memblock.c > > > @@ -156,10 +156,10 @@ static __refdata struct memblock_type *memblock_memory = &memblock.memory; > > > } while (0) > > > static int memblock_debug __initdata_memblock; > > > -static bool system_has_some_mirror __initdata_memblock; > > > static int memblock_can_resize __initdata_memblock; > > > static int memblock_memory_in_slab __initdata_memblock; > > > static int memblock_reserved_in_slab __initdata_memblock; > > > +bool system_has_some_mirror __initdata_memblock; > > > static enum memblock_flags __init_memblock choose_memblock_flags(void) > > > { > > > diff --git a/mm/mm_init.c b/mm/mm_init.c > > > index a1963c3322af..6267b9f75927 100644 > > > --- a/mm/mm_init.c > > > +++ b/mm/mm_init.c > > > @@ -269,7 +269,11 @@ static int __init cmdline_parse_kernelcore(char *p) > > > { > > > /* parse kernelcore=mirror */ > > > if (parse_option_str(p, "mirror")) { > > > - mirrored_kernelcore = true; > > > + if (system_has_some_mirror) > > > + mirrored_kernelcore = true; > > > > On many architectures early parameters are parsed before memblock is setup, > > so system_has_some_mirror will always be true. > > Only x86/arm64 support kernelcore=mirror, system_has_some_mirror is > false by default, so it should no issue for now, but it is better to > move this check into find_zone_movable_pfns_for_nodes(). Sorry, I meant that system_has_some_mirror is false by default, and both x86/arm64 parse early parameters before they set up memblock, so system_has_some_mirror will be always false at this point. > > > + else > > > + pr_warn("The system has no mirror memory, disable kernelcore=mirror.\n"); > > > + > > > return 0; > > > } > > > -- > > > 2.25.1 > > > > > -- Sincerely yours, Mike.