From: Baoquan He The xswap routing check calls obj_cgroup_may_zswap(), which walks the memcg hierarchy and flushes the stats of every ancestor with a zswap limit, to read how full it is. The check only picks the device: a page zswap refuses falls back to a physical backend. Use mem_cgroup_may_zswap() with may_flush set to false, which the charge helper split added, and keep the rstat lock out of the swapout path. A stale "full" cannot be ignored, though: without a physical backend, the folio would be routed away from the only xswap device and the allocation would fail. Flush and check again when the lockless check says there is no room. Signed-off-by: Baoquan He --- mm/swapfile.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index c6df87019df0..2bd573b159ee 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2126,10 +2126,22 @@ static int swap_dup_entries_cluster(struct swap_info_struct *si, static bool folio_may_zswap(struct folio *folio) { struct obj_cgroup *objcg = get_obj_cgroup_from_folio(folio); - bool may_zswap = !objcg || obj_cgroup_may_zswap(objcg); + struct mem_cgroup *memcg; + bool may_zswap = true; - if (objcg) + if (objcg) { + memcg = get_mem_cgroup_from_objcg(objcg); + /* + * The lockless check reads a stale snapshot. If it says + * full, flush and look again: a false negative would route + * the folio away from the only xswap device and fail the + * allocation. + */ + may_zswap = mem_cgroup_may_zswap(memcg, false) || + mem_cgroup_may_zswap(memcg, true); + mem_cgroup_put(memcg); obj_cgroup_put(objcg); + } return may_zswap; } -- 2.54.0