frontswap.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _LINUX_FRONTSWAP_H
  2. #define _LINUX_FRONTSWAP_H
  3. #include <linux/swap.h>
  4. #include <linux/mm.h>
  5. #include <linux/bitops.h>
  6. struct frontswap_ops {
  7. void (*init)(unsigned); /* this swap type was just swapon'ed */
  8. int (*store)(unsigned, pgoff_t, struct page *); /* store a page */
  9. int (*load)(unsigned, pgoff_t, struct page *); /* load a page */
  10. void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */
  11. void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */
  12. struct frontswap_ops *next; /* private pointer to next ops */
  13. };
  14. extern bool frontswap_enabled;
  15. extern void frontswap_register_ops(struct frontswap_ops *ops);
  16. extern void frontswap_shrink(unsigned long);
  17. extern unsigned long frontswap_curr_pages(void);
  18. extern void frontswap_writethrough(bool);
  19. #define FRONTSWAP_HAS_EXCLUSIVE_GETS
  20. extern void frontswap_tmem_exclusive_gets(bool);
  21. extern bool __frontswap_test(struct swap_info_struct *, pgoff_t);
  22. extern void __frontswap_init(unsigned type, unsigned long *map);
  23. extern int __frontswap_store(struct page *page);
  24. extern int __frontswap_load(struct page *page);
  25. extern void __frontswap_invalidate_page(unsigned, pgoff_t);
  26. extern void __frontswap_invalidate_area(unsigned);
  27. #ifdef CONFIG_FRONTSWAP
  28. #define frontswap_enabled (1)
  29. static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
  30. {
  31. return __frontswap_test(sis, offset);
  32. }
  33. static inline void frontswap_map_set(struct swap_info_struct *p,
  34. unsigned long *map)
  35. {
  36. p->frontswap_map = map;
  37. }
  38. static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
  39. {
  40. return p->frontswap_map;
  41. }
  42. #else
  43. /* all inline routines become no-ops and all externs are ignored */
  44. #define frontswap_enabled (0)
  45. static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
  46. {
  47. return false;
  48. }
  49. static inline void frontswap_map_set(struct swap_info_struct *p,
  50. unsigned long *map)
  51. {
  52. }
  53. static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
  54. {
  55. return NULL;
  56. }
  57. #endif
  58. static inline int frontswap_store(struct page *page)
  59. {
  60. int ret = -1;
  61. if (frontswap_enabled)
  62. ret = __frontswap_store(page);
  63. return ret;
  64. }
  65. static inline int frontswap_load(struct page *page)
  66. {
  67. int ret = -1;
  68. if (frontswap_enabled)
  69. ret = __frontswap_load(page);
  70. return ret;
  71. }
  72. static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)
  73. {
  74. if (frontswap_enabled)
  75. __frontswap_invalidate_page(type, offset);
  76. }
  77. static inline void frontswap_invalidate_area(unsigned type)
  78. {
  79. if (frontswap_enabled)
  80. __frontswap_invalidate_area(type);
  81. }
  82. static inline void frontswap_init(unsigned type, unsigned long *map)
  83. {
  84. if (frontswap_enabled)
  85. __frontswap_init(type, map);
  86. }
  87. #endif /* _LINUX_FRONTSWAP_H */