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
@@ -1120,6 +1120,7 @@ static const umf_disjoint_pool_params_t default_params = {
11201120 .max_poolable_size = 2 * 1024 * 1024 , // 2MB default
11211121 .capacity = 4 , // default
11221122 .min_bucket_size = 8 , // default
1123+ .min_bucket_size_set = false,
11231124 .cur_pool_size = 0 ,
11241125 .pool_trace = 0 ,
11251126 .shared_limits = NULL ,
@@ -1191,6 +1192,15 @@ umf_result_t disjoint_pool_post_initialize(void *ppPool) {
11911192 goto err_free_disjoint_pool ;
11921193 }
11931194
1195+ if (!disjoint_pool -> params .min_bucket_size_set ) {
1196+ size_t cache_line_size ;
1197+ umf_result_t ret = umfMemoryProviderGetCacheLineSize (
1198+ disjoint_pool -> provider , & cache_line_size );
1199+ if (ret == UMF_RESULT_SUCCESS ) {
1200+ disjoint_pool -> params .min_bucket_size = cache_line_size ;
1201+ }
1202+ }
1203+
11941204 // Generate buckets sized such as: 64, 96, 128, 192, ..., CutOff.
11951205 // Powers of 2 and the value halfway between the powers of 2.
11961206 size_t Size1 = disjoint_pool -> params .min_bucket_size ;
@@ -1201,6 +1211,11 @@ umf_result_t disjoint_pool_post_initialize(void *ppPool) {
12011211 // Buckets sized smaller than the bucket default size- 8 aren't needed.
12021212 Size1 = utils_max (Size1 , UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE );
12031213
1214+ // Calculate the size of the "halfway" bucket, round it up to the next
1215+ // multiple of min_bucket_size.
1216+ size_t Size2 = Size1 + Size1 / 2 ;
1217+ Size2 = ALIGN_UP_SAFE (Size2 , disjoint_pool -> params .min_bucket_size );
1218+
12041219 // Calculate the exponent for min_bucket_size used for finding buckets.
12051220 disjoint_pool -> min_bucket_size_exp = (size_t )utils_msb64 (Size1 );
12061221 if (umfDisjointPoolSharedLimitsCreate (
@@ -1211,11 +1226,10 @@ umf_result_t disjoint_pool_post_initialize(void *ppPool) {
12111226
12121227 // count number of buckets, start from 1
12131228 disjoint_pool -> buckets_num = 1 ;
1214- size_t Size2 = Size1 + Size1 / 2 ;
1215- size_t ts2 = Size2 , ts1 = Size1 ;
1216- while (Size2 < CutOff ) {
1229+ size_t ts2 = Size2 ;
1230+ while (ts2 < CutOff ) {
12171231 disjoint_pool -> buckets_num += 2 ;
1218- Size2 *= 2 ;
1232+ ts2 *= 2 ;
12191233 }
12201234
12211235 disjoint_pool -> buckets = umf_ba_global_alloc (
@@ -1225,8 +1239,6 @@ umf_result_t disjoint_pool_post_initialize(void *ppPool) {
12251239 }
12261240
12271241 size_t i = 0 ;
1228- Size1 = ts1 ;
1229- Size2 = ts2 ;
12301242 for (; Size2 < CutOff ; Size1 *= 2 , Size2 *= 2 , i += 2 ) {
12311243 disjoint_pool -> buckets [i ] = create_bucket (
12321244 Size1 , disjoint_pool , disjoint_pool_get_limits (disjoint_pool ));
@@ -1733,6 +1745,7 @@ umfDisjointPoolParamsSetMinBucketSize(umf_disjoint_pool_params_handle_t hParams,
17331745 }
17341746
17351747 hParams -> min_bucket_size = minBucketSize ;
1748+ hParams -> min_bucket_size_set = true;
17361749 return UMF_RESULT_SUCCESS ;
17371750}
17381751
0 commit comments