blob: e36b200c2a77831f30d39b7da5145cae424077e2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Tim Chen67afa382017-02-22 15:45:39 -08002#ifndef _LINUX_SWAP_SLOTS_H
3#define _LINUX_SWAP_SLOTS_H
4
5#include <linux/swap.h>
6#include <linux/spinlock.h>
7#include <linux/mutex.h>
8
9#define SWAP_SLOTS_CACHE_SIZE SWAP_BATCH
10#define THRESHOLD_ACTIVATE_SWAP_SLOTS_CACHE (5*SWAP_SLOTS_CACHE_SIZE)
11#define THRESHOLD_DEACTIVATE_SWAP_SLOTS_CACHE (2*SWAP_SLOTS_CACHE_SIZE)
12
13struct swap_slots_cache {
14 bool lock_initialized;
15 struct mutex alloc_lock; /* protects slots, nr, cur */
16 swp_entry_t *slots;
17 int nr;
18 int cur;
19 spinlock_t free_lock; /* protects slots_ret, n_ret */
20 swp_entry_t *slots_ret;
21 int n_ret;
22};
23
24void disable_swap_slots_cache_lock(void);
25void reenable_swap_slots_cache_unlock(void);
26int enable_swap_slots_cache(void);
27int free_swap_slot(swp_entry_t entry);
28
Huang Yingba81f832017-02-22 15:45:46 -080029extern bool swap_slot_cache_enabled;
30
Tim Chen67afa382017-02-22 15:45:39 -080031#endif /* _LINUX_SWAP_SLOTS_H */