Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
lru_cache.c File Reference
#include <linux/module.h>
#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/seq_file.h>
#include <linux/lru_cache.h>

Go to the source code of this file.


#define RETURN(x...)
#define PARANOIA_LC_ELEMENT(lc, e)


 MODULE_AUTHOR ("Philipp Reisner <[email protected]>, ""Lars Ellenberg <[email protected]>")
 MODULE_DESCRIPTION ("lru_cache - Track sets of hot objects")
: descriptive name only used in lc_seq_printf_stats and lc_seq_dump_details

lc_create - prepares to track objects in an active set

: number of elements allowed to be active simultaneously : size of the tracked objects : offset to the &struct lc_element member in a tracked object

Returns a pointer to a newly initialized struct lru_cache on success, or NULL on (allocation) failure.

struct lru_cachelc_create (const char *name, struct kmem_cache *cache, unsigned e_count, size_t e_size, size_t e_off)
void lc_free_by_index (struct lru_cache *lc, unsigned i)
void lc_destroy (struct lru_cache *lc)
void lc_reset (struct lru_cache *lc)
size_t lc_seq_printf_stats (struct seq_file *seq, struct lru_cache *lc)
struct lc_elementlc_find (struct lru_cache *lc, unsigned int enr)
void lc_del (struct lru_cache *lc, struct lc_element *e)
struct lc_elementlc_get (struct lru_cache *lc, unsigned int enr)
struct lc_elementlc_try_get (struct lru_cache *lc, unsigned int enr)
void lc_changed (struct lru_cache *lc, struct lc_element *e)
unsigned int lc_put (struct lru_cache *lc, struct lc_element *e)
struct lc_elementlc_element_by_index (struct lru_cache *lc, unsigned i)
unsigned int lc_index_of (struct lru_cache *lc, struct lc_element *e)
void lc_set (struct lru_cache *lc, unsigned int enr, int index)
void lc_seq_dump_details (struct seq_file *seq, struct lru_cache *lc, char *utext, void(*detail)(struct seq_file *, struct lc_element *))
 EXPORT_SYMBOL (lc_create)
 EXPORT_SYMBOL (lc_reset)
 EXPORT_SYMBOL (lc_destroy)
 EXPORT_SYMBOL (lc_try_get)
 EXPORT_SYMBOL (lc_find)
 EXPORT_SYMBOL (lc_changed)
 EXPORT_SYMBOL (lc_element_by_index)
 EXPORT_SYMBOL (lc_index_of)
 EXPORT_SYMBOL (lc_seq_printf_stats)
 EXPORT_SYMBOL (lc_seq_dump_details)

Macro Definition Documentation

#define PARANOIA_ENTRY ( )
do { \
BUG_ON(!lc); \
BUG_ON(!lc->nr_elements); \
BUG_ON(test_and_set_bit(__LC_PARANOIA, &lc->flags)); \
} while (0)

Definition at line 40 of file lru_cache.c.

#define PARANOIA_LC_ELEMENT (   lc,
do { \
struct lru_cache *lc_ = (lc); \
struct lc_element *e_ = (e); \
unsigned i = e_->lc_index; \
BUG_ON(i >= lc_->nr_elements); \
BUG_ON(lc_->lc_element[i] != e_); } while (0)

Definition at line 51 of file lru_cache.c.

#define RETURN (   x...)
do { \
clear_bit(__LC_PARANOIA, &lc->flags); \
smp_mb__after_clear_bit(); return x ; } while (0)

Definition at line 46 of file lru_cache.c.

Function Documentation

EXPORT_SYMBOL ( lc_create  )
EXPORT_SYMBOL ( lc_reset  )
EXPORT_SYMBOL ( lc_destroy  )
EXPORT_SYMBOL ( lc_set  )
EXPORT_SYMBOL ( lc_del  )
EXPORT_SYMBOL ( lc_try_get  )
EXPORT_SYMBOL ( lc_find  )
EXPORT_SYMBOL ( lc_get  )
EXPORT_SYMBOL ( lc_put  )
EXPORT_SYMBOL ( lc_changed  )
EXPORT_SYMBOL ( lc_element_by_index  )
EXPORT_SYMBOL ( lc_index_of  )
EXPORT_SYMBOL ( lc_seq_printf_stats  )
EXPORT_SYMBOL ( lc_seq_dump_details  )
void lc_changed ( struct lru_cache lc,
struct lc_element e 

lc_changed - tell that the change has been recorded : the lru cache to operate on : the element pending label change

Definition at line 430 of file lru_cache.c.

struct lru_cache* lc_create ( const char name,
struct kmem_cache cache,
unsigned  e_count,
size_t  e_size,
size_t  e_off 

Definition at line 68 of file lru_cache.c.

void lc_del ( struct lru_cache lc,
struct lc_element e 

lc_del - removes an element from the cache : The lru_cache object : The element to remove

must be unused (refcnt == 0). Moves from "lru" to "free" list, sets ->enr to LC_FREE.

Definition at line 277 of file lru_cache.c.

void lc_destroy ( struct lru_cache lc)

lc_destroy - frees memory allocated by lc_create() : the lru cache to destroy

Definition at line 152 of file lru_cache.c.

struct lc_element* lc_element_by_index ( struct lru_cache lc,
unsigned  i 

lc_element_by_index : the lru cache to operate on : the index of the element to return

Definition at line 477 of file lru_cache.c.

struct lc_element* lc_find ( struct lru_cache lc,
unsigned int  enr 

lc_find - find element by label, if present in the hash table : The lru_cache object : element number

Returns the pointer to an element, if the element with the requested "label" or element number is present in the hash table, or NULL if not found. Does not change the refcnt.

Definition at line 236 of file lru_cache.c.

void lc_free_by_index ( struct lru_cache lc,
unsigned  i 

Definition at line 138 of file lru_cache.c.

struct lc_element* lc_get ( struct lru_cache lc,
unsigned int  enr 

lc_get - get element by label, maybe change the active set : the lru cache to operate on : the label to look up

Finds an element in the cache, increases its usage count, "touches" and returns it.

In case the requested number is not present, it needs to be added to the cache. Therefore it is possible that an other element becomes evicted from the cache. In either case, the user is notified so he is able to e.g. keep a persistent log of the cache changes, and therefore the objects in use.

Return values: NULL The cache was marked LC_STARVING, or the requested label was not in the active set and a changing transaction is still pending ( was marked LC_DIRTY). Or no unused or free element could be recycled ( will be marked as LC_STARVING, blocking further lc_get() operations).

pointer to the element with the REQUESTED element number. In this case, it can be used right away

pointer to an UNUSED element with some different element number, where that different number may also be LC_FREE.

In this case, the cache is marked LC_DIRTY (blocking further changes), and the returned element pointer is removed from the lru list and hash collision chains. The user now should do whatever housekeeping is necessary. Then he must call lc_changed(lc,element_pointer), to finish the change.

NOTE: The user needs to check the lc_number on EACH use, so he recognizes any cache set change.

Definition at line 349 of file lru_cache.c.

unsigned int lc_index_of ( struct lru_cache lc,
struct lc_element e 

lc_index_of : the lru cache to operate on : the element to query for its index position in lc->element

Definition at line 490 of file lru_cache.c.

unsigned int lc_put ( struct lru_cache lc,
struct lc_element e 

lc_put - give up refcnt of : the lru cache to operate on : the element to put

If refcnt reaches zero, the element is moved to the lru list, and a LC_STARVING (if set) is cleared. Returns the new (post-decrement) refcnt.

Definition at line 456 of file lru_cache.c.

void lc_reset ( struct lru_cache lc)

lc_reset - does a full reset for and the hash table slots. : the lru cache to operate on

It is roughly the equivalent of re-allocating a fresh lru_cache object, basically a short cut to lc_destroy(lc); lc = lc_create(...);

Definition at line 171 of file lru_cache.c.

void lc_seq_dump_details ( struct seq_file seq,
struct lru_cache lc,
char utext,
void(*)(struct seq_file *, struct lc_element *)  detail 

lc_dump - Dump a complete LRU cache to seq in textual form. : the lru cache to operate on : the &struct seq_file pointer to seq_printf into : user supplied "heading" or other info : function pointer the user may provide to dump further details of the object the lc_element is embedded in.

Definition at line 527 of file lru_cache.c.

size_t lc_seq_printf_stats ( struct seq_file seq,
struct lru_cache lc 

lc_seq_printf_stats - print stats about into : the seq_file to print into : the lru cache to print statistics of

Definition at line 206 of file lru_cache.c.

void lc_set ( struct lru_cache lc,
unsigned int  enr,
int  index 

lc_set - associate index with label : the lru cache to operate on : the label to set : the element index to associate label with.

Used to initialize the active set to some previously recorded state.

Definition at line 504 of file lru_cache.c.

struct lc_element* lc_try_get ( struct lru_cache lc,
unsigned int  enr 

Definition at line 405 of file lru_cache.c.

MODULE_AUTHOR ( "Philipp Reisner <[email protected] ,
""Lars Ellenberg< lars >"   
MODULE_DESCRIPTION ( "lru_cache - Track sets of hot objects"  )