mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
This substantially reworks mempool_cleanup() so that it releases pools with all freed tiles only, but keeps all pools with still-allocated tiles around. This is more correct, as the previous implementation just released all pools regardless if anything was still used or not. This would make valgrind shut up but would just hide memory leaks altogether. Moreover if called during regular runtime of a program would result in bad memory accesses all over. Hence, let's add a proper implementation and only trim pools we really know are empty. This way we can safely call these functions later, when under memory pressure, at any time.
29 lines
670 B
C
29 lines
670 B
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
struct pool;
|
|
|
|
struct mempool {
|
|
struct pool *first_pool;
|
|
void *freelist;
|
|
size_t tile_size;
|
|
size_t at_least;
|
|
};
|
|
|
|
void* mempool_alloc_tile(struct mempool *mp);
|
|
void* mempool_alloc0_tile(struct mempool *mp);
|
|
void* mempool_free_tile(struct mempool *mp, void *p);
|
|
|
|
#define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \
|
|
static struct mempool pool_name = { \
|
|
.tile_size = sizeof(tile_type), \
|
|
.at_least = alloc_at_least, \
|
|
}
|
|
|
|
__attribute__((weak)) bool mempool_enabled(void);
|
|
|
|
void mempool_trim(struct mempool *mp);
|