Skip to content

Commit 09e9408

Browse files
committed
rebase
1 parent 940b2d4 commit 09e9408

File tree

3 files changed

+179
-5
lines changed

3 files changed

+179
-5
lines changed

src/pool/pool_disjoint.c

Lines changed: 147 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ void slab_unreg(slab_t *slab) {
231231
slab_unreg_by_addr(end_addr, slab);
232232
}
233233

234-
bucket_t *create_bucket(size_t sz, disjoint_pool_t *pool,
235-
umf_disjoint_pool_shared_limits_t *shared_limits) {
234+
bucket_t *
235+
create_bucket(size_t sz, disjoint_pool_t *pool,
236+
umf_disjoint_pool_shared_limits_handle_t shared_limits) {
236237

237238
bucket_t *bucket = (bucket_t *)umf_ba_global_alloc(sizeof(bucket_t));
238239
if (bucket == NULL) {
@@ -1089,3 +1090,147 @@ void umfDisjointPoolSharedLimitsDestroy(
10891090
umf_disjoint_pool_shared_limits_t *limits) {
10901091
umf_ba_global_free(limits);
10911092
}
1093+
1094+
umf_result_t
1095+
umfDisjointPoolParamsCreate(umf_disjoint_pool_params_handle_t *hParams) {
1096+
static const char *DEFAULT_NAME = "disjoint_pool";
1097+
1098+
if (!hParams) {
1099+
LOG_ERR("disjoint pool params handle is NULL");
1100+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1101+
}
1102+
1103+
umf_disjoint_pool_params_handle_t params =
1104+
umf_ba_global_alloc(sizeof(umf_disjoint_pool_params_t));
1105+
if (params == NULL) {
1106+
LOG_ERR("cannot allocate memory for disjoint pool params");
1107+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
1108+
}
1109+
1110+
params->SlabMinSize = 0;
1111+
params->MaxPoolableSize = 0;
1112+
params->Capacity = 0;
1113+
params->MinBucketSize = UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE;
1114+
params->CurPoolSize = 0;
1115+
params->PoolTrace = 0;
1116+
params->SharedLimits = NULL;
1117+
params->Name = NULL;
1118+
1119+
umf_result_t ret = umfDisjointPoolParamsSetName(params, DEFAULT_NAME);
1120+
if (ret != UMF_RESULT_SUCCESS) {
1121+
umf_ba_global_free(params);
1122+
return ret;
1123+
}
1124+
1125+
*hParams = params;
1126+
1127+
return UMF_RESULT_SUCCESS;
1128+
}
1129+
1130+
umf_result_t
1131+
umfDisjointPoolParamsDestroy(umf_disjoint_pool_params_handle_t hParams) {
1132+
if (hParams) {
1133+
umf_ba_global_free(hParams->Name);
1134+
umf_ba_global_free(hParams);
1135+
}
1136+
1137+
return UMF_RESULT_SUCCESS;
1138+
}
1139+
1140+
umf_result_t
1141+
umfDisjointPoolParamsSetSlabMinSize(umf_disjoint_pool_params_handle_t hParams,
1142+
size_t slabMinSize) {
1143+
if (!hParams) {
1144+
LOG_ERR("disjoint pool params handle is NULL");
1145+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1146+
}
1147+
1148+
hParams->SlabMinSize = slabMinSize;
1149+
return UMF_RESULT_SUCCESS;
1150+
}
1151+
1152+
umf_result_t umfDisjointPoolParamsSetMaxPoolableSize(
1153+
umf_disjoint_pool_params_handle_t hParams, size_t maxPoolableSize) {
1154+
if (!hParams) {
1155+
LOG_ERR("disjoint pool params handle is NULL");
1156+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1157+
}
1158+
1159+
hParams->MaxPoolableSize = maxPoolableSize;
1160+
return UMF_RESULT_SUCCESS;
1161+
}
1162+
1163+
umf_result_t
1164+
umfDisjointPoolParamsSetCapacity(umf_disjoint_pool_params_handle_t hParams,
1165+
size_t maxCapacity) {
1166+
if (!hParams) {
1167+
LOG_ERR("disjoint pool params handle is NULL");
1168+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1169+
}
1170+
1171+
hParams->Capacity = maxCapacity;
1172+
return UMF_RESULT_SUCCESS;
1173+
}
1174+
1175+
umf_result_t
1176+
umfDisjointPoolParamsSetMinBucketSize(umf_disjoint_pool_params_handle_t hParams,
1177+
size_t minBucketSize) {
1178+
if (!hParams) {
1179+
LOG_ERR("disjoint pool params handle is NULL");
1180+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1181+
}
1182+
1183+
// minBucketSize parameter must be a power of 2 and greater than 0.
1184+
if (minBucketSize == 0 || (minBucketSize & (minBucketSize - 1))) {
1185+
LOG_ERR("minBucketSize must be a power of 2 and greater than 0");
1186+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1187+
}
1188+
1189+
hParams->MinBucketSize = minBucketSize;
1190+
return UMF_RESULT_SUCCESS;
1191+
}
1192+
1193+
umf_result_t
1194+
umfDisjointPoolParamsSetTrace(umf_disjoint_pool_params_handle_t hParams,
1195+
int poolTrace) {
1196+
if (!hParams) {
1197+
LOG_ERR("disjoint pool params handle is NULL");
1198+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1199+
}
1200+
1201+
hParams->PoolTrace = poolTrace;
1202+
return UMF_RESULT_SUCCESS;
1203+
}
1204+
1205+
umf_result_t umfDisjointPoolParamsSetSharedLimits(
1206+
umf_disjoint_pool_params_handle_t hParams,
1207+
umf_disjoint_pool_shared_limits_handle_t hSharedLimits) {
1208+
if (!hParams) {
1209+
LOG_ERR("disjoint pool params handle is NULL");
1210+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1211+
}
1212+
1213+
hParams->SharedLimits = hSharedLimits;
1214+
return UMF_RESULT_SUCCESS;
1215+
}
1216+
1217+
umf_result_t
1218+
umfDisjointPoolParamsSetName(umf_disjoint_pool_params_handle_t hParams,
1219+
const char *name) {
1220+
if (!hParams) {
1221+
LOG_ERR("disjoint pool params handle is NULL");
1222+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
1223+
}
1224+
1225+
char *newName = umf_ba_global_alloc(sizeof(char) * (strlen(name) + 1));
1226+
if (newName == NULL) {
1227+
LOG_ERR("cannot allocate memory for disjoint pool name");
1228+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
1229+
}
1230+
1231+
umf_ba_global_free(hParams->Name);
1232+
hParams->Name = newName;
1233+
strcpy(hParams->Name, name);
1234+
1235+
return UMF_RESULT_SUCCESS;
1236+
}

src/pool/pool_disjoint_internal.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef struct bucket_t {
5151
// routines, slab map and etc.
5252
disjoint_pool_t *pool;
5353

54-
umf_disjoint_pool_shared_limits_t *shared_limits;
54+
umf_disjoint_pool_shared_limits_handle_t shared_limits;
5555

5656
// For buckets used in chunked mode, a counter of slabs in the pool.
5757
// For allocations that use an entire slab each, the entries in the Available
@@ -121,6 +121,35 @@ typedef struct umf_disjoint_pool_shared_limits_t {
121121
size_t total_size; // requires atomic access
122122
} umf_disjoint_pool_shared_limits_t;
123123

124+
typedef struct umf_disjoint_pool_params_t {
125+
// Minimum allocation size that will be requested from the memory provider.
126+
size_t SlabMinSize;
127+
128+
// Allocations up to this limit will be subject to chunking/pooling
129+
size_t MaxPoolableSize;
130+
131+
// When pooling, each bucket will hold a max of 'Capacity' unfreed slabs
132+
size_t Capacity;
133+
134+
// Holds the minimum bucket size valid for allocation of a memory type.
135+
// This value must be a power of 2.
136+
size_t MinBucketSize;
137+
138+
// Holds size of the pool managed by the allocator.
139+
size_t CurPoolSize;
140+
141+
// Whether to print pool usage statistics
142+
int PoolTrace;
143+
144+
// Memory limits that can be shared between multitple pool instances,
145+
// i.e. if multiple pools use the same SharedLimits sum of those pools'
146+
// sizes cannot exceed MaxSize.
147+
umf_disjoint_pool_shared_limits_handle_t SharedLimits;
148+
149+
// Name used in traces
150+
char *Name;
151+
} umf_disjoint_pool_params_t;
152+
124153
typedef struct disjoint_pool_t {
125154
// It's important for the map to be destroyed last after buckets and their
126155
// slabs This is because slab's destructor removes the object from the map.
@@ -139,7 +168,7 @@ typedef struct disjoint_pool_t {
139168
// Configuration for this instance
140169
umf_disjoint_pool_params_t params;
141170

142-
umf_disjoint_pool_shared_limits_t *default_shared_limits;
171+
umf_disjoint_pool_shared_limits_handle_t default_shared_limits;
143172

144173
// Used in algorithm for finding buckets
145174
size_t min_bucket_size_exp;

test/pools/disjoint_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ TEST_F(test, internals) {
8686
umf_memory_provider_handle_t provider_handle;
8787
provider_handle = providerUnique.get();
8888

89-
umf_disjoint_pool_params_t params = poolConfig();
89+
umf_disjoint_pool_params_t params = *poolConfig();
9090
// set to maximum tracing
9191
params.PoolTrace = 3;
9292

0 commit comments

Comments
 (0)