swap_slots.h 841 B

12345678910111213141516171819202122232425262728293031
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_SWAP_SLOTS_H
  3. #define _LINUX_SWAP_SLOTS_H
  4. #include <linux/swap.h>
  5. #include <linux/spinlock.h>
  6. #include <linux/mutex.h>
  7. #define SWAP_SLOTS_CACHE_SIZE SWAP_BATCH
  8. #define THRESHOLD_ACTIVATE_SWAP_SLOTS_CACHE (5*SWAP_SLOTS_CACHE_SIZE)
  9. #define THRESHOLD_DEACTIVATE_SWAP_SLOTS_CACHE (2*SWAP_SLOTS_CACHE_SIZE)
  10. struct swap_slots_cache {
  11. bool lock_initialized;
  12. struct mutex alloc_lock; /* protects slots, nr, cur */
  13. swp_entry_t *slots;
  14. int nr;
  15. int cur;
  16. spinlock_t free_lock; /* protects slots_ret, n_ret */
  17. swp_entry_t *slots_ret;
  18. int n_ret;
  19. };
  20. void disable_swap_slots_cache_lock(void);
  21. void reenable_swap_slots_cache_unlock(void);
  22. void enable_swap_slots_cache(void);
  23. int free_swap_slot(swp_entry_t entry);
  24. extern bool swap_slot_cache_enabled;
  25. #endif /* _LINUX_SWAP_SLOTS_H */