daandemeyer / rpms / systemd

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