26 #include <linux/module.h>
27 #include <linux/bitops.h>
28 #include <linux/slab.h>
29 #include <linux/string.h>
40 #define PARANOIA_ENTRY() do { \
42 BUG_ON(!lc->nr_elements); \
43 BUG_ON(test_and_set_bit(__LC_PARANOIA, &lc->flags)); \
46 #define RETURN(x...) do { \
47 clear_bit(__LC_PARANOIA, &lc->flags); \
48 smp_mb__after_clear_bit(); return x ; } while (0)
51 #define PARANOIA_LC_ELEMENT(lc, e) do { \
52 struct lru_cache *lc_ = (lc); \
53 struct lc_element *e_ = (e); \
54 unsigned i = e_->lc_index; \
55 BUG_ON(i >= lc_->nr_elements); \
56 BUG_ON(lc_->lc_element[i] != e_); } while (0)
69 unsigned e_count,
size_t e_size,
size_t e_off)
78 WARN_ON(cache_obj_size < e_size);
79 if (cache_obj_size < e_size)
98 INIT_LIST_HEAD(&lc->
in_use);
99 INIT_LIST_HEAD(&lc->
lru);
100 INIT_LIST_HEAD(&lc->
free);
112 for (i = 0; i < e_count; i++) {
128 void *
p = element[
i];
175 INIT_LIST_HEAD(&lc->
in_use);
176 INIT_LIST_HEAD(&lc->
lru);
177 INIT_LIST_HEAD(&lc->
free);
216 "hits:%lu misses:%lu starving:%lu dirty:%lu changed:%lu\n",
256 if (list_empty(&lc->
lru))
293 if (list_empty(&lc->
free))
301 static int lc_unused_element_available(
struct lru_cache *lc)
303 if (!list_empty(&lc->
free))
305 if (!list_empty(&lc->
lru))
373 if (!lc_unused_element_available(lc)) {
387 e = lc_get_unused_element(lc);
515 hlist_add_head(&e->
colision, lc_hash_slot(lc, enr));
534 seq_printf(seq,
"\tnn: lc_number refcnt %s\n ", utext);
535 for (i = 0; i < nr_elements; i++) {