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