xfs_mru_cache.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2006-2007 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_MRU_CACHE_H__
  19. #define __XFS_MRU_CACHE_H__
  20. /* Function pointer type for callback to free a client's data pointer. */
  21. typedef void (*xfs_mru_cache_free_func_t)(unsigned long, void*);
  22. typedef struct xfs_mru_cache
  23. {
  24. struct radix_tree_root store; /* Core storage data structure. */
  25. struct list_head *lists; /* Array of lists, one per grp. */
  26. struct list_head reap_list; /* Elements overdue for reaping. */
  27. spinlock_t lock; /* Lock to protect this struct. */
  28. unsigned int grp_count; /* Number of discrete groups. */
  29. unsigned int grp_time; /* Time period spanned by grps. */
  30. unsigned int lru_grp; /* Group containing time zero. */
  31. unsigned long time_zero; /* Time first element was added. */
  32. unsigned long next_reap; /* Time that the reaper should
  33. next do something. */
  34. unsigned int reap_all; /* if set, reap all lists */
  35. xfs_mru_cache_free_func_t free_func; /* Function pointer for freeing. */
  36. struct delayed_work work; /* Workqueue data for reaping. */
  37. } xfs_mru_cache_t;
  38. int xfs_mru_cache_init(void);
  39. void xfs_mru_cache_uninit(void);
  40. int xfs_mru_cache_create(struct xfs_mru_cache **mrup, unsigned int lifetime_ms,
  41. unsigned int grp_count,
  42. xfs_mru_cache_free_func_t free_func);
  43. void xfs_mru_cache_flush(xfs_mru_cache_t *mru, int restart);
  44. void xfs_mru_cache_destroy(struct xfs_mru_cache *mru);
  45. int xfs_mru_cache_insert(struct xfs_mru_cache *mru, unsigned long key,
  46. void *value);
  47. void * xfs_mru_cache_remove(struct xfs_mru_cache *mru, unsigned long key);
  48. void xfs_mru_cache_delete(struct xfs_mru_cache *mru, unsigned long key);
  49. void *xfs_mru_cache_lookup(struct xfs_mru_cache *mru, unsigned long key);
  50. void *xfs_mru_cache_peek(struct xfs_mru_cache *mru, unsigned long key);
  51. void xfs_mru_cache_done(struct xfs_mru_cache *mru);
  52. #endif /* __XFS_MRU_CACHE_H__ */