From patchwork Fri Sep 9 04:46:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12971014 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 71450ECAAA1 for ; Fri, 9 Sep 2022 04:47:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF2FF8D0003; Fri, 9 Sep 2022 00:47:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA4358D0002; Fri, 9 Sep 2022 00:47:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C69BA8D0003; Fri, 9 Sep 2022 00:47:32 -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 B3CF68D0002 for ; Fri, 9 Sep 2022 00:47:32 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 781D2A070C for ; Fri, 9 Sep 2022 04:47:32 +0000 (UTC) X-FDA: 79891313544.02.03F2330 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf01.hostedemail.com (Postfix) with ESMTP id 293274007A for ; Fri, 9 Sep 2022 04:47:31 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id z9-20020a17090a468900b001ffff693b27so450300pjf.2 for ; Thu, 08 Sep 2022 21:47: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=BgevpXCXyJRdHIavWwf0+sCtJ11OZoQmWFH5Zljj9zk=; b=e52TqdnsTZ29PNbWzDy1byVkFEAN2+wryaW0zj8qb6JBaKCnDi3Rkee5B5kd5pRT2W aDvzdm+TL6vcW2RHpdLKUiEn/cTT9jUdgJUhlJO3eeBZi6C64i3XOXaE3ZegoJR5pL5x VjI3MX0Mez+7h3rbkY1YKquOlER0qFe1FPDuHupwtRTh+egxL8SIcohRex/QurMlS1Et CD3U5KpM26plk1XVeXipFm6JMmv+xxr965gy36DmWKB2G+AyOxC4sqWFbi808I8RoPn2 k6pRms5oY69rj06VFz1MwtlTFRxVfe7/kaGdztzol0JYjFOCtv62uMFaJ3ViHoofdYCI DLyA== 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=BgevpXCXyJRdHIavWwf0+sCtJ11OZoQmWFH5Zljj9zk=; b=TeMz4J35f6Mtt+mWaq/u6f0ziv3WQ1nB/0ZAjALD50+XbveEiZGWgrj1GfV1tkaX2r a8r2DzEfXGpXEMWwlJ/13PYItWabRJaUPsK6QUgTMmJaddgRgVRt9UIHJIvykLRwMO6r j8tQqAILePX0AphAxFRE652LPZs1vTCoFUIHopLCzw/pFE+2U3o14MSQYlnvtYgHt4mZ oADwYXsG4S/aJ6YKbqC1Tunsx3UD8SsfKczdEalKEUXbrWLhzk4dmgYboPKcVqluw98b zlr4/XfyYgMOmKZN27UfE4eqLuuESc9CK4v7mmhB54T2PAX8tDypUA0qlfKwboFFqb4E YDPA== X-Gm-Message-State: ACgBeo07+tQRCWbZ/zo6S/BpHLIgYrFOgVV9V249CbLQMxTe5AWWRw+5 x65LExb+iClzFT6ypVNHOAk= X-Google-Smtp-Source: AA6agR7O8Tn/2Xmm79PQwyuwJkxhmBYzy4MCkEDP4P8NrwazRLvhzQ+pwu1HZkNVYH7QoqWhiVl8Kw== X-Received: by 2002:a17:902:d4c4:b0:170:9fdb:4a2a with SMTP id o4-20020a170902d4c400b001709fdb4a2amr11488677plg.137.1662698851059; Thu, 08 Sep 2022 21:47:31 -0700 (PDT) Received: from sophie ([89.46.114.153]) by smtp.gmail.com with ESMTPSA id e11-20020a170902784b00b00176c891c893sm387556pln.131.2022.09.08.21.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 21:47:30 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH v5 1/4] memblock tests: add simulation of physical memory with multiple NUMA nodes Date: Thu, 8 Sep 2022 23:46:42 -0500 Message-Id: <5ac0e2f8d6b6cb985e2d6f308edeec2b699ecbea.1662698159.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; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=e52Tqdns; spf=pass (imf01.hostedemail.com: domain of remckee0@gmail.com designates 209.85.216.67 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=1662698852; a=rsa-sha256; cv=none; b=JHF4BY2Voy1BTAJvdyp7gfnzlsdQchImPBrVvFO4dvAe2LIYMzxPuEjE8t9WW1HrBUKn7f VglO6c3WId/xYeB0hCjz8lLU3TKg3mEqVvfG/4XXBgSUo2LI7rVgQOdsdoQiDQV07RjEJg sKsnAxTpWOMyN+kD8t9EVAVdzk56cc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662698852; 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=BgevpXCXyJRdHIavWwf0+sCtJ11OZoQmWFH5Zljj9zk=; b=2aZ/4cf4bgMDZyCN5333xPoHKLN6dXcPlUM11rEUyH/Egw2TJnZgM7ARUog4BhPbCgTvhU D0qsUTEhLQMU/DeGhnXzUdqDsxI3B9iiUqda8o5lEy0CWq1XjWQeoVh1rUQS00PuC99fGg wD7P+MRxYYSKUJG6g+ZwJWtvI8E/B4o= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 293274007A Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=e52Tqdns; spf=pass (imf01.hostedemail.com: domain of remckee0@gmail.com designates 209.85.216.67 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: iwrsdqrfoo4kbqq9nx51ppgsopohta9m X-Rspam-User: X-HE-Tag: 1662698851-188086 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. Signed-off-by: Rebecca Mckeever Reviewed-by: David Hildenbrand --- .../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..9d9ad7df298b 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 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 && node_fracs[i] > 0); + 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..f87ca5b3638e 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 int node_fracs[]); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void); void parse_args(int argc, char **argv);