From patchwork Wed Dec 13 00:04:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 13490138 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 AB461C4332F for ; Wed, 13 Dec 2023 00:05:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4084D6B019E; Tue, 12 Dec 2023 19:05:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3912E6B01A2; Tue, 12 Dec 2023 19:05:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E4676B01A5; Tue, 12 Dec 2023 19:05:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 024906B019E for ; Tue, 12 Dec 2023 19:05:21 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C0462120A9B for ; Wed, 13 Dec 2023 00:05:20 +0000 (UTC) X-FDA: 81559850400.22.B583D05 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 9209516001C for ; Wed, 13 Dec 2023 00:05:18 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=X9Yt1Xsm; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf08.hostedemail.com: domain of "prvs=704f7accf=graf@amazon.de" designates 99.78.197.217 as permitted sender) smtp.mailfrom="prvs=704f7accf=graf@amazon.de" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702425918; 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:dkim-signature; bh=omkZqOlO4bdGSVCdXn2us+8UWaNPdUSggP3ul/1DY+c=; b=MC8xncBcZJYZuBvo47bho0cwHTGK/HilcT2iejjLmPI+BDSe4Hfc0s4X03lHnOnHthMvEE kU5dp3yeJZDANdfsTQt/DwJo8evUzP5g3fueioVWD7vmkMQ5M13HYe4hOXipkuht2AMICj VjI5fmCoLJ4QWnuxvtNvnnjQkFCzpM4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=X9Yt1Xsm; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf08.hostedemail.com: domain of "prvs=704f7accf=graf@amazon.de" designates 99.78.197.217 as permitted sender) smtp.mailfrom="prvs=704f7accf=graf@amazon.de" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702425918; a=rsa-sha256; cv=none; b=GXi8fCJZafSKQ3nK0DbtszSDrqn98blyPjY4r3n1g/iD0PuXAPrVYOxx2qC56SLzVJ/bkD 5mk40daeI3/fJbQDTxTiR5Z1v2bjUYTblVYCQ9RHmbEC2AvL7zCh1siyoU+O4G5Fvf9jIV zqUsKCIOXHtfqdauoA0zGs1v48kmpbM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1702425919; x=1733961919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=omkZqOlO4bdGSVCdXn2us+8UWaNPdUSggP3ul/1DY+c=; b=X9Yt1XsmBO8hon59sSvxtQj8sudWqrFA2eMdbdpBcQ7uvQVRzlSxKrQO OgbmJ+MikfkjHekk6fTOHfUOOaW5/W3wi27SdbsmJK7gFp6xC4x6MaBSN +v/6pCqlkBiJmxKg2mK6bWWImATRTVukCgdh4ubZa9hSTvH9GZbvI2+t8 Y=; X-IronPort-AV: E=Sophos;i="6.04,271,1695686400"; d="scan'208";a="258636775" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-d23e07e8.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 00:05:16 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1d-m6i4x-d23e07e8.us-east-1.amazon.com (Postfix) with ESMTPS id 8651A80643; Wed, 13 Dec 2023 00:05:07 +0000 (UTC) Received: from EX19MTAUWA001.ant.amazon.com [10.0.21.151:38785] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.34.165:2525] with esmtp (Farcaster) id ac23c6ff-3564-413c-9f1d-e68dec397645; Wed, 13 Dec 2023 00:05:06 +0000 (UTC) X-Farcaster-Flow-ID: ac23c6ff-3564-413c-9f1d-e68dec397645 Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWA001.ant.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 13 Dec 2023 00:05:06 +0000 Received: from dev-dsk-graf-1a-5ce218e4.eu-west-1.amazon.com (10.253.83.51) by EX19D020UWC004.ant.amazon.com (10.13.138.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 13 Dec 2023 00:05:02 +0000 From: Alexander Graf To: CC: , , , , , , , Eric Biederman , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Rob Herring" , Steven Rostedt , "Andrew Morton" , Mark Rutland , "Tom Lendacky" , Ashish Kalra , James Gowans , Stanislav Kinsburskii , , , , Anthony Yznaga , Usama Arif , David Woodhouse , Benjamin Herrenschmidt Subject: [PATCH 02/15] memblock: Declare scratch memory as CMA Date: Wed, 13 Dec 2023 00:04:39 +0000 Message-ID: <20231213000452.88295-3-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213000452.88295-1-graf@amazon.com> References: <20231213000452.88295-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.253.83.51] X-ClientProxiedBy: EX19D031UWC001.ant.amazon.com (10.13.139.241) To EX19D020UWC004.ant.amazon.com (10.13.138.149) X-Rspamd-Queue-Id: 9209516001C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ymc6hemajyaiy5799fnbrnp6typy4jai X-HE-Tag: 1702425918-549451 X-HE-Meta: U2FsdGVkX1/CLCtLGbKTStqdxG8tJg3vBSsxmNMybQLTwyhcVkLCq1DnLzEtT2IRAGNOMbIHAS/QqVLBerAeYX7ZjjHmJ/fYKtS+k8NgsLZ1teiUxc7af8lFj8CBmH0w49UZAsZolu6fQyQZnZs9VJhpOb9XomrTu8eWNo/ORrX076hQo2183GpqTVoYM8M7ynjc3lF16WjNMU0NNN1UQsADBvYZxzkoQDmIQPqcjx1Gpnn73m76ffVlZpbUt/n4ZzrHMv3E2dQhoBo8QDRHoh7AOHgWlmit6eBDYQkQytRgwd6KbDol8pZn2iS0lCdx62fqJw/lvhHIRTBi0SOJnVLA92BxzWCUQJLnjuiB3cZydZkvksDYkmJbB0zPnCRzmS+FiFxsW5d/xFnNRytaXLx2EUANL3qtujWdUmp6fKtcJ7PELUQoqYpdduxWyfrTqFf6r2U6g09DScTrymx3lW1TQG1GEn4FXeEoi7r+aqAslmtyK1fOMVm+E1kLHYBfxSiCyrUUATY9iazhzL3H5hnTaHx91Gu8KO+uCFPtnpDcCTZKODhMIpfSV4jrADunYxMdFJ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, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When we finish populating our memory, we don't want to lose the scratch region as memory we can use for useful data. Do do that, we mark it as CMA memory. That means that any allocation within it only happens with movable memory which we can then happily discard for the next kexec. That way we don't lose the scratch region's memory anymore for allocations after boot. Signed-off-by: Alexander Graf --- mm/memblock.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index e89e6c8f9d75..44741424dab7 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -1100,10 +1101,6 @@ static bool should_skip_region(struct memblock_type *type, if ((flags & MEMBLOCK_SCRATCH) && !memblock_is_scratch(m)) return true; - /* Leave scratch memory alone after scratch-only phase */ - if (!(flags & MEMBLOCK_SCRATCH) && memblock_is_scratch(m)) - return true; - return false; } @@ -2153,6 +2150,20 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end) } } +static void reserve_scratch_mem(phys_addr_t start, phys_addr_t end) +{ +#ifdef CONFIG_MEMBLOCK_SCRATCH + ulong start_pfn = pageblock_start_pfn(PFN_DOWN(start)); + ulong end_pfn = pageblock_align(PFN_UP(end)); + ulong pfn; + + for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { + /* Mark as CMA to prevent kernel allocations in it */ + set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_CMA); + } +#endif +} + static unsigned long __init __free_memory_core(phys_addr_t start, phys_addr_t end) { @@ -2214,6 +2225,17 @@ static unsigned long __init free_low_memory_core_early(void) memmap_init_reserved_pages(); +#ifdef CONFIG_MEMBLOCK_SCRATCH + /* + * Mark scratch mem as CMA before we return it. That way we ensure that + * no kernel allocations happen on it. That means we can reuse it as + * scratch memory again later. + */ + __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, + MEMBLOCK_SCRATCH, &start, &end, NULL) + reserve_scratch_mem(start, end); +#endif + /* * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id * because in some case like Node0 doesn't have RAM installed