Skip to content

Commit c01357a

Browse files
committed
Fix memspace_highest_capacity test
The test was using get_mempolicy to verify whether allocation was done on a specific node but params to get_mem_policy were wrong. Instead of returning the nodeId, get_mempolicy was returning a policy associated with the address which was always: all nodes set.
1 parent e17a0ad commit c01357a

File tree

6 files changed

+56
-26
lines changed

6 files changed

+56
-26
lines changed

.github/workflows/qemu.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ jobs:
7373
-machine q35,usb=off,hmat=on \
7474
-enable-kvm \
7575
-net nic -net user,hostfwd=tcp::2222-:22 \
76-
-m 3G \
76+
-m 3500M \
7777
-smp 4 \
78-
-object memory-backend-ram,size=1G,id=ram0 \
79-
-object memory-backend-ram,size=1G,id=ram1 \
80-
-object memory-backend-ram,size=1G,id=ram2 \
78+
-object memory-backend-ram,size=1100M,id=ram0 \
79+
-object memory-backend-ram,size=1200M,id=ram1 \
80+
-object memory-backend-ram,size=1200M,id=ram2 \
8181
-numa node,nodeid=0,memdev=ram0,cpus=0-1 \
8282
-numa node,nodeid=1,memdev=ram1,cpus=2-3 \
8383
-numa node,nodeid=2,memdev=ram2,initiator=0 \

scripts/qemu/run-build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ make -j $(nproc)
3636

3737
ctest --output-on-failure
3838

39+
# run tests bound to a numa node
40+
numactl -N 0 ctest --output-on-failure
41+
numactl -N 1 ctest --output-on-failure

test/common/numa_helpers.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2023-2024 Intel Corporation
2+
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
// This file contains helpers for tests for UMF pool API
5+
6+
#ifndef UMF_NUMA_HELPERS_H
7+
#define UMF_NUMA_HELPERS_H 1
8+
9+
#include <numa.h>
10+
#include <numaif.h>
11+
#include <stdint.h>
12+
#include <stdio.h>
13+
14+
#include "test_helpers.h"
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
// returns the node where page starting at 'ptr' resides
21+
int getNumaNodeByPtr(void *ptr) {
22+
int nodeId;
23+
int retm =
24+
get_mempolicy(&nodeId, nullptr, 0, ptr, MPOL_F_ADDR | MPOL_F_NODE);
25+
UT_ASSERTeq(retm, 0);
26+
return nodeId;
27+
}
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
#endif /* UMF_NUMA_HELPERS_H */

test/memspaces/memspace_highest_capacity.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "memory_target_numa.h"
66
#include "memspace_helpers.hpp"
77
#include "memspace_internal.h"
8+
#include "numa_helpers.h"
89
#include "test_helpers.h"
910
#include "utils_sanitizers.h"
1011

@@ -40,28 +41,29 @@ TEST_F(memspaceHighestCapacityProviderTest, highestCapacityVerify) {
4041
static constexpr size_t alloc_size = 1024;
4142

4243
long long maxCapacity = 0;
43-
int maxCapacityNode = -1;
44+
std::vector<int> maxCapacityNodes{};
4445
for (auto nodeId : nodeIds) {
4546
if (numa_node_size64(nodeId, nullptr) > maxCapacity) {
46-
maxCapacityNode = nodeId;
4747
maxCapacity = numa_node_size64(nodeId, nullptr);
4848
}
4949
}
5050

51+
for (auto nodeId : nodeIds) {
52+
if (numa_node_size64(nodeId, nullptr) == maxCapacity) {
53+
maxCapacityNodes.push_back(nodeId);
54+
}
55+
}
56+
5157
// Confirm that the HighestCapacity memspace indeed has highest capacity
5258
void *ptr;
5359
auto ret = umfMemoryProviderAlloc(hProvider, alloc_size, 0, &ptr);
60+
memset(ptr, 0, alloc_size);
5461
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
5562

56-
struct bitmask *nodemask = numa_allocate_nodemask();
57-
UT_ASSERTne(nodemask, nullptr);
58-
int retm = get_mempolicy(nullptr, nodemask->maskp, nodemask->size, ptr,
59-
MPOL_F_ADDR);
60-
UT_ASSERTeq(retm, 0);
61-
UT_ASSERT(numa_bitmask_isbitset(nodemask, maxCapacityNode));
63+
auto nodeId = getNumaNodeByPtr(ptr);
64+
ASSERT_TRUE(std::any_of(maxCapacityNodes.begin(), maxCapacityNodes.end(),
65+
[nodeId](int node) { return nodeId == node; }));
6266

6367
ret = umfMemoryProviderFree(hProvider, ptr, alloc_size);
6468
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
65-
66-
numa_bitmask_free(nodemask);
6769
}

test/memspaces/memspace_host_all.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "memory_target_numa.h"
66
#include "memspace_helpers.hpp"
77
#include "memspace_internal.h"
8+
#include "numa_helpers.h"
89
#include "test_helpers.h"
910
#include "utils_sanitizers.h"
1011

@@ -91,9 +92,7 @@ static void getAllocationPolicy(void *ptr, unsigned long maxNodeId, int &mode,
9192
}
9293

9394
// Get the node that allocated the memory at 'ptr'.
94-
int nodeId = -1;
95-
ret = get_mempolicy(&nodeId, nullptr, 0, ptr, MPOL_F_ADDR | MPOL_F_NODE);
96-
UT_ASSERTeq(ret, 0);
95+
int nodeId = getNumaNodeByPtr(ptr);
9796
allocNodeId = static_cast<size_t>(nodeId);
9897
}
9998

test/provider_os_memory_multiple_numa_nodes.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#include "base.hpp"
6+
#include "numa_helpers.h"
67

78
#include <numa.h>
89
#include <numaif.h>
@@ -52,14 +53,6 @@ struct testNumaNodes : public testing::TestWithParam<int> {
5253
ASSERT_NE(os_memory_provider, nullptr);
5354
}
5455

55-
int retrieve_numa_node_number(void *addr) {
56-
int numa_node;
57-
int ret = get_mempolicy(&numa_node, nullptr, 0, addr,
58-
MPOL_F_NODE | MPOL_F_ADDR);
59-
EXPECT_EQ(ret, 0);
60-
return numa_node;
61-
}
62-
6356
void TearDown() override {
6457
umf_result_t umf_result;
6558
if (ptr) {
@@ -108,6 +101,6 @@ TEST_P(testNumaNodes, checkNumaNodesAllocations) {
108101
// This pointer must point to an initialized value before retrieving a number of
109102
// the numa node that the pointer was allocated on (calling get_mempolicy).
110103
memset(ptr, 0xFF, alloc_size);
111-
int retrieved_numa_node_number = retrieve_numa_node_number(ptr);
104+
int retrieved_numa_node_number = getNumaNodeByPtr(ptr);
112105
ASSERT_EQ(retrieved_numa_node_number, numa_node_number);
113106
}

0 commit comments

Comments
 (0)