daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
9fc0f6
From 79d427226ea91530362d41e778e1064a396aad09 Mon Sep 17 00:00:00 2001
9fc0f6
From: Lennart Poettering <lennart@poettering.net>
9fc0f6
Date: Tue, 19 Nov 2013 21:02:59 +0100
9fc0f6
Subject: [PATCH] hashmap: be a bit more conservative with pre-allocating hash
9fc0f6
 tables and items
9fc0f6
9fc0f6
---
9fc0f6
 src/shared/hashmap.c | 9 +++++----
9fc0f6
 1 file changed, 5 insertions(+), 4 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
9fc0f6
index f06fce6..8f5957b 100644
9fc0f6
--- a/src/shared/hashmap.c
9fc0f6
+++ b/src/shared/hashmap.c
9fc0f6
@@ -66,13 +66,14 @@ static void *first_hashmap_tile = NULL;
9fc0f6
 static struct pool *first_entry_pool = NULL;
9fc0f6
 static void *first_entry_tile = NULL;
9fc0f6
 
9fc0f6
-static void* allocate_tile(struct pool **first_pool, void **first_tile, size_t tile_size) {
9fc0f6
+static void* allocate_tile(struct pool **first_pool, void **first_tile, size_t tile_size, unsigned at_least) {
9fc0f6
         unsigned i;
9fc0f6
 
9fc0f6
         /* When a tile is released we add it to the list and simply
9fc0f6
          * place the next pointer at its offset 0. */
9fc0f6
 
9fc0f6
         assert(tile_size >= sizeof(void*));
9fc0f6
+        assert(at_least > 0);
9fc0f6
 
9fc0f6
         if (*first_tile) {
9fc0f6
                 void *r;
9fc0f6
@@ -88,7 +89,7 @@ static void* allocate_tile(struct pool **first_pool, void **first_tile, size_t t
9fc0f6
                 struct pool *p;
9fc0f6
 
9fc0f6
                 n = *first_pool ? (*first_pool)->n_tiles : 0;
9fc0f6
-                n = MAX(512U, n * 2);
9fc0f6
+                n = MAX(at_least, n * 2);
9fc0f6
                 size = PAGE_ALIGN(ALIGN(sizeof(struct pool)) + n*tile_size);
9fc0f6
                 n = (size - ALIGN(sizeof(struct pool))) / tile_size;
9fc0f6
 
9fc0f6
@@ -191,7 +192,7 @@ Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) {
9fc0f6
         size = ALIGN(sizeof(Hashmap)) + INITIAL_N_BUCKETS * sizeof(struct hashmap_entry*);
9fc0f6
 
9fc0f6
         if (b) {
9fc0f6
-                h = allocate_tile(&first_hashmap_pool, &first_hashmap_tile, size);
9fc0f6
+                h = allocate_tile(&first_hashmap_pool, &first_hashmap_tile, size, 8);
9fc0f6
                 if (!h)
9fc0f6
                         return NULL;
9fc0f6
 
9fc0f6
@@ -476,7 +477,7 @@ int hashmap_put(Hashmap *h, const void *key, void *value) {
9fc0f6
                 hash = bucket_hash(h, key);
9fc0f6
 
9fc0f6
         if (h->from_pool)
9fc0f6
-                e = allocate_tile(&first_entry_pool, &first_entry_tile, sizeof(struct hashmap_entry));
9fc0f6
+                e = allocate_tile(&first_entry_pool, &first_entry_tile, sizeof(struct hashmap_entry), 64U);
9fc0f6
         else
9fc0f6
                 e = new(struct hashmap_entry, 1);
9fc0f6