replace gettimeofday() with sliding counter in LRUCache::Lookup #25

matthewvon opened this Issue Jul 13, 2012 · 2 comments


None yet

2 participants


I hammered gettimeofday() into LRUCache::Lookup in place of the previous mechanism that constantly reordered the list, requiring a write lock. gettimeofday() is a relatively expensive OS call. A better design would use an incrementing counter. When the counter crossed a threshold, all instances of the counter would be right shifted 32 bits.


Not really for Linux at least. Linux kernel optimizes for gettimeofday() by sharing kernel page (vsyscall or vdso) with user apps so that some functions like gettimeofday() don't need to change to kernel mode. It works faster than an atomic counter (if that is what you are proposing...) especially on multi-core machines.


addressed in post Riak 1.4 code

@matthewvon matthewvon closed this Aug 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment