X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ffld%2Ffld_cache.c;h=41aae69f89b036bcc59cef45207f36a17169aaa2;hb=dd392dfbfb1a71423f18166a56e43d9234c739d7;hp=3b6b898215ce7793ed78d489672b31142347234c;hpb=500f334631c6ebec72f5791472f21603da3e0ef9;p=fs%2Flustre-release.git diff --git a/lustre/fld/fld_cache.c b/lustre/fld/fld_cache.c index 3b6b898..41aae69 100644 --- a/lustre/fld/fld_cache.c +++ b/lustre/fld/fld_cache.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -92,34 +88,21 @@ struct fld_cache *fld_cache_init(const char *name, */ void fld_cache_fini(struct fld_cache *cache) { - __u64 pct; - ENTRY; + LASSERT(cache != NULL); + fld_cache_flush(cache); - LASSERT(cache != NULL); - fld_cache_flush(cache); - - if (cache->fci_stat.fst_count > 0) { - pct = cache->fci_stat.fst_cache * 100; - do_div(pct, cache->fci_stat.fst_count); - } else { - pct = 0; - } - - CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name); - CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count); + CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name); CDEBUG(D_INFO, " Cache reqs: %llu\n", cache->fci_stat.fst_cache); - CDEBUG(D_INFO, " Cache hits: %llu%%\n", pct); - - OBD_FREE_PTR(cache); + CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count); - EXIT; + OBD_FREE_PTR(cache); } /** * delete given node from list. */ -void fld_cache_entry_delete(struct fld_cache *cache, - struct fld_cache_entry *node) +static void fld_cache_entry_delete(struct fld_cache *cache, + struct fld_cache_entry *node) { list_del(&node->fce_list); list_del(&node->fce_lru); @@ -214,31 +197,30 @@ static inline void fld_cache_entry_add(struct fld_cache *cache, */ static int fld_cache_shrink(struct fld_cache *cache) { - struct fld_cache_entry *flde; - struct list_head *curr; - int num = 0; - ENTRY; + int num = 0; - LASSERT(cache != NULL); + ENTRY; - if (cache->fci_cache_count < cache->fci_cache_size) - RETURN(0); + LASSERT(cache != NULL); - curr = cache->fci_lru.prev; + if (cache->fci_cache_count < cache->fci_cache_size) + RETURN(0); - while (cache->fci_cache_count + cache->fci_threshold > - cache->fci_cache_size && curr != &cache->fci_lru) { + while (cache->fci_cache_count + cache->fci_threshold > + cache->fci_cache_size && + !list_empty(&cache->fci_lru)) { + struct fld_cache_entry *flde = + list_last_entry(&cache->fci_lru, struct fld_cache_entry, + fce_lru); - flde = list_entry(curr, struct fld_cache_entry, fce_lru); - curr = curr->prev; - fld_cache_entry_delete(cache, flde); - num++; - } + fld_cache_entry_delete(cache, flde); + num++; + } - CDEBUG(D_INFO, "%s: FLD cache - Shrunk by " - "%d entries\n", cache->fci_name, num); + CDEBUG(D_INFO, "%s: FLD cache - Shrunk by " + "%d entries\n", cache->fci_name, num); - RETURN(0); + RETURN(0); } /** @@ -403,8 +385,7 @@ int fld_cache_insert_nolock(struct fld_cache *cache, * insertion loop. */ - if (!cache->fci_no_shrink) - fld_cache_shrink(cache); + fld_cache_shrink(cache); head = &cache->fci_entries_head; @@ -473,56 +454,6 @@ void fld_cache_delete_nolock(struct fld_cache *cache, } /** - * Delete FLD entry in FLD cache. - * - */ -void fld_cache_delete(struct fld_cache *cache, - const struct lu_seq_range *range) -{ - write_lock(&cache->fci_lock); - fld_cache_delete_nolock(cache, range); - write_unlock(&cache->fci_lock); -} - -struct fld_cache_entry * -fld_cache_entry_lookup_nolock(struct fld_cache *cache, - const struct lu_seq_range *range) -{ - struct fld_cache_entry *flde; - struct fld_cache_entry *got = NULL; - struct list_head *head; - - head = &cache->fci_entries_head; - list_for_each_entry(flde, head, fce_list) { - if (range->lsr_start == flde->fce_range.lsr_start || - (range->lsr_end == flde->fce_range.lsr_end && - range->lsr_flags == flde->fce_range.lsr_flags)) { - got = flde; - break; - } - } - - RETURN(got); -} - -/** - * lookup \a seq sequence for range in fld cache. - */ -struct fld_cache_entry * -fld_cache_entry_lookup(struct fld_cache *cache, - const struct lu_seq_range *range) -{ - struct fld_cache_entry *got = NULL; - ENTRY; - - read_lock(&cache->fci_lock); - got = fld_cache_entry_lookup_nolock(cache, range); - read_unlock(&cache->fci_lock); - - RETURN(got); -} - -/** * lookup \a seq sequence for range in fld cache. */ int fld_cache_lookup(struct fld_cache *cache,