From patchwork Fri Aug 19 09:05:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12948577 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 95315C32771 for ; Fri, 19 Aug 2022 09:10:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0BB98D0003; Fri, 19 Aug 2022 05:10:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBB4C8D0001; Fri, 19 Aug 2022 05:10:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D82D48D0003; Fri, 19 Aug 2022 05:10:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C6EC38D0001 for ; Fri, 19 Aug 2022 05:10:03 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8D8B6ABB91 for ; Fri, 19 Aug 2022 09:10:03 +0000 (UTC) X-FDA: 79815770286.21.C7F5E80 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by imf03.hostedemail.com (Postfix) with ESMTP id 3924D20012 for ; Fri, 19 Aug 2022 09:10:03 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id h4so2882273qtj.11 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=dpojld4f2o3zMFxEXCswj8NHuxexYT+AjDIi6i+yqNG6GiomzBE3jbNsDuXp0o+P/S Ca74NEs43dTZZiRI44p3WB37z9D+iI1q21N84PkAL6RwokzKeSvszAfr2vYqh04ZIomd QFoVP0NsLdj6WAQ8fwBCWeqOizz5EDhK3KIJTuxnf1gr4oNGfk6650TIRjbim1uvrkkJ XI0q3nxKrV4x+JN76jrioUIVGGn5MHo/SLz0GPzOG5dqFkndoTTUa3XLO2yRtmowvTMi wRxCL2scAgu5gkkrSosSG8Qg7G778ZP1Mr60b6cbstidwydsJAjnfDDZSuD3DsxdOsRQ 0Q1A== X-Gm-Message-State: ACgBeo15yftqqFNQV8Q9HBgTFde7EFKwh8Ch103fUE1xmdU32228gGvq hNZZV4g0B4HZj8I69VZSqto= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660900203; a=rsa-sha256; cv=none; b=BX4pnr1f89Sg6kI4iSpo6CvOoGol4/dJ8jZDRsdEVoHZeAYAE58UDR/9XgS1FLVEUp28lc cpvHBW65H6uIoogqK0NO454iM73fhFmvJB88rwlHrooVnV1kZiyAc2QNCN6ecd4/T6KQD/ MtBp7X4a9M9109R2QQ/6rauPZTFpXvI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gOjMhoM+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.193 as permitted sender) smtp.mailfrom=remckee0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660900203; 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=2z0FzeFb0sFurgTQB3OFi4LJtDp72dKYIdEv0EoSLB0=; b=Jmi3xXgyOUwqz5NBbfzH+8HOIE3tM5Zz64CSTvgG0fSN+udfMJJ1cp4QdCCicFSQ94SI91 z0HesgzZzG7mCpWYPZ52XbA6YpInrufhHpY9U6eWJcxsiLeDHugScNbgh7KcjKZ8UWDDQ4 wwZayNcE5abHlIpVvjw4H5/rWlrJ0d8= Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gOjMhoM+; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.193 as permitted sender) smtp.mailfrom=remckee0@gmail.com X-Rspam-User: X-Stat-Signature: xpef1hgrj1zwpx6xoyhpqhjz3zppq4jx X-Rspamd-Queue-Id: 3924D20012 X-Rspamd-Server: rspam03 X-HE-Tag: 1660900203-479583 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: 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=1 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/testing/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 @@ # Simulate CONFIG_NUMA=y ifeq ($(NUMA), 1) - CFLAGS += -D CONFIG_NUMA + CFLAGS += -D CONFIG_NUMA -D CONFIG_NODES_SHIFT=4 endif # 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[] = { static int verbose; +static const phys_addr_t node_sizes[] = { + 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; @@ -72,6 +76,40 @@ void setup_memblock(void) fill_memblock(); } +/** + * setup_numa_memblock_generic: + * Set up a memory layout with multiple NUMA nodes in a previously allocated + * 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 = (phys_addr_t)memory_block.base; + flags = (movable_node_is_enabled()) ? MEMBLOCK_NONE : MEMBLOCK_HOTPLUG; + + for (int i = 0; i < node_cnt; i++) { + phys_addr_t size = factor * nodes[i]; + + memblock_add_node(base, size, i, flags); + base += 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 = 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> -#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) enum test_flags { TEST_ZEROED = 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);