]>
git.proxmox.com Git - systemd.git/blob - src/basic/mempool.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 #include "memory-util.h"
10 #include "process-util.h"
19 void* mempool_alloc_tile(struct mempool
*mp
) {
22 /* When a tile is released we add it to the list and simply
23 * place the next pointer at its offset 0. */
25 assert(mp
->tile_size
>= sizeof(void*));
26 assert(mp
->at_least
> 0);
32 mp
->freelist
= * (void**) mp
->freelist
;
36 if (_unlikely_(!mp
->first_pool
) ||
37 _unlikely_(mp
->first_pool
->n_used
>= mp
->first_pool
->n_tiles
)) {
41 n
= mp
->first_pool
? mp
->first_pool
->n_tiles
: 0;
42 n
= MAX(mp
->at_least
, n
* 2);
43 size
= PAGE_ALIGN(ALIGN(sizeof(struct pool
)) + n
*mp
->tile_size
);
44 n
= (size
- ALIGN(sizeof(struct pool
))) / mp
->tile_size
;
50 p
->next
= mp
->first_pool
;
57 i
= mp
->first_pool
->n_used
++;
59 return ((uint8_t*) mp
->first_pool
) + ALIGN(sizeof(struct pool
)) + i
*mp
->tile_size
;
62 void* mempool_alloc0_tile(struct mempool
*mp
) {
65 p
= mempool_alloc_tile(mp
);
67 memzero(p
, mp
->tile_size
);
71 void mempool_free_tile(struct mempool
*mp
, void *p
) {
72 * (void**) p
= mp
->freelist
;
76 bool mempool_enabled(void) {
79 if (!is_main_thread())
82 if (!mempool_use_allowed
)
85 b
= getenv_bool("SYSTEMD_MEMPOOL") != 0;
91 void mempool_drop(struct mempool
*mp
) {
92 struct pool
*p
= mp
->first_pool
;