From patchwork Sun Jul 30 15:16:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13333454 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 BEC17C001DF for ; Sun, 30 Jul 2023 15:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E25D2900003; Sun, 30 Jul 2023 11:16:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD528900002; Sun, 30 Jul 2023 11:16:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C28C2900003; Sun, 30 Jul 2023 11:16:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B010D900002 for ; Sun, 30 Jul 2023 11:16:16 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8BC741601C7 for ; Sun, 30 Jul 2023 15:16:16 +0000 (UTC) X-FDA: 81068629152.24.79D355E Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by imf02.hostedemail.com (Postfix) with ESMTP id A40FE80015 for ; Sun, 30 Jul 2023 15:16:14 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="W/lVFu8o"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of usama.arif@bytedance.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=usama.arif@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690730174; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sRlgK3gsc81CRpAMRRPsywIlI5j9OUiW8IxZjNa20o0=; b=v3dudHXarJYWzuRBKs50YKnPM0Nie5CMWqcuNKIjpIga6fKhRhmZpWMO7j6VBTGJHgsGiz dzh+3JLMEClFn1yAfHkaIeNt2qMhG1Wos6TxLPZ+u0mXfA/ymEzj0somcYr9yBj0VOMIvt iAJilgRxBwY5PE0rj1piZHAF7DFK+lg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="W/lVFu8o"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of usama.arif@bytedance.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=usama.arif@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690730174; a=rsa-sha256; cv=none; b=8ocWL4wiwWWfjtNfq56NCtarftvfqyveIvPVpRSYqTqBUZSrSZBOehq/CzamgQOFVhr5j2 OXdDKm5YtqRzxI7daazdARHiU/kvtFuTClNOx4pp84yaSe/jLAWhKl1qWRqmxl5/KPtyfL Q8WqdVD22rUKSODDAGLiofawC2ax2Ws= Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-3fe2048c910so2025525e9.1 for ; Sun, 30 Jul 2023 08:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690730173; x=1691334973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sRlgK3gsc81CRpAMRRPsywIlI5j9OUiW8IxZjNa20o0=; b=W/lVFu8oBYOHaQON2+IUAE4OeTID9l1Wz5BLxJdEu8LJBB9z/KErJPNGKn4gPKcqET TOz183J9eC9oj+adoUW1wOIA2x17GqKNs+kATE99/ZRY8Fjp8O5VirlHjPixUUm43ku4 z+wT3z1JbZFobFUIlYBs/gN3XFoPKT2xOzlfLL6MoMgEtn/SiRo+2YI4xg86K/JhVl3i MuhecVQM9cEuPwUzqT4PGXvn5nnp3Ror/whrcq0G86C37cVp/BcEGPKbi/b5/niap3Zq DtL+erRe6APzX6GQNORLFAEQj9gidto4zepL9icunXIYosg8Xv4r0ivr6Y0+U81B8I1M t8+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690730173; x=1691334973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sRlgK3gsc81CRpAMRRPsywIlI5j9OUiW8IxZjNa20o0=; b=cd/xGjf7YFe4vDAVswo1b7NB/me1a3NiLyKOGuqdZ2DXSKD4uUTnkZ6RCEeHMdJgn2 NtAQlm2zcbitIzxS+TH54TRgryK2FwhIP4Sm4QknaKfoiuGXM1bu9El0MAD4cQcZGXfQ t5TrVgr0cw06NBl5eCwEhfqp9BptfrQUNcY/as0htzyoz5MNt95Sief42V7CYZQNlw/n orOXmMw/ANCv8zjUJjoEZz61A34M2jjr7zM8knz1IRa0hLMxp3Y9Ueg0Yv4nS4p84BWv fawMe0PSRioJP93CEAKzepXfgeON4MnpqOKbBiv/A0m1jwT88ddKD+50inwaLiBPNYOf /rOQ== X-Gm-Message-State: ABy/qLZ+aWc1TEiAvdxAksHIm3ixa/9V6EdorfOX47YjFC+Iy0nAYN2u UWrOuqCs6hDku9Xh87wuMUIbBK9bYnVfKKbKsLI= X-Google-Smtp-Source: APBJJlFzVJI2UxHIjpRrxyZbsv8rAC3x9G9eCF0qIIb2iLIkSv48sgus3BhU4mIBADGNAt8oxdN7wQ== X-Received: by 2002:a05:600c:2809:b0:3fa:9767:c816 with SMTP id m9-20020a05600c280900b003fa9767c816mr5021376wmb.39.1690730173023; Sun, 30 Jul 2023 08:16:13 -0700 (PDT) Received: from localhost.localdomain ([2a02:6b6a:b465:0:eda5:aa63:ce24:dac2]) by smtp.gmail.com with ESMTPSA id f17-20020a7bcc11000000b003fd2d33ea53sm9123027wmh.14.2023.07.30.08.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 08:16:12 -0700 (PDT) From: Usama Arif To: linux-mm@kvack.org, muchun.song@linux.dev, mike.kravetz@oracle.com, rppt@kernel.org Cc: linux-kernel@vger.kernel.org, fam.zheng@bytedance.com, liangma@liangbit.com, simon.evans@bytedance.com, punit.agrawal@bytedance.com, Usama Arif Subject: [v2 4/6] memblock: introduce MEMBLOCK_RSRV_NOINIT flag Date: Sun, 30 Jul 2023 16:16:04 +0100 Message-Id: <20230730151606.2871391-5-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230730151606.2871391-1-usama.arif@bytedance.com> References: <20230730151606.2871391-1-usama.arif@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A40FE80015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: d5hbjj5jg5i9prwbsmujdpn3j1smqqc3 X-HE-Tag: 1690730174-591149 X-HE-Meta: U2FsdGVkX1/hRmCTUmePrBvRVMs4oIb6qoJGk07ZCA8FEv0b09trRM128E8rp/wampRVJf57vakSKa8GUKhMPRDN/0YyUDZ74xRCZEABmQc612/Fcm8BRrQjsP/vLTYMTIksx3MmfFEqw+9ogNwBii0ydDEDjA2IALkgl9ZfF1wRne7+cSYRxkkAk2fexZmJtcBxjCZu+SEEhN1Z6ZmH30bhnnbZqaeg2D/68B0cLUcZCSUFZ9qSw/LX3qtBaXYLBtHNuZiCVFUF2bfAon2mf5PtvtFykdn8GeS8Hwq/B+1HlsZLPHyk5rzsoXdrLrQK3ll2tB/2fNVyMKTzkZwbW0ZsGdlyK7k+S+X4PrGPQzANmoS28Mx9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rY36U11ooQel6GF6KlwNMNZqj5Mc/6Wg== 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: For reserved memory regions marked with this flag, reserve_bootmem_region is not called during memmap_init_reserved_pages. This can be used to avoid struct page initialization for regions which won't need them, for e.g. hugepages with HVO enabled. Signed-off-by: Usama Arif --- include/linux/memblock.h | 9 +++++++++ mm/memblock.c | 30 +++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index f71ff9f0ec81..de7760aeb870 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -40,6 +40,8 @@ extern unsigned long long max_possible_pfn; * via a driver, and never indicated in the firmware-provided memory map as * system RAM. This corresponds to IORESOURCE_SYSRAM_DRIVER_MANAGED in the * kernel resource tree. + * @MEMBLOCK_RSRV_NOINIT: memory region for which struct pages are not initialized + * (only for reserved regions). */ enum memblock_flags { MEMBLOCK_NONE = 0x0, /* No special request */ @@ -47,6 +49,7 @@ enum memblock_flags { MEMBLOCK_MIRROR = 0x2, /* mirrored region */ MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ + MEMBLOCK_RSRV_NOINIT = 0x10, /* don't initialize struct pages */ }; /** @@ -125,6 +128,7 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); +int memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t size); void memblock_free_all(void); void memblock_free(void *ptr, size_t size); @@ -259,6 +263,11 @@ static inline bool memblock_is_nomap(struct memblock_region *m) return m->flags & MEMBLOCK_NOMAP; } +static inline bool memblock_is_noinit(struct memblock_region *m) +{ + return m->flags & MEMBLOCK_RSRV_NOINIT; +} + static inline bool memblock_is_driver_managed(struct memblock_region *m) { return m->flags & MEMBLOCK_DRIVER_MANAGED; diff --git a/mm/memblock.c b/mm/memblock.c index 43cb4404d94c..40690ce0b06e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -991,6 +991,21 @@ int __init_memblock memblock_clear_nomap(phys_addr_t base, phys_addr_t size) return memblock_setclr_flag(&memblock.memory, base, size, 0, MEMBLOCK_NOMAP); } +/** + * memblock_reserved_mark_noinit - Mark a reserved memory region with flag MEMBLOCK_RSRV_NOINIT. + * @base: the base phys addr of the region + * @size: the size of the region + * + * struct pages will not be initialized for reserved memory regions marked with + * %MEMBLOCK_RSRV_NOINIT. + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t size) +{ + return memblock_setclr_flag(&memblock.reserved, base, size, 1, MEMBLOCK_RSRV_NOINIT); +} + static bool should_skip_region(struct memblock_type *type, struct memblock_region *m, int nid, int flags) @@ -2107,13 +2122,18 @@ static void __init memmap_init_reserved_pages(void) memblock_set_node(start, end, &memblock.reserved, nid); } - /* initialize struct pages for the reserved regions */ + /* + * initialize struct pages for reserved regions that don't have + * the MEMBLOCK_RSRV_NOINIT flag set + */ for_each_reserved_mem_region(region) { - nid = memblock_get_region_node(region); - start = region->base; - end = start + region->size; + if (!memblock_is_noinit(region)) { + nid = memblock_get_region_node(region); + start = region->base; + end = start + region->size; - reserve_bootmem_region(start, end, nid); + reserve_bootmem_region(start, end, nid); + } } }