mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-14 06:22:34 +02:00
Add zswap_never_enabled() to skip the xarray lookup in zswap_load() if zswap was never enabled on the system. It is implemented using static branches for efficiency, as enabling zswap should be a rare event. This could shave some cycles off zswap_load() when CONFIG_ZSWAP is used but zswap is never enabled. However, the real motivation behind this patch is two-fold: - Incoming large folio swapin work will need to fallback to order-0 folios if zswap was ever enabled, because any part of the folio could be in zswap, until proper handling of large folios with zswap is added. - A warning and recovery attempt will be added in a following change in case the above was not done incorrectly. Zswap will fail the read if the folio is large and it was ever enabled. Expose zswap_never_enabled() in the header for the swapin work to use it later. [yosryahmed@google.com: expose zswap_never_enabled() in the header] Link: https://lkml.kernel.org/r/Zmjf0Dr8s9xSW41X@google.com Link: https://lkml.kernel.org/r/20240611024516.1375191-2-yosryahmed@google.com Signed-off-by: Yosry Ahmed <yosryahmed@google.com> Reviewed-by: Nhat Pham <nphamcs@gmail.com> Cc: Barry Song <baohua@kernel.org> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Chris Li <chrisl@kernel.org> Cc: David Hildenbrand <david@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_ZSWAP_H
|
|
#define _LINUX_ZSWAP_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/mm_types.h>
|
|
|
|
struct lruvec;
|
|
|
|
extern atomic_t zswap_stored_pages;
|
|
|
|
#ifdef CONFIG_ZSWAP
|
|
|
|
struct zswap_lruvec_state {
|
|
/*
|
|
* Number of pages in zswap that should be protected from the shrinker.
|
|
* This number is an estimate of the following counts:
|
|
*
|
|
* a) Recent page faults.
|
|
* b) Recent insertion to the zswap LRU. This includes new zswap stores,
|
|
* as well as recent zswap LRU rotations.
|
|
*
|
|
* These pages are likely to be warm, and might incur IO if the are written
|
|
* to swap.
|
|
*/
|
|
atomic_long_t nr_zswap_protected;
|
|
};
|
|
|
|
unsigned long zswap_total_pages(void);
|
|
bool zswap_store(struct folio *folio);
|
|
bool zswap_load(struct folio *folio);
|
|
void zswap_invalidate(swp_entry_t swp);
|
|
int zswap_swapon(int type, unsigned long nr_pages);
|
|
void zswap_swapoff(int type);
|
|
void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg);
|
|
void zswap_lruvec_state_init(struct lruvec *lruvec);
|
|
void zswap_folio_swapin(struct folio *folio);
|
|
bool zswap_is_enabled(void);
|
|
bool zswap_never_enabled(void);
|
|
#else
|
|
|
|
struct zswap_lruvec_state {};
|
|
|
|
static inline bool zswap_store(struct folio *folio)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool zswap_load(struct folio *folio)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline void zswap_invalidate(swp_entry_t swp) {}
|
|
static inline int zswap_swapon(int type, unsigned long nr_pages)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline void zswap_swapoff(int type) {}
|
|
static inline void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) {}
|
|
static inline void zswap_lruvec_state_init(struct lruvec *lruvec) {}
|
|
static inline void zswap_folio_swapin(struct folio *folio) {}
|
|
|
|
static inline bool zswap_is_enabled(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool zswap_never_enabled(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* _LINUX_ZSWAP_H */
|