From nobody Fri Apr 10 21:55:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3D2DC25B0E for ; Fri, 19 Aug 2022 09:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347978AbiHSJKH (ORCPT ); Fri, 19 Aug 2022 05:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347975AbiHSJKE (ORCPT ); Fri, 19 Aug 2022 05:10:04 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF23F14DC for ; Fri, 19 Aug 2022 02:10:03 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id a4so2882286qto.10 for ; Fri, 19 Aug 2022 02:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=2z0FzeFb0sFurgTQB3OFi4LJtDp72dKYIdEv0EoSLB0=; b=gOjMhoM+81Tf0KMrOOhrqnacshHYdirV3D7iBKZn5xNxwWUEiQKNnoC/09C3xJeZJD OANCu1KLBk5xqH4x7OEge3VSzxyrbCN9enO1YCk6j474gET6/4NeqxEvJmpbJ9yheeuL 0ib6fzOVcjkiztbJ/xZ4EuDKRtxfdXNpOB80oxyIN+utjsBBZLPFOf+pWvkR2EJaFi2A Z2bTvQE24nr7WuhK8KOlRrXrhByMAsTAH+fkg75VLWax38j8opYNYZRK5px31hCMmQdO ctB2LQNvyM9g/6iHOdR02kO7epICj9DdrPK9pxVv1PGlVfuTiF/6BTPhwtzPl7hiPKAu jdEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=2z0FzeFb0sFurgTQB3OFi4LJtDp72dKYIdEv0EoSLB0=; b=hrVmJXmQcD534oukLSb881kmkSJE2Y/LiM7tJxVq0WvUBm3mncqt/AlaLcvPCDXXs0 9HSqdKr+EvETd3JefqxGrlPVzmtbO2CUe3Yvwy58m5CqvC10eGtuVUBScrrUsc9FB4Sg 9hFPTHMsP20xQPy6CPN9nWtpywKCuKrKQdgTT9RP3Cu+RBuFYmUxtKsp8NMD6vn7oqyL UilM7fPWxjLWdBjYfQun7FLca8Qy3ZpzwNzQYUf2J0Bjh1HPQjFf1aJDenOIGc3tB7xl btH7hGT1An+pJIYvP0GsthcuBVoz6QexeIw1OQRXf/FGYP7vF+la64R+2aTNiXhndC8b ozww== X-Gm-Message-State: ACgBeo0UhDXgHBANmezuqn+/mLtkVw68uc0Cuf6cgF7eydLfHFfV/K+T g0Zjg1Xr34XcNwjgpm+Au4E= X-Google-Smtp-Source: AA6agR6AxIlBI3ibgp9VwsAzdSnR0jpMpVkwwL0Z/sWHdrBUOGmGm6JpJeTx6+3bfVrLhyG4Z5VJiA== X-Received: by 2002:a05:622a:1055:b0:344:9748:493f with SMTP id f21-20020a05622a105500b003449748493fmr3983395qte.190.1660900202518; Fri, 19 Aug 2022 02:10:02 -0700 (PDT) Received: from sophie ([89.46.62.64]) by smtp.gmail.com with ESMTPSA id r25-20020ae9d619000000b006bb2f555ba4sm3215017qkk.41.2022.08.19.02.10.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 02:10:02 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH v2 1/4] memblock tests: add simulation of physical memory with multiple NUMA nodes Date: Fri, 19 Aug 2022 02:05:31 -0700 Message-Id: <0cfb3c69ba6ca9ff55e1fc2528d18d108416ba57.1660897864.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add functions setup_numa_memblock_generic() and setup_numa_memblock() for setting up a memory layout with multiple NUMA nodes in a previously allocated dummy physical memory. These functions can be used in place of setup_memblock() in tests that need to simulate a NUMA system. setup_numa_memblock_generic(): - allows for setting up a custom memory layout by specifying the amount of memory in each node, the number of nodes, and a factor that will be used to scale the memory in each node setup_numa_memblock(): - allows for setting up a default memory layout Introduce constant MEM_FACTOR, which is used to scale the default memory layout based on MEM_SIZE. Set CONFIG_NODES_SHIFT to 4 when building with NUMA=3D1 to allow for up to 16 NUMA nodes. Signed-off-by: Rebecca Mckeever --- .../testing/memblock/scripts/Makefile.include | 2 +- tools/testing/memblock/tests/common.c | 38 +++++++++++++++++++ tools/testing/memblock/tests/common.h | 9 ++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/tools/testing/memblock/scripts/Makefile.include b/tools/testin= g/memblock/scripts/Makefile.include index aa6d82d56a23..998281723590 100644 --- a/tools/testing/memblock/scripts/Makefile.include +++ b/tools/testing/memblock/scripts/Makefile.include @@ -3,7 +3,7 @@ =20 # Simulate CONFIG_NUMA=3Dy ifeq ($(NUMA), 1) - CFLAGS +=3D -D CONFIG_NUMA + CFLAGS +=3D -D CONFIG_NUMA -D CONFIG_NODES_SHIFT=3D4 endif =20 # Use 32 bit physical addresses. diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock= /tests/common.c index eec6901081af..15d8767dc70c 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -34,6 +34,10 @@ static const char * const help_opts[] =3D { =20 static int verbose; =20 +static const phys_addr_t node_sizes[] =3D { + SZ_4K, SZ_1K, SZ_2K, SZ_2K, SZ_1K, SZ_1K, SZ_4K, SZ_1K +}; + /* sets global variable returned by movable_node_is_enabled() stub */ bool movable_node_enabled; =20 @@ -72,6 +76,40 @@ void setup_memblock(void) fill_memblock(); } =20 +/** + * setup_numa_memblock_generic: + * Set up a memory layout with multiple NUMA nodes in a previously allocat= ed + * dummy physical memory. + * @nodes: an array containing the amount of memory in each node + * @node_cnt: the size of @nodes + * @factor: a factor that will be used to scale the memory in each node + * + * The nids will be set to 0 through node_cnt - 1. + */ +void setup_numa_memblock_generic(const phys_addr_t nodes[], + int node_cnt, int factor) +{ + phys_addr_t base; + int flags; + + reset_memblock_regions(); + base =3D (phys_addr_t)memory_block.base; + flags =3D (movable_node_is_enabled()) ? MEMBLOCK_NONE : MEMBLOCK_HOTPLUG; + + for (int i =3D 0; i < node_cnt; i++) { + phys_addr_t size =3D factor * nodes[i]; + + memblock_add_node(base, size, i, flags); + base +=3D size; + } + fill_memblock(); +} + +void setup_numa_memblock(void) +{ + setup_numa_memblock_generic(node_sizes, NUMA_NODES, MEM_FACTOR); +} + void dummy_physical_memory_init(void) { memory_block.base =3D malloc(MEM_SIZE); diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock= /tests/common.h index 4fd3534ff955..e5117d959d6c 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -10,7 +10,11 @@ #include #include <../selftests/kselftest.h> =20 -#define MEM_SIZE SZ_16K +#define MEM_SIZE SZ_16K +#define NUMA_NODES 8 + +/* used to resize values that need to scale with MEM_SIZE */ +#define MEM_FACTOR (MEM_SIZE / SZ_16K) =20 enum test_flags { TEST_ZEROED =3D 0x0, @@ -100,6 +104,9 @@ struct region { void reset_memblock_regions(void); void reset_memblock_attributes(void); void setup_memblock(void); +void setup_numa_memblock_generic(const phys_addr_t nodes[], + int node_cnt, int factor); +void setup_numa_memblock(void); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void); void parse_args(int argc, char **argv); --=20 2.25.1