Skip to content

Commit 9badc83

Browse files
authored
Merge pull request #922 from DamianDuy/ensureMinBucketHasCorrectValues
[umf] ensure MinBucketSize parameter is a power of two
2 parents c282ba0 + 47314b3 commit 9badc83

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

source/common/umf_pools/disjoint_pool.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,12 @@ umf_result_t DisjointPool::initialize(umf_memory_provider_handle_t *providers,
894894
if (numProviders != 1 || !providers[0]) {
895895
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
896896
}
897+
// MinBucketSize parameter must be a power of 2 for bucket sizes
898+
// to generate correctly.
899+
if (!parameters.MinBucketSize ||
900+
!((parameters.MinBucketSize & (parameters.MinBucketSize - 1)) == 0)) {
901+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
902+
}
897903

898904
impl = std::make_unique<AllocImpl>(providers[0], parameters);
899905
return UMF_RESULT_SUCCESS;

source/common/umf_pools/disjoint_pool.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class DisjointPoolConfig {
4545
size_t Capacity = 0;
4646

4747
// Holds the minimum bucket size valid for allocation of a memory type.
48-
size_t MinBucketSize = 0;
48+
// This value must be a power of 2.
49+
size_t MinBucketSize = 1;
4950

5051
// Holds size of the pool managed by the allocator.
5152
size_t CurPoolSize = 0;

0 commit comments

Comments
 (0)