hashmap: add an environment variable to turn off the memory pool used by hashmaps
Triggered by https://bugzilla.redhat.com/show_bug.cgi?id=1609349
This commit is contained in:
parent
64a7ef8bc0
commit
b4f607433c
|
@ -42,6 +42,9 @@ All tools:
|
||||||
are understood, too (us, ms, s, min, h, d, w, month, y). If it is not set or set
|
are understood, too (us, ms, s, min, h, d, w, month, y). If it is not set or set
|
||||||
to 0, then the built-in default is used.
|
to 0, then the built-in default is used.
|
||||||
|
|
||||||
|
* `$SYSTEMD_MEMPOOL=0` — if set the internal memory caching logic employed by
|
||||||
|
hash tables is turned off, and libc malloc() is used for all allocations.
|
||||||
|
|
||||||
systemctl:
|
systemctl:
|
||||||
|
|
||||||
* `$SYSTEMCTL_FORCE_BUS=1` — if set, do not connect to PID1's private D-Bus
|
* `$SYSTEMCTL_FORCE_BUS=1` — if set, do not connect to PID1's private D-Bus
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "hashmap.h"
|
#include "env-util.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
|
#include "hashmap.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "process-util.h"
|
#include "process-util.h"
|
||||||
|
@ -766,20 +767,31 @@ static void reset_direct_storage(HashmapBase *h) {
|
||||||
memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets);
|
memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool use_pool(void) {
|
||||||
|
static int b = -1;
|
||||||
|
|
||||||
|
if (!is_main_thread())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (b < 0)
|
||||||
|
b = getenv_bool("SYSTEMD_MEMPOOL") != 0;
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
|
static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
|
||||||
HashmapBase *h;
|
HashmapBase *h;
|
||||||
const struct hashmap_type_info *hi = &hashmap_type_info[type];
|
const struct hashmap_type_info *hi = &hashmap_type_info[type];
|
||||||
bool use_pool;
|
bool up;
|
||||||
|
|
||||||
use_pool = is_main_thread();
|
up = use_pool();
|
||||||
|
|
||||||
h = use_pool ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
|
|
||||||
|
|
||||||
|
h = up ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
|
||||||
if (!h)
|
if (!h)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
h->type = type;
|
h->type = type;
|
||||||
h->from_pool = use_pool;
|
h->from_pool = up;
|
||||||
h->hash_ops = hash_ops ? hash_ops : &trivial_hash_ops;
|
h->hash_ops = hash_ops ? hash_ops : &trivial_hash_ops;
|
||||||
|
|
||||||
if (type == HASHMAP_TYPE_ORDERED) {
|
if (type == HASHMAP_TYPE_ORDERED) {
|
||||||
|
|
Loading…
Reference in New Issue