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