blob: 6ef92d17633da7eb1c138a9e79195cf644f9038d [file] [log] [blame]
Tim Chen67afa382017-02-22 15:45:39 -08001#ifndef _LINUX_SWAP_SLOTS_H
2#define _LINUX_SWAP_SLOTS_H
3
4#include <linux/swap.h>
5#include <linux/spinlock.h>
6#include <linux/mutex.h>
7
8#define SWAP_SLOTS_CACHE_SIZE SWAP_BATCH
9#define THRESHOLD_ACTIVATE_SWAP_SLOTS_CACHE (5*SWAP_SLOTS_CACHE_SIZE)
10#define THRESHOLD_DEACTIVATE_SWAP_SLOTS_CACHE (2*SWAP_SLOTS_CACHE_SIZE)
11
12struct swap_slots_cache {
13 bool lock_initialized;
14 struct mutex alloc_lock; /* protects slots, nr, cur */
15 swp_entry_t *slots;
16 int nr;
17 int cur;
18 spinlock_t free_lock; /* protects slots_ret, n_ret */
19 swp_entry_t *slots_ret;
20 int n_ret;
21};
22
23void disable_swap_slots_cache_lock(void);
24void reenable_swap_slots_cache_unlock(void);
25int enable_swap_slots_cache(void);
26int free_swap_slot(swp_entry_t entry);
27
Huang Yingba81f832017-02-22 15:45:46 -080028extern bool swap_slot_cache_enabled;
29
Tim Chen67afa382017-02-22 15:45:39 -080030#endif /* _LINUX_SWAP_SLOTS_H */