1 mbcache2: rename to mbcache
3 From: Jan Kara <jack@suse.cz>
5 Since old mbcache code is gone, let's rename new code to mbcache since
6 number 2 is now meaningless. This is just a mechanical replacement.
8 Signed-off-by: Jan Kara <jack@suse.cz>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 fs/ext2/xattr.c | 48 +++---
14 fs/ext2/xattr.h | 8 +-
16 fs/ext4/xattr.c | 54 +++---
17 fs/ext4/xattr.h | 4 +-
18 fs/mbcache.c | 424 +++++++++++++++++++++++++++++++++++++++++++++++
19 fs/mbcache2.c | 424 -----------------------------------------------
20 include/linux/mbcache.h | 53 ++++++
21 include/linux/mbcache2.h | 53 ------
22 11 files changed, 538 insertions(+), 538 deletions(-)
23 create mode 100644 fs/mbcache.c
24 delete mode 100644 fs/mbcache2.c
25 create mode 100644 include/linux/mbcache.h
26 delete mode 100644 include/linux/mbcache2.h
28 diff --git a/fs/Makefile b/fs/Makefile
29 index 59b844007fbc..79f522575cba 100644
32 @@ -41,7 +41,7 @@ obj-$(CONFIG_COMPAT_BINFMT_ELF) += compat_binfmt_elf.o
33 obj-$(CONFIG_BINFMT_ELF_FDPIC) += binfmt_elf_fdpic.o
34 obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o
36 -obj-$(CONFIG_FS_MBCACHE) += mbcache2.o
37 +obj-$(CONFIG_FS_MBCACHE) += mbcache.o
38 obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
39 obj-$(CONFIG_NFS_COMMON) += nfs_common/
40 obj-$(CONFIG_COREDUMP) += coredump.o
41 diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
42 index f98ce7e60a0f..170939f379d7 100644
45 @@ -61,7 +61,7 @@ struct ext2_block_alloc_info {
46 #define rsv_start rsv_window._rsv_start
47 #define rsv_end rsv_window._rsv_end
53 * second extended-fs super-block data in memory
54 @@ -113,7 +113,7 @@ struct ext2_sb_info {
55 * of the mount options.
58 - struct mb2_cache *s_mb_cache;
59 + struct mb_cache *s_mb_cache;
62 static inline spinlock_t *
63 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
64 index 7162b4869bc3..71d58c2d7a19 100644
68 #include <linux/buffer_head.h>
69 #include <linux/init.h>
70 #include <linux/slab.h>
71 -#include <linux/mbcache2.h>
72 +#include <linux/mbcache.h>
73 #include <linux/quotaops.h>
74 #include <linux/rwsem.h>
75 #include <linux/security.h>
77 static int ext2_xattr_set2(struct inode *, struct buffer_head *,
78 struct ext2_xattr_header *);
80 -static int ext2_xattr_cache_insert(struct mb2_cache *, struct buffer_head *);
81 +static int ext2_xattr_cache_insert(struct mb_cache *, struct buffer_head *);
82 static struct buffer_head *ext2_xattr_cache_find(struct inode *,
83 struct ext2_xattr_header *);
84 static void ext2_xattr_rehash(struct ext2_xattr_header *,
85 @@ -150,7 +150,7 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
86 size_t name_len, size;
89 - struct mb2_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
90 + struct mb_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
92 ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
93 name_index, name, buffer, (long)buffer_size);
94 @@ -246,7 +246,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
96 size_t rest = buffer_size;
98 - struct mb2_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
99 + struct mb_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
101 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
102 buffer, (long)buffer_size);
103 @@ -493,8 +493,8 @@ bad_block: ext2_error(sb, "ext2_xattr_set",
104 * This must happen under buffer lock for
105 * ext2_xattr_set2() to reliably detect modified block
107 - mb2_cache_entry_delete_block(EXT2_SB(sb)->s_mb_cache,
108 - hash, bh->b_blocknr);
109 + mb_cache_entry_delete_block(EXT2_SB(sb)->s_mb_cache,
110 + hash, bh->b_blocknr);
112 /* keep the buffer locked while modifying it. */
114 @@ -627,7 +627,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
115 struct super_block *sb = inode->i_sb;
116 struct buffer_head *new_bh = NULL;
118 - struct mb2_cache *ext2_mb_cache = EXT2_SB(sb)->s_mb_cache;
119 + struct mb_cache *ext2_mb_cache = EXT2_SB(sb)->s_mb_cache;
122 new_bh = ext2_xattr_cache_find(inode, header);
123 @@ -721,8 +721,8 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
124 * This must happen under buffer lock for
125 * ext2_xattr_set2() to reliably detect freed block
127 - mb2_cache_entry_delete_block(ext2_mb_cache,
128 - hash, old_bh->b_blocknr);
129 + mb_cache_entry_delete_block(ext2_mb_cache,
130 + hash, old_bh->b_blocknr);
131 /* Free the old block. */
132 ea_bdebug(old_bh, "freeing");
133 ext2_free_blocks(inode, old_bh->b_blocknr, 1);
134 @@ -786,8 +786,8 @@ ext2_xattr_delete_inode(struct inode *inode)
135 * This must happen under buffer lock for ext2_xattr_set2() to
136 * reliably detect freed block
138 - mb2_cache_entry_delete_block(EXT2_SB(inode->i_sb)->s_mb_cache,
139 - hash, bh->b_blocknr);
140 + mb_cache_entry_delete_block(EXT2_SB(inode->i_sb)->s_mb_cache,
141 + hash, bh->b_blocknr);
142 ext2_free_blocks(inode, EXT2_I(inode)->i_file_acl, 1);
145 @@ -818,12 +818,12 @@ cleanup:
146 * Returns 0, or a negative error number on failure.
149 -ext2_xattr_cache_insert(struct mb2_cache *cache, struct buffer_head *bh)
150 +ext2_xattr_cache_insert(struct mb_cache *cache, struct buffer_head *bh)
152 __u32 hash = le32_to_cpu(HDR(bh)->h_hash);
155 - error = mb2_cache_entry_create(cache, GFP_NOFS, hash, bh->b_blocknr);
156 + error = mb_cache_entry_create(cache, GFP_NOFS, hash, bh->b_blocknr);
158 if (error == -EBUSY) {
159 ea_bdebug(bh, "already in cache (%d cache entries)",
160 @@ -887,14 +887,14 @@ static struct buffer_head *
161 ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
163 __u32 hash = le32_to_cpu(header->h_hash);
164 - struct mb2_cache_entry *ce;
165 - struct mb2_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
166 + struct mb_cache_entry *ce;
167 + struct mb_cache *ext2_mb_cache = EXT2_SB(inode->i_sb)->s_mb_cache;
170 return NULL; /* never share */
171 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
173 - ce = mb2_cache_entry_find_first(ext2_mb_cache, hash);
174 + ce = mb_cache_entry_find_first(ext2_mb_cache, hash);
176 struct buffer_head *bh;
178 @@ -915,7 +915,7 @@ again:
179 * entry is still hashed is reliable.
181 if (hlist_bl_unhashed(&ce->e_hash_list)) {
182 - mb2_cache_entry_put(ext2_mb_cache, ce);
183 + mb_cache_entry_put(ext2_mb_cache, ce);
187 @@ -928,14 +928,14 @@ again:
188 } else if (!ext2_xattr_cmp(header, HDR(bh))) {
189 ea_bdebug(bh, "b_count=%d",
190 atomic_read(&(bh->b_count)));
191 - mb2_cache_entry_touch(ext2_mb_cache, ce);
192 - mb2_cache_entry_put(ext2_mb_cache, ce);
193 + mb_cache_entry_touch(ext2_mb_cache, ce);
194 + mb_cache_entry_put(ext2_mb_cache, ce);
200 - ce = mb2_cache_entry_find_next(ext2_mb_cache, ce);
201 + ce = mb_cache_entry_find_next(ext2_mb_cache, ce);
205 @@ -1010,13 +1010,13 @@ static void ext2_xattr_rehash(struct ext2_xattr_header *header,
207 #define HASH_BUCKET_BITS 10
209 -struct mb2_cache *ext2_xattr_create_cache(void)
210 +struct mb_cache *ext2_xattr_create_cache(void)
212 - return mb2_cache_create(HASH_BUCKET_BITS);
213 + return mb_cache_create(HASH_BUCKET_BITS);
216 -void ext2_xattr_destroy_cache(struct mb2_cache *cache)
217 +void ext2_xattr_destroy_cache(struct mb_cache *cache)
220 - mb2_cache_destroy(cache);
221 + mb_cache_destroy(cache);
223 diff --git a/fs/ext2/xattr.h b/fs/ext2/xattr.h
224 index 6ea38aa9563a..6f82ab1b00ca 100644
225 --- a/fs/ext2/xattr.h
226 +++ b/fs/ext2/xattr.h
227 @@ -53,7 +53,7 @@ struct ext2_xattr_entry {
228 #define EXT2_XATTR_SIZE(size) \
229 (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
234 # ifdef CONFIG_EXT2_FS_XATTR
236 @@ -68,8 +68,8 @@ extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_
238 extern void ext2_xattr_delete_inode(struct inode *);
240 -extern struct mb2_cache *ext2_xattr_create_cache(void);
241 -extern void ext2_xattr_destroy_cache(struct mb2_cache *cache);
242 +extern struct mb_cache *ext2_xattr_create_cache(void);
243 +extern void ext2_xattr_destroy_cache(struct mb_cache *cache);
245 extern const struct xattr_handler *ext2_xattr_handlers[];
247 @@ -94,7 +94,7 @@ ext2_xattr_delete_inode(struct inode *inode)
251 -static inline void ext2_xattr_destroy_cache(struct mb2_cache *cache)
252 +static inline void ext2_xattr_destroy_cache(struct mb_cache *cache)
256 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
257 index b53cbc05b172..0662b285dc8a 100644
260 @@ -1468,7 +1468,7 @@ struct ext4_sb_info {
261 struct list_head s_es_list; /* List of inodes with reclaimable extents */
263 struct ext4_es_stats s_es_stats;
264 - struct mb2_cache *s_mb_cache;
265 + struct mb_cache *s_mb_cache;
266 spinlock_t s_es_lock ____cacheline_aligned_in_smp;
268 /* Ratelimit ext4 messages. */
269 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
270 index fe9f8d6ab6c9..c6af8a7a436a 100644
271 --- a/fs/ext4/xattr.c
272 +++ b/fs/ext4/xattr.c
274 #include <linux/init.h>
275 #include <linux/fs.h>
276 #include <linux/slab.h>
277 -#include <linux/mbcache2.h>
278 +#include <linux/mbcache.h>
279 #include <linux/quotaops.h>
280 #include "ext4_jbd2.h"
283 # define ea_bdebug(bh, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
286 -static void ext4_xattr_cache_insert(struct mb2_cache *, struct buffer_head *);
287 +static void ext4_xattr_cache_insert(struct mb_cache *, struct buffer_head *);
288 static struct buffer_head *ext4_xattr_cache_find(struct inode *,
289 struct ext4_xattr_header *,
290 - struct mb2_cache_entry **);
291 + struct mb_cache_entry **);
292 static void ext4_xattr_rehash(struct ext4_xattr_header *,
293 struct ext4_xattr_entry *);
294 static int ext4_xattr_list(struct dentry *dentry, char *buffer,
295 @@ -276,7 +276,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
296 struct ext4_xattr_entry *entry;
299 - struct mb2_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
300 + struct mb_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
302 ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
303 name_index, name, buffer, (long)buffer_size);
304 @@ -428,7 +428,7 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
305 struct inode *inode = d_inode(dentry);
306 struct buffer_head *bh = NULL;
308 - struct mb2_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
309 + struct mb_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
311 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
312 buffer, (long)buffer_size);
313 @@ -561,8 +561,8 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
314 * This must happen under buffer lock for
315 * ext4_xattr_block_set() to reliably detect freed block
317 - mb2_cache_entry_delete_block(EXT4_GET_MB_CACHE(inode), hash,
319 + mb_cache_entry_delete_block(EXT4_GET_MB_CACHE(inode), hash,
323 ext4_free_blocks(handle, inode, bh, 0, 1,
324 @@ -782,9 +782,9 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
325 struct super_block *sb = inode->i_sb;
326 struct buffer_head *new_bh = NULL;
327 struct ext4_xattr_search *s = &bs->s;
328 - struct mb2_cache_entry *ce = NULL;
329 + struct mb_cache_entry *ce = NULL;
331 - struct mb2_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
332 + struct mb_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
334 #define header(x) ((struct ext4_xattr_header *)(x))
336 @@ -805,8 +805,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
337 * ext4_xattr_block_set() to reliably detect modified
340 - mb2_cache_entry_delete_block(ext4_mb_cache, hash,
341 - bs->bh->b_blocknr);
342 + mb_cache_entry_delete_block(ext4_mb_cache, hash,
343 + bs->bh->b_blocknr);
344 ea_bdebug(bs->bh, "modifying in-place");
345 error = ext4_xattr_set_entry(i, s);
347 @@ -904,7 +904,7 @@ inserted:
348 EXT4_C2B(EXT4_SB(sb),
351 - mb2_cache_entry_put(ext4_mb_cache, ce);
352 + mb_cache_entry_put(ext4_mb_cache, ce);
356 @@ -919,8 +919,8 @@ inserted:
360 - mb2_cache_entry_touch(ext4_mb_cache, ce);
361 - mb2_cache_entry_put(ext4_mb_cache, ce);
362 + mb_cache_entry_touch(ext4_mb_cache, ce);
363 + mb_cache_entry_put(ext4_mb_cache, ce);
365 } else if (bs->bh && s->base == bs->bh->b_data) {
366 /* We were modifying this block in-place. */
367 @@ -985,7 +985,7 @@ getblk_failed:
371 - mb2_cache_entry_put(ext4_mb_cache, ce);
372 + mb_cache_entry_put(ext4_mb_cache, ce);
374 if (!(bs->bh && s->base == bs->bh->b_data))
376 @@ -1546,13 +1546,13 @@ cleanup:
377 * Returns 0, or a negative error number on failure.
380 -ext4_xattr_cache_insert(struct mb2_cache *ext4_mb_cache, struct buffer_head *bh)
381 +ext4_xattr_cache_insert(struct mb_cache *ext4_mb_cache, struct buffer_head *bh)
383 __u32 hash = le32_to_cpu(BHDR(bh)->h_hash);
386 - error = mb2_cache_entry_create(ext4_mb_cache, GFP_NOFS, hash,
388 + error = mb_cache_entry_create(ext4_mb_cache, GFP_NOFS, hash,
392 ea_bdebug(bh, "already in cache");
393 @@ -1610,16 +1610,16 @@ ext4_xattr_cmp(struct ext4_xattr_header *header1,
395 static struct buffer_head *
396 ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,
397 - struct mb2_cache_entry **pce)
398 + struct mb_cache_entry **pce)
400 __u32 hash = le32_to_cpu(header->h_hash);
401 - struct mb2_cache_entry *ce;
402 - struct mb2_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
403 + struct mb_cache_entry *ce;
404 + struct mb_cache *ext4_mb_cache = EXT4_GET_MB_CACHE(inode);
407 return NULL; /* never share */
408 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
409 - ce = mb2_cache_entry_find_first(ext4_mb_cache, hash);
410 + ce = mb_cache_entry_find_first(ext4_mb_cache, hash);
412 struct buffer_head *bh;
414 @@ -1638,7 +1638,7 @@ ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,
418 - ce = mb2_cache_entry_find_next(ext4_mb_cache, ce);
419 + ce = mb_cache_entry_find_next(ext4_mb_cache, ce);
423 @@ -1713,15 +1713,15 @@ static void ext4_xattr_rehash(struct ext4_xattr_header *header,
425 #define HASH_BUCKET_BITS 10
429 ext4_xattr_create_cache(void)
431 - return mb2_cache_create(HASH_BUCKET_BITS);
432 + return mb_cache_create(HASH_BUCKET_BITS);
435 -void ext4_xattr_destroy_cache(struct mb2_cache *cache)
436 +void ext4_xattr_destroy_cache(struct mb_cache *cache)
439 - mb2_cache_destroy(cache);
440 + mb_cache_destroy(cache);
443 diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
444 index 10b0f7323ed6..69dd3e6566e0 100644
445 --- a/fs/ext4/xattr.h
446 +++ b/fs/ext4/xattr.h
447 @@ -123,8 +123,8 @@ extern int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode,
448 struct ext4_xattr_info *i,
449 struct ext4_xattr_ibody_find *is);
451 -extern struct mb2_cache *ext4_xattr_create_cache(void);
452 -extern void ext4_xattr_destroy_cache(struct mb2_cache *);
453 +extern struct mb_cache *ext4_xattr_create_cache(void);
454 +extern void ext4_xattr_destroy_cache(struct mb_cache *);
456 #ifdef CONFIG_EXT4_FS_SECURITY
457 extern int ext4_init_security(handle_t *handle, struct inode *inode,
458 diff --git a/fs/mbcache.c b/fs/mbcache.c
460 index 000000000000..4241b633f155
464 +#include <linux/spinlock.h>
465 +#include <linux/slab.h>
466 +#include <linux/list.h>
467 +#include <linux/list_bl.h>
468 +#include <linux/module.h>
469 +#include <linux/sched.h>
470 +#include <linux/workqueue.h>
471 +#include <linux/mbcache.h>
474 + * Mbcache is a simple key-value store. Keys need not be unique, however
475 + * key-value pairs are expected to be unique (we use this fact in
476 + * mb_cache_entry_delete_block()).
478 + * Ext2 and ext4 use this cache for deduplication of extended attribute blocks.
479 + * They use hash of a block contents as a key and block number as a value.
480 + * That's why keys need not be unique (different xattr blocks may end up having
481 + * the same hash). However block number always uniquely identifies a cache
484 + * We provide functions for creation and removal of entries, search by key,
485 + * and a special "delete entry with given key-value pair" operation. Fixed
486 + * size hash table is used for fast key lookups.
490 + /* Hash table of entries */
491 + struct hlist_bl_head *c_hash;
492 + /* log2 of hash table size */
494 + /* Maximum entries in cache to avoid degrading hash too much */
496 + /* Protects c_list, c_entry_count */
497 + spinlock_t c_list_lock;
498 + struct list_head c_list;
499 + /* Number of entries in cache */
500 + unsigned long c_entry_count;
501 + struct shrinker c_shrink;
502 + /* Work for shrinking when the cache has too many entries */
503 + struct work_struct c_shrink_work;
506 +static struct kmem_cache *mb_entry_cache;
508 +static unsigned long mb_cache_shrink(struct mb_cache *cache,
509 + unsigned int nr_to_scan);
511 +static inline bool mb_cache_entry_referenced(struct mb_cache_entry *entry)
513 + return entry->_e_hash_list_head & 1;
516 +static inline void mb_cache_entry_set_referenced(struct mb_cache_entry *entry)
518 + entry->_e_hash_list_head |= 1;
521 +static inline void mb_cache_entry_clear_referenced(
522 + struct mb_cache_entry *entry)
524 + entry->_e_hash_list_head &= ~1;
527 +static inline struct hlist_bl_head *mb_cache_entry_head(
528 + struct mb_cache_entry *entry)
530 + return (struct hlist_bl_head *)
531 + (entry->_e_hash_list_head & ~1);
535 + * Number of entries to reclaim synchronously when there are too many entries
538 +#define SYNC_SHRINK_BATCH 64
541 + * mb_cache_entry_create - create entry in cache
542 + * @cache - cache where the entry should be created
543 + * @mask - gfp mask with which the entry should be allocated
544 + * @key - key of the entry
545 + * @block - block that contains data
547 + * Creates entry in @cache with key @key and records that data is stored in
548 + * block @block. The function returns -EBUSY if entry with the same key
549 + * and for the same block already exists in cache. Otherwise 0 is returned.
551 +int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
554 + struct mb_cache_entry *entry, *dup;
555 + struct hlist_bl_node *dup_node;
556 + struct hlist_bl_head *head;
558 + /* Schedule background reclaim if there are too many entries */
559 + if (cache->c_entry_count >= cache->c_max_entries)
560 + schedule_work(&cache->c_shrink_work);
561 + /* Do some sync reclaim if background reclaim cannot keep up */
562 + if (cache->c_entry_count >= 2*cache->c_max_entries)
563 + mb_cache_shrink(cache, SYNC_SHRINK_BATCH);
565 + entry = kmem_cache_alloc(mb_entry_cache, mask);
569 + INIT_LIST_HEAD(&entry->e_list);
570 + /* One ref for hash, one ref returned */
571 + atomic_set(&entry->e_refcnt, 1);
572 + entry->e_key = key;
573 + entry->e_block = block;
574 + head = &cache->c_hash[hash_32(key, cache->c_bucket_bits)];
575 + entry->_e_hash_list_head = (unsigned long)head;
576 + hlist_bl_lock(head);
577 + hlist_bl_for_each_entry(dup, dup_node, head, e_hash_list) {
578 + if (dup->e_key == key && dup->e_block == block) {
579 + hlist_bl_unlock(head);
580 + kmem_cache_free(mb_entry_cache, entry);
584 + hlist_bl_add_head(&entry->e_hash_list, head);
585 + hlist_bl_unlock(head);
587 + spin_lock(&cache->c_list_lock);
588 + list_add_tail(&entry->e_list, &cache->c_list);
589 + /* Grab ref for LRU list */
590 + atomic_inc(&entry->e_refcnt);
591 + cache->c_entry_count++;
592 + spin_unlock(&cache->c_list_lock);
596 +EXPORT_SYMBOL(mb_cache_entry_create);
598 +void __mb_cache_entry_free(struct mb_cache_entry *entry)
600 + kmem_cache_free(mb_entry_cache, entry);
602 +EXPORT_SYMBOL(__mb_cache_entry_free);
604 +static struct mb_cache_entry *__entry_find(struct mb_cache *cache,
605 + struct mb_cache_entry *entry,
608 + struct mb_cache_entry *old_entry = entry;
609 + struct hlist_bl_node *node;
610 + struct hlist_bl_head *head;
613 + head = mb_cache_entry_head(entry);
615 + head = &cache->c_hash[hash_32(key, cache->c_bucket_bits)];
616 + hlist_bl_lock(head);
617 + if (entry && !hlist_bl_unhashed(&entry->e_hash_list))
618 + node = entry->e_hash_list.next;
620 + node = hlist_bl_first(head);
622 + entry = hlist_bl_entry(node, struct mb_cache_entry,
624 + if (entry->e_key == key) {
625 + atomic_inc(&entry->e_refcnt);
632 + hlist_bl_unlock(head);
634 + mb_cache_entry_put(cache, old_entry);
640 + * mb_cache_entry_find_first - find the first entry in cache with given key
641 + * @cache: cache where we should search
642 + * @key: key to look for
644 + * Search in @cache for entry with key @key. Grabs reference to the first
645 + * entry found and returns the entry.
647 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache,
650 + return __entry_find(cache, NULL, key);
652 +EXPORT_SYMBOL(mb_cache_entry_find_first);
655 + * mb_cache_entry_find_next - find next entry in cache with the same
656 + * @cache: cache where we should search
657 + * @entry: entry to start search from
659 + * Finds next entry in the hash chain which has the same key as @entry.
660 + * If @entry is unhashed (which can happen when deletion of entry races
661 + * with the search), finds the first entry in the hash chain. The function
662 + * drops reference to @entry and returns with a reference to the found entry.
664 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
665 + struct mb_cache_entry *entry)
667 + return __entry_find(cache, entry, entry->e_key);
669 +EXPORT_SYMBOL(mb_cache_entry_find_next);
671 +/* mb_cache_entry_delete_block - remove information about block from cache
672 + * @cache - cache we work with
673 + * @key - key of the entry to remove
674 + * @block - block containing data for @key
676 + * Remove entry from cache @cache with key @key with data stored in @block.
678 +void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
681 + struct hlist_bl_node *node;
682 + struct hlist_bl_head *head;
683 + struct mb_cache_entry *entry;
685 + head = &cache->c_hash[hash_32(key, cache->c_bucket_bits)];
686 + hlist_bl_lock(head);
687 + hlist_bl_for_each_entry(entry, node, head, e_hash_list) {
688 + if (entry->e_key == key && entry->e_block == block) {
689 + /* We keep hash list reference to keep entry alive */
690 + hlist_bl_del_init(&entry->e_hash_list);
691 + hlist_bl_unlock(head);
692 + spin_lock(&cache->c_list_lock);
693 + if (!list_empty(&entry->e_list)) {
694 + list_del_init(&entry->e_list);
695 + cache->c_entry_count--;
696 + atomic_dec(&entry->e_refcnt);
698 + spin_unlock(&cache->c_list_lock);
699 + mb_cache_entry_put(cache, entry);
703 + hlist_bl_unlock(head);
705 +EXPORT_SYMBOL(mb_cache_entry_delete_block);
707 +/* mb_cache_entry_touch - cache entry got used
708 + * @cache - cache the entry belongs to
709 + * @entry - entry that got used
711 + * Marks entry as used to give hit higher chances of surviving in cache.
713 +void mb_cache_entry_touch(struct mb_cache *cache,
714 + struct mb_cache_entry *entry)
716 + mb_cache_entry_set_referenced(entry);
718 +EXPORT_SYMBOL(mb_cache_entry_touch);
720 +static unsigned long mb_cache_count(struct shrinker *shrink,
721 + struct shrink_control *sc)
723 + struct mb_cache *cache = container_of(shrink, struct mb_cache,
726 + return cache->c_entry_count;
729 +/* Shrink number of entries in cache */
730 +static unsigned long mb_cache_shrink(struct mb_cache *cache,
731 + unsigned int nr_to_scan)
733 + struct mb_cache_entry *entry;
734 + struct hlist_bl_head *head;
735 + unsigned int shrunk = 0;
737 + spin_lock(&cache->c_list_lock);
738 + while (nr_to_scan-- && !list_empty(&cache->c_list)) {
739 + entry = list_first_entry(&cache->c_list,
740 + struct mb_cache_entry, e_list);
741 + if (mb_cache_entry_referenced(entry)) {
742 + mb_cache_entry_clear_referenced(entry);
743 + list_move_tail(&cache->c_list, &entry->e_list);
746 + list_del_init(&entry->e_list);
747 + cache->c_entry_count--;
749 + * We keep LRU list reference so that entry doesn't go away
752 + spin_unlock(&cache->c_list_lock);
753 + head = mb_cache_entry_head(entry);
754 + hlist_bl_lock(head);
755 + if (!hlist_bl_unhashed(&entry->e_hash_list)) {
756 + hlist_bl_del_init(&entry->e_hash_list);
757 + atomic_dec(&entry->e_refcnt);
759 + hlist_bl_unlock(head);
760 + if (mb_cache_entry_put(cache, entry))
763 + spin_lock(&cache->c_list_lock);
765 + spin_unlock(&cache->c_list_lock);
770 +static unsigned long mb_cache_scan(struct shrinker *shrink,
771 + struct shrink_control *sc)
773 + int nr_to_scan = sc->nr_to_scan;
774 + struct mb_cache *cache = container_of(shrink, struct mb_cache,
776 + return mb_cache_shrink(cache, nr_to_scan);
779 +/* We shrink 1/X of the cache when we have too many entries in it */
780 +#define SHRINK_DIVISOR 16
782 +static void mb_cache_shrink_worker(struct work_struct *work)
784 + struct mb_cache *cache = container_of(work, struct mb_cache,
786 + mb_cache_shrink(cache, cache->c_max_entries / SHRINK_DIVISOR);
790 + * mb_cache_create - create cache
791 + * @bucket_bits: log2 of the hash table size
793 + * Create cache for keys with 2^bucket_bits hash entries.
795 +struct mb_cache *mb_cache_create(int bucket_bits)
797 + struct mb_cache *cache;
798 + int bucket_count = 1 << bucket_bits;
801 + if (!try_module_get(THIS_MODULE))
804 + cache = kzalloc(sizeof(struct mb_cache), GFP_KERNEL);
807 + cache->c_bucket_bits = bucket_bits;
808 + cache->c_max_entries = bucket_count << 4;
809 + INIT_LIST_HEAD(&cache->c_list);
810 + spin_lock_init(&cache->c_list_lock);
811 + cache->c_hash = kmalloc(bucket_count * sizeof(struct hlist_bl_head),
813 + if (!cache->c_hash) {
817 + for (i = 0; i < bucket_count; i++)
818 + INIT_HLIST_BL_HEAD(&cache->c_hash[i]);
820 + cache->c_shrink.count_objects = mb_cache_count;
821 + cache->c_shrink.scan_objects = mb_cache_scan;
822 + cache->c_shrink.seeks = DEFAULT_SEEKS;
823 + register_shrinker(&cache->c_shrink);
825 + INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker);
830 + module_put(THIS_MODULE);
833 +EXPORT_SYMBOL(mb_cache_create);
836 + * mb_cache_destroy - destroy cache
837 + * @cache: the cache to destroy
839 + * Free all entries in cache and cache itself. Caller must make sure nobody
840 + * (except shrinker) can reach @cache when calling this.
842 +void mb_cache_destroy(struct mb_cache *cache)
844 + struct mb_cache_entry *entry, *next;
846 + unregister_shrinker(&cache->c_shrink);
849 + * We don't bother with any locking. Cache must not be used at this
852 + list_for_each_entry_safe(entry, next, &cache->c_list, e_list) {
853 + if (!hlist_bl_unhashed(&entry->e_hash_list)) {
854 + hlist_bl_del_init(&entry->e_hash_list);
855 + atomic_dec(&entry->e_refcnt);
858 + list_del(&entry->e_list);
859 + WARN_ON(atomic_read(&entry->e_refcnt) != 1);
860 + mb_cache_entry_put(cache, entry);
862 + kfree(cache->c_hash);
864 + module_put(THIS_MODULE);
866 +EXPORT_SYMBOL(mb_cache_destroy);
868 +static int __init mbcache_init(void)
870 + mb_entry_cache = kmem_cache_create("mbcache",
871 + sizeof(struct mb_cache_entry), 0,
872 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL);
873 + BUG_ON(!mb_entry_cache);
877 +static void __exit mbcache_exit(void)
879 + kmem_cache_destroy(mb_entry_cache);
882 +module_init(mbcache_init)
883 +module_exit(mbcache_exit)
885 +MODULE_AUTHOR("Jan Kara <jack@suse.cz>");
886 +MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
887 +MODULE_LICENSE("GPL");
888 diff --git a/fs/mbcache2.c b/fs/mbcache2.c
889 deleted file mode 100644
890 index 49f7a6feaa83..000000000000
894 -#include <linux/spinlock.h>
895 -#include <linux/slab.h>
896 -#include <linux/list.h>
897 -#include <linux/list_bl.h>
898 -#include <linux/module.h>
899 -#include <linux/sched.h>
900 -#include <linux/workqueue.h>
901 -#include <linux/mbcache2.h>
904 - * Mbcache is a simple key-value store. Keys need not be unique, however
905 - * key-value pairs are expected to be unique (we use this fact in
906 - * mb2_cache_entry_delete_block()).
908 - * Ext2 and ext4 use this cache for deduplication of extended attribute blocks.
909 - * They use hash of a block contents as a key and block number as a value.
910 - * That's why keys need not be unique (different xattr blocks may end up having
911 - * the same hash). However block number always uniquely identifies a cache
914 - * We provide functions for creation and removal of entries, search by key,
915 - * and a special "delete entry with given key-value pair" operation. Fixed
916 - * size hash table is used for fast key lookups.
920 - /* Hash table of entries */
921 - struct hlist_bl_head *c_hash;
922 - /* log2 of hash table size */
924 - /* Maximum entries in cache to avoid degrading hash too much */
926 - /* Protects c_list, c_entry_count */
927 - spinlock_t c_list_lock;
928 - struct list_head c_list;
929 - /* Number of entries in cache */
930 - unsigned long c_entry_count;
931 - struct shrinker c_shrink;
932 - /* Work for shrinking when the cache has too many entries */
933 - struct work_struct c_shrink_work;
936 -static struct kmem_cache *mb2_entry_cache;
938 -static unsigned long mb2_cache_shrink(struct mb2_cache *cache,
939 - unsigned int nr_to_scan);
941 -static inline bool mb2_cache_entry_referenced(struct mb2_cache_entry *entry)
943 - return entry->_e_hash_list_head & 1;
946 -static inline void mb2_cache_entry_set_referenced(struct mb2_cache_entry *entry)
948 - entry->_e_hash_list_head |= 1;
951 -static inline void mb2_cache_entry_clear_referenced(
952 - struct mb2_cache_entry *entry)
954 - entry->_e_hash_list_head &= ~1;
957 -static inline struct hlist_bl_head *mb2_cache_entry_head(
958 - struct mb2_cache_entry *entry)
960 - return (struct hlist_bl_head *)
961 - (entry->_e_hash_list_head & ~1);
965 - * Number of entries to reclaim synchronously when there are too many entries
968 -#define SYNC_SHRINK_BATCH 64
971 - * mb2_cache_entry_create - create entry in cache
972 - * @cache - cache where the entry should be created
973 - * @mask - gfp mask with which the entry should be allocated
974 - * @key - key of the entry
975 - * @block - block that contains data
977 - * Creates entry in @cache with key @key and records that data is stored in
978 - * block @block. The function returns -EBUSY if entry with the same key
979 - * and for the same block already exists in cache. Otherwise 0 is returned.
981 -int mb2_cache_entry_create(struct mb2_cache *cache, gfp_t mask, u32 key,
984 - struct mb2_cache_entry *entry, *dup;
985 - struct hlist_bl_node *dup_node;
986 - struct hlist_bl_head *head;
988 - /* Schedule background reclaim if there are too many entries */
989 - if (cache->c_entry_count >= cache->c_max_entries)
990 - schedule_work(&cache->c_shrink_work);
991 - /* Do some sync reclaim if background reclaim cannot keep up */
992 - if (cache->c_entry_count >= 2*cache->c_max_entries)
993 - mb2_cache_shrink(cache, SYNC_SHRINK_BATCH);
995 - entry = kmem_cache_alloc(mb2_entry_cache, mask);
999 - INIT_LIST_HEAD(&entry->e_list);
1000 - /* One ref for hash, one ref returned */
1001 - atomic_set(&entry->e_refcnt, 1);
1002 - entry->e_key = key;
1003 - entry->e_block = block;
1004 - head = &cache->c_hash[hash_32(key, cache->c_bucket_bits)];
1005 - entry->_e_hash_list_head = (unsigned long)head;
1006 - hlist_bl_lock(head);
1007 - hlist_bl_for_each_entry(dup, dup_node, head, e_hash_list) {
1008 - if (dup->e_key == key && dup->e_block == block) {
1009 - hlist_bl_unlock(head);
1010 - kmem_cache_free(mb2_entry_cache, entry);
1014 - hlist_bl_add_head(&entry->e_hash_list, head);
1015 - hlist_bl_unlock(head);
1017 - spin_lock(&cache->c_list_lock);
1018 - list_add_tail(&entry->e_list, &cache->c_list);
1019 - /* Grab ref for LRU list */
1020 - atomic_inc(&entry->e_refcnt);
1021 - cache->c_entry_count++;
1022 - spin_unlock(&cache->c_list_lock);
1026 -EXPORT_SYMBOL(mb2_cache_entry_create);
1028 -void __mb2_cache_entry_free(struct mb2_cache_entry *entry)
1030 - kmem_cache_free(mb2_entry_cache, entry);
1032 -EXPORT_SYMBOL(__mb2_cache_entry_free);
1034 -static struct mb2_cache_entry *__entry_find(struct mb2_cache *cache,
1035 - struct mb2_cache_entry *entry,
1038 - struct mb2_cache_entry *old_entry = entry;
1039 - struct hlist_bl_node *node;
1040 - struct hlist_bl_head *head;
1043 - head = mb2_cache_entry_head(entry);
1045 - head = &cache->c_hash[hash_32(key, cache->c_bucket_bits)];
1046 - hlist_bl_lock(head);
1047 - if (entry && !hlist_bl_unhashed(&entry->e_hash_list))
1048 - node = entry->e_hash_list.next;
1050 - node = hlist_bl_first(head);
1052 - entry = hlist_bl_entry(node, struct mb2_cache_entry,
1054 - if (entry->e_key == key) {
1055 - atomic_inc(&entry->e_refcnt);
1058 - node = node->next;
1062 - hlist_bl_unlock(head);
1064 - mb2_cache_entry_put(cache, old_entry);
1070 - * mb2_cache_entry_find_first - find the first entry in cache with given key
1071 - * @cache: cache where we should search
1072 - * @key: key to look for
1074 - * Search in @cache for entry with key @key. Grabs reference to the first
1075 - * entry found and returns the entry.
1077 -struct mb2_cache_entry *mb2_cache_entry_find_first(struct mb2_cache *cache,
1080 - return __entry_find(cache, NULL, key);
1082 -EXPORT_SYMBOL(mb2_cache_entry_find_first);
1085 - * mb2_cache_entry_find_next - find next entry in cache with the same
1086 - * @cache: cache where we should search
1087 - * @entry: entry to start search from
1089 - * Finds next entry in the hash chain which has the same key as @entry.
1090 - * If @entry is unhashed (which can happen when deletion of entry races
1091 - * with the search), finds the first entry in the hash chain. The function
1092 - * drops reference to @entry and returns with a reference to the found entry.
1094 -struct mb2_cache_entry *mb2_cache_entry_find_next(struct mb2_cache *cache,
1095 - struct mb2_cache_entry *entry)
1097 - return __entry_find(cache, entry, entry->e_key);
1099 -EXPORT_SYMBOL(mb2_cache_entry_find_next);
1101 -/* mb2_cache_entry_delete_block - remove information about block from cache
1102 - * @cache - cache we work with
1103 - * @key - key of the entry to remove
1104 - * @block - block containing data for @key
1106 - * Remove entry from cache @cache with key @key with data stored in @block.
1108 -void mb2_cache_entry_delete_block(struct mb2_cache *cache, u32 key,
1111 - struct hlist_bl_node *node;
1112 - struct hlist_bl_head *head;
1113 - struct mb2_cache_entry *entry;
1115 - head = &cache->c_hash[hash_32(key, cache->c_bucket_bits)];
1116 - hlist_bl_lock(head);
1117 - hlist_bl_for_each_entry(entry, node, head, e_hash_list) {
1118 - if (entry->e_key == key && entry->e_block == block) {
1119 - /* We keep hash list reference to keep entry alive */
1120 - hlist_bl_del_init(&entry->e_hash_list);
1121 - hlist_bl_unlock(head);
1122 - spin_lock(&cache->c_list_lock);
1123 - if (!list_empty(&entry->e_list)) {
1124 - list_del_init(&entry->e_list);
1125 - cache->c_entry_count--;
1126 - atomic_dec(&entry->e_refcnt);
1128 - spin_unlock(&cache->c_list_lock);
1129 - mb2_cache_entry_put(cache, entry);
1133 - hlist_bl_unlock(head);
1135 -EXPORT_SYMBOL(mb2_cache_entry_delete_block);
1137 -/* mb2_cache_entry_touch - cache entry got used
1138 - * @cache - cache the entry belongs to
1139 - * @entry - entry that got used
1141 - * Marks entry as used to give hit higher chances of surviving in cache.
1143 -void mb2_cache_entry_touch(struct mb2_cache *cache,
1144 - struct mb2_cache_entry *entry)
1146 - mb2_cache_entry_set_referenced(entry);
1148 -EXPORT_SYMBOL(mb2_cache_entry_touch);
1150 -static unsigned long mb2_cache_count(struct shrinker *shrink,
1151 - struct shrink_control *sc)
1153 - struct mb2_cache *cache = container_of(shrink, struct mb2_cache,
1156 - return cache->c_entry_count;
1159 -/* Shrink number of entries in cache */
1160 -static unsigned long mb2_cache_shrink(struct mb2_cache *cache,
1161 - unsigned int nr_to_scan)
1163 - struct mb2_cache_entry *entry;
1164 - struct hlist_bl_head *head;
1165 - unsigned int shrunk = 0;
1167 - spin_lock(&cache->c_list_lock);
1168 - while (nr_to_scan-- && !list_empty(&cache->c_list)) {
1169 - entry = list_first_entry(&cache->c_list,
1170 - struct mb2_cache_entry, e_list);
1171 - if (mb2_cache_entry_referenced(entry)) {
1172 - mb2_cache_entry_clear_referenced(entry);
1173 - list_move_tail(&cache->c_list, &entry->e_list);
1176 - list_del_init(&entry->e_list);
1177 - cache->c_entry_count--;
1179 - * We keep LRU list reference so that entry doesn't go away
1182 - spin_unlock(&cache->c_list_lock);
1183 - head = mb2_cache_entry_head(entry);
1184 - hlist_bl_lock(head);
1185 - if (!hlist_bl_unhashed(&entry->e_hash_list)) {
1186 - hlist_bl_del_init(&entry->e_hash_list);
1187 - atomic_dec(&entry->e_refcnt);
1189 - hlist_bl_unlock(head);
1190 - if (mb2_cache_entry_put(cache, entry))
1193 - spin_lock(&cache->c_list_lock);
1195 - spin_unlock(&cache->c_list_lock);
1200 -static unsigned long mb2_cache_scan(struct shrinker *shrink,
1201 - struct shrink_control *sc)
1203 - int nr_to_scan = sc->nr_to_scan;
1204 - struct mb2_cache *cache = container_of(shrink, struct mb2_cache,
1206 - return mb2_cache_shrink(cache, nr_to_scan);
1209 -/* We shrink 1/X of the cache when we have too many entries in it */
1210 -#define SHRINK_DIVISOR 16
1212 -static void mb2_cache_shrink_worker(struct work_struct *work)
1214 - struct mb2_cache *cache = container_of(work, struct mb2_cache,
1216 - mb2_cache_shrink(cache, cache->c_max_entries / SHRINK_DIVISOR);
1220 - * mb2_cache_create - create cache
1221 - * @bucket_bits: log2 of the hash table size
1223 - * Create cache for keys with 2^bucket_bits hash entries.
1225 -struct mb2_cache *mb2_cache_create(int bucket_bits)
1227 - struct mb2_cache *cache;
1228 - int bucket_count = 1 << bucket_bits;
1231 - if (!try_module_get(THIS_MODULE))
1234 - cache = kzalloc(sizeof(struct mb2_cache), GFP_KERNEL);
1237 - cache->c_bucket_bits = bucket_bits;
1238 - cache->c_max_entries = bucket_count << 4;
1239 - INIT_LIST_HEAD(&cache->c_list);
1240 - spin_lock_init(&cache->c_list_lock);
1241 - cache->c_hash = kmalloc(bucket_count * sizeof(struct hlist_bl_head),
1243 - if (!cache->c_hash) {
1247 - for (i = 0; i < bucket_count; i++)
1248 - INIT_HLIST_BL_HEAD(&cache->c_hash[i]);
1250 - cache->c_shrink.count_objects = mb2_cache_count;
1251 - cache->c_shrink.scan_objects = mb2_cache_scan;
1252 - cache->c_shrink.seeks = DEFAULT_SEEKS;
1253 - register_shrinker(&cache->c_shrink);
1255 - INIT_WORK(&cache->c_shrink_work, mb2_cache_shrink_worker);
1260 - module_put(THIS_MODULE);
1263 -EXPORT_SYMBOL(mb2_cache_create);
1266 - * mb2_cache_destroy - destroy cache
1267 - * @cache: the cache to destroy
1269 - * Free all entries in cache and cache itself. Caller must make sure nobody
1270 - * (except shrinker) can reach @cache when calling this.
1272 -void mb2_cache_destroy(struct mb2_cache *cache)
1274 - struct mb2_cache_entry *entry, *next;
1276 - unregister_shrinker(&cache->c_shrink);
1279 - * We don't bother with any locking. Cache must not be used at this
1282 - list_for_each_entry_safe(entry, next, &cache->c_list, e_list) {
1283 - if (!hlist_bl_unhashed(&entry->e_hash_list)) {
1284 - hlist_bl_del_init(&entry->e_hash_list);
1285 - atomic_dec(&entry->e_refcnt);
1288 - list_del(&entry->e_list);
1289 - WARN_ON(atomic_read(&entry->e_refcnt) != 1);
1290 - mb2_cache_entry_put(cache, entry);
1292 - kfree(cache->c_hash);
1294 - module_put(THIS_MODULE);
1296 -EXPORT_SYMBOL(mb2_cache_destroy);
1298 -static int __init mb2cache_init(void)
1300 - mb2_entry_cache = kmem_cache_create("mbcache",
1301 - sizeof(struct mb2_cache_entry), 0,
1302 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL);
1303 - BUG_ON(!mb2_entry_cache);
1307 -static void __exit mb2cache_exit(void)
1309 - kmem_cache_destroy(mb2_entry_cache);
1312 -module_init(mb2cache_init)
1313 -module_exit(mb2cache_exit)
1315 -MODULE_AUTHOR("Jan Kara <jack@suse.cz>");
1316 -MODULE_DESCRIPTION("Meta block cache (for extended attributes)");
1317 -MODULE_LICENSE("GPL");
1318 diff --git a/include/linux/mbcache.h b/include/linux/mbcache.h
1319 new file mode 100644
1320 index 000000000000..a74a1f3082fb
1322 +++ b/include/linux/mbcache.h
1324 +#ifndef _LINUX_MBCACHE_H
1325 +#define _LINUX_MBCACHE_H
1327 +#include <linux/hash.h>
1328 +#include <linux/list_bl.h>
1329 +#include <linux/list.h>
1330 +#include <linux/atomic.h>
1331 +#include <linux/fs.h>
1335 +struct mb_cache_entry {
1336 + /* List of entries in cache - protected by cache->c_list_lock */
1337 + struct list_head e_list;
1338 + /* Hash table list - protected by bitlock in e_hash_list_head */
1339 + struct hlist_bl_node e_hash_list;
1340 + atomic_t e_refcnt;
1341 + /* Key in hash - stable during lifetime of the entry */
1343 + /* Block number of hashed block - stable during lifetime of the entry */
1346 + * Head of hash list (for list bit lock) - stable. Combined with
1347 + * referenced bit of entry
1349 + unsigned long _e_hash_list_head;
1352 +struct mb_cache *mb_cache_create(int bucket_bits);
1353 +void mb_cache_destroy(struct mb_cache *cache);
1355 +int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
1357 +void __mb_cache_entry_free(struct mb_cache_entry *entry);
1358 +static inline int mb_cache_entry_put(struct mb_cache *cache,
1359 + struct mb_cache_entry *entry)
1361 + if (!atomic_dec_and_test(&entry->e_refcnt))
1363 + __mb_cache_entry_free(entry);
1367 +void mb_cache_entry_delete_block(struct mb_cache *cache, u32 key,
1369 +struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache,
1371 +struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
1372 + struct mb_cache_entry *entry);
1373 +void mb_cache_entry_touch(struct mb_cache *cache,
1374 + struct mb_cache_entry *entry);
1376 +#endif /* _LINUX_MBCACHE_H */
1377 diff --git a/include/linux/mbcache2.h b/include/linux/mbcache2.h
1378 deleted file mode 100644
1379 index c934843a6a31..000000000000
1380 --- a/include/linux/mbcache2.h
1383 -#ifndef _LINUX_MB2CACHE_H
1384 -#define _LINUX_MB2CACHE_H
1386 -#include <linux/hash.h>
1387 -#include <linux/list_bl.h>
1388 -#include <linux/list.h>
1389 -#include <linux/atomic.h>
1390 -#include <linux/fs.h>
1394 -struct mb2_cache_entry {
1395 - /* List of entries in cache - protected by cache->c_list_lock */
1396 - struct list_head e_list;
1397 - /* Hash table list - protected by bitlock in e_hash_list_head */
1398 - struct hlist_bl_node e_hash_list;
1399 - atomic_t e_refcnt;
1400 - /* Key in hash - stable during lifetime of the entry */
1402 - /* Block number of hashed block - stable during lifetime of the entry */
1405 - * Head of hash list (for list bit lock) - stable. Combined with
1406 - * referenced bit of entry
1408 - unsigned long _e_hash_list_head;
1411 -struct mb2_cache *mb2_cache_create(int bucket_bits);
1412 -void mb2_cache_destroy(struct mb2_cache *cache);
1414 -int mb2_cache_entry_create(struct mb2_cache *cache, gfp_t mask, u32 key,
1416 -void __mb2_cache_entry_free(struct mb2_cache_entry *entry);
1417 -static inline int mb2_cache_entry_put(struct mb2_cache *cache,
1418 - struct mb2_cache_entry *entry)
1420 - if (!atomic_dec_and_test(&entry->e_refcnt))
1422 - __mb2_cache_entry_free(entry);
1426 -void mb2_cache_entry_delete_block(struct mb2_cache *cache, u32 key,
1428 -struct mb2_cache_entry *mb2_cache_entry_find_first(struct mb2_cache *cache,
1430 -struct mb2_cache_entry *mb2_cache_entry_find_next(struct mb2_cache *cache,
1431 - struct mb2_cache_entry *entry);
1432 -void mb2_cache_entry_touch(struct mb2_cache *cache,
1433 - struct mb2_cache_entry *entry);
1435 -#endif /* _LINUX_MB2CACHE_H */