mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
ba81f83842
Because during swap off, a swap entry may have swap_map[] == SWAP_HAS_CACHE (for example, just allocated). If we return NULL in __read_swap_cache_async(), the swap off will abort. So when swap slot cache is disabled, (for swap off), we will wait for page to be put into swap cache in such race condition. This should not be a problem for swap slot cache, because swap slot cache should be drained after clearing swap_slot_cache_enabled. [ying.huang@intel.com: fix memory leak in __read_swap_cache_async()] Link: http://lkml.kernel.org/r/874lzt6znd.fsf@yhuang-dev.intel.com Link: http://lkml.kernel.org/r/5e2c5f6abe8e6eb0797408897b1bba80938e9b9d.1484082593.git.tim.c.chen@linux.intel.com Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com> Cc: Aaron Lu <aaron.lu@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Hillf Danton <hillf.zj@alibaba-inc.com> Cc: Huang Ying <ying.huang@intel.com> Cc: Hugh Dickins <hughd@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Corbet <corbet@lwn.net> escreveu: Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Rik van Riel <riel@redhat.com> Cc: Shaohua Li <shli@kernel.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
31 lines
801 B
C
31 lines
801 B
C
#ifndef _LINUX_SWAP_SLOTS_H
|
|
#define _LINUX_SWAP_SLOTS_H
|
|
|
|
#include <linux/swap.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/mutex.h>
|
|
|
|
#define SWAP_SLOTS_CACHE_SIZE SWAP_BATCH
|
|
#define THRESHOLD_ACTIVATE_SWAP_SLOTS_CACHE (5*SWAP_SLOTS_CACHE_SIZE)
|
|
#define THRESHOLD_DEACTIVATE_SWAP_SLOTS_CACHE (2*SWAP_SLOTS_CACHE_SIZE)
|
|
|
|
struct swap_slots_cache {
|
|
bool lock_initialized;
|
|
struct mutex alloc_lock; /* protects slots, nr, cur */
|
|
swp_entry_t *slots;
|
|
int nr;
|
|
int cur;
|
|
spinlock_t free_lock; /* protects slots_ret, n_ret */
|
|
swp_entry_t *slots_ret;
|
|
int n_ret;
|
|
};
|
|
|
|
void disable_swap_slots_cache_lock(void);
|
|
void reenable_swap_slots_cache_unlock(void);
|
|
int enable_swap_slots_cache(void);
|
|
int free_swap_slot(swp_entry_t entry);
|
|
|
|
extern bool swap_slot_cache_enabled;
|
|
|
|
#endif /* _LINUX_SWAP_SLOTS_H */
|