zswap-make-shrinking-memcg-aware.patch removed from -mm tree
The quilt patch titled
Subject: zswap: make shrinking memcg-aware
has been removed from the -mm tree. Its filename was
zswap-make-shrinking-memcg-aware.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Domenico Cerasuolo <[email protected]>
Subject: zswap: make shrinking memcg-aware
Date: Thu, 30 Nov 2023 11:40:20 -0800
Currently, we only have a single global LRU for zswap. This makes it impossible to perform worload-specific shrinking - an memcg cannot determine which pages in the pool it owns, and often ends up writing pages from other memcgs. This issue has been previously observed in practice and mitigated by simply disabling memcg-initiated shrinking:
https://lore.kernel.org/all/[email protected]/T/#u
This patch fully resolves the issue by replacing the global zswap LRU with memcg- and NUMA-specific LRUs, and modify the reclaim logic:
a) When a store attempt hits an memcg limit, it now triggers a synchronous reclaim attempt that, if successful, allows the new hotter page to be accepted by zswap.
b) If the store attempt instead hits the global zswap limit, it will trigger an asynchronous reclaim attempt, in which an memcg is selected for reclaim in a round-robin-like fashion.
---
include/linux/memcontrol.h | 5 include/linux/zswap.h | 2 mm/memcontrol.c | 2 mm/swap.h | 3 mm/swap_state.c | 24 ++- mm/zswap.c | 268 ++++++++++++++++++++++++++++------- 6 files changed, 245 insertions(+), 59 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~zswap-make-shrinking-memcg-aware +5 -0
@@ -1192,6 +1192,11 @@ static inline struct mem_cgroup *page_mereturn NULL ; } +static inline struct mem_cgroup *get_mem_cgroup_from_objcg (struct obj_cgroup *objcg) +{ +return NULL ; +} +static inline bool folio_memcg_kmem (struct folio *folio) {return false;
include/linux/zswap.h renamed from include/linux/zswap.h~zswap-make-shrinking-memcg-aware +2 -0
@@ -15,6 +15,7 @@ bool zswap_load(struct folio *folio);void zswap_invalidate (int type,pgoff_t offset);void zswap_swapon (int type);void zswap_swapoff (int type); +void zswap_memcg_offline_cleanup (struct mem_cgroup *memcg);#else
@@ -31,6 +32,7 @@ static inline bool zswap_load(struct folstatic inline void zswap_invalidate (int type,pgoff_t offset) {}static inline void zswap_swapon (int type) {}static inline void zswap_swapoff (int type) {} +static inline void zswap_memcg_offline_cleanup (struct mem_cgroup *memcg) {}#endif
mm/memcontrol.c renamed from mm/memcontrol.c~zswap-make-shrinking-memcg-aware +2 -0
@@ -5614,6 +5614,8 @@ static void mem_cgroup_css_offline(strucpage_counter_set_min (&memcg->memory,0 );page_counter_set_low (&memcg->memory,0 ); +zswap_memcg_offline_cleanup (memcg); +memcg_offline_kmem (memcg);reparent_shrinker_deferred (memcg);wb_memcg_offline (memcg);
mm/swap.h renamed from mm/swap.h~zswap-make-shrinking-memcg-aware +2 -1
@@ -51,7 +51,8 @@ struct page *read_swap_cache_async(swp_e struct swap_iocb **plug);struct page *__read_swap_cache_async (swp_entry_t entry,gfp_t gfp_mask,struct mempolicy *mpol,pgoff_t ilx, -bool *new_page_allocated); +bool *new_page_allocated, +bool skip_if_exists);struct page *swap_cluster_readahead (swp_entry_t entry,gfp_t flag,struct mempolicy *mpol,pgoff_t ilx); struct page *swapin_readahead(swp_entry_t entry, gfp_t flag,
mm/swap_state.c renamed from mm/swap_state.c~zswap-make-shrinking-memcg-aware +18 -6
@@ -412,7 +412,8 @@ struct folio *filemap_get_incore_folio(sstruct page *__read_swap_cache_async (swp_entry_t entry,gfp_t gfp_mask,struct mempolicy *mpol,pgoff_t ilx, -bool *new_page_allocated) +bool *new_page_allocated, +bool skip_if_exists) {struct swap_info_struct *si;struct folio *folio;
@@ -471,6 +472,17 @@ struct page *__read_swap_cache_async(swp goto fail_put_swap;/* +* Protect against a recursive call to __read_swap_cache_async() +* on the same entry waiting forever here because SWAP_HAS_CACHE +* is set but the folio is not the swap cache yet. This can +* happen today if mem_cgroup_swapin_charge_folio() below +* triggers reclaim through zswap, which may call +* __read_swap_cache_async() in the writeback path. +*/ +if (skip_if_exists) + goto fail_put_swap; + +/* * We might race against __delete_from_swap_cache(), and * stumble across a swap_map entry whose SWAP_HAS_CACHE * has not yet been cleared. Or race against another
@@ -537,7 +549,7 @@ struct page *read_swap_cache_async(swp_e mpol =get_vma_policy (vma, addr,0 , &ilx); page =__read_swap_cache_async (entry, gfp_mask, mpol, ilx, - &page_allocated); + &page_allocated, false);mpol_cond_put (mpol);if (page_allocated)
@@ -654,7 +666,7 @@ struct page *swap_cluster_readahead(swp_/* Ok, do the async read-ahead now */ page =__read_swap_cache_async (swp_entry (swp_type (entry), offset), - gfp_mask, mpol, ilx, &page_allocated); + gfp_mask, mpol, ilx, &page_allocated, false);if (!page)continue ;if (page_allocated) {
@@ -672,7 +684,7 @@ struct page *swap_cluster_readahead(swp_ skip:/* The page was likely read above, so no need for plugging here */ page =__read_swap_cache_async (entry, gfp_mask, mpol, ilx, - &page_allocated); + &page_allocated, false);if (unlikely (page_allocated))swap_readpage (page, false,NULL );return page;
@@ -827,7 +839,7 @@ static struct page *swap_vma_readahead(spte_unmap (pte); pte =NULL ; page =__read_swap_cache_async (entry, gfp_mask, mpol, ilx, - &page_allocated); + &page_allocated, false);if (!page)continue ;if (page_allocated) {
@@ -847,7 +859,7 @@ static struct page *swap_vma_readahead(s skip:/* The page was likely read above, so no need for plugging here */ page =__read_swap_cache_async (targ_entry, gfp_mask, mpol, targ_ilx, - &page_allocated); + &page_allocated, false);if (unlikely (page_allocated))swap_readpage (page, false,NULL );return page;
mm/zswap.c renamed from mm/zswap.c~zswap-make-shrinking-memcg-aware +216 -52
419 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are