Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003    lru_cache.c
0004 
0005    This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
0006 
0007    Copyright (C) 2003-2008, LINBIT Information Technologies GmbH.
0008    Copyright (C) 2003-2008, Philipp Reisner <philipp.reisner@linbit.com>.
0009    Copyright (C) 2003-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
0010 
0011 
0012  */
0013 
0014 #include <linux/module.h>
0015 #include <linux/bitops.h>
0016 #include <linux/slab.h>
0017 #include <linux/string.h> /* for memset */
0018 #include <linux/seq_file.h> /* for seq_printf */
0019 #include <linux/lru_cache.h>
0020 
0021 MODULE_AUTHOR("Philipp Reisner <phil@linbit.com>, "
0022           "Lars Ellenberg <lars@linbit.com>");
0023 MODULE_DESCRIPTION("lru_cache - Track sets of hot objects");
0024 MODULE_LICENSE("GPL");
0025 
0026 /* this is developers aid only.
0027  * it catches concurrent access (lack of locking on the users part) */
0028 #define PARANOIA_ENTRY() do {       \
0029     BUG_ON(!lc);            \
0030     BUG_ON(!lc->nr_elements);   \
0031     BUG_ON(test_and_set_bit(__LC_PARANOIA, &lc->flags)); \
0032 } while (0)
0033 
0034 #define RETURN(x...)     do { \
0035     clear_bit_unlock(__LC_PARANOIA, &lc->flags); \
0036     return x ; } while (0)
0037 
0038 /* BUG() if e is not one of the elements tracked by lc */
0039 #define PARANOIA_LC_ELEMENT(lc, e) do { \
0040     struct lru_cache *lc_ = (lc);   \
0041     struct lc_element *e_ = (e);    \
0042     unsigned i = e_->lc_index;  \
0043     BUG_ON(i >= lc_->nr_elements);  \
0044     BUG_ON(lc_->lc_element[i] != e_); } while (0)
0045 
0046 
0047 /* We need to atomically
0048  *  - try to grab the lock (set LC_LOCKED)
0049  *  - only if there is no pending transaction
0050  *    (neither LC_DIRTY nor LC_STARVING is set)
0051  * Because of PARANOIA_ENTRY() above abusing lc->flags as well,
0052  * it is not sufficient to just say
0053  *  return 0 == cmpxchg(&lc->flags, 0, LC_LOCKED);
0054  */
0055 int lc_try_lock(struct lru_cache *lc)
0056 {
0057     unsigned long val;
0058     do {
0059         val = cmpxchg(&lc->flags, 0, LC_LOCKED);
0060     } while (unlikely (val == LC_PARANOIA));
0061     /* Spin until no-one is inside a PARANOIA_ENTRY()/RETURN() section. */
0062     return 0 == val;
0063 #if 0
0064     /* Alternative approach, spin in case someone enters or leaves a
0065      * PARANOIA_ENTRY()/RETURN() section. */
0066     unsigned long old, new, val;
0067     do {
0068         old = lc->flags & LC_PARANOIA;
0069         new = old | LC_LOCKED;
0070         val = cmpxchg(&lc->flags, old, new);
0071     } while (unlikely (val == (old ^ LC_PARANOIA)));
0072     return old == val;
0073 #endif
0074 }
0075 
0076 /**
0077  * lc_create - prepares to track objects in an active set
0078  * @name: descriptive name only used in lc_seq_printf_stats and lc_seq_dump_details
0079  * @cache: cache root pointer
0080  * @max_pending_changes: maximum changes to accumulate until a transaction is required
0081  * @e_count: number of elements allowed to be active simultaneously
0082  * @e_size: size of the tracked objects
0083  * @e_off: offset to the &struct lc_element member in a tracked object
0084  *
0085  * Returns a pointer to a newly initialized struct lru_cache on success,
0086  * or NULL on (allocation) failure.
0087  */
0088 struct lru_cache *lc_create(const char *name, struct kmem_cache *cache,
0089         unsigned max_pending_changes,
0090         unsigned e_count, size_t e_size, size_t e_off)
0091 {
0092     struct hlist_head *slot = NULL;
0093     struct lc_element **element = NULL;
0094     struct lru_cache *lc;
0095     struct lc_element *e;
0096     unsigned cache_obj_size = kmem_cache_size(cache);
0097     unsigned i;
0098 
0099     WARN_ON(cache_obj_size < e_size);
0100     if (cache_obj_size < e_size)
0101         return NULL;
0102 
0103     /* e_count too big; would probably fail the allocation below anyways.
0104      * for typical use cases, e_count should be few thousand at most. */
0105     if (e_count > LC_MAX_ACTIVE)
0106         return NULL;
0107 
0108     slot = kcalloc(e_count, sizeof(struct hlist_head), GFP_KERNEL);
0109     if (!slot)
0110         goto out_fail;
0111     element = kcalloc(e_count, sizeof(struct lc_element *), GFP_KERNEL);
0112     if (!element)
0113         goto out_fail;
0114 
0115     lc = kzalloc(sizeof(*lc), GFP_KERNEL);
0116     if (!lc)
0117         goto out_fail;
0118 
0119     INIT_LIST_HEAD(&lc->in_use);
0120     INIT_LIST_HEAD(&lc->lru);
0121     INIT_LIST_HEAD(&lc->free);
0122     INIT_LIST_HEAD(&lc->to_be_changed);
0123 
0124     lc->name = name;
0125     lc->element_size = e_size;
0126     lc->element_off = e_off;
0127     lc->nr_elements = e_count;
0128     lc->max_pending_changes = max_pending_changes;
0129     lc->lc_cache = cache;
0130     lc->lc_element = element;
0131     lc->lc_slot = slot;
0132 
0133     /* preallocate all objects */
0134     for (i = 0; i < e_count; i++) {
0135         void *p = kmem_cache_alloc(cache, GFP_KERNEL);
0136         if (!p)
0137             break;
0138         memset(p, 0, lc->element_size);
0139         e = p + e_off;
0140         e->lc_index = i;
0141         e->lc_number = LC_FREE;
0142         e->lc_new_number = LC_FREE;
0143         list_add(&e->list, &lc->free);
0144         element[i] = e;
0145     }
0146     if (i == e_count)
0147         return lc;
0148 
0149     /* else: could not allocate all elements, give up */
0150     while (i) {
0151         void *p = element[--i];
0152         kmem_cache_free(cache, p - e_off);
0153     }
0154     kfree(lc);
0155 out_fail:
0156     kfree(element);
0157     kfree(slot);
0158     return NULL;
0159 }
0160 
0161 static void lc_free_by_index(struct lru_cache *lc, unsigned i)
0162 {
0163     void *p = lc->lc_element[i];
0164     WARN_ON(!p);
0165     if (p) {
0166         p -= lc->element_off;
0167         kmem_cache_free(lc->lc_cache, p);
0168     }
0169 }
0170 
0171 /**
0172  * lc_destroy - frees memory allocated by lc_create()
0173  * @lc: the lru cache to destroy
0174  */
0175 void lc_destroy(struct lru_cache *lc)
0176 {
0177     unsigned i;
0178     if (!lc)
0179         return;
0180     for (i = 0; i < lc->nr_elements; i++)
0181         lc_free_by_index(lc, i);
0182     kfree(lc->lc_element);
0183     kfree(lc->lc_slot);
0184     kfree(lc);
0185 }
0186 
0187 /**
0188  * lc_reset - does a full reset for @lc and the hash table slots.
0189  * @lc: the lru cache to operate on
0190  *
0191  * It is roughly the equivalent of re-allocating a fresh lru_cache object,
0192  * basically a short cut to lc_destroy(lc); lc = lc_create(...);
0193  */
0194 void lc_reset(struct lru_cache *lc)
0195 {
0196     unsigned i;
0197 
0198     INIT_LIST_HEAD(&lc->in_use);
0199     INIT_LIST_HEAD(&lc->lru);
0200     INIT_LIST_HEAD(&lc->free);
0201     INIT_LIST_HEAD(&lc->to_be_changed);
0202     lc->used = 0;
0203     lc->hits = 0;
0204     lc->misses = 0;
0205     lc->starving = 0;
0206     lc->locked = 0;
0207     lc->changed = 0;
0208     lc->pending_changes = 0;
0209     lc->flags = 0;
0210     memset(lc->lc_slot, 0, sizeof(struct hlist_head) * lc->nr_elements);
0211 
0212     for (i = 0; i < lc->nr_elements; i++) {
0213         struct lc_element *e = lc->lc_element[i];
0214         void *p = e;
0215         p -= lc->element_off;
0216         memset(p, 0, lc->element_size);
0217         /* re-init it */
0218         e->lc_index = i;
0219         e->lc_number = LC_FREE;
0220         e->lc_new_number = LC_FREE;
0221         list_add(&e->list, &lc->free);
0222     }
0223 }
0224 
0225 /**
0226  * lc_seq_printf_stats - print stats about @lc into @seq
0227  * @seq: the seq_file to print into
0228  * @lc: the lru cache to print statistics of
0229  */
0230 void lc_seq_printf_stats(struct seq_file *seq, struct lru_cache *lc)
0231 {
0232     /* NOTE:
0233      * total calls to lc_get are
0234      * (starving + hits + misses)
0235      * misses include "locked" count (update from an other thread in
0236      * progress) and "changed", when this in fact lead to an successful
0237      * update of the cache.
0238      */
0239     seq_printf(seq, "\t%s: used:%u/%u hits:%lu misses:%lu starving:%lu locked:%lu changed:%lu\n",
0240            lc->name, lc->used, lc->nr_elements,
0241            lc->hits, lc->misses, lc->starving, lc->locked, lc->changed);
0242 }
0243 
0244 static struct hlist_head *lc_hash_slot(struct lru_cache *lc, unsigned int enr)
0245 {
0246     return  lc->lc_slot + (enr % lc->nr_elements);
0247 }
0248 
0249 
0250 static struct lc_element *__lc_find(struct lru_cache *lc, unsigned int enr,
0251         bool include_changing)
0252 {
0253     struct lc_element *e;
0254 
0255     BUG_ON(!lc);
0256     BUG_ON(!lc->nr_elements);
0257     hlist_for_each_entry(e, lc_hash_slot(lc, enr), colision) {
0258         /* "about to be changed" elements, pending transaction commit,
0259          * are hashed by their "new number". "Normal" elements have
0260          * lc_number == lc_new_number. */
0261         if (e->lc_new_number != enr)
0262             continue;
0263         if (e->lc_new_number == e->lc_number || include_changing)
0264             return e;
0265         break;
0266     }
0267     return NULL;
0268 }
0269 
0270 /**
0271  * lc_find - find element by label, if present in the hash table
0272  * @lc: The lru_cache object
0273  * @enr: element number
0274  *
0275  * Returns the pointer to an element, if the element with the requested
0276  * "label" or element number is present in the hash table,
0277  * or NULL if not found. Does not change the refcnt.
0278  * Ignores elements that are "about to be used", i.e. not yet in the active
0279  * set, but still pending transaction commit.
0280  */
0281 struct lc_element *lc_find(struct lru_cache *lc, unsigned int enr)
0282 {
0283     return __lc_find(lc, enr, 0);
0284 }
0285 
0286 /**
0287  * lc_is_used - find element by label
0288  * @lc: The lru_cache object
0289  * @enr: element number
0290  *
0291  * Returns true, if the element with the requested "label" or element number is
0292  * present in the hash table, and is used (refcnt > 0).
0293  * Also finds elements that are not _currently_ used but only "about to be
0294  * used", i.e. on the "to_be_changed" list, pending transaction commit.
0295  */
0296 bool lc_is_used(struct lru_cache *lc, unsigned int enr)
0297 {
0298     struct lc_element *e = __lc_find(lc, enr, 1);
0299     return e && e->refcnt;
0300 }
0301 
0302 /**
0303  * lc_del - removes an element from the cache
0304  * @lc: The lru_cache object
0305  * @e: The element to remove
0306  *
0307  * @e must be unused (refcnt == 0). Moves @e from "lru" to "free" list,
0308  * sets @e->enr to %LC_FREE.
0309  */
0310 void lc_del(struct lru_cache *lc, struct lc_element *e)
0311 {
0312     PARANOIA_ENTRY();
0313     PARANOIA_LC_ELEMENT(lc, e);
0314     BUG_ON(e->refcnt);
0315 
0316     e->lc_number = e->lc_new_number = LC_FREE;
0317     hlist_del_init(&e->colision);
0318     list_move(&e->list, &lc->free);
0319     RETURN();
0320 }
0321 
0322 static struct lc_element *lc_prepare_for_change(struct lru_cache *lc, unsigned new_number)
0323 {
0324     struct list_head *n;
0325     struct lc_element *e;
0326 
0327     if (!list_empty(&lc->free))
0328         n = lc->free.next;
0329     else if (!list_empty(&lc->lru))
0330         n = lc->lru.prev;
0331     else
0332         return NULL;
0333 
0334     e = list_entry(n, struct lc_element, list);
0335     PARANOIA_LC_ELEMENT(lc, e);
0336 
0337     e->lc_new_number = new_number;
0338     if (!hlist_unhashed(&e->colision))
0339         __hlist_del(&e->colision);
0340     hlist_add_head(&e->colision, lc_hash_slot(lc, new_number));
0341     list_move(&e->list, &lc->to_be_changed);
0342 
0343     return e;
0344 }
0345 
0346 static int lc_unused_element_available(struct lru_cache *lc)
0347 {
0348     if (!list_empty(&lc->free))
0349         return 1; /* something on the free list */
0350     if (!list_empty(&lc->lru))
0351         return 1;  /* something to evict */
0352 
0353     return 0;
0354 }
0355 
0356 /* used as internal flags to __lc_get */
0357 enum {
0358     LC_GET_MAY_CHANGE = 1,
0359     LC_GET_MAY_USE_UNCOMMITTED = 2,
0360 };
0361 
0362 static struct lc_element *__lc_get(struct lru_cache *lc, unsigned int enr, unsigned int flags)
0363 {
0364     struct lc_element *e;
0365 
0366     PARANOIA_ENTRY();
0367     if (lc->flags & LC_STARVING) {
0368         ++lc->starving;
0369         RETURN(NULL);
0370     }
0371 
0372     e = __lc_find(lc, enr, 1);
0373     /* if lc_new_number != lc_number,
0374      * this enr is currently being pulled in already,
0375      * and will be available once the pending transaction
0376      * has been committed. */
0377     if (e) {
0378         if (e->lc_new_number != e->lc_number) {
0379             /* It has been found above, but on the "to_be_changed"
0380              * list, not yet committed.  Don't pull it in twice,
0381              * wait for the transaction, then try again...
0382              */
0383             if (!(flags & LC_GET_MAY_USE_UNCOMMITTED))
0384                 RETURN(NULL);
0385             /* ... unless the caller is aware of the implications,
0386              * probably preparing a cumulative transaction. */
0387             ++e->refcnt;
0388             ++lc->hits;
0389             RETURN(e);
0390         }
0391         /* else: lc_new_number == lc_number; a real hit. */
0392         ++lc->hits;
0393         if (e->refcnt++ == 0)
0394             lc->used++;
0395         list_move(&e->list, &lc->in_use); /* Not evictable... */
0396         RETURN(e);
0397     }
0398     /* e == NULL */
0399 
0400     ++lc->misses;
0401     if (!(flags & LC_GET_MAY_CHANGE))
0402         RETURN(NULL);
0403 
0404     /* To avoid races with lc_try_lock(), first, mark us dirty
0405      * (using test_and_set_bit, as it implies memory barriers), ... */
0406     test_and_set_bit(__LC_DIRTY, &lc->flags);
0407 
0408     /* ... only then check if it is locked anyways. If lc_unlock clears
0409      * the dirty bit again, that's not a problem, we will come here again.
0410      */
0411     if (test_bit(__LC_LOCKED, &lc->flags)) {
0412         ++lc->locked;
0413         RETURN(NULL);
0414     }
0415 
0416     /* In case there is nothing available and we can not kick out
0417      * the LRU element, we have to wait ...
0418      */
0419     if (!lc_unused_element_available(lc)) {
0420         __set_bit(__LC_STARVING, &lc->flags);
0421         RETURN(NULL);
0422     }
0423 
0424     /* It was not present in the active set.  We are going to recycle an
0425      * unused (or even "free") element, but we won't accumulate more than
0426      * max_pending_changes changes.  */
0427     if (lc->pending_changes >= lc->max_pending_changes)
0428         RETURN(NULL);
0429 
0430     e = lc_prepare_for_change(lc, enr);
0431     BUG_ON(!e);
0432 
0433     clear_bit(__LC_STARVING, &lc->flags);
0434     BUG_ON(++e->refcnt != 1);
0435     lc->used++;
0436     lc->pending_changes++;
0437 
0438     RETURN(e);
0439 }
0440 
0441 /**
0442  * lc_get - get element by label, maybe change the active set
0443  * @lc: the lru cache to operate on
0444  * @enr: the label to look up
0445  *
0446  * Finds an element in the cache, increases its usage count,
0447  * "touches" and returns it.
0448  *
0449  * In case the requested number is not present, it needs to be added to the
0450  * cache. Therefore it is possible that an other element becomes evicted from
0451  * the cache. In either case, the user is notified so he is able to e.g. keep
0452  * a persistent log of the cache changes, and therefore the objects in use.
0453  *
0454  * Return values:
0455  *  NULL
0456  *     The cache was marked %LC_STARVING,
0457  *     or the requested label was not in the active set
0458  *     and a changing transaction is still pending (@lc was marked %LC_DIRTY).
0459  *     Or no unused or free element could be recycled (@lc will be marked as
0460  *     %LC_STARVING, blocking further lc_get() operations).
0461  *
0462  *  pointer to the element with the REQUESTED element number.
0463  *     In this case, it can be used right away
0464  *
0465  *  pointer to an UNUSED element with some different element number,
0466  *          where that different number may also be %LC_FREE.
0467  *
0468  *          In this case, the cache is marked %LC_DIRTY,
0469  *          so lc_try_lock() will no longer succeed.
0470  *          The returned element pointer is moved to the "to_be_changed" list,
0471  *          and registered with the new element number on the hash collision chains,
0472  *          so it is possible to pick it up from lc_is_used().
0473  *          Up to "max_pending_changes" (see lc_create()) can be accumulated.
0474  *          The user now should do whatever housekeeping is necessary,
0475  *          typically serialize on lc_try_lock_for_transaction(), then call
0476  *          lc_committed(lc) and lc_unlock(), to finish the change.
0477  *
0478  * NOTE: The user needs to check the lc_number on EACH use, so he recognizes
0479  *       any cache set change.
0480  */
0481 struct lc_element *lc_get(struct lru_cache *lc, unsigned int enr)
0482 {
0483     return __lc_get(lc, enr, LC_GET_MAY_CHANGE);
0484 }
0485 
0486 /**
0487  * lc_get_cumulative - like lc_get; also finds to-be-changed elements
0488  * @lc: the lru cache to operate on
0489  * @enr: the label to look up
0490  *
0491  * Unlike lc_get this also returns the element for @enr, if it is belonging to
0492  * a pending transaction, so the return values are like for lc_get(),
0493  * plus:
0494  *
0495  * pointer to an element already on the "to_be_changed" list.
0496  *  In this case, the cache was already marked %LC_DIRTY.
0497  *
0498  * Caller needs to make sure that the pending transaction is completed,
0499  * before proceeding to actually use this element.
0500  */
0501 struct lc_element *lc_get_cumulative(struct lru_cache *lc, unsigned int enr)
0502 {
0503     return __lc_get(lc, enr, LC_GET_MAY_CHANGE|LC_GET_MAY_USE_UNCOMMITTED);
0504 }
0505 
0506 /**
0507  * lc_try_get - get element by label, if present; do not change the active set
0508  * @lc: the lru cache to operate on
0509  * @enr: the label to look up
0510  *
0511  * Finds an element in the cache, increases its usage count,
0512  * "touches" and returns it.
0513  *
0514  * Return values:
0515  *  NULL
0516  *     The cache was marked %LC_STARVING,
0517  *     or the requested label was not in the active set
0518  *
0519  *  pointer to the element with the REQUESTED element number.
0520  *     In this case, it can be used right away
0521  */
0522 struct lc_element *lc_try_get(struct lru_cache *lc, unsigned int enr)
0523 {
0524     return __lc_get(lc, enr, 0);
0525 }
0526 
0527 /**
0528  * lc_committed - tell @lc that pending changes have been recorded
0529  * @lc: the lru cache to operate on
0530  *
0531  * User is expected to serialize on explicit lc_try_lock_for_transaction()
0532  * before the transaction is started, and later needs to lc_unlock() explicitly
0533  * as well.
0534  */
0535 void lc_committed(struct lru_cache *lc)
0536 {
0537     struct lc_element *e, *tmp;
0538 
0539     PARANOIA_ENTRY();
0540     list_for_each_entry_safe(e, tmp, &lc->to_be_changed, list) {
0541         /* count number of changes, not number of transactions */
0542         ++lc->changed;
0543         e->lc_number = e->lc_new_number;
0544         list_move(&e->list, &lc->in_use);
0545     }
0546     lc->pending_changes = 0;
0547     RETURN();
0548 }
0549 
0550 
0551 /**
0552  * lc_put - give up refcnt of @e
0553  * @lc: the lru cache to operate on
0554  * @e: the element to put
0555  *
0556  * If refcnt reaches zero, the element is moved to the lru list,
0557  * and a %LC_STARVING (if set) is cleared.
0558  * Returns the new (post-decrement) refcnt.
0559  */
0560 unsigned int lc_put(struct lru_cache *lc, struct lc_element *e)
0561 {
0562     PARANOIA_ENTRY();
0563     PARANOIA_LC_ELEMENT(lc, e);
0564     BUG_ON(e->refcnt == 0);
0565     BUG_ON(e->lc_number != e->lc_new_number);
0566     if (--e->refcnt == 0) {
0567         /* move it to the front of LRU. */
0568         list_move(&e->list, &lc->lru);
0569         lc->used--;
0570         clear_bit_unlock(__LC_STARVING, &lc->flags);
0571     }
0572     RETURN(e->refcnt);
0573 }
0574 
0575 /**
0576  * lc_element_by_index
0577  * @lc: the lru cache to operate on
0578  * @i: the index of the element to return
0579  */
0580 struct lc_element *lc_element_by_index(struct lru_cache *lc, unsigned i)
0581 {
0582     BUG_ON(i >= lc->nr_elements);
0583     BUG_ON(lc->lc_element[i] == NULL);
0584     BUG_ON(lc->lc_element[i]->lc_index != i);
0585     return lc->lc_element[i];
0586 }
0587 
0588 /**
0589  * lc_index_of
0590  * @lc: the lru cache to operate on
0591  * @e: the element to query for its index position in lc->element
0592  */
0593 unsigned int lc_index_of(struct lru_cache *lc, struct lc_element *e)
0594 {
0595     PARANOIA_LC_ELEMENT(lc, e);
0596     return e->lc_index;
0597 }
0598 
0599 /**
0600  * lc_set - associate index with label
0601  * @lc: the lru cache to operate on
0602  * @enr: the label to set
0603  * @index: the element index to associate label with.
0604  *
0605  * Used to initialize the active set to some previously recorded state.
0606  */
0607 void lc_set(struct lru_cache *lc, unsigned int enr, int index)
0608 {
0609     struct lc_element *e;
0610     struct list_head *lh;
0611 
0612     if (index < 0 || index >= lc->nr_elements)
0613         return;
0614 
0615     e = lc_element_by_index(lc, index);
0616     BUG_ON(e->lc_number != e->lc_new_number);
0617     BUG_ON(e->refcnt != 0);
0618 
0619     e->lc_number = e->lc_new_number = enr;
0620     hlist_del_init(&e->colision);
0621     if (enr == LC_FREE)
0622         lh = &lc->free;
0623     else {
0624         hlist_add_head(&e->colision, lc_hash_slot(lc, enr));
0625         lh = &lc->lru;
0626     }
0627     list_move(&e->list, lh);
0628 }
0629 
0630 /**
0631  * lc_seq_dump_details - Dump a complete LRU cache to seq in textual form.
0632  * @lc: the lru cache to operate on
0633  * @seq: the &struct seq_file pointer to seq_printf into
0634  * @utext: user supplied additional "heading" or other info
0635  * @detail: function pointer the user may provide to dump further details
0636  * of the object the lc_element is embedded in. May be NULL.
0637  * Note: a leading space ' ' and trailing newline '\n' is implied.
0638  */
0639 void lc_seq_dump_details(struct seq_file *seq, struct lru_cache *lc, char *utext,
0640          void (*detail) (struct seq_file *, struct lc_element *))
0641 {
0642     unsigned int nr_elements = lc->nr_elements;
0643     struct lc_element *e;
0644     int i;
0645 
0646     seq_printf(seq, "\tnn: lc_number (new nr) refcnt %s\n ", utext);
0647     for (i = 0; i < nr_elements; i++) {
0648         e = lc_element_by_index(lc, i);
0649         if (e->lc_number != e->lc_new_number)
0650             seq_printf(seq, "\t%5d: %6d %8d %6d ",
0651                 i, e->lc_number, e->lc_new_number, e->refcnt);
0652         else
0653             seq_printf(seq, "\t%5d: %6d %-8s %6d ",
0654                 i, e->lc_number, "-\"-", e->refcnt);
0655         if (detail)
0656             detail(seq, e);
0657         seq_putc(seq, '\n');
0658     }
0659 }
0660 
0661 EXPORT_SYMBOL(lc_create);
0662 EXPORT_SYMBOL(lc_reset);
0663 EXPORT_SYMBOL(lc_destroy);
0664 EXPORT_SYMBOL(lc_set);
0665 EXPORT_SYMBOL(lc_del);
0666 EXPORT_SYMBOL(lc_try_get);
0667 EXPORT_SYMBOL(lc_find);
0668 EXPORT_SYMBOL(lc_get);
0669 EXPORT_SYMBOL(lc_put);
0670 EXPORT_SYMBOL(lc_committed);
0671 EXPORT_SYMBOL(lc_element_by_index);
0672 EXPORT_SYMBOL(lc_index_of);
0673 EXPORT_SYMBOL(lc_seq_printf_stats);
0674 EXPORT_SYMBOL(lc_seq_dump_details);
0675 EXPORT_SYMBOL(lc_try_lock);
0676 EXPORT_SYMBOL(lc_is_used);
0677 EXPORT_SYMBOL(lc_get_cumulative);