Skip to content

Commit ce9eb09

Browse files
committed
use the provider's GetCachelineSize() to calculate bucket sizes in DP
1 parent 4ca3630 commit ce9eb09

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

include/umf/pools/pool_disjoint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023-2025 Intel Corporation
3+
* Copyright (C) 2023-2026 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -82,7 +82,7 @@ umfDisjointPoolParamsSetCapacity(umf_disjoint_pool_params_handle_t hParams,
8282
size_t maxCapacity);
8383

8484
/// @brief Set minimum bucket allocation size.
85-
/// @details Default value for minimum bucket size is 8.
85+
/// @details If not set, the pool uses the provider cache line size.
8686
/// @param hParams handle to the parameters of the disjoint pool.
8787
/// @param minBucketSize minimum bucket size. Must be power of 2.
8888
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.

src/pool/pool_disjoint.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2025 Intel Corporation
2+
* Copyright (C) 2022-2026 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -1191,6 +1191,15 @@ umf_result_t disjoint_pool_post_initialize(void *ppPool) {
11911191
goto err_free_disjoint_pool;
11921192
}
11931193

1194+
if (!(disjoint_pool->params_overridden & DP_OVERRIDE_MIN_BUCKET_SIZE)) {
1195+
size_t cache_line_size;
1196+
umf_result_t ret = umfMemoryProviderGetCacheLineSize(
1197+
disjoint_pool->provider, &cache_line_size);
1198+
if (ret == UMF_RESULT_SUCCESS) {
1199+
disjoint_pool->params.min_bucket_size = cache_line_size;
1200+
}
1201+
}
1202+
11941203
// Generate buckets sized such as: 64, 96, 128, 192, ..., CutOff.
11951204
// Powers of 2 and the value halfway between the powers of 2.
11961205
size_t Size1 = disjoint_pool->params.min_bucket_size;

src/pool/pool_disjoint_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2025 Intel Corporation
2+
* Copyright (C) 2025-2026 Intel Corporation
33
*
44
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
55
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -120,7 +120,7 @@ typedef struct umf_disjoint_pool_params_t {
120120

121121
// Holds the minimum bucket size valid for allocation of a memory type.
122122
// This value must be a power of 2.
123-
size_t min_bucket_size; // Default: 8
123+
size_t min_bucket_size; // Default: provider cache line size
124124

125125
// Holds size of the pool managed by the allocator.
126126
size_t cur_pool_size; // Default: 0

test/pools/disjoint_pool.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2023-2025 Intel Corporation
1+
// Copyright (C) 2023-2026 Intel Corporation
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

@@ -44,6 +44,11 @@ TEST_F(test, internals) {
4444
*pageSize = 1024;
4545
return UMF_RESULT_SUCCESS;
4646
}
47+
48+
umf_result_t get_cache_line_size(size_t *size) noexcept {
49+
*size = 128;
50+
return UMF_RESULT_SUCCESS;
51+
}
4752
};
4853
umf_memory_provider_ops_t provider_ops =
4954
umf_test::providerMakeCOps<memory_provider, void>();
@@ -78,7 +83,11 @@ TEST_F(test, internals) {
7883
EXPECT_EQ(pool->provider_min_page_size, (size_t)1024);
7984

8085
// check buckets sizes
81-
size_t expected_size = DEFAULT_DISJOINT_MIN_BUCKET_SIZE;
86+
size_t cacheline_size = 0;
87+
res = umfMemoryProviderGetCacheLineSize(provider_handle, &cacheline_size);
88+
EXPECT_EQ(res, UMF_RESULT_SUCCESS);
89+
size_t expected_size = cacheline_size;
90+
8291
EXPECT_EQ(pool->buckets[0]->size, expected_size);
8392
EXPECT_EQ(pool->buckets[pool->buckets_num - 1]->size,
8493
(size_t)1 << 31); // 2GB
@@ -87,12 +96,11 @@ TEST_F(test, internals) {
8796
EXPECT_NE(bucket, nullptr);
8897
EXPECT_EQ(bucket->size, expected_size);
8998

90-
// assuming DEFAULT_DISJOINT_MIN_BUCKET_SIZE = 64, expected bucket
91-
// sizes are: 64, 96, 128, 192, 256, ..., 2GB
99+
// expected bucket sizes are: 128, 192, 256, ..., 2GB
92100
if (i % 2 == 0) {
93101
expected_size += expected_size / 2;
94102
} else {
95-
expected_size = DEFAULT_DISJOINT_MIN_BUCKET_SIZE << ((i + 1) / 2);
103+
expected_size = cacheline_size << ((i + 1) / 2);
96104
}
97105
}
98106

0 commit comments

Comments
 (0)