Skip to content

Commit 805919a

Browse files
committed
[disjoint] Set default parameters for disjoint pool
1 parent 3a4a335 commit 805919a

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

include/umf/pools/pool_disjoint.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ umf_result_t
5151
umfDisjointPoolParamsDestroy(umf_disjoint_pool_params_handle_t hParams);
5252

5353
/// @brief Set minimum allocation size that will be requested from the memory provider.
54+
/// @details Default value for minimum size of slab's is 64KB.
5455
/// @param hParams handle to the parameters of the disjoint pool.
5556
/// @param slabMinSize minimum allocation size.
5657
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
@@ -59,6 +60,7 @@ umfDisjointPoolParamsSetSlabMinSize(umf_disjoint_pool_params_handle_t hParams,
5960
size_t slabMinSize);
6061

6162
/// @brief Set size limit for allocations that are subject to pooling.
63+
/// @details Default value for maximum poolable size is 2MB.
6264
/// @param hParams handle to the parameters of the disjoint pool.
6365
/// @param maxPoolableSize maximum poolable size.
6466
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
@@ -67,6 +69,7 @@ umf_result_t umfDisjointPoolParamsSetMaxPoolableSize(
6769

6870
/// @brief Set maximum capacity of each bucket. Each bucket will hold a
6971
/// max of \p maxCapacity unfreed slabs.
72+
/// @details Default value for capacity is 4.
7073
/// @param hParams handle to the parameters of the disjoint pool.
7174
/// @param maxCapacity maximum capacity of each bucket.
7275
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.

src/pool/pool_disjoint.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,9 @@ umfDisjointPoolParamsCreate(umf_disjoint_pool_params_handle_t *hParams) {
10731073
}
10741074

10751075
*params = (umf_disjoint_pool_params_t){
1076-
.slab_min_size = 0,
1077-
.max_poolable_size = 0,
1078-
.capacity = 0,
1076+
.slab_min_size = 64 * 1024, // 64K
1077+
.max_poolable_size = 2 * 1024 * 1024, // 2MB
1078+
.capacity = 4,
10791079
.min_bucket_size = UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE,
10801080
.cur_pool_size = 0,
10811081
.pool_trace = 0,

src/pool/pool_disjoint_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ typedef struct umf_disjoint_pool_shared_limits_t {
110110

111111
typedef struct umf_disjoint_pool_params_t {
112112
// Minimum allocation size that will be requested from the memory provider.
113-
size_t slab_min_size;
113+
size_t slab_min_size; // Default: 64KB
114114

115115
// Allocations up to this limit will be subject to chunking/pooling
116-
size_t max_poolable_size;
116+
size_t max_poolable_size; // Default: 2MB
117117

118118
// When pooling, each bucket will hold a max of 'capacity' unfreed slabs
119-
size_t capacity;
119+
size_t capacity; // Default: 4
120120

121121
// Holds the minimum bucket size valid for allocation of a memory type.
122122
// This value must be a power of 2.

test/pools/disjoint_pool.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,57 @@ TEST_F(test, disjointPoolName) {
356356
umfDisjointPoolParamsDestroy(params);
357357
}
358358

359+
TEST_F(test, disjointPoolDefaultParams) {
360+
umf_disjoint_pool_params_handle_t params = nullptr;
361+
umf_memory_pool_handle_t pool = nullptr;
362+
umf_memory_provider_handle_t provider_handle = nullptr;
363+
364+
// Create disjoint pool parameters with default settings
365+
umf_result_t res = umfDisjointPoolParamsCreate(&params);
366+
EXPECT_EQ(res, UMF_RESULT_SUCCESS);
367+
368+
struct memory_provider : public umf_test::provider_base_t {
369+
umf_result_t alloc(size_t size, size_t alignment, void **ptr) noexcept {
370+
*ptr = umf_ba_global_aligned_alloc(size, alignment);
371+
return UMF_RESULT_SUCCESS;
372+
}
373+
374+
umf_result_t free(void *ptr, [[maybe_unused]] size_t size) noexcept {
375+
// do the actual free only when we expect the success
376+
umf_ba_global_free(ptr);
377+
return UMF_RESULT_SUCCESS;
378+
}
379+
};
380+
381+
umf_memory_provider_ops_t provider_ops =
382+
umf_test::providerMakeCOps<memory_provider, void>();
383+
384+
auto providerUnique =
385+
wrapProviderUnique(createProviderChecked(&provider_ops, nullptr));
386+
provider_handle = providerUnique.get();
387+
388+
umf_result_t ret =
389+
umfPoolCreate(umfDisjointPoolOps(), provider_handle, params,
390+
UMF_POOL_CREATE_FLAG_DISABLE_TRACKING, &pool);
391+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
392+
393+
// Test allocation and deallocation
394+
// This will use the default disjoint pool parameters
395+
void *ptr = umfPoolMalloc(pool, 64);
396+
ASSERT_NE(ptr, nullptr);
397+
ret = umfPoolFree(pool, ptr);
398+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
399+
400+
// Test allocation and deallocation with a different size
401+
ptr = umfPoolMalloc(pool, 1024);
402+
ASSERT_NE(ptr, nullptr);
403+
ret = umfPoolFree(pool, ptr);
404+
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
405+
406+
umfPoolDestroy(pool);
407+
umfDisjointPoolParamsDestroy(params);
408+
}
409+
359410
INSTANTIATE_TEST_SUITE_P(disjointPoolTests, umfPoolTest,
360411
::testing::Values(poolCreateExtParams{
361412
umfDisjointPoolOps(), defaultDisjointPoolConfig,

0 commit comments

Comments
 (0)