(git:5a3db73)
Loading...
Searching...
No Matches
offload_mempool.c
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7#include "offload_mempool.h"
8#include "../mpiwrap/cp_mpi.h"
9#include "offload_library.h"
10#include "offload_runtime.h"
11
12#include "../base/cp_assert.h"
13#include <inttypes.h>
14#include <omp.h>
15#include <stdbool.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#if defined(__parallel)
21#include <mpi.h>
22#endif
23
24#define OFFLOAD_MEMPOOL_PRINT(FN, MSG, OUTPUT_UNIT) \
25 ((FN)(MSG, (int)strlen(MSG), OUTPUT_UNIT))
26#define OFFLOAD_MEMPOOL_OMPALLOC 1
27// A reused chunk exceeds the requested size by at most this fraction, and the
28// pool holds at most the most ever requested at once plus this fraction of it:
29// what a workload needs again stays cached, whereas sizes that do not fit
30// cannot let the pool grow without bound (the bound covers the reuse waste).
31#define OFFLOAD_MEMPOOL_SLACK 4 /* 1/4 */
33
34/*******************************************************************************
35 * \brief Private struct for storing a chunk of memory.
36 * \author Ole Schuett
37 ******************************************************************************/
38typedef struct offload_memchunk {
39 void *mem; // first: allows to cast memchunk into mem-ptr...
40 struct offload_memchunk *next; // hash chain or idle stack of one size
42 union {
43 struct offload_memchunk *right; // idle size tree
44 size_t used; // requested bytes while on loan
45 };
46 size_t size;
48
49/*******************************************************************************
50 * \brief Private struct for storing a memory pool.
51 * \author Ole Schuett
52 ******************************************************************************/
53typedef struct offload_mempool {
54 offload_memchunk_t *available; // one tree node per distinct idle capacity
55 offload_memchunk_t **allocated; // allocated chunks indexed by address
58 uint64_t mallocs; // backend allocations, retained across clear
60 uint64_t allocated_used, used_peak; // requested sizes in use, most ever
61 uint64_t peak_size; // peak total capacity before trimming
63
64/*******************************************************************************
65 * \brief Private pools for host and device memory.
66 * \author Ole Schuett
67 ******************************************************************************/
68static offload_mempool_t mempool_host = {.allocated =
69 mempool_host.initial_buckets,
70 .nbuckets = MEMPOOL_INITIAL_BUCKETS};
71static offload_mempool_t mempool_device = {.allocated =
72 mempool_device.initial_buckets,
73 .nbuckets = MEMPOOL_INITIAL_BUCKETS};
74
75/*******************************************************************************
76 * \brief Returns the larger of two given integer (missing from the C standard)
77 * \author Ole Schuett
78 ******************************************************************************/
79static inline uint64_t imax(uint64_t x, uint64_t y) { return (x > y ? x : y); }
80
81/*******************************************************************************
82 * \brief Private routine for actually allocating system memory.
83 * \author Ole Schuett
84 ******************************************************************************/
85static void *actual_malloc(const size_t size, const bool on_device) {
86 if (size == 0) {
87 return NULL;
88 }
89
90 void *memory = NULL;
91 (void)on_device; // used only by offload backends
92
93// This pool must not sit on top of LIBXSTREAM's pool (double caching).
94#if defined(__OFFLOAD) && defined(__LIBXSTREAM)
96 if (on_device) {
97 OFFLOAD_CHECK(libxstream_mem_dev_allocate_hint(&memory, size,
98 LIBXSTREAM_MALLOC_CP2K));
99 } else {
100 OFFLOAD_CHECK(libxstream_mem_host_allocate_hint(&memory, size,
101 LIBXSTREAM_MALLOC_CP2K));
102 }
103#elif defined(__OFFLOAD)
104 if (on_device) {
106 offloadMalloc(&memory, size);
107 } else {
109 offloadMallocHost(&memory, size);
110 }
111#elif OFFLOAD_MEMPOOL_OMPALLOC && (201811 /*v5.0*/ <= _OPENMP)
112 memory = omp_alloc(size, omp_null_allocator);
113#elif defined(__parallel) && !OFFLOAD_MEMPOOL_OMPALLOC
114 if (MPI_SUCCESS != MPI_Alloc_mem((MPI_Aint)size, MPI_INFO_NULL, &memory)) {
115 fprintf(stderr, "ERROR: MPI_Alloc_mem failed at %s:%i\n", name, __FILE__,
116 __LINE__);
117 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
118 }
119#else
120 memory = malloc(size);
121#endif
122
123 cp_assert(memory != NULL);
124 return memory;
125}
126
127/*******************************************************************************
128 * \brief Private routine for actually freeing system memory.
129 * \author Ole Schuett
130 ******************************************************************************/
131static void actual_free(void *memory, const bool on_device) {
132 if (NULL == memory) {
133 return;
134 }
135
136// This pool must not sit on top of LIBXSTREAM's pool (double caching).
137#if defined(__OFFLOAD) && defined(__LIBXSTREAM)
139 if (on_device) {
140 OFFLOAD_CHECK(
141 libxstream_mem_dev_deallocate_hint(memory, LIBXSTREAM_MALLOC_CP2K));
142 } else {
143 OFFLOAD_CHECK(
144 libxstream_mem_host_deallocate_hint(memory, LIBXSTREAM_MALLOC_CP2K));
145 }
146#elif defined(__OFFLOAD)
147 if (on_device) {
149 offloadFree(memory);
150 } else {
152 offloadFreeHost(memory);
153 }
154#elif OFFLOAD_MEMPOOL_OMPALLOC && (201811 /*v5.0*/ <= _OPENMP)
155 (void)on_device; // mark used
156 omp_free(memory, omp_null_allocator);
157#elif defined(__parallel) && !OFFLOAD_MEMPOOL_OMPALLOC
158 (void)on_device; // mark used
159 if (MPI_SUCCESS != MPI_Free_mem(memory)) {
160 fprintf(stderr, "ERROR: MPI_Free_mem failed at %s:%i\n", name, __FILE__,
161 __LINE__);
162 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
163 }
164#else
165 (void)on_device; // mark used
166 free(memory);
167#endif
168}
169
170/*******************************************************************************
171 * \brief Bucket for an aligned host or device address (power-of-two table).
172 ******************************************************************************/
173static size_t mempool_bucket(const void *mem, size_t nbuckets) {
174 uint64_t key = (uintptr_t)mem;
175 key ^= key >> 32;
176 key *= UINT64_C(11400714819323198485);
177 return (key ^ (key >> 32)) & (nbuckets - 1);
178}
179
180/*******************************************************************************
181 * \brief Grow the address index. Chaining still works if resizing fails.
182 ******************************************************************************/
184 const size_t n = 2 * pool->nbuckets;
185 offload_memchunk_t **buckets = calloc(n, sizeof(*buckets));
186 if (buckets == NULL) {
187 return;
188 }
189 for (size_t i = 0; i < pool->nbuckets; ++i) {
190 offload_memchunk_t *entry = pool->allocated[i];
191 while (entry != NULL) {
192 offload_memchunk_t *next = entry->next;
193 const size_t bucket = mempool_bucket(entry->mem, n);
194 entry->next = buckets[bucket];
195 buckets[bucket] = entry;
196 entry = next;
197 }
198 }
199 if (pool->allocated != pool->initial_buckets) {
200 free(pool->allocated);
201 }
202 pool->allocated = buckets;
203 pool->nbuckets = n;
204}
205
206/*******************************************************************************
207 * \brief Register a loan and account for the requested and actual chunk sizes.
208 * All index operations on the pool use offload_mempool_modify.
209 ******************************************************************************/
211 size_t requested) {
212 if (pool->nallocated >= pool->nbuckets) {
213 mempool_grow_table(pool);
214 }
215 const size_t bucket = mempool_bucket(chunk->mem, pool->nbuckets);
216 chunk->next = pool->allocated[bucket];
217 pool->allocated[bucket] = chunk;
218 ++pool->nallocated;
219 chunk->used = requested;
220 pool->allocated_size += chunk->size;
221 pool->allocated_used += requested;
222 pool->used_peak = imax(pool->used_peak, pool->allocated_used);
223}
224
225/*******************************************************************************
226 * \brief Bring an idle capacity (or the last node on its search path) to the
227 * root. Top-down splaying needs no parent pointers or recursion.
228 ******************************************************************************/
230 size_t size) {
231 offload_memchunk_t head, *less = &head, *greater = &head;
232 head.left = head.right = NULL;
233 for (;;) {
234 if (size < root->size && root->left != NULL) {
235 offload_memchunk_t *child = root->left;
236 if (size < child->size) {
237 root->left = child->right;
238 child->right = root;
239 root = child;
240 if (root->left == NULL) {
241 break;
242 }
243 }
244 greater->left = root;
245 greater = root;
246 root = root->left;
247 } else if (size > root->size && root->right != NULL) {
248 offload_memchunk_t *child = root->right;
249 if (size > child->size) {
250 root->right = child->left;
251 child->left = root;
252 root = child;
253 if (root->right == NULL) {
254 break;
255 }
256 }
257 less->right = root;
258 less = root;
259 root = root->right;
260 } else {
261 break;
262 }
263 }
264 less->right = root->left;
265 greater->left = root->right;
266 root->left = head.right;
267 root->right = head.left;
268 return root;
269}
270
271/*******************************************************************************
272 * \brief Insert a returned chunk by its actual capacity. Within a size, the
273 * most recently returned chunk is the first one reused or trimmed.
274 ******************************************************************************/
276 offload_memchunk_t *root = pool->available;
277 if (root != NULL && root->size != chunk->size) {
278 root = mempool_splay(root, chunk->size);
279 }
280 if (root != NULL && root->size == chunk->size) {
281 chunk->next = root->next;
282 root->next = chunk;
283 pool->available = root;
284 } else {
285 chunk->next = chunk->left = chunk->right = NULL;
286 if (root != NULL) {
287 if (chunk->size < root->size) {
288 chunk->left = root->left;
289 chunk->right = root;
290 root->left = NULL;
291 } else {
292 chunk->right = root->right;
293 chunk->left = root;
294 root->right = NULL;
295 }
296 }
297 pool->available = chunk;
298 }
299 pool->available_size += chunk->size;
300}
301
302/*******************************************************************************
303 * \brief Take a chunk from the size currently at the root of the idle tree.
304 ******************************************************************************/
306 offload_memchunk_t *root = pool->available;
307 offload_memchunk_t *chunk = root->next;
308 if (chunk != NULL) {
309 root->next = chunk->next;
310 } else {
311 chunk = root;
312 if (root->left == NULL) {
313 pool->available = root->right;
314 } else if (root->right == NULL) {
315 pool->available = root->left;
316 } else {
317 pool->available = mempool_splay(root->left, root->size);
318 pool->available->right = root->right;
319 }
320 }
321 pool->available_size -= chunk->size;
322 return chunk;
323}
324
325/*******************************************************************************
326 * \brief Take the smallest idle chunk within the existing reuse tolerance.
327 ******************************************************************************/
329 size_t size) {
330 offload_memchunk_t *root = pool->available;
331 if (root == NULL) {
332 return NULL;
333 }
334 if (root->size != size) {
335 root = mempool_splay(root, size);
336 if (root->size < size && root->right != NULL) {
337 // The search ended at the predecessor. Promote its successor.
338 offload_memchunk_t *successor = mempool_splay(root->right, size);
339 cp_assert(successor->left == NULL);
340 root->right = NULL;
341 successor->left = root;
342 root = successor;
343 }
344 pool->available = root;
345 }
346 if (root->size < size || root->size - size > size / OFFLOAD_MEMPOOL_SLACK) {
347 return NULL;
348 }
349 return mempool_take_root(pool);
350}
351
352/*******************************************************************************
353 * \brief Trim the largest idle chunks after a backend allocation. A cache hit
354 * or return only transfers capacity between the idle and live sets.
355 ******************************************************************************/
357 offload_memchunk_t *release = NULL;
358 uint64_t total = pool->available_size + pool->allocated_size;
359 while (pool->available != NULL && total > pool->used_peak &&
360 total - pool->used_peak > pool->used_peak / OFFLOAD_MEMPOOL_SLACK) {
361 if (pool->available->right != NULL) {
362 pool->available = mempool_splay(pool->available, SIZE_MAX);
363 }
365 total -= chunk->size;
366 chunk->next = release;
367 release = chunk;
368 }
369 return release;
370}
371
372/*******************************************************************************
373 * \brief Private routine for freeing the chunks taken out of the pool.
374 ******************************************************************************/
376 const bool on_device) {
377 while (release != NULL) {
378 offload_memchunk_t *const chunk = release;
379 release = chunk->next;
380 actual_free(chunk->mem, on_device);
381 free(chunk);
382 }
383}
384
385/*******************************************************************************
386 * \brief Private routine for allocating host or device memory from the pool.
387 * \author Ole Schuett and Hans Pabst
388 ******************************************************************************/
389static void *internal_mempool_malloc(offload_mempool_t *pool, const size_t size,
390 const bool on_device) {
391 if (size == 0) {
392 return NULL;
393 }
394
395 offload_memchunk_t *chunk;
396#pragma omp critical(offload_mempool_modify)
397 {
398 chunk = mempool_take_fit(pool, size);
399 if (chunk != NULL) {
400 mempool_register(pool, chunk, size);
401 }
402 }
403
404 if (chunk == NULL) {
405 chunk = malloc(sizeof(*chunk));
406 if (chunk == NULL) {
407 return NULL;
408 }
409 chunk->mem = actual_malloc(size, on_device);
410 if (chunk->mem == NULL) {
411 free(chunk);
412 return NULL;
413 }
414 chunk->size = size;
415 offload_memchunk_t *release;
416#pragma omp critical(offload_mempool_modify)
417 {
418 mempool_register(pool, chunk, size);
419 ++pool->mallocs;
420 pool->peak_size =
421 imax(pool->peak_size, pool->available_size + pool->allocated_size);
422 release = internal_mempool_trim(pool);
423 }
424 internal_mempool_release(release, on_device);
425 }
426 return chunk->mem;
427}
428
429/*******************************************************************************
430 * \brief Internal routine for allocating host memory from the pool.
431 * \author Ole Schuett
432 ******************************************************************************/
433void *offload_mempool_host_malloc(const size_t size) {
434 return internal_mempool_malloc(&mempool_host, size, false);
435}
436
437/*******************************************************************************
438 * \brief Internal routine for allocating device memory from the pool
439 * \author Ole Schuett
440 ******************************************************************************/
441void *offload_mempool_device_malloc(const size_t size) {
442 return internal_mempool_malloc(&mempool_device, size, true);
443}
444
445/*******************************************************************************
446 * \brief Private routine for releasing memory back to the pool.
447 * \author Ole Schuett
448 ******************************************************************************/
449static void internal_mempool_free(offload_mempool_t *pool, const void *mem) {
450 if (mem == NULL) {
451 return;
452 }
453#pragma omp critical(offload_mempool_modify)
454 {
455 cp_assert(pool->nallocated > 0);
456 const size_t bucket = mempool_bucket(mem, pool->nbuckets);
457 offload_memchunk_t **link = &pool->allocated[bucket];
458 while (*link != NULL && (*link)->mem != mem) {
459 link = &(*link)->next;
460 }
461 offload_memchunk_t *chunk = *link;
462 cp_assert(chunk != NULL);
463 *link = chunk->next;
464 --pool->nallocated;
465 pool->allocated_size -= chunk->size;
466 pool->allocated_used -= chunk->used;
467 mempool_cache(pool, chunk);
468 }
469}
470
471/*******************************************************************************
472 * \brief Internal routine for releasing memory back to the pool.
473 * \author Ole Schuett
474 ******************************************************************************/
475void offload_mempool_host_free(const void *memory) {
477}
478
479/*******************************************************************************
480 * \brief Internal routine for releasing memory back to the pool.
481 * \author Ole Schuett
482 ******************************************************************************/
483void offload_mempool_device_free(const void *memory) {
485}
486
487/*******************************************************************************
488 * \brief Private routine for freeing all memory in the pool.
489 * \author Ole Schuett
490 ******************************************************************************/
492 const bool on_device) {
493 offload_memchunk_t *available, **buckets = NULL;
494#pragma omp critical(offload_mempool_modify)
495 {
496 cp_assert(pool->nallocated == 0);
497 if (pool->nallocated == 0 && pool->allocated != pool->initial_buckets) {
498 buckets = pool->allocated;
499 memset(pool->initial_buckets, 0, sizeof(pool->initial_buckets));
500 pool->allocated = pool->initial_buckets;
502 }
503 available = pool->available;
504 pool->available = NULL;
505 pool->available_size = 0;
506 pool->used_peak = pool->allocated_used;
507 }
508 free(buckets);
509 while (available != NULL) {
510 if (available->right != NULL) {
511 available = mempool_splay(available, SIZE_MAX);
512 }
513 offload_memchunk_t *next = available->left;
514 internal_mempool_release(available, on_device);
515 available = next;
516 }
517}
518
519/*******************************************************************************
520 * \brief Internal routine for freeing all memory in the pool.
521 * \author Ole Schuett and Hans Pabst
522 ******************************************************************************/
527
528/*******************************************************************************
529 * \brief Internal routine to query statistics.
530 * \author Hans Pabst
531 ******************************************************************************/
533 cp_assert(NULL != memstats);
534#pragma omp critical(offload_mempool_modify)
535 {
536 memstats->host_mallocs = mempool_host.mallocs;
537 memstats->host_used = mempool_host.used_peak;
538 memstats->host_size =
539 mempool_host.available_size + mempool_host.allocated_size;
540 memstats->host_peak = mempool_host.peak_size;
541
542 memstats->device_mallocs = mempool_device.mallocs;
543 memstats->device_used = mempool_device.used_peak;
544 memstats->device_size =
545 mempool_device.available_size + mempool_device.allocated_size;
546 memstats->device_peak = mempool_device.peak_size;
547 }
548}
549
550/*******************************************************************************
551 * \brief Print allocation statistics..
552 * \author Hans Pabst
553 ******************************************************************************/
554void offload_mempool_stats_print(int fortran_comm,
555 void (*print_func)(const char *, int, int),
556 int output_unit) {
557 cp_assert(omp_get_num_threads() == 1);
558
559 char buffer[100];
560 const cp_mpi_comm_t comm = cp_mpi_comm_f2c(fortran_comm);
562 offload_mempool_stats_get(&memstats);
563 cp_mpi_max_uint64(&memstats.device_mallocs, 1, comm);
564 cp_mpi_max_uint64(&memstats.host_mallocs, 1, comm);
565
566 if (0 != memstats.device_mallocs || 0 != memstats.host_mallocs) {
567 OFFLOAD_MEMPOOL_PRINT(print_func, "\n", output_unit);
570 " ----------------------------------------------------------------"
571 "---------------\n",
572 output_unit);
575 " - "
576 " -\n",
577 output_unit);
578
581 " - OFFLOAD MEMPOOL STATISTICS "
582 " -\n",
583 output_unit);
586 " - "
587 " -\n",
588 output_unit);
591 " ----------------------------------------------------------------"
592 "---------------\n",
593 output_unit);
595 " Memory consumption "
596 " Number of allocations Used [MiB] Size [MiB]\n",
597 output_unit);
598 }
599#if defined(__OFFLOAD)
600 if (0 < memstats.device_mallocs) {
601 cp_mpi_max_uint64(&memstats.device_peak, 1, comm);
602 snprintf(buffer, sizeof(buffer),
603 " Device "
604 " %20" PRIuPTR " %10" PRIuPTR " %10" PRIuPTR "\n",
605 (uintptr_t)memstats.device_mallocs,
606 (uintptr_t)((memstats.device_used + (512U << 10)) >> 20),
607 (uintptr_t)((memstats.device_peak + (512U << 10)) >> 20));
608 OFFLOAD_MEMPOOL_PRINT(print_func, buffer, output_unit);
609 }
610#endif
611 if (0 < memstats.host_mallocs) {
612 cp_mpi_max_uint64(&memstats.host_peak, 1, comm);
613 snprintf(buffer, sizeof(buffer),
614 " Host "
615 " %20" PRIuPTR " %10" PRIuPTR " %10" PRIuPTR "\n",
616 (uintptr_t)memstats.host_mallocs,
617 (uintptr_t)((memstats.host_used + (512U << 10)) >> 20),
618 (uintptr_t)((memstats.host_peak + (512U << 10)) >> 20));
619 OFFLOAD_MEMPOOL_PRINT(print_func, buffer, output_unit);
620 }
621 if (0 < memstats.device_mallocs || 0 < memstats.host_mallocs) {
624 " ----------------------------------------------------------------"
625 "---------------\n",
626 output_unit);
627 }
628}
629
630// EOF
#define cp_assert(condition)
Definition cp_assert.h:22
void cp_mpi_max_uint64(uint64_t *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_UINT64_T.
Definition cp_mpi.c:380
cp_mpi_comm_t cp_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
Definition cp_mpi.c:162
int cp_mpi_comm_t
Definition cp_mpi.h:18
static void print_func(const char *msg, int msglen, int output_unit)
Wrapper for printf, passed to dbm_library_print_stats.
Definition dbm_miniapp.c:26
static void const int const int i
void offload_activate_chosen_device(void)
Activates the device selected via offload_set_chosen_device().
static void internal_mempool_free(offload_mempool_t *pool, const void *mem)
Private routine for releasing memory back to the pool.
static void mempool_grow_table(offload_mempool_t *pool)
Grow the address index. Chaining still works if resizing fails.
struct offload_memchunk offload_memchunk_t
Private struct for storing a chunk of memory.
static offload_mempool_t mempool_device
static void actual_free(void *memory, const bool on_device)
Private routine for actually freeing system memory.
void offload_mempool_host_free(const void *memory)
Internal routine for releasing memory back to the pool.
void offload_mempool_clear(void)
Internal routine for freeing all memory in the pool.
void offload_mempool_device_free(const void *memory)
Internal routine for releasing memory back to the pool.
static void * internal_mempool_malloc(offload_mempool_t *pool, const size_t size, const bool on_device)
Private routine for allocating host or device memory from the pool.
#define OFFLOAD_MEMPOOL_PRINT(FN, MSG, OUTPUT_UNIT)
void offload_mempool_stats_get(offload_mempool_stats_t *memstats)
Internal routine to query statistics.
static offload_memchunk_t * mempool_take_fit(offload_mempool_t *pool, size_t size)
Take the smallest idle chunk within the existing reuse tolerance.
static size_t mempool_bucket(const void *mem, size_t nbuckets)
Bucket for an aligned host or device address (power-of-two table).
#define OFFLOAD_MEMPOOL_SLACK
static void * actual_malloc(const size_t size, const bool on_device)
Private routine for actually allocating system memory.
static void internal_mempool_clear(offload_mempool_t *pool, const bool on_device)
Private routine for freeing all memory in the pool.
static uint64_t imax(uint64_t x, uint64_t y)
Returns the larger of two given integer (missing from the C standard).
struct offload_mempool offload_mempool_t
Private struct for storing a memory pool.
@ MEMPOOL_INITIAL_BUCKETS
static void mempool_cache(offload_mempool_t *pool, offload_memchunk_t *chunk)
Insert a returned chunk by its actual capacity. Within a size, the most recently returned chunk is th...
static offload_memchunk_t * mempool_splay(offload_memchunk_t *root, size_t size)
Bring an idle capacity (or the last node on its search path) to the root. Top-down splaying needs no ...
void offload_mempool_stats_print(int fortran_comm, void(*print_func)(const char *, int, int), int output_unit)
Print allocation statistics..
void * offload_mempool_host_malloc(const size_t size)
Internal routine for allocating host memory from the pool.
void * offload_mempool_device_malloc(const size_t size)
Internal routine for allocating device memory from the pool.
static offload_memchunk_t * mempool_take_root(offload_mempool_t *pool)
Take a chunk from the size currently at the root of the idle tree.
static offload_mempool_t mempool_host
Private pools for host and device memory.
static offload_memchunk_t * internal_mempool_trim(offload_mempool_t *pool)
Trim the largest idle chunks after a backend allocation. A cache hit or return only transfers capacit...
static void internal_mempool_release(offload_memchunk_t *release, const bool on_device)
Private routine for freeing the chunks taken out of the pool.
static void mempool_register(offload_mempool_t *pool, offload_memchunk_t *chunk, size_t requested)
Register a loan and account for the requested and actual chunk sizes. All index operations on the poo...
Private struct for storing a chunk of memory.
struct offload_memchunk * next
struct offload_memchunk * left
struct offload_memchunk * right
Internal struct for pool statistics.
Private struct for storing a memory pool.
offload_memchunk_t * available
offload_memchunk_t ** allocated
uint64_t allocated_used
uint64_t allocated_size
offload_memchunk_t * initial_buckets[MEMPOOL_INITIAL_BUCKETS]
uint64_t available_size