From patchwork Sat Aug 27 05:52:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12956794 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 76D38C0502C for ; Sat, 27 Aug 2022 05:53:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3E746B0073; Sat, 27 Aug 2022 01:53:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEC9F940007; Sat, 27 Aug 2022 01:53:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDBB56B0075; Sat, 27 Aug 2022 01:53:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BF3BE6B0073 for ; Sat, 27 Aug 2022 01:53:15 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 07C3EA014C for ; Sat, 27 Aug 2022 05:53:15 +0000 (UTC) X-FDA: 79844304750.21.460ACE4 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf26.hostedemail.com (Postfix) with ESMTP id B5F98140038 for ; Sat, 27 Aug 2022 05:53:14 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id c2so3325295plo.3 for ; Fri, 26 Aug 2022 22:53:14 -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=3vruw+02EGohl42JHnb+fQiaZ/J0kK4j56/PwARaSrI=; b=XDY4JN0TIQ6PZiqGlGCb8faE581BDPjXvnf//IEDm2giRScDsLN5tWyFRb3Zfkwo3A +3fSaZ7XLaA6ILMIe587iiyXphzGzBEHCs79EnCCyA7zUfQ2aai+H76tQCO+aPbYlhKC lHHuFuGTKIowEaXqIErCxihk7rm8+m4VVbOlrXfUkAOIiz30xSNVO89S/q3DxNDZNT7s Qmv79zCIkq3cOA6zUV9VB+yE0ZwKp7gSJHMjzZQKXxnTQfjHicgd2Raxxodz80Mm/TJ4 gwsou8eXbff9t8MCodfipaKxhM77DmM6Ok2Cfq+sHQ25+upFVY81wj9zWQuinpVZwYmT 4/YA== 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=3vruw+02EGohl42JHnb+fQiaZ/J0kK4j56/PwARaSrI=; b=jKDHiDGqnkGM6/kT3evtFrYGI/gOdjk+GaiFuWu2QzFwIhSIor8mpNRzF0TtDL+3kh YG0C63951Em5/VyJxFdZh5BCvDV6zEzjY8i26AiVPP8wstGut4hS2jyqrGFsFRs9vuuZ W+nFPJL2aiZJKBj2r1st+vt1slNxwgdklajXP/NXYKInAeIZguwyNCBRYdQPoDQ3gZeN u2LNGpiw2yrfMkgB3EpqwRNiah3sBndcYsDnRn3mXnb/NFhpdxUoO8T6o2fZBpRev9jw 7FcV28n9Amsh3R5ALoB/1IJaU2uxENX7z+XvDSUEPaVUoNTZDz4+yA3Pyd2orTu2nNdz 4eEQ== X-Gm-Message-State: ACgBeo2hJCvTkU0oldbpALB5qOYK3DkYtoOowDVROdiLcQWP+1Y4adOK o32LTJIfA8yxtUgbNESPeK/gsDJcS2A= X-Google-Smtp-Source: AA6agR7IkPeo3iHneHscPJnpE5D/O/PB/E2II2/9eKWUySXs9hbJpFZCHifQkTsC8G6hlWbp/irm0A== X-Received: by 2002:a17:903:244c:b0:171:55cf:a930 with SMTP id l12-20020a170903244c00b0017155cfa930mr6889557pls.35.1661579593650; Fri, 26 Aug 2022 22:53:13 -0700 (PDT) Received: from sophie ([89.46.114.37]) by smtp.gmail.com with ESMTPSA id p125-20020a62d083000000b00537e40747b0sm944012pfg.42.2022.08.26.22.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 22:53:13 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH v3 1/4] memblock tests: add simulation of physical memory with multiple NUMA nodes Date: Sat, 27 Aug 2022 00:52:59 -0500 Message-Id: <25b727327d365a435cc1c56c10fb96cd71b6898a.1661578435.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XDY4JN0T; spf=pass (imf26.hostedemail.com: domain of remckee0@gmail.com designates 209.85.214.196 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661579594; a=rsa-sha256; cv=none; b=zbr/uGxD2tu6m2FF/GuCiV0Gg2J1pevv3Zef3DYc5FLR3zZb4oxwpS4x7lrNv5YmtGxF9X HI2RmKnxNL0pYVifBrDLyPvigAC0k4ffBAI5Uwfmjo78NpyH/795UJaEllJr+SaPdUWowC ud5AK0gc/bbUPo8lr9WTbzihkV319eU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661579594; 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=3vruw+02EGohl42JHnb+fQiaZ/J0kK4j56/PwARaSrI=; b=IU3OKOnwKovGtBj/dsj8DIhcjTmve5GW8A8fWB/FqXTBSxpaoZZ1A1qBssE9fdOSucK178 RDSAJYhlV4y6bwaNpVJdLeNpW3GeioAI6lSRjHtsEiF/C1CzdYj7T71PQlWiTwLIyeTppu 0JVaTZkEoOH2aRmgKOzyDrgFU75xVIM= X-Rspam-User: X-Stat-Signature: tjmf9rtnhx3qbf5xz3x9rresnxfb69z4 X-Rspamd-Queue-Id: B5F98140038 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XDY4JN0T; spf=pass (imf26.hostedemail.com: domain of remckee0@gmail.com designates 209.85.214.196 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam09 X-HE-Tag: 1661579594-422977 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 78128e109a95..2a17453107dc 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 { /* No special request. */ @@ -102,6 +106,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);