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 22B24EB64DD for ; Mon, 31 Jul 2023 02:06:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64FD56B00A9; Sun, 30 Jul 2023 22:06:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FF8F6B00AA; Sun, 30 Jul 2023 22:06:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EE346B00AB; Sun, 30 Jul 2023 22:06:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4160E6B00A9 for ; Sun, 30 Jul 2023 22:06:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 068B51409EB for ; Mon, 31 Jul 2023 02:06:51 +0000 (UTC) X-FDA: 81070268664.08.16D87FE Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf23.hostedemail.com (Postfix) with ESMTP id D9A2B14000B for ; Mon, 31 Jul 2023 02:06:48 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690769210; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OrLIA+NFq5YjdESmlWMzt7Jk9LXftN7eFgLJgB/9Jzg=; b=429LV06fkeozVO7vvJnZ/28EKllTHPEnzRA4nSSFPHezlU/buFpVeOgH8jFSJ8ylkWG50T 3Arluvcs3moztsn27vqlZQveTiEc1ses0Uz2v4B7W/6Ki5tNf8N3UT2AtPfoU7a6qaeYTp JpwQRW4przdw3SpPRi/n1CbpoDwgG+w= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690769210; a=rsa-sha256; cv=none; b=4hV5I6HPjEtYJHXs01a1TpNGjICH01SOmKg7Z7rpMsWPhgcwREwXACNSncrpxZCnOOy8Go +UYRnFcacOH3gIUhiZj2Rdz6Hl7jEFylAP8p1Ny9Ti+kGXqVD6PdcHkluqg3FlOhsmSz7J KIOIte8fdgXlc2bi+E8NI++/hlhoD64= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RDhRD6h3PzrRy6; Mon, 31 Jul 2023 10:05:44 +0800 (CST) Received: from [10.174.178.120] (10.174.178.120) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 31 Jul 2023 10:06:44 +0800 Message-ID: <921f5590-268d-fdd6-e319-a496d79a4b3c@huawei.com> Date: Mon, 31 Jul 2023 10:06:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird CC: , , Subject: Re: [PATCH] mm: disable kernelcore=mirror when no mirror memory Content-Language: en-US To: , References: <20230728040124.4093229-1-mawupeng1@huawei.com> <20230729081218.GH1901145@kernel.org> <20230730065353.GJ1901145@kernel.org> From: mawupeng In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.120] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: D9A2B14000B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fkopbcdy1y9i5o11f9ff6xmhnid8q4wj X-HE-Tag: 1690769208-827803 X-HE-Meta: U2FsdGVkX18AuQkcGoRCrSX7KFb/lNnPoQat8EY6yti1Le0B9qVv+Ydynz8hemRg7RcUs0YeDzZKibukQDPBs9iQ8D2S9KNZOspCVUh3ei41BWSk7Nvdx9fbXf/uMD9hROVxfW8FhVIPm305/xzSwErlvfX5p3+LzilHQjHKLdLOUaYqmgXhPPZFckc3PnEXUcN6U1AbBJxVZK+83yMAI7imb4ygaBurxMXllzFInju9+fq6RGlnFeMqOMEBF2NR3IJkdiAcedemdFudbYqbMilq1dK2+xz34AlcDK5T+smBMgLjZZ4Aed1YscuKdpqE1Ie5A3RFPoAY7ENareI7BEzmFFpd16tkc2D3hGwZXMm5YZDonHQsayPHs3W0DvqgK7O6wAxS1lGWQSFBs5/ZMXU8wgqZaEGV9MWaDtrfKv8OWTo+nFn+B4TtDUP0rrTyicqXNFcHXMm5N8bSYS4aU9l6u7gZlttCewO4OesiXspHaBXJAM8IHze1PAkz5JN55k1qu2lqAj+v/RVGq/wddT4fJL/Lva1NY4BNirQAKqZ7sTE1kDyygc5Et0QjxeYPUZAQlOa8/ULsULA9AhLyyqymQ3frDwrA20lEgtM31a7z0FaClbkw7XuY39CExOb1HEJmtevBc1+X20Ra6k5ROKGujI9pvv4pdyeGVWad9JP4cPYThafsv/Au6N1830HpI85VT0nRXNcaC8FbysW6fsw1sy2g3LtCxMA460TRgpLh2JOvN7dG5uMY6h/8SEC7nfCWxCvlinHrOl6LGwkZ4TccXSQ8IrPcwQC3xcRlX6pESQu11dG1tmzyvIVBXD9lL3ISp+c1hKQoJc7wzxfnbmrP3Uoq1XQ74i2nQtNhdsrW3BXxmvRiV74oprNTm1GOqM9BEtvjbVOwpZofkjJjEhlR99RMv/Ss1mcrHJTLYbMbbajJqcN4G3Ibxh/RKVkoLat//kEzPDJCajdHjIo e1e+kw2n wsgtBPmv5pf9Gj66muNFxvUb/rubm5BJw8ovAT87/IwK5/mY6UqWU9asz+TflQLAriZQFFIkpUeszUZl+6CeC3qNhaoqYBCfYYLYXWQvh8u8nXbRYaCT9r46sn/vpmCtnqQHM59bD6fprtliiITud4b1Ni8b56DmqLeusmwfCQekhidUH/AdZJIMQTUvid4A/Gw6M 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 2023/7/31 9:39, Kefeng Wang wrote: > > > On 2023/7/30 14:53, Mike Rapoport wrote: >> 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. > > Clear, so let's move check into find_zone_movable_pfns_for_nodes()(no test), is this ok? > > diff --git a/mm/internal.h b/mm/internal.h > index a7d9e980429a..1599becc9079 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -1005,6 +1005,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma, >  } > >  extern bool mirrored_kernelcore; > +extern bool system_has_some_mirror; > >  static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma) >  { > 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..c444da6065a6 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -377,6 +377,11 @@ static void __init find_zone_movable_pfns_for_nodes(void) >      if (mirrored_kernelcore) { >          bool mem_below_4gb_not_mirrored = false; > > +        if (!system_has_some_mirror) { > +            pr_warn("The system has no mirror memory, ignore kernelcore=mirror.\n"); > +            goto out; > +        } > + >          for_each_mem_region(r) { >              if (memblock_is_mirror(r)) >                  continue; Test on 6.5.0-rc3-next-20230728, everything works fine.