-
Notifications
You must be signed in to change notification settings - Fork 10
/
evict.h
44 lines (36 loc) · 1.55 KB
/
evict.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef __EVICT_H__
#define __EVICT_H__
#include "object.h"
#include "dict.h"
/* ----------------------------------------------------------------------------
* Data structures
* --------------------------------------------------------------------------*/
/* To improve the quality of the LRU approximation we take a set of keys
* that are good candidate for eviction across freeMemoryIfNeeded() calls.
*
* Entries inside the eviciton pool are taken ordered by idle time, putting
* greater idle times to the right (ascending order).
*
* When an LFU policy is used instead, a reverse frequency indication is used
* instead of the idle time, so that we still evict by larger value (larger
* inverse frequency means to evict keys with the least frequent accesses).
*
* Empty entries have the key pointer set to NULL. */
#define EVPOOL_SIZE 16
#define EVPOOL_CACHED_SDS_SIZE 255
struct evictionPoolEntry {
unsigned long long idle; /* Object idle time (inverse frequency for LFU) */
sds key; /* Key name. */
sds cached; /* Cached SDS object for key name. */
};
unsigned int getLRUClock(void);
unsigned int LRU_CLOCK(void);
unsigned long long estimateObjectIdleTime(robj *o);
struct evictionPoolEntry* evictionPoolAlloc(void);
void evictionPoolDestroy(struct evictionPoolEntry *pool);
void evictionPoolPopulate(dict *sampledict, dict *keydict, struct evictionPoolEntry *pool);
#define LFU_INIT_VAL 5
unsigned long LFUGetTimeInMinutes(void);
uint8_t LFULogIncr(uint8_t value);
unsigned long LFUDecrAndReturn(robj *o);
#endif