summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/bihash_template.h
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-02-07 13:14:06 -0500
committerDamjan Marion <dmarion.lists@gmail.com>2018-02-08 10:02:16 +0000
commite7d212fe41de88863884dc24dff9e24e5f37b421 (patch)
tree4d38c30d330de2ce27207bdcee537f7874f62574 /src/vppinfra/bihash_template.h
parentdb3c480e375bd7eb22c27887590c8dca07293719 (diff)
Minimize bihash memory consumption
Reference-count the number of entries in each bucket. If the reference count goes to zero, free the backing store. Add long-term churn-testing to test_bihash_template.c, thanks to Andrew Yourtchenko for the initial implementation. Change-Id: I4fbd9229cacfaba8027a85cbf87b74afdead6e39 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vppinfra/bihash_template.h')
-rw-r--r--src/vppinfra/bihash_template.h32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h
index 9df418b5d7d..4e5d995cd9f 100644
--- a/src/vppinfra/bihash_template.h
+++ b/src/vppinfra/bihash_template.h
@@ -61,11 +61,12 @@ typedef struct
u32 offset;
u8 linear_search;
u8 log2_pages;
- u16 cache_lru;
+ i16 refcnt;
};
u64 as_u64;
};
#if BIHASH_KVP_CACHE_SIZE > 0
+ u16 cache_lru;
BVT (clib_bihash_kv) cache[BIHASH_KVP_CACHE_SIZE];
#endif
} BVT (clib_bihash_bucket);
@@ -82,7 +83,6 @@ typedef struct
u32 nbuckets;
u32 log2_nbuckets;
- u32 linear_buckets;
u8 *name;
u64 cache_hits;
@@ -102,13 +102,11 @@ typedef struct
static inline void
BV (clib_bihash_update_lru) (BVT (clib_bihash_bucket) * b, u8 slot)
{
+#if BIHASH_KVP_CACHE_SIZE > 1
u16 value, tmp, mask;
u8 found_lru_pos;
u16 save_hi;
- if (BIHASH_KVP_CACHE_SIZE < 2)
- return;
-
ASSERT (slot < BIHASH_KVP_CACHE_SIZE);
/* First, find the slot in cache_lru */
@@ -154,6 +152,7 @@ BV (clib_bihash_update_lru) (BVT (clib_bihash_bucket) * b, u8 slot)
value = save_hi | (tmp << 3) | slot;
b->cache_lru = value;
+#endif
}
void
@@ -197,28 +196,29 @@ static inline void BV (clib_bihash_reset_cache) (BVT (clib_bihash_bucket) * b)
static inline int BV (clib_bihash_lock_bucket) (BVT (clib_bihash_bucket) * b)
{
- BVT (clib_bihash_bucket) tmp_b;
- u64 rv;
+#if BIHASH_KVP_CACHE_SIZE > 0
+ u16 cache_lru_bit;
+ u16 rv;
- tmp_b.as_u64 = 0;
- tmp_b.cache_lru = 1 << 15;
+ cache_lru_bit = 1 << 15;
- rv = __sync_fetch_and_or (&b->as_u64, tmp_b.as_u64);
- tmp_b.as_u64 = rv;
+ rv = __sync_fetch_and_or (&b->cache_lru, cache_lru_bit);
/* Was already locked? */
- if (tmp_b.cache_lru & (1 << 15))
+ if (rv & (1 << 15))
return 0;
+#endif
return 1;
}
static inline void BV (clib_bihash_unlock_bucket)
(BVT (clib_bihash_bucket) * b)
{
- BVT (clib_bihash_bucket) tmp_b;
+#if BIHASH_KVP_CACHE_SIZE > 0
+ u16 cache_lru;
- tmp_b.as_u64 = b->as_u64;
- tmp_b.cache_lru &= ~(1 << 15);
- b->as_u64 = tmp_b.as_u64;
+ cache_lru = b->cache_lru & ~(1 << 15);
+ b->cache_lru = cache_lru;
+#endif
}
static inline void *BV (clib_bihash_get_value) (BVT (clib_bihash) * h,