diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-02-01 12:14:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-02-01 12:14:34 +0000 |
commit | c40899832e2194fd78bd9d7dc64e5f791e3de24f (patch) | |
tree | 98cd5a72b62559ef8f023bc3628f03fae7a6d72b /src/libutil/hash.c | |
parent | 9dcae9b27979fd4acc541d89877d74e6dc8e0980 (diff) | |
download | rspamd-c40899832e2194fd78bd9d7dc64e5f791e3de24f.tar.gz rspamd-c40899832e2194fd78bd9d7dc64e5f791e3de24f.zip |
[Minor] LRU: Mark fresh node as immportal to avoid its early eviction
Diffstat (limited to 'src/libutil/hash.c')
-rw-r--r-- | src/libutil/hash.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libutil/hash.c b/src/libutil/hash.c index 086eba8d1..b42dc6c51 100644 --- a/src/libutil/hash.c +++ b/src/libutil/hash.c @@ -48,6 +48,7 @@ struct rspamd_lru_hash_s { enum rspamd_lru_element_flags { RSPAMD_LRU_ELEMENT_NORMAL = 0, RSPAMD_LRU_ELEMENT_VOLATILE = (1 << 0), + RSPAMD_LRU_ELEMENT_IMMORTAL = (1 << 1), }; struct rspamd_lru_element_s { @@ -444,7 +445,6 @@ rspamd_lru_hash_evict (rspamd_lru_hash_t *hash, time_t now) * or, at some probability scan all table and update eviction * list first */ - r = rspamd_random_double_fast (); if (r < ((double)eviction_candidates) / hash->maxsize) { @@ -455,6 +455,10 @@ rspamd_lru_hash_evict (rspamd_lru_hash_t *hash, time_t now) kh_foreach_value_ptr (hash, cur, { rspamd_lru_element_t *node = &cur->e; + if (node->flags & RSPAMD_LRU_ELEMENT_IMMORTAL) { + continue; + } + if (node->flags & RSPAMD_LRU_ELEMENT_VOLATILE) { /* If element is expired, just remove it */ if (now - cur->creation_time > cur->ttl) { @@ -596,7 +600,7 @@ rspamd_lru_hash_insert (rspamd_lru_hash_t *hash, node = &vnode->e; if (ret == 0) { - /* Existing element, be carefull about destructors */ + /* Existing element, be careful about destructors */ if (hash->value_destroy) { /* Remove old data */ hash->value_destroy (vnode->e.data); @@ -629,7 +633,9 @@ rspamd_lru_hash_insert (rspamd_lru_hash_t *hash, if (ret != 0) { /* Also need to check maxsize */ if (kh_size (hash) >= hash->maxsize) { + node->flags |= RSPAMD_LRU_ELEMENT_IMMORTAL; rspamd_lru_hash_evict (hash, now); + node->flags &= ~RSPAMD_LRU_ELEMENT_IMMORTAL; } } |