2007-03-08 07:56:53 +00:00
|
|
|
/**
|
|
|
|
@file
|
|
|
|
|
|
|
|
Implements cache replacement policies. Eventually, this could be
|
|
|
|
extended to support application specific caching schemes.
|
|
|
|
|
|
|
|
@todo Stasis used to use LRU-2S. LRU-2S is described in Markatos
|
|
|
|
"On Caching Searching Engine Results". (This needs to be
|
|
|
|
re-implemented properly.)
|
|
|
|
|
|
|
|
For now, Stasis uses plain-old LRU. DB-MIN would be an interesting
|
|
|
|
extension.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct replacementPolicy {
|
2011-08-23 18:25:26 +00:00
|
|
|
/** Factory method */
|
2007-03-08 07:56:53 +00:00
|
|
|
struct replacementPolicy* (*init)();
|
2011-08-23 18:25:26 +00:00
|
|
|
/** Destructor */
|
2007-03-08 07:56:53 +00:00
|
|
|
void (*deinit) (struct replacementPolicy* impl);
|
2011-08-23 18:25:26 +00:00
|
|
|
/** The page has been touched. Reflect this fact (currently not called) */
|
2011-04-20 20:25:17 +00:00
|
|
|
void (*hit) (struct replacementPolicy* impl, Page* page);
|
2011-08-23 18:25:26 +00:00
|
|
|
/** Find a page that is "stale". Do not remove it.
|
|
|
|
*
|
|
|
|
* @deprecated This function is essentially impossible to use correctly in a concurrent setting, and is not necessarily threadsafe.
|
|
|
|
* */
|
2011-04-20 20:25:17 +00:00
|
|
|
Page* (*getStale)(struct replacementPolicy* impl);
|
2011-08-23 18:25:26 +00:00
|
|
|
/** Remove a page from consideration. This method needs to increment the
|
|
|
|
* "pinCount" field of Page (or perform other bookkeeping), since the page
|
|
|
|
* may be removed multiple times before it is re-inserted. Pages that
|
|
|
|
* have been removed should not be returned as "stale". */
|
2011-04-20 20:25:17 +00:00
|
|
|
Page* (*remove) (struct replacementPolicy* impl, Page* page);
|
2011-08-23 18:25:26 +00:00
|
|
|
/** Atomically getStale(), and remove() the page it returns.
|
|
|
|
*
|
|
|
|
* @return the page that was stale, and that has now been removed.
|
|
|
|
*/
|
2011-04-20 20:25:17 +00:00
|
|
|
Page* (*getStaleAndRemove)(struct replacementPolicy* impl);
|
2011-08-23 18:25:26 +00:00
|
|
|
/** Insert a page into the replacement policy, and decrement the pinCount.
|
|
|
|
* The page has just been "hit", and is now a candidate for getStale() to
|
|
|
|
* consider (unless it has a non-zero pincount).
|
|
|
|
*/
|
2011-04-20 20:25:17 +00:00
|
|
|
void (*insert) (struct replacementPolicy* impl, Page* page);
|
2007-03-08 07:56:53 +00:00
|
|
|
void * impl;
|
|
|
|
} replacementPolicy;
|
|
|
|
|
2009-05-13 22:06:58 +00:00
|
|
|
replacementPolicy * stasis_replacement_policy_lru_init();
|
2011-04-20 20:25:17 +00:00
|
|
|
replacementPolicy * lruFastInit();
|
2009-11-09 20:53:05 +00:00
|
|
|
replacementPolicy* replacementPolicyThreadsafeWrapperInit(replacementPolicy* rp);
|
|
|
|
replacementPolicy* replacementPolicyConcurrentWrapperInit(replacementPolicy** rp, int count);
|
2011-08-23 18:25:26 +00:00
|
|
|
replacementPolicy* replacementPolicyClockInit(Page * pageArray, int page_count);
|