Message ID | 20230330114956.20342-4-kirill.shutemov@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1067288vqo; Thu, 30 Mar 2023 04:57:36 -0700 (PDT) X-Google-Smtp-Source: AK7set/j6G9sgDdeCe+UWIp8fkErIYfIpea5krKyN6m0QHc/wRfaWFQp1M3AlefqVN3Pq49SK82b X-Received: by 2002:a05:6a20:c426:b0:d5:e640:15ec with SMTP id en38-20020a056a20c42600b000d5e64015ecmr19872169pzb.29.1680177455864; Thu, 30 Mar 2023 04:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680177455; cv=none; d=google.com; s=arc-20160816; b=XY7uW5SWMig4Bv7kaj2ggXlO6uTr7uI9jtO0CvCMX1HtwSY+b9A0J+g3h+EaGXvC++ jgVEUeSOoroQw44Gj9kPoU+Kf8mUSdnLMkEOWsSsp7kWDL9a1W0XCMPayiXImcxQdadU TtCLR34jsBJt1VL0zHS8VpjKH/znH7qL5jvNWmG5Wk8CMi4YvUeehFz1ZSDFPQNa9bjN ZFwKv3MU4IqAVJPEK524qHiB/4+R3Dvo4BCvaLysxz2flUAobgzzu4NtuIerqUNhCE2A e91Cd0D6Q1rzq7jxGaq7f6o8kJv2sIJQkmEhd+tbISoq2q5mEh1r0Ca/785wCmE0A+JQ xgrg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3Xcx87+8at3w01ECUa4i8O3uXEYYImpaB9iORG5znps=; b=lNQY/ch8zb7K/sYOocYtu2tjMOy7dqMnC1KOS0MtR6Mhf3Tdd/lGwhLuCfLwTxu2uF y5Y7o/iCF2rgBHuCTAwn7z+GQM2KpmOAH5rygtM9peeTGDhlPekKdWbeKypUtsEKBmCg oEAhVyKDM6YlapWd5jbUC1ObhMVRtBJuoi6NlW3zEzcVrjBYOt1shuBusQCI7vvjPV5U WBKpD8BHRFbH2C6FQS1ntUcwchkURdRiRGIgkO+e7A3zyh32MyK0MA9uubyMi3SrWX/q 7eEEmdkoeE0PC+ePubpgbLAMqYuBXbKJ1EtTLVlkwEn9/Tywwomm2PEa4pv2IrrN2s/z 62Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jJl+1eQB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l192-20020a6391c9000000b004fb7e7d565asi2938414pge.651.2023.03.30.04.57.22; Thu, 30 Mar 2023 04:57:35 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=jJl+1eQB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231585AbjC3LvD (ORCPT <rfc822;rua109.linux@gmail.com> + 99 others); Thu, 30 Mar 2023 07:51:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231727AbjC3Luk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 30 Mar 2023 07:50:40 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB87F8A5B; Thu, 30 Mar 2023 04:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177031; x=1711713031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j9rCoZtseVkMxXJK20bhOG6vjoCUVN6BwYUe9lsjGyo=; b=jJl+1eQBQQejUCWSPKVgpFg5Jv+fiP9ujTka/dwPCrfhnD91l75vC2V8 lYfxcAbCGvzB38MWhmthHwv9kTLOW4E3jqrYUwkMOCobSZNZOMLBvGbUC C3PTnNzbh+zxpI2FkevBtvAZUwgHoD/jnoo6Lh6nSqBh3LRU8O/TMQOsB KZB0g/YoOI8GMZMBrY7j32QTX13PuynkQPl7ZFTHRi7nY+5TnkWePUzL7 gTeQ8IytE/wF2ZgtFjGm80AIpuo00av31vjZ84psxZaeqNmgAfpfPny0g tCMn6OoqodBOJ6BwqxAWgOkaHisvCpK3HJVZb4hVuzhooVm0I+WHHYzYH Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="342756723" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="342756723" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="634856482" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="634856482" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:02 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 0612B10438E; Thu, 30 Mar 2023 14:50:00 +0300 (+03) From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>, Sean Christopherson <seanjc@google.com>, Andrew Morton <akpm@linux-foundation.org>, Joerg Roedel <jroedel@suse.de>, Ard Biesheuvel <ardb@kernel.org> Cc: Andi Kleen <ak@linux.intel.com>, Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>, David Rientjes <rientjes@google.com>, Vlastimil Babka <vbabka@suse.cz>, Tom Lendacky <thomas.lendacky@amd.com>, Thomas Gleixner <tglx@linutronix.de>, Peter Zijlstra <peterz@infradead.org>, Paolo Bonzini <pbonzini@redhat.com>, Ingo Molnar <mingo@redhat.com>, Dario Faggioli <dfaggioli@suse.com>, Dave Hansen <dave.hansen@intel.com>, Mike Rapoport <rppt@kernel.org>, David Hildenbrand <david@redhat.com>, Mel Gorman <mgorman@techsingularity.net>, marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Subject: [PATCHv9 03/14] mm/page_alloc: Fake unaccepted memory Date: Thu, 30 Mar 2023 14:49:45 +0300 Message-Id: <20230330114956.20342-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761793756006982526?= X-GMAIL-MSGID: =?utf-8?q?1761793756006982526?= |
Series |
mm, x86/cc: Implement support for unaccepted memory
|
|
Commit Message
Kirill A. Shutemov
March 30, 2023, 11:49 a.m. UTC
For testing purposes, it is useful to fake unaccepted memory in the
system. It helps to understand unaccepted memory overhead to the page
allocator.
The patch allows to treat memory above the specified physical memory
address as unaccepted.
The change only fakes unaccepted memory for page allocator. Memblock is
not affected.
It also assumes that arch-provided accept_memory() on already accepted
memory is a nop.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
mm/page_alloc.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
Comments
On 3/30/23 13:49, Kirill A. Shutemov wrote: > For testing purposes, it is useful to fake unaccepted memory in the > system. It helps to understand unaccepted memory overhead to the page > allocator. Ack on being useful for testing, but the question is if we want to also merge this patch into mainline as it is? > The patch allows to treat memory above the specified physical memory > address as unaccepted. > > The change only fakes unaccepted memory for page allocator. Memblock is > not affected. > > It also assumes that arch-provided accept_memory() on already accepted > memory is a nop. I guess to be in mainline it would have to at least gracefully handle the case of accept_memory actually not being a nop, and running on a system with actual unaccepted memory (probably by ignoring the parameter in such case). Then also the parameter would have to be documented. Speaking of documented parameters, I found at least two that seem a more generic variant of this (but I didn't look closely if that makes sense): efi_fake_mem= nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI; X86] Add arbitrary attribute to specific memory range by updating original EFI memory map. memmap=<size>%<offset>-<oldtype>+<newtype> [KNL,ACPI] Convert memory within the specified region from <oldtype> to <newtype>. If "-<oldtype>" is left Would any of those be usable for this usecase? > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> > --- > mm/page_alloc.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index d62fcb2f28bd..509a93b7e5af 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -7213,6 +7213,8 @@ static DEFINE_STATIC_KEY_FALSE(zones_with_unaccepted_pages); > > static bool lazy_accept = true; > > +static unsigned long fake_unaccepted_start = -1UL; > + > static int __init accept_memory_parse(char *p) > { > if (!strcmp(p, "lazy")) { > @@ -7227,11 +7229,30 @@ static int __init accept_memory_parse(char *p) > } > early_param("accept_memory", accept_memory_parse); > > +static int __init fake_unaccepted_start_parse(char *p) > +{ > + if (!p) > + return -EINVAL; > + > + fake_unaccepted_start = memparse(p, &p); > + > + if (*p != '\0') { > + fake_unaccepted_start = -1UL; > + return -EINVAL; > + } > + > + return 0; > +} > +early_param("fake_unaccepted_start", fake_unaccepted_start_parse); > + > static bool page_contains_unaccepted(struct page *page, unsigned int order) > { > phys_addr_t start = page_to_phys(page); > phys_addr_t end = start + (PAGE_SIZE << order); > > + if (start >= fake_unaccepted_start) > + return true; > + > return range_contains_unaccepted_memory(start, end); > } >
On Mon, Apr 03, 2023 at 03:39:53PM +0200, Vlastimil Babka wrote: > On 3/30/23 13:49, Kirill A. Shutemov wrote: > > For testing purposes, it is useful to fake unaccepted memory in the > > system. It helps to understand unaccepted memory overhead to the page > > allocator. > > Ack on being useful for testing, but the question is if we want to also > merge this patch into mainline as it is? I don't insist on getting it upstream, but it can be handy to debug related bugs in the future. > > The patch allows to treat memory above the specified physical memory > > address as unaccepted. > > > > The change only fakes unaccepted memory for page allocator. Memblock is > > not affected. > > > > It also assumes that arch-provided accept_memory() on already accepted > > memory is a nop. > > I guess to be in mainline it would have to at least gracefully handle the > case of accept_memory actually not being a nop, and running on a system with > actual unaccepted memory (probably by ignoring the parameter in such case). > Then also the parameter would have to be documented. As it is written now, accept_memory() is nop on system with real unaccepted memory if the memory is already accepted. Arch-specific code will check against own records to see if the memory needs accepting. If not, just return. And the option will not interfere with unaccepted memory declared by EFI memmap. It can extend it, but that's it. Looks safe to me. > Speaking of documented parameters, I found at least two that seem a more > generic variant of this (but I didn't look closely if that makes sense): > > efi_fake_mem= nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI; X86] > Add arbitrary attribute to specific memory range by > updating original EFI memory map. > > memmap=<size>%<offset>-<oldtype>+<newtype> > [KNL,ACPI] Convert memory within the specified region > from <oldtype> to <newtype>. If "-<oldtype>" is left > > Would any of those be usable for this usecase? Oh. I missed them. Will take a closer look. > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> > > --- > > mm/page_alloc.c | 21 +++++++++++++++++++++ > > 1 file changed, 21 insertions(+) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index d62fcb2f28bd..509a93b7e5af 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -7213,6 +7213,8 @@ static DEFINE_STATIC_KEY_FALSE(zones_with_unaccepted_pages); > > > > static bool lazy_accept = true; > > > > +static unsigned long fake_unaccepted_start = -1UL; > > + > > static int __init accept_memory_parse(char *p) > > { > > if (!strcmp(p, "lazy")) { > > @@ -7227,11 +7229,30 @@ static int __init accept_memory_parse(char *p) > > } > > early_param("accept_memory", accept_memory_parse); > > > > +static int __init fake_unaccepted_start_parse(char *p) > > +{ > > + if (!p) > > + return -EINVAL; > > + > > + fake_unaccepted_start = memparse(p, &p); > > + > > + if (*p != '\0') { > > + fake_unaccepted_start = -1UL; > > + return -EINVAL; > > + } > > + > > + return 0; > > +} > > +early_param("fake_unaccepted_start", fake_unaccepted_start_parse); > > + > > static bool page_contains_unaccepted(struct page *page, unsigned int order) > > { > > phys_addr_t start = page_to_phys(page); > > phys_addr_t end = start + (PAGE_SIZE << order); > > > > + if (start >= fake_unaccepted_start) > > + return true; > > + > > return range_contains_unaccepted_memory(start, end); > > } > > >
On 30.03.23 13:49, Kirill A. Shutemov wrote: > For testing purposes, it is useful to fake unaccepted memory in the > system. It helps to understand unaccepted memory overhead to the page > allocator. > > The patch allows to treat memory above the specified physical memory > address as unaccepted. > > The change only fakes unaccepted memory for page allocator. Memblock is > not affected. > > It also assumes that arch-provided accept_memory() on already accepted > memory is a nop. > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> > --- > mm/page_alloc.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index d62fcb2f28bd..509a93b7e5af 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -7213,6 +7213,8 @@ static DEFINE_STATIC_KEY_FALSE(zones_with_unaccepted_pages); > > static bool lazy_accept = true; > > +static unsigned long fake_unaccepted_start = -1UL; > + > static int __init accept_memory_parse(char *p) > { > if (!strcmp(p, "lazy")) { > @@ -7227,11 +7229,30 @@ static int __init accept_memory_parse(char *p) > } > early_param("accept_memory", accept_memory_parse); > > +static int __init fake_unaccepted_start_parse(char *p) > +{ > + if (!p) > + return -EINVAL; > + > + fake_unaccepted_start = memparse(p, &p); > + > + if (*p != '\0') { > + fake_unaccepted_start = -1UL; > + return -EINVAL; > + } > + > + return 0; > +} > +early_param("fake_unaccepted_start", fake_unaccepted_start_parse); > + > static bool page_contains_unaccepted(struct page *page, unsigned int order) > { > phys_addr_t start = page_to_phys(page); > phys_addr_t end = start + (PAGE_SIZE << order); > > + if (start >= fake_unaccepted_start) > + return true; > + > return range_contains_unaccepted_memory(start, end); > } > The "unpleasant" thing about this is, that page_contains_unaccepted() could not be used for sanity checks because the result is static. For example, something like if (page_contains_unaccepted(page, 0)) accept_memory(page, 0); BUG_ON(!page_contains_unaccepted(page, 0)); Would work on real hardware, however, not for the fake variant.
On Mon, Apr 03, 2023 at 04:43:08PM +0200, David Hildenbrand wrote: > On 30.03.23 13:49, Kirill A. Shutemov wrote: > > For testing purposes, it is useful to fake unaccepted memory in the > > system. It helps to understand unaccepted memory overhead to the page > > allocator. > > > > The patch allows to treat memory above the specified physical memory > > address as unaccepted. > > > > The change only fakes unaccepted memory for page allocator. Memblock is > > not affected. > > > > It also assumes that arch-provided accept_memory() on already accepted > > memory is a nop. > > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> > > --- > > mm/page_alloc.c | 21 +++++++++++++++++++++ > > 1 file changed, 21 insertions(+) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index d62fcb2f28bd..509a93b7e5af 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -7213,6 +7213,8 @@ static DEFINE_STATIC_KEY_FALSE(zones_with_unaccepted_pages); > > static bool lazy_accept = true; > > +static unsigned long fake_unaccepted_start = -1UL; > > + > > static int __init accept_memory_parse(char *p) > > { > > if (!strcmp(p, "lazy")) { > > @@ -7227,11 +7229,30 @@ static int __init accept_memory_parse(char *p) > > } > > early_param("accept_memory", accept_memory_parse); > > +static int __init fake_unaccepted_start_parse(char *p) > > +{ > > + if (!p) > > + return -EINVAL; > > + > > + fake_unaccepted_start = memparse(p, &p); > > + > > + if (*p != '\0') { > > + fake_unaccepted_start = -1UL; > > + return -EINVAL; > > + } > > + > > + return 0; > > +} > > +early_param("fake_unaccepted_start", fake_unaccepted_start_parse); > > + > > static bool page_contains_unaccepted(struct page *page, unsigned int order) > > { > > phys_addr_t start = page_to_phys(page); > > phys_addr_t end = start + (PAGE_SIZE << order); > > + if (start >= fake_unaccepted_start) > > + return true; > > + > > return range_contains_unaccepted_memory(start, end); > > } > > The "unpleasant" thing about this is, that page_contains_unaccepted() could > not be used for sanity checks because the result is static. > > For example, something like > > if (page_contains_unaccepted(page, 0)) > accept_memory(page, 0); > BUG_ON(!page_contains_unaccepted(page, 0)); > > Would work on real hardware, however, not for the fake variant. Need for raw_page_contains_unaccepted()? :P
On Mon, Apr 03, 2023 at 05:39:15PM +0300, Kirill A. Shutemov wrote: > On Mon, Apr 03, 2023 at 03:39:53PM +0200, Vlastimil Babka wrote: > > On 3/30/23 13:49, Kirill A. Shutemov wrote: > > > For testing purposes, it is useful to fake unaccepted memory in the > > > system. It helps to understand unaccepted memory overhead to the page > > > allocator. > > > > Ack on being useful for testing, but the question is if we want to also > > merge this patch into mainline as it is? > > I don't insist on getting it upstream, but it can be handy to debug > related bugs in the future. > > > > The patch allows to treat memory above the specified physical memory > > > address as unaccepted. > > > > > > The change only fakes unaccepted memory for page allocator. Memblock is > > > not affected. > > > > > > It also assumes that arch-provided accept_memory() on already accepted > > > memory is a nop. > > > > I guess to be in mainline it would have to at least gracefully handle the > > case of accept_memory actually not being a nop, and running on a system with > > actual unaccepted memory (probably by ignoring the parameter in such case). > > Then also the parameter would have to be documented. > > As it is written now, accept_memory() is nop on system with real > unaccepted memory if the memory is already accepted. Arch-specific code > will check against own records to see if the memory needs accepting. If > not, just return. > > And the option will not interfere with unaccepted memory declared by EFI > memmap. It can extend it, but that's it. > > Looks safe to me. > > > Speaking of documented parameters, I found at least two that seem a more > > generic variant of this (but I didn't look closely if that makes sense): > > > > efi_fake_mem= nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI; X86] > > Add arbitrary attribute to specific memory range by > > updating original EFI memory map. As of now, efi_fake_mem= can adjust attributes of memory. Unaccepted is type of memory, not an attribute. I guess we can allow it override type too. But syntax is going to be fun. > > memmap=<size>%<offset>-<oldtype>+<newtype> > > [KNL,ACPI] Convert memory within the specified region > > from <oldtype> to <newtype>. If "-<oldtype>" is left It overrides E820 map, but unaccepted memory is not represented there. Unaccepted memory is just RAM in E820.
On Mon, Apr 03, 2023 at 06:50:11PM +0300, Kirill A. Shutemov wrote: > On Mon, Apr 03, 2023 at 05:39:15PM +0300, Kirill A. Shutemov wrote: > > On Mon, Apr 03, 2023 at 03:39:53PM +0200, Vlastimil Babka wrote: > > > On 3/30/23 13:49, Kirill A. Shutemov wrote: > > > > For testing purposes, it is useful to fake unaccepted memory in the > > > > system. It helps to understand unaccepted memory overhead to the page > > > > allocator. > > > > > > Ack on being useful for testing, but the question is if we want to also > > > merge this patch into mainline as it is? > > > > I don't insist on getting it upstream, but it can be handy to debug > > related bugs in the future. > > > > > > The patch allows to treat memory above the specified physical memory > > > > address as unaccepted. > > > > > > > > The change only fakes unaccepted memory for page allocator. Memblock is > > > > not affected. > > > > > > > > It also assumes that arch-provided accept_memory() on already accepted > > > > memory is a nop. > > > > > > I guess to be in mainline it would have to at least gracefully handle the > > > case of accept_memory actually not being a nop, and running on a system with > > > actual unaccepted memory (probably by ignoring the parameter in such case). > > > Then also the parameter would have to be documented. > > > > As it is written now, accept_memory() is nop on system with real > > unaccepted memory if the memory is already accepted. Arch-specific code > > will check against own records to see if the memory needs accepting. If > > not, just return. > > > > And the option will not interfere with unaccepted memory declared by EFI > > memmap. It can extend it, but that's it. > > > > Looks safe to me. > > > > > Speaking of documented parameters, I found at least two that seem a more > > > generic variant of this (but I didn't look closely if that makes sense): > > > > > > efi_fake_mem= nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI; X86] > > > Add arbitrary attribute to specific memory range by > > > updating original EFI memory map. > > As of now, efi_fake_mem= can adjust attributes of memory. Unaccepted is > type of memory, not an attribute. I guess we can allow it override type > too. But syntax is going to be fun. efi_fake_mem applied too late. Bitmap that represents unaccepted memory for kernel created at kernel decompression stage, but efi_fake_mem= handled in main kernel. I don't think pushing efi_fake_mem to decompressor makes sesne. I would rather drom the feature altogether.
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d62fcb2f28bd..509a93b7e5af 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7213,6 +7213,8 @@ static DEFINE_STATIC_KEY_FALSE(zones_with_unaccepted_pages); static bool lazy_accept = true; +static unsigned long fake_unaccepted_start = -1UL; + static int __init accept_memory_parse(char *p) { if (!strcmp(p, "lazy")) { @@ -7227,11 +7229,30 @@ static int __init accept_memory_parse(char *p) } early_param("accept_memory", accept_memory_parse); +static int __init fake_unaccepted_start_parse(char *p) +{ + if (!p) + return -EINVAL; + + fake_unaccepted_start = memparse(p, &p); + + if (*p != '\0') { + fake_unaccepted_start = -1UL; + return -EINVAL; + } + + return 0; +} +early_param("fake_unaccepted_start", fake_unaccepted_start_parse); + static bool page_contains_unaccepted(struct page *page, unsigned int order) { phys_addr_t start = page_to_phys(page); phys_addr_t end = start + (PAGE_SIZE << order); + if (start >= fake_unaccepted_start) + return true; + return range_contains_unaccepted_memory(start, end); }