Skip to content

Commit

Permalink
Merge pull request #922 from DamianDuy/ensureMinBucketHasCorrectValues
Browse files Browse the repository at this point in the history
[umf] ensure MinBucketSize parameter is a power of two
  • Loading branch information
igchor authored Oct 6, 2023
2 parents c282ba0 + 47314b3 commit 9badc83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions source/common/umf_pools/disjoint_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,12 @@ umf_result_t DisjointPool::initialize(umf_memory_provider_handle_t *providers,
if (numProviders != 1 || !providers[0]) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}
// MinBucketSize parameter must be a power of 2 for bucket sizes
// to generate correctly.
if (!parameters.MinBucketSize ||
!((parameters.MinBucketSize & (parameters.MinBucketSize - 1)) == 0)) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}

impl = std::make_unique<AllocImpl>(providers[0], parameters);
return UMF_RESULT_SUCCESS;
Expand Down
3 changes: 2 additions & 1 deletion source/common/umf_pools/disjoint_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class DisjointPoolConfig {
size_t Capacity = 0;

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

// Holds size of the pool managed by the allocator.
size_t CurPoolSize = 0;
Expand Down

0 comments on commit 9badc83

Please sign in to comment.