From patchwork Thu Mar 30 11:49:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 77153 Return-Path: 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 + 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 ); 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" To: Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , Mel Gorman , 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" 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 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: 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?= 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 --- 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); }