mbcache.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_MBCACHE_H
  3. #define _LINUX_MBCACHE_H
  4. #include <linux/hash.h>
  5. #include <linux/list_bl.h>
  6. #include <linux/list.h>
  7. #include <linux/atomic.h>
  8. #include <linux/fs.h>
  9. struct mb_cache;
  10. struct mb_cache_entry {
  11. /* List of entries in cache - protected by cache->c_list_lock */
  12. struct list_head e_list;
  13. /* Hash table list - protected by hash chain bitlock */
  14. struct hlist_bl_node e_hash_list;
  15. atomic_t e_refcnt;
  16. /* Key in hash - stable during lifetime of the entry */
  17. u32 e_key;
  18. u32 e_referenced:1;
  19. u32 e_reusable:1;
  20. /* User provided value - stable during lifetime of the entry */
  21. u64 e_value;
  22. };
  23. struct mb_cache *mb_cache_create(int bucket_bits);
  24. void mb_cache_destroy(struct mb_cache *cache);
  25. int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
  26. u64 value, bool reusable);
  27. void __mb_cache_entry_free(struct mb_cache_entry *entry);
  28. static inline int mb_cache_entry_put(struct mb_cache *cache,
  29. struct mb_cache_entry *entry)
  30. {
  31. if (!atomic_dec_and_test(&entry->e_refcnt))
  32. return 0;
  33. __mb_cache_entry_free(entry);
  34. return 1;
  35. }
  36. void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value);
  37. struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
  38. u64 value);
  39. struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache,
  40. u32 key);
  41. struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
  42. struct mb_cache_entry *entry);
  43. void mb_cache_entry_touch(struct mb_cache *cache,
  44. struct mb_cache_entry *entry);
  45. #endif /* _LINUX_MBCACHE_H */