From patchwork Sun Sep 4 04:21:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12965118 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 9E723ECAAD5 for ; Sun, 4 Sep 2022 04:21:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1CD88017F; Sun, 4 Sep 2022 00:21:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECEE78015A; Sun, 4 Sep 2022 00:21:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1F7B8017F; Sun, 4 Sep 2022 00:21:28 -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 C37A18015A for ; Sun, 4 Sep 2022 00:21:28 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 986F2C0C05 for ; Sun, 4 Sep 2022 04:21:28 +0000 (UTC) X-FDA: 79873103856.10.8C9C4C4 Received: from mail-oa1-f68.google.com (mail-oa1-f68.google.com [209.85.160.68]) by imf23.hostedemail.com (Postfix) with ESMTP id 42F5D14006C for ; Sun, 4 Sep 2022 04:21:28 +0000 (UTC) Received: by mail-oa1-f68.google.com with SMTP id 586e51a60fabf-11eab59db71so14492677fac.11 for ; Sat, 03 Sep 2022 21:21:28 -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=wW5p1q73OkEZN8E3EwbNVJG/rp2qE6vBkOjLbct9Gck=; b=fJg/LYOf8ME2lCaH6ZbuaoZqZ0dcWzcZjvzxNOMITKSYdrg2r5+w+YVwNZsykp5jfw +mwKcs207+yz6fjoI4oi3cj826srJ+m4jQotF8VY2Pemfwv2WanseK/cnNqTy3okNgjU HmIjqU3qlY90PdbSCIHecxB1b63/hoaUaT2cjLRFW7K0dFeBgqpGh9gB+ef3nrt4xWJh yZm7frk2BvUfr2AxwgFHlqqNneo6TbZs7Ow1Sb+UwLMOIFYTXyq3iQTBORq7LwwJLxEr DV7+iy4XSq1w2psSIVHEd6wH4ymcUXI1N0VF2D+TokAzvFEdQwuj6fssyXT3qUJ07sf7 Rq2w== 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=wW5p1q73OkEZN8E3EwbNVJG/rp2qE6vBkOjLbct9Gck=; b=NACtM96OBcvT/5zBhod2DsyhgplDzlJa7m55Fz2gXUNSgQ1lKH1/GhiGFHqtR4FEPe E/rIa6ZwYUT14Qk3CaORLzLJDDpKNHeZg7ng+cWlVfcxnalekybBB8Ab2tVZLvXPFN+J qwZlsaLtvXfqhUCZZM1KVNHLEPctn1+n1x07vm2aRZK7UDMhiyt/dtEngGC3Gc4IJXiJ KF6T06Nkaci/zSIPSrEV4KtBlL/yfY2Wp/KC5uSw/rNqoOE+HQgA4JinE/VHepXxvfXS Eid15k96pNJ6OrcjDhDasjEpzcWrJnRVblX2z/dg0zxLXzJvU39vky7gIdzIan+esiC5 W8Hw== X-Gm-Message-State: ACgBeo0HNTQFApFLE5Ige+QCktplVtcZZGDJq6Fh06PTw5LqiJcIs4S8 vxgR0j2nbXIlKPV7jSI1YQ8= X-Google-Smtp-Source: AA6agR4t5k66gduBqA1qPjytKeqEh1n1uRB3Cou7Kfovk1xRThGzhgDl9nBjq1nfNc07HhHPYJ5cdQ== X-Received: by 2002:aca:1809:0:b0:345:5649:95a2 with SMTP id h9-20020aca1809000000b00345564995a2mr4841351oih.45.1662265287535; Sat, 03 Sep 2022 21:21:27 -0700 (PDT) Received: from sophie (static-198-54-128-109.cust.tzulo.com. [198.54.128.109]) by smtp.gmail.com with ESMTPSA id i7-20020a056870890700b0010bf07976c9sm3485382oao.41.2022.09.03.21.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Sep 2022 21:21:27 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH v4 1/4] memblock tests: add simulation of physical memory with multiple NUMA nodes Date: Sat, 3 Sep 2022 23:21:05 -0500 Message-Id: <49b96ce88dece5b394d5dd4332c1572da917b30a.1662264560.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; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="fJg/LYOf"; spf=pass (imf23.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.68 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=1662265288; a=rsa-sha256; cv=none; b=iipyDzI9NeAQaBxF86W1rlKFtR7YHbO947PgjkXLetlkruW4MbeiBv4bDuf++ZXxAcVLvZ XbjVvTRDDYjX4HPAnc5sPaWcwUYKh109ecTCfKw5Mc/B9tGjeNYgmxS/xenzMX0kTtuz45 Kos5ME9pY/MyX/4txASxA7K2VwCi7Hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662265288; 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=wW5p1q73OkEZN8E3EwbNVJG/rp2qE6vBkOjLbct9Gck=; b=Ou0T2s2e/ly5lA/2oPeCIY7DWmghXqVBfKG2Z6brEYWu/rGNWg7eWyxEcMEVp7yb9H3Zs/ Q92b7WLCTPojpvYYMsn+ysTJHOgPPMeP/AtlZ/41xtJAqDpFD/+C7kJGWOYncmHdoiHmzT uBu8JxP850Iu6nO/hSX17XcCfhp7EMM= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="fJg/LYOf"; spf=pass (imf23.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-Stat-Signature: knkyocoxxrqxhyxikb3p87x3njjufauc X-Rspam-User: X-Rspamd-Queue-Id: 42F5D14006C X-HE-Tag: 1662265288-64755 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 --- .../testing/memblock/scripts/Makefile.include | 2 +- tools/testing/memblock/tests/common.c | 29 +++++++++++++++++++ tools/testing/memblock/tests/common.h | 4 ++- 3 files changed, 33 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..b6110df21b2a 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -72,6 +72,35 @@ 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. + * @nodes: an array containing the denominators of the fractions of MEM_SIZE + * contained in each node (e.g., if nodes[0] = SZ_8, node 0 will + * contain 1/8th of MEM_SIZE) + * + * The nids will be set to 0 through NUMA_NODES - 1. + */ +void setup_numa_memblock(const phys_addr_t nodes[]) +{ + 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(nodes[i] <= MEM_SIZE && nodes[i] > 0); + phys_addr_t size = MEM_SIZE / nodes[i]; + + 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..caf01543a315 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 phys_addr_t nodes[]); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void); void parse_args(int argc, char **argv);