From patchwork Tue Sep 13 05:21:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12974408 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 A6A91C6FA82 for ; Tue, 13 Sep 2022 05:21:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09E888D0002; Tue, 13 Sep 2022 01:21:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 025676B0073; Tue, 13 Sep 2022 01:21:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF8328D0002; Tue, 13 Sep 2022 01:21:31 -0400 (EDT) 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 C017C6B0072 for ; Tue, 13 Sep 2022 01:21:31 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9E82FA09AA for ; Tue, 13 Sep 2022 05:21:31 +0000 (UTC) X-FDA: 79905914382.02.E2D4A2A Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf12.hostedemail.com (Postfix) with ESMTP id 6127F400B4 for ; Tue, 13 Sep 2022 05:21:31 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id h21so7867524qta.3 for ; Mon, 12 Sep 2022 22:21:31 -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:subject:date; bh=kZHSFFRZ5TYJ5atwJqJfGrRx7CUtt+wggh+E31jFl6g=; b=QXvfE6sb6vwl8GWA/j8nnaaaNhLCHayCCPovK1KNtkT98dndw/e2zKIRAo+hTDUtii Jdkw31+GvK7b2k4K2T8fitmsTrdqIxwCTQX3c4/yXm2+ALkiMMN0e4znx5IGHhSmETrZ 802vc/ylwMjrgmwZYJaqH5W6ns9Aw4gLLbiVOQ2ajPCqXCvIWuTkpfRf0hyjYo1jCCMy Kljzz28RJo7S8Y3fobHkdw7jhAYAEJAcwhxyPrmuv1YASXEP/ESN7wSgjTSGNPbdacnG SLNUXCwMBnamOnQMS5Eh7FcoKt/twz/jS0OhNfBds/ZJq4l+i/1hkZau6yH0IdC2yK7H qZrA== 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 :subject:date; bh=kZHSFFRZ5TYJ5atwJqJfGrRx7CUtt+wggh+E31jFl6g=; b=k6d6YDGxzm8zshJNouS4FUgH2fKetNBiqnM4C7ZXQkq7zsQmHW3v/APnDLSRcABHl2 CtZgDOX6nS3cUR/kaYJT3e+hdpIny5NUGGTBpsJbDqHRDxg4yTfIh70NltUpkHTGIKKH PhojGUFd+newKtpbChY5EZ1NzSFkZy8HQPaKVMXWq94YloLRsVqJ0sGqOHW+N58l+ds3 8pxREN9RSCo7TeF22Y45P0f4VHTP6Oek8G8p29XkzjDqUrkns9D0obXWYrwfRL5v32Yq Vz3WqM9rxV2SGWI9pXfvcMat3k20XB9nOY/bQ36pfzBktmg90sPOGMu6cfC4rKHVMJy2 DNdw== X-Gm-Message-State: ACgBeo33+r5ApadxRzHI5gftQUJxOlT0bME8rsAK9O0gIaevISG5e99t /jzXHnJ1u5b1qwpDkSn2QBw= X-Google-Smtp-Source: AA6agR6gWUmYOn0H0LRL1BMOcPC2iZJZPoir/yUiTe7eQaLLpfhUb6OxGbY4EFjA4P8UsWtDTrZxjg== X-Received: by 2002:a05:622a:13:b0:35b:bb0f:e90a with SMTP id x19-20020a05622a001300b0035bbb0fe90amr3781984qtw.441.1663046490539; Mon, 12 Sep 2022 22:21:30 -0700 (PDT) Received: from sophie ([45.134.140.166]) by smtp.gmail.com with ESMTPSA id m5-20020ac807c5000000b0035a70a25651sm7861405qth.55.2022.09.12.22.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 22:21:29 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH v6 1/4] memblock tests: add simulation of physical memory with multiple NUMA nodes Date: Tue, 13 Sep 2022 00:21:09 -0500 Message-Id: <4566d816a85f009268d4858d1ef06c7571a960f9.1663046060.git.remckee0@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663046491; 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=kZHSFFRZ5TYJ5atwJqJfGrRx7CUtt+wggh+E31jFl6g=; b=kPV1RWTmYGkaZAWC4X0SvT7LVseFhzvX1eW5bW0CkPsz+ajCFIOTeNa9XAcGnYBv45TctJ mgNfB7dLNXcisCAIzC0lxz8V4SIf/GMulhmYVbPBhzElqdsBVqfZSpYzeLNhpgJA435m2u HuXnveQyAy6h7k/CWFTPCRxRig5BtOQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QXvfE6sb; spf=pass (imf12.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.195 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=1663046491; a=rsa-sha256; cv=none; b=Ezqt1nZEZxEem1IKut1mZCRDi99ZUW59Qq+cI/PIg0H23Gg/noIlOKM1WvnL2fTrXoyC1v GaYUXjoXjpJ45ok97h8CjTXeBqMbMEoSPtjxcw5qveGNhgDGBO/r94nLtsX0vLZI5Cjzys ggEV8lqPYii8hM1r+5oMj+9BDSRf5Fg= X-Stat-Signature: s9w41fuaikwgmcnjtigqph38sojwoejh X-Rspamd-Queue-Id: 6127F400B4 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QXvfE6sb; spf=pass (imf12.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1663046491-804671 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 function setup_numa_memblock() for setting up a memory layout with multiple NUMA nodes in a previously allocated dummy physical memory. This function can be used in place of setup_memblock() in tests that need to simulate a NUMA system. setup_numa_memblock(): - allows for setting up a memory layout by specifying the fraction of MEM_SIZE in each node Set CONFIG_NODES_SHIFT to 4 when building with NUMA=1 to allow for up to 16 NUMA nodes. Reviewed-by: David Hildenbrand Signed-off-by: Rebecca Mckeever --- .../testing/memblock/scripts/Makefile.include | 2 +- tools/testing/memblock/tests/common.c | 31 +++++++++++++++++++ tools/testing/memblock/tests/common.h | 4 ++- 3 files changed, 35 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..3f795047bbe1 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -9,6 +9,7 @@ #define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS #define PREFIXES_MAX 15 #define DELIM ": " +#define BASIS 10000 static struct test_memory memory_block; static const char __maybe_unused *prefixes[PREFIXES_MAX]; @@ -72,6 +73,36 @@ void setup_memblock(void) fill_memblock(); } +/** + * setup_numa_memblock: + * Set up a memory layout with multiple NUMA nodes in a previously allocated + * dummy physical memory. + * @node_fracs: an array representing the fraction of MEM_SIZE contained in + * each node in basis point units (one hundredth of 1% or 1/10000). + * For example, if node 0 should contain 1/8 of MEM_SIZE, + * node_fracs[0] = 1250. + * + * The nids will be set to 0 through NUMA_NODES - 1. + */ +void setup_numa_memblock(const unsigned int node_fracs[]) +{ + 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 < NUMA_NODES; i++) { + assert(node_fracs[i] <= BASIS); + phys_addr_t size = MEM_SIZE * node_fracs[i] / BASIS; + + memblock_add_node(base, size, i, flags); + base += size; + } + fill_memblock(); +} + 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..def71648887f 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -10,7 +10,8 @@ #include #include <../selftests/kselftest.h> -#define MEM_SIZE SZ_16K +#define MEM_SIZE SZ_16K +#define NUMA_NODES 8 enum test_flags { /* No special request. */ @@ -102,6 +103,7 @@ struct region { void reset_memblock_regions(void); void reset_memblock_attributes(void); void setup_memblock(void); +void setup_numa_memblock(const unsigned int node_fracs[]); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void); void parse_args(int argc, char **argv);