/kern_oII/fs/mbcache.c

http://omnia2droid.googlecode.com/ · C · 679 lines · 442 code · 78 blank · 159 comment · 63 complexity · a585d932cf1e75adaf9a9a7e556f2cb7 MD5 · raw file

  1. /*
  2. * linux/fs/mbcache.c
  3. * (C) 2001-2002 Andreas Gruenbacher, <a.gruenbacher@computer.org>
  4. */
  5. /*
  6. * Filesystem Meta Information Block Cache (mbcache)
  7. *
  8. * The mbcache caches blocks of block devices that need to be located
  9. * by their device/block number, as well as by other criteria (such
  10. * as the block's contents).
  11. *
  12. * There can only be one cache entry in a cache per device and block number.
  13. * Additional indexes need not be unique in this sense. The number of
  14. * additional indexes (=other criteria) can be hardwired at compile time
  15. * or specified at cache create time.
  16. *
  17. * Each cache entry is of fixed size. An entry may be `valid' or `invalid'
  18. * in the cache. A valid entry is in the main hash tables of the cache,
  19. * and may also be in the lru list. An invalid entry is not in any hashes
  20. * or lists.
  21. *
  22. * A valid cache entry is only in the lru list if no handles refer to it.
  23. * Invalid cache entries will be freed when the last handle to the cache
  24. * entry is released. Entries that cannot be freed immediately are put
  25. * back on the lru list.
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/hash.h>
  30. #include <linux/fs.h>
  31. #include <linux/mm.h>
  32. #include <linux/slab.h>
  33. #include <linux/sched.h>
  34. #include <linux/init.h>
  35. #include <linux/mbcache.h>
  36. #ifdef MB_CACHE_DEBUG
  37. # define mb_debug(f...) do { \
  38. printk(KERN_DEBUG f); \
  39. printk("\n"); \
  40. } while (0)
  41. #define mb_assert(c) do { if (!(c)) \
  42. printk(KERN_ERR "assertion " #c " failed\n"); \
  43. } while(0)
  44. #else
  45. # define mb_debug(f...) do { } while(0)
  46. # define mb_assert(c) do { } while(0)
  47. #endif
  48. #define mb_error(f...) do { \
  49. printk(KERN_ERR f); \
  50. printk("\n"); \
  51. } while(0)
  52. #define MB_CACHE_WRITER ((unsigned short)~0U >> 1)
  53. static DECLARE_WAIT_QUEUE_HEAD(mb_cache_queue);
  54. MODULE_AUTHOR("Andreas Gruenbacher <a.gruenbacher@computer.org>");
  55. MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
  56. MODULE_LICENSE("GPL");
  57. EXPORT_SYMBOL(mb_cache_create);
  58. EXPORT_SYMBOL(mb_cache_shrink);
  59. EXPORT_SYMBOL(mb_cache_destroy);
  60. EXPORT_SYMBOL(mb_cache_entry_alloc);
  61. EXPORT_SYMBOL(mb_cache_entry_insert);
  62. EXPORT_SYMBOL(mb_cache_entry_release);
  63. EXPORT_SYMBOL(mb_cache_entry_free);
  64. EXPORT_SYMBOL(mb_cache_entry_get);
  65. #if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
  66. EXPORT_SYMBOL(mb_cache_entry_find_first);
  67. EXPORT_SYMBOL(mb_cache_entry_find_next);
  68. #endif
  69. struct mb_cache {
  70. struct list_head c_cache_list;
  71. const char *c_name;
  72. struct mb_cache_op c_op;
  73. atomic_t c_entry_count;
  74. int c_bucket_bits;
  75. #ifndef MB_CACHE_INDEXES_COUNT
  76. int c_indexes_count;
  77. #endif
  78. struct kmem_cache *c_entry_cache;
  79. struct list_head *c_block_hash;
  80. struct list_head *c_indexes_hash[0];
  81. };
  82. /*
  83. * Global data: list of all mbcache's, lru list, and a spinlock for
  84. * accessing cache data structures on SMP machines. The lru list is
  85. * global across all mbcaches.
  86. */
  87. static LIST_HEAD(mb_cache_list);
  88. static LIST_HEAD(mb_cache_lru_list);
  89. static DEFINE_SPINLOCK(mb_cache_spinlock);
  90. static inline int
  91. mb_cache_indexes(struct mb_cache *cache)
  92. {
  93. #ifdef MB_CACHE_INDEXES_COUNT
  94. return MB_CACHE_INDEXES_COUNT;
  95. #else
  96. return cache->c_indexes_count;
  97. #endif
  98. }
  99. /*
  100. * What the mbcache registers as to get shrunk dynamically.
  101. */
  102. static int mb_cache_shrink_fn(int nr_to_scan, gfp_t gfp_mask);
  103. static struct shrinker mb_cache_shrinker = {
  104. .shrink = mb_cache_shrink_fn,
  105. .seeks = DEFAULT_SEEKS,
  106. };
  107. static inline int
  108. __mb_cache_entry_is_hashed(struct mb_cache_entry *ce)
  109. {
  110. return !list_empty(&ce->e_block_list);
  111. }
  112. static void
  113. __mb_cache_entry_unhash(struct mb_cache_entry *ce)
  114. {
  115. int n;
  116. if (__mb_cache_entry_is_hashed(ce)) {
  117. list_del_init(&ce->e_block_list);
  118. for (n=0; n<mb_cache_indexes(ce->e_cache); n++)
  119. list_del(&ce->e_indexes[n].o_list);
  120. }
  121. }
  122. static void
  123. __mb_cache_entry_forget(struct mb_cache_entry *ce, gfp_t gfp_mask)
  124. {
  125. struct mb_cache *cache = ce->e_cache;
  126. mb_assert(!(ce->e_used || ce->e_queued));
  127. if (cache->c_op.free && cache->c_op.free(ce, gfp_mask)) {
  128. /* free failed -- put back on the lru list
  129. for freeing later. */
  130. spin_lock(&mb_cache_spinlock);
  131. list_add(&ce->e_lru_list, &mb_cache_lru_list);
  132. spin_unlock(&mb_cache_spinlock);
  133. } else {
  134. kmem_cache_free(cache->c_entry_cache, ce);
  135. atomic_dec(&cache->c_entry_count);
  136. }
  137. }
  138. static void
  139. __mb_cache_entry_release_unlock(struct mb_cache_entry *ce)
  140. __releases(mb_cache_spinlock)
  141. {
  142. /* Wake up all processes queuing for this cache entry. */
  143. if (ce->e_queued)
  144. wake_up_all(&mb_cache_queue);
  145. if (ce->e_used >= MB_CACHE_WRITER)
  146. ce->e_used -= MB_CACHE_WRITER;
  147. ce->e_used--;
  148. if (!(ce->e_used || ce->e_queued)) {
  149. if (!__mb_cache_entry_is_hashed(ce))
  150. goto forget;
  151. mb_assert(list_empty(&ce->e_lru_list));
  152. list_add_tail(&ce->e_lru_list, &mb_cache_lru_list);
  153. }
  154. spin_unlock(&mb_cache_spinlock);
  155. return;
  156. forget:
  157. spin_unlock(&mb_cache_spinlock);
  158. __mb_cache_entry_forget(ce, GFP_KERNEL);
  159. }
  160. /*
  161. * mb_cache_shrink_fn() memory pressure callback
  162. *
  163. * This function is called by the kernel memory management when memory
  164. * gets low.
  165. *
  166. * @nr_to_scan: Number of objects to scan
  167. * @gfp_mask: (ignored)
  168. *
  169. * Returns the number of objects which are present in the cache.
  170. */
  171. static int
  172. mb_cache_shrink_fn(int nr_to_scan, gfp_t gfp_mask)
  173. {
  174. LIST_HEAD(free_list);
  175. struct list_head *l, *ltmp;
  176. int count = 0;
  177. spin_lock(&mb_cache_spinlock);
  178. list_for_each(l, &mb_cache_list) {
  179. struct mb_cache *cache =
  180. list_entry(l, struct mb_cache, c_cache_list);
  181. mb_debug("cache %s (%d)", cache->c_name,
  182. atomic_read(&cache->c_entry_count));
  183. count += atomic_read(&cache->c_entry_count);
  184. }
  185. mb_debug("trying to free %d entries", nr_to_scan);
  186. if (nr_to_scan == 0) {
  187. spin_unlock(&mb_cache_spinlock);
  188. goto out;
  189. }
  190. while (nr_to_scan-- && !list_empty(&mb_cache_lru_list)) {
  191. struct mb_cache_entry *ce =
  192. list_entry(mb_cache_lru_list.next,
  193. struct mb_cache_entry, e_lru_list);
  194. list_move_tail(&ce->e_lru_list, &free_list);
  195. __mb_cache_entry_unhash(ce);
  196. }
  197. spin_unlock(&mb_cache_spinlock);
  198. list_for_each_safe(l, ltmp, &free_list) {
  199. __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
  200. e_lru_list), gfp_mask);
  201. }
  202. out:
  203. return (count / 100) * sysctl_vfs_cache_pressure;
  204. }
  205. /*
  206. * mb_cache_create() create a new cache
  207. *
  208. * All entries in one cache are equal size. Cache entries may be from
  209. * multiple devices. If this is the first mbcache created, registers
  210. * the cache with kernel memory management. Returns NULL if no more
  211. * memory was available.
  212. *
  213. * @name: name of the cache (informal)
  214. * @cache_op: contains the callback called when freeing a cache entry
  215. * @entry_size: The size of a cache entry, including
  216. * struct mb_cache_entry
  217. * @indexes_count: number of additional indexes in the cache. Must equal
  218. * MB_CACHE_INDEXES_COUNT if the number of indexes is
  219. * hardwired.
  220. * @bucket_bits: log2(number of hash buckets)
  221. */
  222. struct mb_cache *
  223. mb_cache_create(const char *name, struct mb_cache_op *cache_op,
  224. size_t entry_size, int indexes_count, int bucket_bits)
  225. {
  226. int m=0, n, bucket_count = 1 << bucket_bits;
  227. struct mb_cache *cache = NULL;
  228. if(entry_size < sizeof(struct mb_cache_entry) +
  229. indexes_count * sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]))
  230. return NULL;
  231. cache = kmalloc(sizeof(struct mb_cache) +
  232. indexes_count * sizeof(struct list_head), GFP_KERNEL);
  233. if (!cache)
  234. goto fail;
  235. cache->c_name = name;
  236. cache->c_op.free = NULL;
  237. if (cache_op)
  238. cache->c_op.free = cache_op->free;
  239. atomic_set(&cache->c_entry_count, 0);
  240. cache->c_bucket_bits = bucket_bits;
  241. #ifdef MB_CACHE_INDEXES_COUNT
  242. mb_assert(indexes_count == MB_CACHE_INDEXES_COUNT);
  243. #else
  244. cache->c_indexes_count = indexes_count;
  245. #endif
  246. cache->c_block_hash = kmalloc(bucket_count * sizeof(struct list_head),
  247. GFP_KERNEL);
  248. if (!cache->c_block_hash)
  249. goto fail;
  250. for (n=0; n<bucket_count; n++)
  251. INIT_LIST_HEAD(&cache->c_block_hash[n]);
  252. for (m=0; m<indexes_count; m++) {
  253. cache->c_indexes_hash[m] = kmalloc(bucket_count *
  254. sizeof(struct list_head),
  255. GFP_KERNEL);
  256. if (!cache->c_indexes_hash[m])
  257. goto fail;
  258. for (n=0; n<bucket_count; n++)
  259. INIT_LIST_HEAD(&cache->c_indexes_hash[m][n]);
  260. }
  261. cache->c_entry_cache = kmem_cache_create(name, entry_size, 0,
  262. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL);
  263. if (!cache->c_entry_cache)
  264. goto fail;
  265. spin_lock(&mb_cache_spinlock);
  266. list_add(&cache->c_cache_list, &mb_cache_list);
  267. spin_unlock(&mb_cache_spinlock);
  268. return cache;
  269. fail:
  270. if (cache) {
  271. while (--m >= 0)
  272. kfree(cache->c_indexes_hash[m]);
  273. kfree(cache->c_block_hash);
  274. kfree(cache);
  275. }
  276. return NULL;
  277. }
  278. /*
  279. * mb_cache_shrink()
  280. *
  281. * Removes all cache entries of a device from the cache. All cache entries
  282. * currently in use cannot be freed, and thus remain in the cache. All others
  283. * are freed.
  284. *
  285. * @bdev: which device's cache entries to shrink
  286. */
  287. void
  288. mb_cache_shrink(struct block_device *bdev)
  289. {
  290. LIST_HEAD(free_list);
  291. struct list_head *l, *ltmp;
  292. spin_lock(&mb_cache_spinlock);
  293. list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
  294. struct mb_cache_entry *ce =
  295. list_entry(l, struct mb_cache_entry, e_lru_list);
  296. if (ce->e_bdev == bdev) {
  297. list_move_tail(&ce->e_lru_list, &free_list);
  298. __mb_cache_entry_unhash(ce);
  299. }
  300. }
  301. spin_unlock(&mb_cache_spinlock);
  302. list_for_each_safe(l, ltmp, &free_list) {
  303. __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
  304. e_lru_list), GFP_KERNEL);
  305. }
  306. }
  307. /*
  308. * mb_cache_destroy()
  309. *
  310. * Shrinks the cache to its minimum possible size (hopefully 0 entries),
  311. * and then destroys it. If this was the last mbcache, un-registers the
  312. * mbcache from kernel memory management.
  313. */
  314. void
  315. mb_cache_destroy(struct mb_cache *cache)
  316. {
  317. LIST_HEAD(free_list);
  318. struct list_head *l, *ltmp;
  319. int n;
  320. spin_lock(&mb_cache_spinlock);
  321. list_for_each_safe(l, ltmp, &mb_cache_lru_list) {
  322. struct mb_cache_entry *ce =
  323. list_entry(l, struct mb_cache_entry, e_lru_list);
  324. if (ce->e_cache == cache) {
  325. list_move_tail(&ce->e_lru_list, &free_list);
  326. __mb_cache_entry_unhash(ce);
  327. }
  328. }
  329. list_del(&cache->c_cache_list);
  330. spin_unlock(&mb_cache_spinlock);
  331. list_for_each_safe(l, ltmp, &free_list) {
  332. __mb_cache_entry_forget(list_entry(l, struct mb_cache_entry,
  333. e_lru_list), GFP_KERNEL);
  334. }
  335. if (atomic_read(&cache->c_entry_count) > 0) {
  336. mb_error("cache %s: %d orphaned entries",
  337. cache->c_name,
  338. atomic_read(&cache->c_entry_count));
  339. }
  340. kmem_cache_destroy(cache->c_entry_cache);
  341. for (n=0; n < mb_cache_indexes(cache); n++)
  342. kfree(cache->c_indexes_hash[n]);
  343. kfree(cache->c_block_hash);
  344. kfree(cache);
  345. }
  346. /*
  347. * mb_cache_entry_alloc()
  348. *
  349. * Allocates a new cache entry. The new entry will not be valid initially,
  350. * and thus cannot be looked up yet. It should be filled with data, and
  351. * then inserted into the cache using mb_cache_entry_insert(). Returns NULL
  352. * if no more memory was available.
  353. */
  354. struct mb_cache_entry *
  355. mb_cache_entry_alloc(struct mb_cache *cache, gfp_t gfp_flags)
  356. {
  357. struct mb_cache_entry *ce;
  358. ce = kmem_cache_alloc(cache->c_entry_cache, gfp_flags);
  359. if (ce) {
  360. atomic_inc(&cache->c_entry_count);
  361. INIT_LIST_HEAD(&ce->e_lru_list);
  362. INIT_LIST_HEAD(&ce->e_block_list);
  363. ce->e_cache = cache;
  364. ce->e_used = 1 + MB_CACHE_WRITER;
  365. ce->e_queued = 0;
  366. }
  367. return ce;
  368. }
  369. /*
  370. * mb_cache_entry_insert()
  371. *
  372. * Inserts an entry that was allocated using mb_cache_entry_alloc() into
  373. * the cache. After this, the cache entry can be looked up, but is not yet
  374. * in the lru list as the caller still holds a handle to it. Returns 0 on
  375. * success, or -EBUSY if a cache entry for that device + inode exists
  376. * already (this may happen after a failed lookup, but when another process
  377. * has inserted the same cache entry in the meantime).
  378. *
  379. * @bdev: device the cache entry belongs to
  380. * @block: block number
  381. * @keys: array of additional keys. There must be indexes_count entries
  382. * in the array (as specified when creating the cache).
  383. */
  384. int
  385. mb_cache_entry_insert(struct mb_cache_entry *ce, struct block_device *bdev,
  386. sector_t block, unsigned int keys[])
  387. {
  388. struct mb_cache *cache = ce->e_cache;
  389. unsigned int bucket;
  390. struct list_head *l;
  391. int error = -EBUSY, n;
  392. bucket = hash_long((unsigned long)bdev + (block & 0xffffffff),
  393. cache->c_bucket_bits);
  394. spin_lock(&mb_cache_spinlock);
  395. list_for_each_prev(l, &cache->c_block_hash[bucket]) {
  396. struct mb_cache_entry *ce =
  397. list_entry(l, struct mb_cache_entry, e_block_list);
  398. if (ce->e_bdev == bdev && ce->e_block == block)
  399. goto out;
  400. }
  401. __mb_cache_entry_unhash(ce);
  402. ce->e_bdev = bdev;
  403. ce->e_block = block;
  404. list_add(&ce->e_block_list, &cache->c_block_hash[bucket]);
  405. for (n=0; n<mb_cache_indexes(cache); n++) {
  406. ce->e_indexes[n].o_key = keys[n];
  407. bucket = hash_long(keys[n], cache->c_bucket_bits);
  408. list_add(&ce->e_indexes[n].o_list,
  409. &cache->c_indexes_hash[n][bucket]);
  410. }
  411. error = 0;
  412. out:
  413. spin_unlock(&mb_cache_spinlock);
  414. return error;
  415. }
  416. /*
  417. * mb_cache_entry_release()
  418. *
  419. * Release a handle to a cache entry. When the last handle to a cache entry
  420. * is released it is either freed (if it is invalid) or otherwise inserted
  421. * in to the lru list.
  422. */
  423. void
  424. mb_cache_entry_release(struct mb_cache_entry *ce)
  425. {
  426. spin_lock(&mb_cache_spinlock);
  427. __mb_cache_entry_release_unlock(ce);
  428. }
  429. /*
  430. * mb_cache_entry_free()
  431. *
  432. * This is equivalent to the sequence mb_cache_entry_takeout() --
  433. * mb_cache_entry_release().
  434. */
  435. void
  436. mb_cache_entry_free(struct mb_cache_entry *ce)
  437. {
  438. spin_lock(&mb_cache_spinlock);
  439. mb_assert(list_empty(&ce->e_lru_list));
  440. __mb_cache_entry_unhash(ce);
  441. __mb_cache_entry_release_unlock(ce);
  442. }
  443. /*
  444. * mb_cache_entry_get()
  445. *
  446. * Get a cache entry by device / block number. (There can only be one entry
  447. * in the cache per device and block.) Returns NULL if no such cache entry
  448. * exists. The returned cache entry is locked for exclusive access ("single
  449. * writer").
  450. */
  451. struct mb_cache_entry *
  452. mb_cache_entry_get(struct mb_cache *cache, struct block_device *bdev,
  453. sector_t block)
  454. {
  455. unsigned int bucket;
  456. struct list_head *l;
  457. struct mb_cache_entry *ce;
  458. bucket = hash_long((unsigned long)bdev + (block & 0xffffffff),
  459. cache->c_bucket_bits);
  460. spin_lock(&mb_cache_spinlock);
  461. list_for_each(l, &cache->c_block_hash[bucket]) {
  462. ce = list_entry(l, struct mb_cache_entry, e_block_list);
  463. if (ce->e_bdev == bdev && ce->e_block == block) {
  464. DEFINE_WAIT(wait);
  465. if (!list_empty(&ce->e_lru_list))
  466. list_del_init(&ce->e_lru_list);
  467. while (ce->e_used > 0) {
  468. ce->e_queued++;
  469. prepare_to_wait(&mb_cache_queue, &wait,
  470. TASK_UNINTERRUPTIBLE);
  471. spin_unlock(&mb_cache_spinlock);
  472. schedule();
  473. spin_lock(&mb_cache_spinlock);
  474. ce->e_queued--;
  475. }
  476. finish_wait(&mb_cache_queue, &wait);
  477. ce->e_used += 1 + MB_CACHE_WRITER;
  478. if (!__mb_cache_entry_is_hashed(ce)) {
  479. __mb_cache_entry_release_unlock(ce);
  480. return NULL;
  481. }
  482. goto cleanup;
  483. }
  484. }
  485. ce = NULL;
  486. cleanup:
  487. spin_unlock(&mb_cache_spinlock);
  488. return ce;
  489. }
  490. #if !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0)
  491. static struct mb_cache_entry *
  492. __mb_cache_entry_find(struct list_head *l, struct list_head *head,
  493. int index, struct block_device *bdev, unsigned int key)
  494. {
  495. while (l != head) {
  496. struct mb_cache_entry *ce =
  497. list_entry(l, struct mb_cache_entry,
  498. e_indexes[index].o_list);
  499. if (ce->e_bdev == bdev && ce->e_indexes[index].o_key == key) {
  500. DEFINE_WAIT(wait);
  501. if (!list_empty(&ce->e_lru_list))
  502. list_del_init(&ce->e_lru_list);
  503. /* Incrementing before holding the lock gives readers
  504. priority over writers. */
  505. ce->e_used++;
  506. while (ce->e_used >= MB_CACHE_WRITER) {
  507. ce->e_queued++;
  508. prepare_to_wait(&mb_cache_queue, &wait,
  509. TASK_UNINTERRUPTIBLE);
  510. spin_unlock(&mb_cache_spinlock);
  511. schedule();
  512. spin_lock(&mb_cache_spinlock);
  513. ce->e_queued--;
  514. }
  515. finish_wait(&mb_cache_queue, &wait);
  516. if (!__mb_cache_entry_is_hashed(ce)) {
  517. __mb_cache_entry_release_unlock(ce);
  518. spin_lock(&mb_cache_spinlock);
  519. return ERR_PTR(-EAGAIN);
  520. }
  521. return ce;
  522. }
  523. l = l->next;
  524. }
  525. return NULL;
  526. }
  527. /*
  528. * mb_cache_entry_find_first()
  529. *
  530. * Find the first cache entry on a given device with a certain key in
  531. * an additional index. Additonal matches can be found with
  532. * mb_cache_entry_find_next(). Returns NULL if no match was found. The
  533. * returned cache entry is locked for shared access ("multiple readers").
  534. *
  535. * @cache: the cache to search
  536. * @index: the number of the additonal index to search (0<=index<indexes_count)
  537. * @bdev: the device the cache entry should belong to
  538. * @key: the key in the index
  539. */
  540. struct mb_cache_entry *
  541. mb_cache_entry_find_first(struct mb_cache *cache, int index,
  542. struct block_device *bdev, unsigned int key)
  543. {
  544. unsigned int bucket = hash_long(key, cache->c_bucket_bits);
  545. struct list_head *l;
  546. struct mb_cache_entry *ce;
  547. mb_assert(index < mb_cache_indexes(cache));
  548. spin_lock(&mb_cache_spinlock);
  549. l = cache->c_indexes_hash[index][bucket].next;
  550. ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
  551. index, bdev, key);
  552. spin_unlock(&mb_cache_spinlock);
  553. return ce;
  554. }
  555. /*
  556. * mb_cache_entry_find_next()
  557. *
  558. * Find the next cache entry on a given device with a certain key in an
  559. * additional index. Returns NULL if no match could be found. The previous
  560. * entry is atomatically released, so that mb_cache_entry_find_next() can
  561. * be called like this:
  562. *
  563. * entry = mb_cache_entry_find_first();
  564. * while (entry) {
  565. * ...
  566. * entry = mb_cache_entry_find_next(entry, ...);
  567. * }
  568. *
  569. * @prev: The previous match
  570. * @index: the number of the additonal index to search (0<=index<indexes_count)
  571. * @bdev: the device the cache entry should belong to
  572. * @key: the key in the index
  573. */
  574. struct mb_cache_entry *
  575. mb_cache_entry_find_next(struct mb_cache_entry *prev, int index,
  576. struct block_device *bdev, unsigned int key)
  577. {
  578. struct mb_cache *cache = prev->e_cache;
  579. unsigned int bucket = hash_long(key, cache->c_bucket_bits);
  580. struct list_head *l;
  581. struct mb_cache_entry *ce;
  582. mb_assert(index < mb_cache_indexes(cache));
  583. spin_lock(&mb_cache_spinlock);
  584. l = prev->e_indexes[index].o_list.next;
  585. ce = __mb_cache_entry_find(l, &cache->c_indexes_hash[index][bucket],
  586. index, bdev, key);
  587. __mb_cache_entry_release_unlock(prev);
  588. return ce;
  589. }
  590. #endif /* !defined(MB_CACHE_INDEXES_COUNT) || (MB_CACHE_INDEXES_COUNT > 0) */
  591. static int __init init_mbcache(void)
  592. {
  593. register_shrinker(&mb_cache_shrinker);
  594. return 0;
  595. }
  596. static void __exit exit_mbcache(void)
  597. {
  598. unregister_shrinker(&mb_cache_shrinker);
  599. }
  600. module_init(init_mbcache)
  601. module_exit(exit_mbcache)