summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-08-03 16:45:21 +0200
committerSven Eden <sven.eden@prydeworx.com>2018-10-29 10:18:30 +0100
commitf0d86baa42c3e699d1deeac4db9ef4dad3c4def5 (patch)
tree08e4077f05366f6fccb3645983b82f085396762d /src/basic
parent7e174f4ebccb5725e32dd5b78385ca0d41395c2c (diff)
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 (cherry picked from commit b4f607433cac749b617e15b3d5d122322ed2bc71)
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/hashmap.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 15c8c8816..2ece12e6c 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -6,8 +6,9 @@
#include <string.h>
#include "alloc-util.h"
-#include "hashmap.h"
+//#include "env-util.h"
#include "fileio.h"
+//#include "hashmap.h"
#include "macro.h"
#include "mempool.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);
}
+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) {
HashmapBase *h;
const struct hashmap_type_info *hi = &hashmap_type_info[type];
- bool use_pool;
-
- use_pool = is_main_thread();
+ bool up;
- h = use_pool ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
+ up = use_pool();
+ h = up ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
if (!h)
return NULL;
h->type = type;
- h->from_pool = use_pool;
+ h->from_pool = up;
h->hash_ops = hash_ops ? hash_ops : &trivial_hash_ops;
if (type == HASHMAP_TYPE_ORDERED) {