Outdated comments, replace COUNTER_INIT_VAL with LFU_INIT_VAL, fix typo (#10888)

`COUNTER_INIT_VAL` doesn't exist in the code anymore so we can replace it with `LFU_INIT_VAL` entries
This commit is contained in:
Vlad 2022-06-21 07:14:31 +02:00 committed by GitHub
parent 091701f363
commit a3fdc9cd82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -266,14 +266,14 @@ void evictionPoolPopulate(int dbid, dict *sampledict, dict *keydict, struct evic
* has a low value. * has a low value.
* *
* New keys don't start at zero, in order to have the ability to collect * New keys don't start at zero, in order to have the ability to collect
* some accesses before being trashed away, so they start at COUNTER_INIT_VAL. * some accesses before being trashed away, so they start at LFU_INIT_VAL.
* The logarithmic increment performed on LOG_C takes care of COUNTER_INIT_VAL * The logarithmic increment performed on LOG_C takes care of LFU_INIT_VAL
* when incrementing the key, so that keys starting at COUNTER_INIT_VAL * when incrementing the key, so that keys starting at LFU_INIT_VAL
* (or having a smaller value) have a very high chance of being incremented * (or having a smaller value) have a very high chance of being incremented
* on access. * on access.
* *
* During decrement, the value of the logarithmic counter is halved if * During decrement, the value of the logarithmic counter is halved if
* its current value is greater than two times the COUNTER_INIT_VAL, otherwise * its current value is greater than two times the LFU_INIT_VAL, otherwise
* it is just decremented by one. * it is just decremented by one.
* --------------------------------------------------------------------------*/ * --------------------------------------------------------------------------*/
@ -295,7 +295,7 @@ unsigned long LFUTimeElapsed(unsigned long ldt) {
} }
/* Logarithmically increment a counter. The greater is the current counter value /* Logarithmically increment a counter. The greater is the current counter value
* the less likely is that it gets really implemented. Saturate it at 255. */ * the less likely is that it gets really incremented. Saturate it at 255. */
uint8_t LFULogIncr(uint8_t counter) { uint8_t LFULogIncr(uint8_t counter) {
if (counter == 255) return 255; if (counter == 255) return 255;
double r = (double)rand()/RAND_MAX; double r = (double)rand()/RAND_MAX;

View File

@ -19,7 +19,7 @@ struct entry {
}; };
#define to_16bit_minutes(x) ((x/60) & 65535) #define to_16bit_minutes(x) ((x/60) & 65535)
#define COUNTER_INIT_VAL 5 #define LFU_INIT_VAL 5
/* Compute the difference in minutes between two 16 bit minutes times /* Compute the difference in minutes between two 16 bit minutes times
* obtained with to_16bit_minutes(). Since they can wrap around if * obtained with to_16bit_minutes(). Since they can wrap around if
@ -36,7 +36,7 @@ uint16_t minutes_diff(uint16_t now, uint16_t prev) {
uint8_t log_incr(uint8_t counter) { uint8_t log_incr(uint8_t counter) {
if (counter == 255) return counter; if (counter == 255) return counter;
double r = (double)rand()/RAND_MAX; double r = (double)rand()/RAND_MAX;
double baseval = counter-COUNTER_INIT_VAL; double baseval = counter-LFU_INIT_VAL;
if (baseval < 0) baseval = 0; if (baseval < 0) baseval = 0;
double limit = 1.0/(baseval*10+1); double limit = 1.0/(baseval*10+1);
if (r < limit) counter++; if (r < limit) counter++;
@ -56,7 +56,7 @@ uint8_t scan_entry(struct entry *e) {
>= decr_every) >= decr_every)
{ {
if (e->counter) { if (e->counter) {
if (e->counter > COUNTER_INIT_VAL*2) { if (e->counter > LFU_INIT_VAL*2) {
e->counter /= 2; e->counter /= 2;
} else { } else {
e->counter--; e->counter--;
@ -89,7 +89,7 @@ int main(void) {
/* Initialize. */ /* Initialize. */
for (j = 0; j < keyspace_size; j++) { for (j = 0; j < keyspace_size; j++) {
entries[j].counter = COUNTER_INIT_VAL; entries[j].counter = LFU_INIT_VAL;
entries[j].decrtime = to_16bit_minutes(start); entries[j].decrtime = to_16bit_minutes(start);
entries[j].hits = 0; entries[j].hits = 0;
entries[j].ctime = time(NULL); entries[j].ctime = time(NULL);
@ -131,7 +131,7 @@ int main(void) {
* 10 and 19, a random one every 10 seconds. */ * 10 and 19, a random one every 10 seconds. */
if (new_entry_time <= now) { if (new_entry_time <= now) {
idx = 10+(rand()%10); idx = 10+(rand()%10);
entries[idx].counter = COUNTER_INIT_VAL; entries[idx].counter = LFU_INIT_VAL;
entries[idx].decrtime = to_16bit_minutes(time(NULL)); entries[idx].decrtime = to_16bit_minutes(time(NULL));
entries[idx].hits = 0; entries[idx].hits = 0;
entries[idx].ctime = time(NULL); entries[idx].ctime = time(NULL);