29 #include <linux/kernel.h>
30 #include <linux/module.h>
32 #include <linux/hash.h>
35 #include <linux/slab.h>
36 #include <linux/sched.h>
42 # define mb_debug(f...) do { \
43 printk(KERN_DEBUG f); \
46 #define mb_assert(c) do { if (!(c)) \
47 printk(KERN_ERR "assertion " #c " failed\n"); \
50 # define mb_debug(f...) do { } while(0)
51 # define mb_assert(c) do { } while(0)
53 #define mb_error(f...) do { \
58 #define MB_CACHE_WRITER ((unsigned short)~0U >> 1)
74 #if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
96 static struct shrinker mb_cache_shrinker = {
97 .shrink = mb_cache_shrink_fn,
111 if (__mb_cache_entry_is_hashed(ce)) {
140 if (!__mb_cache_entry_is_hashed(ce))
145 spin_unlock(&mb_cache_spinlock);
148 spin_unlock(&mb_cache_spinlock);
174 mb_debug(
"trying to free %d entries", nr_to_scan);
175 spin_lock(&mb_cache_spinlock);
176 while (nr_to_scan-- && !list_empty(&mb_cache_lru_list)) {
181 __mb_cache_entry_unhash(ce);
188 spin_unlock(&mb_cache_spinlock);
190 __mb_cache_entry_forget(entry, gfp_mask);
210 int n, bucket_count = 1 << bucket_bits;
223 for (n=0; n<bucket_count; n++)
229 for (n=0; n<bucket_count; n++)
243 spin_lock(&mb_cache_spinlock);
245 spin_unlock(&mb_cache_spinlock);
273 spin_lock(&mb_cache_spinlock);
279 __mb_cache_entry_unhash(ce);
282 spin_unlock(&mb_cache_spinlock);
303 spin_lock(&mb_cache_spinlock);
309 __mb_cache_entry_unhash(ce);
313 spin_unlock(&mb_cache_spinlock);
321 mb_error(
"cache %s: %d orphaned entries",
347 spin_lock(&mb_cache_spinlock);
348 if (!list_empty(&mb_cache_lru_list)) {
352 __mb_cache_entry_unhash(ce);
354 spin_unlock(&mb_cache_spinlock);
394 bucket = hash_long((
unsigned long)bdev + (block & 0xffffffff),
396 spin_lock(&mb_cache_spinlock);
403 __mb_cache_entry_unhash(ce);
412 spin_unlock(&mb_cache_spinlock);
427 spin_lock(&mb_cache_spinlock);
428 __mb_cache_entry_release_unlock(ce);
441 spin_lock(&mb_cache_spinlock);
443 __mb_cache_entry_unhash(ce);
444 __mb_cache_entry_release_unlock(ce);
464 bucket = hash_long((
unsigned long)bdev + (block & 0xffffffff),
466 spin_lock(&mb_cache_spinlock);
479 spin_unlock(&mb_cache_spinlock);
481 spin_lock(&mb_cache_spinlock);
487 if (!__mb_cache_entry_is_hashed(ce)) {
488 __mb_cache_entry_release_unlock(ce);
497 spin_unlock(&mb_cache_spinlock);
501 #if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
523 spin_unlock(&mb_cache_spinlock);
525 spin_lock(&mb_cache_spinlock);
530 if (!__mb_cache_entry_is_hashed(ce)) {
531 __mb_cache_entry_release_unlock(ce);
532 spin_lock(&mb_cache_spinlock);
563 spin_lock(&mb_cache_spinlock);
565 ce = __mb_cache_entry_find(l, &cache->
c_index_hash[bucket], bdev, key);
566 spin_unlock(&mb_cache_spinlock);
598 spin_lock(&mb_cache_spinlock);
600 ce = __mb_cache_entry_find(l, &cache->
c_index_hash[bucket], bdev, key);
601 __mb_cache_entry_release_unlock(prev);
607 static int __init init_mbcache(
void)
613 static void __exit exit_mbcache(
void)