From patchwork Sun Sep 25 21:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12988138 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 92488C6FA86 for ; Sun, 25 Sep 2022 21:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22D276B00CE; Sun, 25 Sep 2022 17:27:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18E326B00D0; Sun, 25 Sep 2022 17:27:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED20D8E0007; Sun, 25 Sep 2022 17:27:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C69746B00CE for ; Sun, 25 Sep 2022 17:27:20 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9C1901C3449 for ; Sun, 25 Sep 2022 21:27:20 +0000 (UTC) X-FDA: 79951893840.03.0B6A43F Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf24.hostedemail.com (Postfix) with ESMTP id 49794180002 for ; Sun, 25 Sep 2022 21:27:20 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id g23so3130933qtu.2 for ; Sun, 25 Sep 2022 14:27:20 -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=eGAcKbYoA45EhpEphg+aCEcYqZsvjPC//SZfHS2nD+Q=; b=BZUaotWyI5iIgL37Qxwa6OqgaARlh6b+WRxbFtb2Yjw1pktFmbnJFs7IUA5vVB7Gy7 HzcMpep8LuR7UPybgPylfiu5yO0n5VLuDVsCQdwGLS92C0nnDzT8q5PoBJGWYCq2OzdJ u/oChTDH6aQ/hFx5+sPMjd6dlohkFHWELXKgVj6cJcEoYNdzVrlu8nFLN8cLMtmDNmKI oP9Ra4pvlmhtA3/DovZTOyWLktF0PIZG0dhYjxWAM0uVd/+YXNdx7OJztmr29gPPI9qI iSJq8X3yqV6hRDK/mLDdgW0yaD5hRvM//HKnhwHRRLwE3rmmbDvMzfbhYFAtA0SkWZoL oC5Q== 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=eGAcKbYoA45EhpEphg+aCEcYqZsvjPC//SZfHS2nD+Q=; b=QZAUsGSuapk4x/I/kBD2nIfWagjwM2UoQIPn/Ff/hBiNZPpzDj1+ZnUnev7aWVL+5a 1k99f/FLQFBIRg4I4h3QUOthvP45GuTWfb6oa4LAQzoKTHTcouqb6lQmCMtXJBrCAjuw C/C7WpUiidLFhL0XRoiKaLOug5EFevYkC/Lz5psI69e9iO8a818cCbXQQ2cFfvXDG0OT 0XbIMivhyhmtPe+Sm7/ksehvUR/ZgrU16CcSDemH1uSWcTy4kJch3sFOp4oluYK8rJLW 84MxR6xJ0323fFFczBpKdxu8DS83sS70tYx2WidU5unZ8YxzDNfnxBACt3y3gRFKj2Ak iZwA== X-Gm-Message-State: ACrzQf0Q2wu8iRsuwhyEiLz7t17ewSPK4pDeCVLQE2+npW3iKPAA70Wu mtaKUajhMTT8Tv2qY5u6i54= X-Google-Smtp-Source: AMsMyM5o9hX1/tJThRDpFBY2r59Tb1L8qCKm/kMDsgqoHxEIF6Ot0b+FcI8I7uBw+eNKyArc39c/gw== X-Received: by 2002:ac8:7f8f:0:b0:35c:cbd2:9261 with SMTP id z15-20020ac87f8f000000b0035ccbd29261mr15907639qtj.485.1664141239444; Sun, 25 Sep 2022 14:27:19 -0700 (PDT) Received: from sophie ([185.156.46.189]) by smtp.gmail.com with ESMTPSA id i15-20020a05620a404f00b006ccc96c78easm10170623qko.134.2022.09.25.14.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 14:27:19 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH 3/5] memblock tests: add bottom-up NUMA tests for memblock_alloc_exact_nid_raw Date: Sun, 25 Sep 2022 16:26:54 -0500 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664141240; a=rsa-sha256; cv=none; b=z2lwdFTJhFz8UgfdJNNbsw56pfmz4brkx1spnmhMzkd/bghJoORIfglp6TGpdV0K2znLe0 pPeICX4Vqq6xVRFesqXxBlhUSpTm0pghYs1D9AB2HuliRWRhNWIsoeyFDNxoILdf8t1qCU c4tJ3JGD/JNhc5DLDkFw/giMw9OPBLU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BZUaotWy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664141240; 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=eGAcKbYoA45EhpEphg+aCEcYqZsvjPC//SZfHS2nD+Q=; b=Zh/ZRu0mHd0A6QRXuazRRJsHnohuEfBaQqhITP5H0bEOIVb6ZNIFOP9hR4aj85twhdpkHN wq0OFY+AWGrJnL2gzDpINmFZ6lodK8IktobX4IgZ4xbQA0JqKdp6d5I/KtsscZPXlx/vS6 phf4EwZxzXWCy0ZXyZRCSNWeN3u1OkI= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=BZUaotWy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.195 as permitted sender) smtp.mailfrom=remckee0@gmail.com X-Rspam-User: X-Stat-Signature: rm3sgw3bdasbmoz7ug3krsxcq1tgyggt X-Rspamd-Queue-Id: 49794180002 X-Rspamd-Server: rspam09 X-HE-Tag: 1664141240-850509 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 tests for memblock_alloc_exact_nid_raw() where the simulated physical memory is set up with multiple NUMA nodes. Additionally, all of these tests set nid != NUMA_NO_NODE. These tests are run with a bottom-up allocation direction. The tested scenarios are: Range unrestricted: - region can be allocated in the specific node requested: + there are no previously reserved regions + the requested node is partially reserved but has enough space Range restricted: - region can be allocated in the specific node requested after dropping min_addr: + range partially overlaps with two different nodes, where the first node is the requested node + range partially overlaps with two different nodes, where the requested node ends before min_addr + range overlaps with multiple nodes along node boundaries, and the requested node ends before min_addr Signed-off-by: Rebecca Mckeever --- .../memblock/tests/alloc_exact_nid_api.c | 282 ++++++++++++++++++ 1 file changed, 282 insertions(+) diff --git a/tools/testing/memblock/tests/alloc_exact_nid_api.c b/tools/testing/memblock/tests/alloc_exact_nid_api.c index 48c1b97a3f98..63279d1e35b1 100644 --- a/tools/testing/memblock/tests/alloc_exact_nid_api.c +++ b/tools/testing/memblock/tests/alloc_exact_nid_api.c @@ -1474,12 +1474,286 @@ static int alloc_exact_nid_top_down_numa_no_overlap_low_check(void) return 0; } +/* + * A test that tries to allocate a memory region in a specific NUMA node that + * has enough memory to allocate a region of the requested size. + * Expect to allocate an aligned region at the beginning of the requested node. + */ +static int alloc_exact_nid_bottom_up_numa_simple_check(void) +{ + int nid_req = 3; + struct memblock_region *new_rgn = &memblock.reserved.regions[0]; + struct memblock_region *req_node = &memblock.memory.regions[nid_req]; + void *allocated_ptr = NULL; + phys_addr_t size; + phys_addr_t min_addr; + phys_addr_t max_addr; + + PREFIX_PUSH(); + setup_numa_memblock(node_fractions); + + ASSERT_LE(SZ_4, req_node->size); + size = req_node->size / SZ_4; + min_addr = memblock_start_of_DRAM(); + max_addr = memblock_end_of_DRAM(); + + allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES, + min_addr, max_addr, + nid_req); + + ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_NE(allocated_ptr, 0, size); + + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_LE(region_end(new_rgn), region_end(req_node)); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, size); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to allocate a memory region in a specific NUMA node that + * is partially reserved but has enough memory for the allocated region: + * + * | +---------------------------------------+ | + * | | requested | | + * +-----------+---------------------------------------+---------+ + * + * | +------------------+-----+ | + * | | reserved | new | | + * +-----------+------------------+-----+------------------------+ + * + * Expect to allocate an aligned region in the requested node that merges with + * the existing reserved region. The total size gets updated. + */ +static int alloc_exact_nid_bottom_up_numa_part_reserved_check(void) +{ + int nid_req = 4; + struct memblock_region *new_rgn = &memblock.reserved.regions[0]; + struct memblock_region *req_node = &memblock.memory.regions[nid_req]; + void *allocated_ptr = NULL; + struct region r1; + phys_addr_t size; + phys_addr_t min_addr; + phys_addr_t max_addr; + phys_addr_t total_size; + + PREFIX_PUSH(); + setup_numa_memblock(node_fractions); + + ASSERT_LE(SZ_8, req_node->size); + r1.base = req_node->base; + r1.size = req_node->size / SZ_2; + size = r1.size / SZ_4; + min_addr = memblock_start_of_DRAM(); + max_addr = memblock_end_of_DRAM(); + total_size = size + r1.size; + + memblock_reserve(r1.base, r1.size); + allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES, + min_addr, max_addr, + nid_req); + + ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_NE(allocated_ptr, 0, size); + + ASSERT_EQ(new_rgn->size, total_size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_LE(region_end(new_rgn), region_end(req_node)); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, total_size); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to allocate a memory region that spans over the min_addr + * and max_addr range and overlaps with two different nodes, where the first + * node is the requested node: + * + * min_addr + * | max_addr + * | | + * v v + * | +-----------------------+-----------+ | + * | | requested | node3 | | + * +-----------+-----------------------+-----------+--------------+ + * + + + * | +-----------+ | + * | | rgn | | + * +-----------+-----------+--------------------------------------+ + * + * Expect to drop the lower limit and allocate a memory region at the beginning + * of the requested node. + */ +static int alloc_exact_nid_bottom_up_numa_split_range_low_check(void) +{ + int nid_req = 2; + struct memblock_region *new_rgn = &memblock.reserved.regions[0]; + struct memblock_region *req_node = &memblock.memory.regions[nid_req]; + void *allocated_ptr = NULL; + phys_addr_t size = SZ_512; + phys_addr_t min_addr; + phys_addr_t max_addr; + phys_addr_t req_node_end; + + PREFIX_PUSH(); + setup_numa_memblock(node_fractions); + + req_node_end = region_end(req_node); + min_addr = req_node_end - SZ_256; + max_addr = min_addr + size; + + allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES, + min_addr, max_addr, + nid_req); + + ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_NE(allocated_ptr, 0, size); + + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_LE(region_end(new_rgn), req_node_end); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, size); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to allocate a memory region that spans over the min_addr + * and max_addr range and overlaps with two different nodes, where the requested + * node ends before min_addr: + * + * min_addr + * | max_addr + * | | + * v v + * | +---------------+ +-------------+---------+ | + * | | requested | | node1 | node2 | | + * +----+---------------+--------+-------------+---------+---------+ + * + + + * | +---------+ | + * | | rgn | | + * +----+---------+------------------------------------------------+ + * + * Expect to drop the lower limit and allocate a memory region that starts at + * the beginning of the requested node. + */ +static int alloc_exact_nid_bottom_up_numa_no_overlap_split_check(void) +{ + int nid_req = 2; + struct memblock_region *new_rgn = &memblock.reserved.regions[0]; + struct memblock_region *req_node = &memblock.memory.regions[nid_req]; + struct memblock_region *node2 = &memblock.memory.regions[6]; + void *allocated_ptr = NULL; + phys_addr_t size; + phys_addr_t min_addr; + phys_addr_t max_addr; + + PREFIX_PUSH(); + setup_numa_memblock(node_fractions); + + size = SZ_512; + min_addr = node2->base - SZ_256; + max_addr = min_addr + size; + + allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES, + min_addr, max_addr, + nid_req); + + ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_NE(allocated_ptr, 0, size); + + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_LE(region_end(new_rgn), region_end(req_node)); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, size); + + test_pass_pop(); + + return 0; +} + +/* + * A test that tries to allocate memory within min_addr and max_add range when + * the requested node and the range do not overlap, and requested node ends + * before min_addr. The range overlaps with multiple nodes along node + * boundaries: + * + * min_addr + * | max_addr + * | | + * v v + * |-----------+ +----------+----...----+----------+ | + * | requested | | min node | ... | max node | | + * +-----------+-----------+----------+----...----+----------+------+ + * + + + * |-----+ | + * | rgn | | + * +-----+----------------------------------------------------------+ + * + * Expect to drop the lower limit and allocate a memory region that starts at + * the beginning of the requested node. + */ +static int alloc_exact_nid_bottom_up_numa_no_overlap_low_check(void) +{ + int nid_req = 0; + struct memblock_region *new_rgn = &memblock.reserved.regions[0]; + struct memblock_region *req_node = &memblock.memory.regions[nid_req]; + struct memblock_region *min_node = &memblock.memory.regions[2]; + struct memblock_region *max_node = &memblock.memory.regions[5]; + void *allocated_ptr = NULL; + phys_addr_t size = SZ_64; + phys_addr_t max_addr; + phys_addr_t min_addr; + + PREFIX_PUSH(); + setup_numa_memblock(node_fractions); + + min_addr = min_node->base; + max_addr = region_end(max_node); + + allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES, + min_addr, max_addr, + nid_req); + + ASSERT_NE(allocated_ptr, NULL); + ASSERT_MEM_NE(allocated_ptr, 0, size); + + ASSERT_EQ(new_rgn->size, size); + ASSERT_EQ(new_rgn->base, req_node->base); + ASSERT_LE(region_end(new_rgn), region_end(req_node)); + + ASSERT_EQ(memblock.reserved.cnt, 1); + ASSERT_EQ(memblock.reserved.total_size, size); + + test_pass_pop(); + + return 0; +} + /* Test case wrappers for NUMA tests */ static int alloc_exact_nid_numa_simple_check(void) { test_print("\tRunning %s...\n", __func__); memblock_set_bottom_up(false); alloc_exact_nid_top_down_numa_simple_check(); + memblock_set_bottom_up(true); + alloc_exact_nid_bottom_up_numa_simple_check(); return 0; } @@ -1489,6 +1763,8 @@ static int alloc_exact_nid_numa_part_reserved_check(void) test_print("\tRunning %s...\n", __func__); memblock_set_bottom_up(false); alloc_exact_nid_top_down_numa_part_reserved_check(); + memblock_set_bottom_up(true); + alloc_exact_nid_bottom_up_numa_part_reserved_check(); return 0; } @@ -1498,6 +1774,8 @@ static int alloc_exact_nid_numa_split_range_low_check(void) test_print("\tRunning %s...\n", __func__); memblock_set_bottom_up(false); alloc_exact_nid_top_down_numa_split_range_low_check(); + memblock_set_bottom_up(true); + alloc_exact_nid_bottom_up_numa_split_range_low_check(); return 0; } @@ -1507,6 +1785,8 @@ static int alloc_exact_nid_numa_no_overlap_split_check(void) test_print("\tRunning %s...\n", __func__); memblock_set_bottom_up(false); alloc_exact_nid_top_down_numa_no_overlap_split_check(); + memblock_set_bottom_up(true); + alloc_exact_nid_bottom_up_numa_no_overlap_split_check(); return 0; } @@ -1516,6 +1796,8 @@ static int alloc_exact_nid_numa_no_overlap_low_check(void) test_print("\tRunning %s...\n", __func__); memblock_set_bottom_up(false); alloc_exact_nid_top_down_numa_no_overlap_low_check(); + memblock_set_bottom_up(true); + alloc_exact_nid_bottom_up_numa_no_overlap_low_check(); return 0; }