top | item 38860655

(no title)

1a1a11a | 2 years ago

I totally agree with you, this is not designed for hardware... and as others mentioned RRIP might be better for set-associative caches

discuss

order

vidarh|2 years ago

With respect to my other reply mentioning a ring instead of a linked list, here's a quick and dirty Ruby port because I couldn't resist that uses a ring with a single dummy head node to simplify the logic:

https://gist.github.com/vidarh/b72615c16673cb38630cab5148190...

You'll note it avoids a bunch of conditionals in add_to_head, remove_node and evict because the wraparound happens automatically and the next/prev pointers are never nil/None

I've not verified it matches the behaviour of yours exactly other than adding a handful of extra access calls and comparing the state.

If you're not familiar with Ruby, the one particularly dirty trick I'm using is that in Ruby you can define methods directly on a specific object, so by defining the method "@head.visited" to always return true, the eviction will just try to set it to false and move straight over it every run, cutting a conditional. You could do a ring without a dummy @head to but it makes the insertion/deletion logic more annoying.

1a1a11a|2 years ago

it looks like the ring is implemented using a linked list?