From patchwork Tue Oct 24 20:32:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13435241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFA33C25B6B for ; Tue, 24 Oct 2023 20:33:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C8166B02E8; Tue, 24 Oct 2023 16:33:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 878436B02E9; Tue, 24 Oct 2023 16:33:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7667B6B02EA; Tue, 24 Oct 2023 16:33:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 67FE86B02E8 for ; Tue, 24 Oct 2023 16:33:07 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 47E78A02DD for ; Tue, 24 Oct 2023 20:33:07 +0000 (UTC) X-FDA: 81381504414.14.516C547 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf03.hostedemail.com (Postfix) with ESMTP id 55C2C20028 for ; Tue, 24 Oct 2023 20:33:05 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PFg9zB6r; spf=pass (imf03.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698179585; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Cxd8yIiWNp4SN7aWyP2DJ3W2qpks9IKgGTIB0vbrgeM=; b=g104bqss6qWe7488jL/Ni6sipDrYjgcCcuX4ROleLBJKC/IOX39IwW+vUf9G6ptVxl9Z7y cIAV9DTbzM2KQoGOZ00K1Z0lLjWOR7Tbl+0WWeKhuTrFjAglUQOSFQVlPBcZg6+xvkR5gq Ca++6nCwMyae/zl7Ie/g0IidSGcHLnU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PFg9zB6r; spf=pass (imf03.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698179585; a=rsa-sha256; cv=none; b=ahsBjGK/bARhiehOXAMoRSGjSAcEPZvoeYWTWYQBe99+mVJRKQzuxHXzNXriIL0BU06ggh p832OTyWLpbk9OV3ElTDwMv1iCeGNn2KXMU7BXvyfF4Uu8zaEemhyZuY6CCBlRVRmRlRfz AqJmn0YBj3KDke3ggyrAAaDS5CpV7zE= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1caad0bcc95so32426125ad.0 for ; Tue, 24 Oct 2023 13:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698179584; x=1698784384; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Cxd8yIiWNp4SN7aWyP2DJ3W2qpks9IKgGTIB0vbrgeM=; b=PFg9zB6rUK0x96dy8KJhMFXssrlrZaR9YVjrygj729ariYaYGvqBs5sQMO+eIrQrsf TUikUAo9DJOpN4cQnmriioNDCf3v7nkCmCKfdZ5GW/R2zixkU5C2dXBaBwaNRPD0qAF2 dvOS3Lr0HrS/YGIeLgHcNgVRs8h1sf+pDWlWECMVSX3qZ1/qClvoxEB4ZmSzEYrakviB 6Vci6yd11hiv4yKM2kfprP2vTJWI+YqZJo19Xo9EAYP1Xq7I46o+y8rlcMyyp1LPzkgP JjltpvRPbnInby392w9woqD0Pvs5LTqMqeaq1W8IzunXEEsUEzewwZYcAhvmmNI+f/Zj WTvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698179584; x=1698784384; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Cxd8yIiWNp4SN7aWyP2DJ3W2qpks9IKgGTIB0vbrgeM=; b=XYZB7DQURHjGU0m/plh8DOE1KZ7nB6MpSlYKfakt0HKFrMviPo0I/Y+3D6eF+2QnqJ Vri6/estDJVwXgnvrV2/E4dol3Qgm4r4rot+zmhpXC/uOsaykSwB+MD0Z6pwZDCtyOQx VxvlgA256xiajlpWmqPlTLG/YFIoGdOzBKzzsTutXWPCJx7ZVgecNafGdLNwL/PLZZOA utY7ESLAw+SYv8CsgnUKVx3WkeYA+g/KJVM4+mvoiKHn9MD+YB3UK7DB6ez/OF9lVCN0 KysFIcXe5X0pPsNygIYSr+Zc1PvjIEMzpCySsk2Ub/PtVuEasoXTsOMlpehd8dtqHcBJ Z8Wg== X-Gm-Message-State: AOJu0Yy111ga/CRHVFqXfHeElPStwuvHcGqrRPWXDP/ep5k/uRcd/h3x +kSFEudJyP/jOhrbtGkjUUM= X-Google-Smtp-Source: AGHT+IEztSTrjikFmnkLIpiilubvgm2U1b8XxGpaC5cbdcAdlNaHKoR1ds3ApUoqcuA1b/ZOqMDgaQ== X-Received: by 2002:a17:902:e3c1:b0:1ca:2c3b:7747 with SMTP id r1-20020a170902e3c100b001ca2c3b7747mr9349501ple.20.1698179583985; Tue, 24 Oct 2023 13:33:03 -0700 (PDT) Received: from localhost (fwdproxy-prn-004.fbsv.net. [2a03:2880:ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id i17-20020a17090332d100b001c32fd9e412sm7776395plr.58.2023.10.24.13.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 13:33:03 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, chrisl@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: [PATCH v4 0/5] workload-specific and memory pressure-driven zswap writeback Date: Tue, 24 Oct 2023 13:32:57 -0700 Message-Id: <20231024203302.1920362-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 55C2C20028 X-Rspam-User: X-Stat-Signature: cud9kczbe1x1ai13y7ju7zeoj9crmtn4 X-Rspamd-Server: rspam01 X-HE-Tag: 1698179585-331069 X-HE-Meta: U2FsdGVkX19X6hS9NU8J8pyAXGlTE89sPU80hrB7BYKqTcSQV2h5xpOOAPPUUTCO60g5464BjyAjGc//dpG9POWPz6gA/QtbTlbYU2xPboydNWNjfMhdqSy6PskIR/QRa/MvnIWyU488q2z4Hplk0PbQlS0WuG1M+R/tB4bm6c6BpEeuVYvWdeu+TQ3LlfBw5oOR+kBiRruRdv6dxZkkw0KhNvsXqzXXyuQ7xbEJEoTUGW47V736013k6OGcoxcfeH+I1aF3CqTObaTkbWEZEYzk6AY3zXVRjOfL8yvOZa9QYDHK8+hjjzUvOQt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GFogkCLnx+/teTfpoh1DRZ2pNiCDnS2pUIH5YaTtR1EjRHk1jrR7FPSne8XnxlPytDeDaREcDCX0wb6CfpuxuizGLVbU/AUUYzaXbjbRl0sQHhxCBeyzoqxt7PszNw7li3nvQ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Changelog: v4: * Rename list_lru_add to list_lru_add_obj and __list_lru_add to list_lru_add (patch 1) (suggested by Johannes Weiner and Yosry Ahmed) * Some cleanups on the memcg aware LRU patch (patch 2) (suggested by Yosry Ahmed) * Use event interface for the new per-cgroup writeback counters. (patch 3) (suggested by Yosry Ahmed) * Abstract zswap's lruvec states and handling into zswap_lruvec_state (patch 5) (suggested by Yosry Ahmed) v3: * Add a patch to export per-cgroup zswap writeback counters * Add a patch to update zswap's kselftest * Separate the new list_lru functions into its own prep patch * Do not start from the top of the hierarchy when encounter a memcg that is not online for the global limit zswap writeback (patch 2) (suggested by Yosry Ahmed) * Do not remove the swap entry from list_lru in __read_swapcache_async() (patch 2) (suggested by Yosry Ahmed) * Removed a redundant zswap pool getting (patch 2) (reported by Ryan Roberts) * Use atomic for the nr_zswap_protected (instead of lruvec's lock) (patch 5) (suggested by Yosry Ahmed) * Remove the per-cgroup zswap shrinker knob (patch 5) (suggested by Yosry Ahmed) v2: * Fix loongarch compiler errors * Use pool stats instead of memcg stats when !CONFIG_MEMCG_KEM There are currently several issues with zswap writeback: 1. There is only a single global LRU for zswap, making it impossible to perform worload-specific shrinking - an memcg under memory pressure 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/20230530232435.3097106-1-nphamcs@gmail.com/T/#u But this solution leaves a lot to be desired, as we still do not have an avenue for an memcg to free up its own memory locked up in the zswap pool. 2. We only shrink the zswap pool when the user-defined limit is hit. This means that if we set the limit too high, cold data that are unlikely to be used again will reside in the pool, wasting precious memory. It is hard to predict how much zswap space will be needed ahead of time, as this depends on the workload (specifically, on factors such as memory access patterns and compressibility of the memory pages). This patch series solves these issues by separating the global zswap LRU into per-memcg and per-NUMA LRUs, and performs workload-specific (i.e memcg- and NUMA-aware) zswap writeback under memory pressure. The new shrinker does not have any parameter that must be tuned by the user, and can be opted in or out on a per-memcg basis. As a proof of concept, we ran the following synthetic benchmark: build the linux kernel in a memory-limited cgroup, and allocate some cold data in tmpfs to see if the shrinker could write them out and improved the overall performance. Depending on the amount of cold data generated, we observe from 14% to 35% reduction in kernel CPU time used in the kernel builds. Domenico Cerasuolo (3): zswap: make shrinking memcg-aware mm: memcg: add per-memcg zswap writeback stat selftests: cgroup: update per-memcg zswap writeback selftest Nhat Pham (2): list_lru: allows explicit memcg and NUMA node selection zswap: shrinks zswap pool based on memory pressure Documentation/admin-guide/mm/zswap.rst | 7 + drivers/android/binder_alloc.c | 5 +- fs/dcache.c | 8 +- fs/gfs2/quota.c | 6 +- fs/inode.c | 4 +- fs/nfs/nfs42xattr.c | 8 +- fs/nfsd/filecache.c | 4 +- fs/xfs/xfs_buf.c | 6 +- fs/xfs/xfs_dquot.c | 2 +- fs/xfs/xfs_qm.c | 2 +- include/linux/list_lru.h | 46 ++- include/linux/memcontrol.h | 5 + include/linux/mmzone.h | 2 + include/linux/vm_event_item.h | 1 + include/linux/zswap.h | 25 +- mm/list_lru.c | 48 ++- mm/memcontrol.c | 1 + mm/mmzone.c | 1 + mm/swap.h | 3 +- mm/swap_state.c | 25 +- mm/vmstat.c | 1 + mm/workingset.c | 4 +- mm/zswap.c | 365 ++++++++++++++++---- tools/testing/selftests/cgroup/test_zswap.c | 74 ++-- 24 files changed, 526 insertions(+), 127 deletions(-)