From patchwork Sun Aug 14 06:06:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12942853 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 A7DEAC25B0F for ; Sun, 14 Aug 2022 06:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48B678E0003; Sun, 14 Aug 2022 02:06:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 439CC8E0001; Sun, 14 Aug 2022 02:06:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 302EA8E0003; Sun, 14 Aug 2022 02:06:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 234F18E0001 for ; Sun, 14 Aug 2022 02:06:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E550516025F for ; Sun, 14 Aug 2022 06:06:53 +0000 (UTC) X-FDA: 79797164706.20.2325E15 Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by imf23.hostedemail.com (Postfix) with ESMTP id 9702C140189 for ; Sun, 14 Aug 2022 06:06:53 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id i77so318748ioa.7 for ; Sat, 13 Aug 2022 23:06:53 -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=9BV+JT1RS/2/MYqZZuZ9l7gp2iMxSyyMljieAYG86aA=; b=hl0w8eJQRHA+pvdB89Pl5fKE8tBDO5unKCZF5r1Lz7CMgjgOsH2uR5lhQCRkJM65GF lHHrEb/15NW7rQCUbL97hk317mRjL9IROyozoc608CWryvt7XreyRQoeCeP1t51e01K3 C9CqEvlLA4Wy+H7a7au2R/PmLSHaXtJo1+/AqdZZ4JO3kLRhmEW5MFCCmGbFtweyjVQL 1fC23+3Idb/Co1zfdEIxNsv64XlAcWb0eA/gNWSdUyRtIeMh5UHCxYXR6AL7Sb8CffuH 8JKQjg8nTCjdRnCOcCApRaBGQbz5mo89jDNjon5G00VlNfQAT5AgMGsNCD2GA4O1kzQD 5Kbw== 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=9BV+JT1RS/2/MYqZZuZ9l7gp2iMxSyyMljieAYG86aA=; b=o+1AO+zipADMCcjh4JsSu7IQesMQUX53AYf+obqfFzdbuwHO2aG4DxEQo9IpRSYASM Mk0tf9wtbnWNCvqPoMy7pxIFwGyLalvMfQxSqENhz604QK2xjYbBjVizWmF5o2N/CpSg 88qC9EcFD+PLYboQm2T01wAnJoOi+fBAP1SboVFsZhfPWZNVycoq8Jgb6ahX8sNICye6 4PTJNT3bwPwcFEJZo1qCCWb+GmOK8Y37Dt7XAT+CFru8LqCFUNpiT2O5zYuZTA44sEbm kTUkZOhpO/gbyJTGESx9AlCqNzXLl0Xb4/dkw5ELhbzFymKlOq9hRMwCvSH340uXJ5q8 xiCg== X-Gm-Message-State: ACgBeo13lUb0Ev+Yj7EFnplXeBr70qJSbu+64JmaxisOmjpTY3F0tzO4 nI8ahTadEpVaoN+0uhg/mJDxS5xfo9M= X-Google-Smtp-Source: AA6agR4BlJt6RMS83dyzlyNFbxFOOOcH1bPuMJlZOxm6b+mSIPBO0727x6t48hdu0gSIkkkMO51FbA== X-Received: by 2002:a5d:8ac8:0:b0:67f:ac0f:6cf6 with SMTP id e8-20020a5d8ac8000000b0067fac0f6cf6mr4261512iot.204.1660457212911; Sat, 13 Aug 2022 23:06:52 -0700 (PDT) Received: from sophie ([68.235.43.126]) by smtp.gmail.com with ESMTPSA id j6-20020a6bf906000000b00685a7cccd2csm2865093iog.45.2022.08.13.23.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 23:06:52 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 1/4] memblock tests: add simulation of physical memory with multiple NUMA nodes Date: Sun, 14 Aug 2022 01:06:15 -0500 Message-Id: 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=hl0w8eJQ; spf=pass (imf23.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.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=1660457213; a=rsa-sha256; cv=none; b=ZalKyBofMPUcFkst5ODDW6FxikvnbtRO8muxkW7WlmMwAtG5NsOXr63hSXlkbrJrQWjtsG iddAm2RxPVOiom167dCK3UMJbuezkirtr+2bc1e8ibd4PznynZM2N/qiM4YzcK008M0fM2 XBFYuqY0kVTv0UBIbp0ZvRCgXlnMwg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660457213; 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=9BV+JT1RS/2/MYqZZuZ9l7gp2iMxSyyMljieAYG86aA=; b=KI8yZqHEVSmuzEHoWtBbB0XIs0CVBSznYBI6ADVJOhcMhQNlbEHwQeHdALhq4IOKm+iweK PR5z1eNgMEje6dpO3y6CJwLqiOCeiDzgPmcgd05BXCIFBl00rdjkWsHiMj2Knk1hTf/ru2 2iWZq/c/dg7rml/JURZKIAHo6WuBUfg= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hl0w8eJQ; spf=pass (imf23.hostedemail.com: domain of remckee0@gmail.com designates 209.85.166.67 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9702C140189 X-Stat-Signature: ib54ogmjkkpmx364h68zosgon9sfsap7 X-Rspam-User: X-HE-Tag: 1660457213-902555 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 0ca26fe12c38..179b9b4a8fc8 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 a0594f1e4fe3..abd77beff06c 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, @@ -101,6 +105,9 @@ void reset_memblock_regions(void); void reset_memblock_attributes(void); void fill_memblock(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);