From nobody Sat Feb 7 18:00:53 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FD3E3BBC9 for ; Mon, 21 Apr 2025 09:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226845; cv=none; b=ftMs3kuemnoEDVjFyGcchrhS/BP7UFRckVJ2iQsmxSoBpCNPFp4d/3Opoxxw9WYQpAQ/U04mk8p4AudhlKfLOifIeL718b9on7zhFHLog/d0JsqkvmmXdXdZerBG63/bnEdb56vw5MvNr0nI2tbVjzj5h2Oj19vqmdZQlL/drhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226845; c=relaxed/simple; bh=na0tf5sit+luKBwCF5RgPCxKQY5xZnDJHAwP9xyIyPU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ngp4B0iUUzNC3fW5lJeQr2IOAfcfO+9jylG3E2hHNyHPS3ze4DNKRqtuMY5xiaP9bLTJ2m5ZwUb61nb4gGPNJLYIUdwpJ2FWLJlSxnlPh6IdKRz3GJBSTod0TTE6CPil/ItDGsBxQd1vWrvOoj6+310kuuMcRIRfSkPNbvZ5XAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=h8VOJQwl; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="h8VOJQwl" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-227d6b530d8so37681195ad.3 for ; Mon, 21 Apr 2025 02:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1745226842; x=1745831642; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rwNGrkHqtII9hHebmCv8hT2EO8L3wdoKwS9DkX4S/JM=; b=h8VOJQwlJMaPZBetuBvji2CkvLUdWLtquzf9Kh0bZnPtYpgVC/0a25CLH7dVTnDx1m tMV2JUtR4oO8dwFdd3XSh9VMhhm8+rLFcrgZCxhz2KdjRCkO3QPgct86hepWa343fMaS 3U8VGNPMSoQM2+vVPoZZHfVaQL2U9MM87+dAYrj8s0fbNcigex234EEh9ut+/AIM+gy1 3d176Rxf+oIR1Ou6rfbZX7PuA3zHQxSyJ7qWXVtxzb/nwLcPxiviDusMbuk+tyeZ8QAa ASfD3VVfYpsSn5i7ryWa1ZwdbZMxzMIHGRkE82MEgu0IdzcoKOimzA51CUxpA2HhohDZ WqMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745226842; x=1745831642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rwNGrkHqtII9hHebmCv8hT2EO8L3wdoKwS9DkX4S/JM=; b=jypyNS/GqgwXwkU5MJ1Z+qnIxlkos8PIZnMKeGGU4vMwXtZZjrWTxXTD5MU7Z8n8Ao RVJCRkvEkd1C2Z0HJZtWtaIEXL0ZRYFiS379Od3hjyJA3+6F5c5+hssbHG7pJO/liQMe Z3cKNn+4nbFHG21IOv4WLFRkSZ+yopfQv+i28p8aTzM7zd/EzVTLzzqvIByifznjYyLo IvPyOcekJ7pgeF20Kk/k35g89bksJ/m0FCi7iUrQLH3UhS6EecWjopQzA9wqGgJw1n4w Aqy4+Bfn/pk54nkEPxC/RrDvGUxZNGK3bTSu079C/EIQo3kbLyh5ug19eJMKvm4tTfq8 eFSQ== X-Forwarded-Encrypted: i=1; AJvYcCUa2aCcgVQPxM90vEKyKB+71qJwOTNfSzFwqipxtBA+YBfc8SvCf9MZ62XyqlQMJNSAIST6jBHxqUARJR0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxf9u+KJG4HuIm3tuqwukWPSeWgc93p5ZzDxAlxKK8tNBAw7oJn 4u8McdFdyzveubRku7/HzpHqi5SYoSZktEZsjDB6DV9JrsIRm+3eqhf0MP1a5HI= X-Gm-Gg: ASbGncsXkkjQJIeP558jZvZOPCQWuN50RCHFDZ6MZ+6eELQcEWoJCSrboOwHJbtx5RK Znc4En2XUFR6KMC82/4ZsojwFWBOYRuFbXX3OuDcMFW3ZIOENyv3Q2g+LUZeurQrsYDnUbLsMSN Bz3sNOca3VayQ4nsUhyuvQL3KusDQLKO5SJc4PreQaqB8cQVrhU5dkvaZZRYuq+4c7evCUe6I3V 8J7/urPgfcJuBJSffv2dsrPr8RppuTbFP7MUKh+ox6htuTejvfUhrRBELb9LlxVGuFbQz2MLJO/ VpsEclF4EW+ueNOsqA6+/sMSFKeqo3Cfy2K3bjV5LJIivGR6DZMkZxyO4G0DJR1HdQ== X-Google-Smtp-Source: AGHT+IG8Xt4Ez8eHR0AdyQar+DTN2NHlhc9GFJ7M3y+sg+/0Ss8t7pUCmNYFFQfl4rEm0AP3+cR/yw== X-Received: by 2002:a17:902:e54e:b0:22c:35c5:e30d with SMTP id d9443c01a7336-22c53583e3dmr138421385ad.13.1745226842358; Mon, 21 Apr 2025 02:14:02 -0700 (PDT) Received: from n37-069-081.byted.org ([115.190.40.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b0db157be12sm5246285a12.64.2025.04.21.02.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Apr 2025 02:14:01 -0700 (PDT) From: Zhongkun He To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, mhocko@suse.com, yosry.ahmed@linux.dev, muchun.song@linux.dev, yuzhao@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Subject: [PATCH V4 1/4] mm: add swappiness=max arg to memory.reclaim for only anon reclaim Date: Mon, 21 Apr 2025 17:13:28 +0800 Message-Id: <519e12b9b1f8c31a01e228c8b4b91a2419684f77.1745225696.git.hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With this patch 'commit <68cd9050d871> ("mm: add swappiness=3D arg to memory.reclaim")', we can submit an additional swappiness=3D argument to memory.reclaim. It is very useful because we can dynamically adjust the reclamation ratio based on the anonymous folios and file folios of each cgroup. For example,when swappiness is set to 0, we only reclaim from file folios. However,we have also encountered a new issue: when swappiness is set to the MAX_SWAPPINESS, it may still only reclaim file folios. So, we hope to add a new arg 'swappiness=3Dmax' in memory.reclaim where proactive memory reclaim only reclaims from anonymous folios when swappiness is set to max. The swappiness semantics from a user perspective remain unchanged. For example, something like this: echo "2M swappiness=3Dmax" > /sys/fs/cgroup/memory.reclaim will perform reclaim on the rootcg with a swappiness setting of 'max' (a new mode) regardless of the file folios. Users have a more comprehensive view of the application's memory distribution because there are many metrics available. For example, if we find that a certain cgroup has a large number of inactive anon folios, we can reclaim only those and skip file folios, because with the zram/zswap, the IO tradeoff that cache_trim_mode or other file first logic is making doesn't hold - file refaults will cause IO, whereas anon decompression will not. With this patch, the swappiness argument of memory.reclaim has a new mode 'max', means reclaiming just from anonymous folios both in traditional LRU and MGLRU. Here is the previous discussion: https://lore.kernel.org/all/20250314033350.1156370-1-hezhongkun.hzk@bytedan= ce.com/ https://lore.kernel.org/all/20250312094337.2296278-1-hezhongkun.hzk@bytedan= ce.com/ https://lore.kernel.org/all/20250318135330.3358345-1-hezhongkun.hzk@bytedan= ce.com/ Suggested-by: Yosry Ahmed Signed-off-by: Zhongkun He Acked-by: Muchun Song suggested-by: Yosry Ahmed --- Documentation/admin-guide/cgroup-v2.rst | 3 +++ include/linux/swap.h | 4 ++++ mm/memcontrol.c | 5 +++++ mm/vmscan.c | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-= guide/cgroup-v2.rst index 1a16ce68a4d7..472c01e0eb2c 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1348,6 +1348,9 @@ The following nested keys are defined. same semantics as vm.swappiness applied to memcg reclaim with all the existing limitations and potential future extensions. =20 + The valid range for swappiness is [0-200, max], setting + swappiness=3Dmax exclusively reclaims anonymous memory. + memory.peak A read-write single value file which exists on non-root cgroups. =20 diff --git a/include/linux/swap.h b/include/linux/swap.h index db46b25a65ae..f57c7e0012ba 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -414,6 +414,10 @@ extern unsigned long try_to_free_pages(struct zonelist= *zonelist, int order, #define MEMCG_RECLAIM_PROACTIVE (1 << 2) #define MIN_SWAPPINESS 0 #define MAX_SWAPPINESS 200 + +/* Just recliam from anon folios in proactive memory reclaim */ +#define SWAPPINESS_ANON_ONLY (MAX_SWAPPINESS + 1) + extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, unsigned long nr_pages, gfp_t gfp_mask, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c96c1f2b9cf5..796c78b26e43 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4395,11 +4395,13 @@ static ssize_t memory_oom_group_write(struct kernfs= _open_file *of, =20 enum { MEMORY_RECLAIM_SWAPPINESS =3D 0, + MEMORY_RECLAIM_SWAPPINESS_MAX, MEMORY_RECLAIM_NULL, }; =20 static const match_table_t tokens =3D { { MEMORY_RECLAIM_SWAPPINESS, "swappiness=3D%d"}, + { MEMORY_RECLAIM_SWAPPINESS_MAX, "swappiness=3Dmax"}, { MEMORY_RECLAIM_NULL, NULL }, }; =20 @@ -4433,6 +4435,9 @@ static ssize_t memory_reclaim(struct kernfs_open_file= *of, char *buf, if (swappiness < MIN_SWAPPINESS || swappiness > MAX_SWAPPINESS) return -EINVAL; break; + case MEMORY_RECLAIM_SWAPPINESS_MAX: + swappiness =3D SWAPPINESS_ANON_ONLY; + break; default: return -EINVAL; } diff --git a/mm/vmscan.c b/mm/vmscan.c index 3783e45bfc92..ebe1407f6741 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2503,6 +2503,13 @@ static void get_scan_count(struct lruvec *lruvec, st= ruct scan_control *sc, goto out; } =20 + /* Proactive reclaim initiated by userspace for anonymous memory only */ + if (swappiness =3D=3D SWAPPINESS_ANON_ONLY) { + WARN_ON_ONCE(!sc->proactive); + scan_balance =3D SCAN_ANON; + goto out; + } + /* * Do not apply any pressure balancing cleverness when the * system is close to OOM, scan both anon and file equally --=20 2.39.5 From nobody Sat Feb 7 18:00:53 2026 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BA6A256C97 for ; Mon, 21 Apr 2025 09:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226850; cv=none; b=Bayk0z3A8Zxpg0SMDVQ6jHgmucqhBq2t5Qb6W7qbN0yfdU/go6L3dQgb3JaDMKOfgORMbez9m13m01GjYLh2jl8cz4F/PUWNJf4A8/8frF67rbX9CLef/9MKIi1sFt+wdOWWLb3FH1q8BQ/e+GJgwV4Y9n1ZkcG1lzCTPXxwWew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226850; c=relaxed/simple; bh=Yy9sZgdklGFmFaDuSPWUdtOoXvrQDwdmrdaX+WxA0nI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZuyiFUx/7APlNUKngulKvzzUt1JjdWEVnPpl00dxsIrRbzWWeJnbfSnK6uKiJV5VstoL3oliAxv0TDKDB/VbBcEf8Acm88sNQVR4V/RRBrXtPjAH+gIDdqXGKYSqFvU4Zw0ZOPPBusapRIhkUKFesaxL8O08TxmmZ5dFEQF/CiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=WIRqwg3d; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="WIRqwg3d" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-736aaeed234so3085463b3a.0 for ; Mon, 21 Apr 2025 02:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1745226848; x=1745831648; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AsJEbSZvZdA9M9xR3JLAkzpH6h6tuBABgV3Gz0g2ACA=; b=WIRqwg3dUFnM45O22HOC3DSegKLMaJTLRHw5oUrZ58Jlty4JvR2hiASxnHE1iplYiv AWALNNJu24TcPyzy1X6lFtg12EPOctp7a6YdL1DLHq1P6pHyj5gMHyg7kHdt2IQCjEAh jC0H02+fyxOeBxzrgm/W4FvrX105sN0GBepgs6rN8tsbwvzKvDiWhfCSQBH+NcK6u0sU IeToDjVPMwNc9sDXK6F6Bp9GqXDD0Fvz1mkcaR5zq+y+m9KehMvnKSXkdFAD/x/jFPNM mRwoFNz6Sbum1J3wvPdtpLVqZnl4TNC0q7Yj4z8IPgYY90d1cXvJWbmYpNhehPovoRcW dmZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745226848; x=1745831648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AsJEbSZvZdA9M9xR3JLAkzpH6h6tuBABgV3Gz0g2ACA=; b=uxYlUGyBVjuRtpD2+2S5lzJGrLKsxJwFYLMVWC4bfYe/mrOH7NSnQkIEJlggkO5j1v Prx7Pl3qhzysAsGt67W7mom1qDv6yTsBQnDtt8e8tVh3r3W0dybdG/GcfCo/YGqn9r7S H+6zGJBAbsvhJt4q/qJ7dEqQyy4S5N1NtJyd332YdK8edcfoPHgf2NLvrIJZoRhFALzV N023H1zhNcmyaBDOqrkTpv4OrkH2N6IX640pQcbnBnmELlpECCzrubGPVL71qQT7abRa B40tFprcVXog2HFnELwdUJ+/0pP9a+wyH0TqfdycUnrmlxSGnMWAYX8PVNJG+3QhyR0P 1l8g== X-Forwarded-Encrypted: i=1; AJvYcCUyBlh1gUiGoI7UTZV9md7G1cvqI3Bi0aDMeY1X1ceP7EcpGSsmP9a/izpW9kvCLg/MUMtwhLOPehQZXtU=@vger.kernel.org X-Gm-Message-State: AOJu0YwWZ5sqzR+QaXT29LNqBQL7f8us72dYkNp9UDJRzycdIVPXoz5j YxgjkAydwTTSX0BUZQ4bpNwMNMZ8iLB8D+cdYyY4dFx2t/UdHmpGhXY2Vb+Qew4= X-Gm-Gg: ASbGncuOTfxBG5m2jlNSNWAUaOTzdiKLynYIGT3I+QgFbYNWPvwlNwb0hWGHIR1//k9 OdfMapjYx0KxjWNtkvUuAfXWuGOdlhX0wLmGukJyRsLcUSEqet0fYlrVV2Aa3eFmAlWySwCsOMr zv6uoOcPJPKmRfLZFm4PKFcUnSgYbx5IgVhDiJ6C9X/1r0wcaGNNeQTHvmdx97ZC41Zlh2vxOdJ 5FTCH6JywkFj/3rgBmnJHFTi861X3wxiAcZPO1+fxlSUkbz2LlJx6vzs7QsQ/eZvqTdVT714Xih ydZnIDe+cYmKIftJy+b0qFg6Hg2U3u6ER1HXdv4tUwbqcjS1I2WAE/HSILr3GclBZUeLrcH54Fs e X-Google-Smtp-Source: AGHT+IHueA1196GNLskkec36YuY6fc1vKwEyqs5bJkXUqE3Keaq4gAYLH3kEP+dsJDbTfxHzr5P94w== X-Received: by 2002:a05:6a20:c6cb:b0:1f5:8da5:ffe9 with SMTP id adf61e73a8af0-203cbc55037mr16154792637.12.1745226847909; Mon, 21 Apr 2025 02:14:07 -0700 (PDT) Received: from n37-069-081.byted.org ([115.190.40.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b0db157be12sm5246285a12.64.2025.04.21.02.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Apr 2025 02:14:07 -0700 (PDT) From: Zhongkun He To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, mhocko@suse.com, yosry.ahmed@linux.dev, muchun.song@linux.dev, yuzhao@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Subject: [PATCH V4 2/4] mm: vmscan: add more comments about cache_trim_mode Date: Mon, 21 Apr 2025 17:13:29 +0800 Message-Id: <4baad87ba637f1e6f666e9b99b3fdcb7ab39171b.1745225696.git.hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add more comments for cache_trim_mode, and the annotations provided by Johannes Weiner in [1]. [1]: https://lore.kernel.org/all/20250314141833.GA1316033@cmpxchg.org/ Signed-off-by: Zhongkun He suggested-by: Yosry Ahmed --- mm/vmscan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index ebe1407f6741..49eb2a4e490d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2530,7 +2530,8 @@ static void get_scan_count(struct lruvec *lruvec, str= uct scan_control *sc, =20 /* * If there is enough inactive page cache, we do not reclaim - * anything from the anonymous working right now. + * anything from the anonymous working right now to make sure + * a streaming file access pattern doesn't cause swapping. */ if (sc->cache_trim_mode) { scan_balance =3D SCAN_FILE; --=20 2.39.5 From nobody Sat Feb 7 18:00:53 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DB01214204 for ; Mon, 21 Apr 2025 09:14:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226855; cv=none; b=ubaetpZrbqhIpTlLsEsFO5RkeradfFOsHWmJf+35yn9VpMPnUV98P8g0Qv3hSEnvO3JUHmkatwyfCHFJuZ175y8ySjOt4xvA4iKPDh0m6Q5hjpFqDO9VfwC0hze2NLoozMBlh7FFHqSmMQxeWXXiqeFCDpkAj9HU7eYCWhM0bNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226855; c=relaxed/simple; bh=Sek/1qM6VAaCLISu+e0NpeWjIB1EzF+cjtMiY1AWrUw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LU+w4VrURCA4iIukdGUYyUqCEyCSuWGa9O0UMNI5Wj9JRPh7LQSOzS572uegDdobjeek1ZYUxBxxv7I3D7nD9jufSSRRfvVY3Sz5lyN2nsKwgZFlsMWDc8JlTBItdgAmBlUZbcvcDwseYkKOcNmyKHJw5G0z0OYnCfQgVV7Q/e8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=hE4J3T+p; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="hE4J3T+p" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7394945d37eso3028828b3a.3 for ; Mon, 21 Apr 2025 02:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1745226854; x=1745831654; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ygV5UbjOFbVAxBSeUQbkYKQf+DuR38CRxo53sfgG9F0=; b=hE4J3T+pam/cxSdA+Y2zJ3g3IUDuvnDK4L5eB9lOJyr5y4CBoKZ4NRhxd8dU4Bl79K dUOhkijvVzibD8MtcTS/GWjXdlaz/utOGst3q2RcgrDsB5DWu3hRhmjHSKisQ/ly6Lfh gCxTK9hnKcdJ1yptpBMwoKYQqD+H85fwagzxgM/ykVsWTYTKWt78aeyZ2nfLDAaNFltz tBUatb1ll0PWROpy19D3PsLlLdidYSm9eYe4hzS6lLAI37XP8UYJLVSzunzGNyCfkWdE 539DybguyZVRzq498M5xSbpUJHFxrGI25TU0PWI0Cm1SuMoskfz/3o4mPWILKWRI6xkV 2yIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745226854; x=1745831654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ygV5UbjOFbVAxBSeUQbkYKQf+DuR38CRxo53sfgG9F0=; b=DrXrh/5FL4P6Lk0qG6n9HOGZSq1140C9j+LZbOxuMZoWeCuIfvcfqNlM3qK/s9rpMY X0KdZPedrSik5LIipEf0YMR50Xc0sxBVqoWL8MCuQ2aljRVtc1TMof2b3Z5taEnAnLv3 rjDc92pJlmeKTQjY3klYipFrxhNIdSWcqWY7aQoa5SKoo59vvDCdkwhVkQUYYcZGF9/W lIeL1+NOcVwRdNtECVBNkqO2YWha9ygx63i23Zk79xQS2HodT+Ubr5fJV4zoQG5Cby/c 4sczbS+Uoc1pS1T5ukE/VU4Uw+c2XW6wX9WbyYG94qq1uofkD6B2BA0Seg2p/i0eZs+a sY6w== X-Forwarded-Encrypted: i=1; AJvYcCWKTeKu+dcEWdRXxYF/3CBWX5PK9ZeiAK0cyu5mRF5WWVCT/jFN3QDS0kmj/G3ApgAsvtp29TUcRt6iQS8=@vger.kernel.org X-Gm-Message-State: AOJu0YyFVvhQlBjSSq5Dhbza+HbnH8G9mOgQGYmBNXJRE/7mc3+xlG4/ 4M3+UEd+FbVfK+fluKCqUhDGkKT5oD4wiDnQk15YpG2N8sSf6eUP8lI0MftaJhA= X-Gm-Gg: ASbGnctiAFxzLzu69Er2cohCfQYHiJrzKYFovsusqun65wBEhu1YtcC9F16JmxcbdJZ PLse3nydE4nXClSwMSFKEpKhv0B6H/aaUZuAAcavBP/FKdJ7nYpmYrcJbvowZXnByTb5SaQW6H/ soXlRUmWCxjLUOmO908TUrQXp/YLsBw6BDXQtOS2VBrXatqePJ4W5TyRYeuf/iWuSOfURiRmLzj RHKQ/PBaHxSZUDQZkVdKhCWATDyZ71l56nFeldwamyCFQOjCXuxNx6wAgI/QZzqlfm0ONwLVmm6 paNLxTCZFva5uVRy3RN7KOxvUkYIZw5VMWMb3nBmhOp3mqdPenSZ7iXtDeVvF6dKcQ== X-Google-Smtp-Source: AGHT+IEll/jifAikPxZ2dySlj6rMg3Q4GiFLUm5e3aty/LuvjRx4u1+vE+jTGDM8X0cXAuamrHwh3g== X-Received: by 2002:a05:6a21:9202:b0:1f5:55b7:1bb2 with SMTP id adf61e73a8af0-203cbc22e32mr14573489637.6.1745226853712; Mon, 21 Apr 2025 02:14:13 -0700 (PDT) Received: from n37-069-081.byted.org ([115.190.40.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b0db157be12sm5246285a12.64.2025.04.21.02.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Apr 2025 02:14:13 -0700 (PDT) From: Zhongkun He To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, mhocko@suse.com, yosry.ahmed@linux.dev, muchun.song@linux.dev, yuzhao@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Subject: [PATCH V4 3/4] mm: add max swappiness arg to lru_gen for anonymous memory only Date: Mon, 21 Apr 2025 17:13:30 +0800 Message-Id: <65181f7745d657d664d833c26d8a94cae40538b9.1745225696.git.hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MGLRU already supports reclaiming only from anonymous memory via the /sys/kernel/debug/lru_gen interface. Now, memory.reclaim also supports the swappiness=3Dmax parameter to enable reclaiming solely from anonymous memory. To unify the semantics of proactive reclaiming from anonymous folios, the max parameter is introduced. Signed-off-by: Zhongkun He Acked-by: Muchun Song suggested-by: Yosry Ahmed --- Documentation/admin-guide/mm/multigen_lru.rst | 5 +++-- mm/vmscan.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/mm/multigen_lru.rst b/Documentation/= admin-guide/mm/multigen_lru.rst index 33e068830497..9cb54b4ff5d9 100644 --- a/Documentation/admin-guide/mm/multigen_lru.rst +++ b/Documentation/admin-guide/mm/multigen_lru.rst @@ -151,8 +151,9 @@ generations less than or equal to ``min_gen_nr``. ``min_gen_nr`` should be less than ``max_gen_nr-1``, since ``max_gen_nr`` and ``max_gen_nr-1`` are not fully aged (equivalent to the active list) and therefore cannot be evicted. ``swappiness`` -overrides the default value in ``/proc/sys/vm/swappiness``. -``nr_to_reclaim`` limits the number of pages to evict. +overrides the default value in ``/proc/sys/vm/swappiness`` and the valid +range is [0-200, max], with max being exclusively used for the reclamation +of anonymous memory. ``nr_to_reclaim`` limits the number of pages to evict. =20 A typical use case is that a job scheduler runs this command before it tries to land a new job on a server. If it fails to materialize enough diff --git a/mm/vmscan.c b/mm/vmscan.c index 49eb2a4e490d..b442c20d1168 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -5581,7 +5581,7 @@ static ssize_t lru_gen_seq_write(struct file *file, c= onst char __user *src, while ((cur =3D strsep(&next, ",;\n"))) { int n; int end; - char cmd; + char cmd, swap_string[5]; unsigned int memcg_id; unsigned int nid; unsigned long seq; @@ -5592,13 +5592,22 @@ static ssize_t lru_gen_seq_write(struct file *file,= const char __user *src, if (!*cur) continue; =20 - n =3D sscanf(cur, "%c %u %u %lu %n %u %n %lu %n", &cmd, &memcg_id, &nid, - &seq, &end, &swappiness, &end, &opt, &end); + n =3D sscanf(cur, "%c %u %u %lu %n %4s %n %lu %n", &cmd, &memcg_id, &nid, + &seq, &end, swap_string, &end, &opt, &end); if (n < 4 || cur[end]) { err =3D -EINVAL; break; } =20 + /* set by userspace for anonymous memory only */ + if (!strncmp("max", swap_string, sizeof("max"))) { + swappiness =3D SWAPPINESS_ANON_ONLY; + } else { + err =3D kstrtouint(swap_string, 0, &swappiness); + if (err) + break; + } + err =3D run_cmd(cmd, memcg_id, nid, seq, &sc, swappiness, opt); if (err) break; --=20 2.39.5 From nobody Sat Feb 7 18:00:53 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF7C1214204 for ; Mon, 21 Apr 2025 09:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226867; cv=none; b=cGU3QfcW62XeaUH57wj1j8+536pQbdYxKOEsxJYGs3wnkID7ndP2lqEGoEmY29W3t1XD8q9wNvU7UtRDHG4gD++awxeA2dvFN4WV/yjQ9kCeKoaXQv8OrxGYyBp2JaKyKHef2w55ysAKkRLCFgQewg/hemlBpiQfgIQemBzkSO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745226867; c=relaxed/simple; bh=xJAn4UIXvQuiDi11k6XmNtizTjAQbPrsINs6eKBFhQk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JwpevJfpMrMJKYZRi+4lf2CU9od5oUAAluFknnpxvsF5VfQHMHj8rwSkF30MQw4lgW4dV+ZyiZ3jvI5Q4+cOINSqx5KyLnsDQETgycXWV4AKC/byNO6p5mf+l+IEsAipn6nFZWxGoVVQS/YZnmP1fPT0Bfqstp+JpeeJwT57va4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=RAPJKIgH; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="RAPJKIgH" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-736c062b1f5so2889726b3a.0 for ; Mon, 21 Apr 2025 02:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1745226865; x=1745831665; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C7mT3KrK1rUUgtVlbM9yHGXwYTpp6cBRIH33dYCoAPI=; b=RAPJKIgH/+HbKgAhSQxoBZPRxybycMbfUjrU2OhGS9OAajrNxzbcMvoiL+YfsAaeOJ k9Ce0DBnc4rdCvI7dhBrQnlQ7flia6aIeWT0vpBGGj0Osn0s8JDHsObdnv2BOs6TPpN9 hdQH0shIIMYuFSL0K0K/VSWyJb7F8o1WfMnCyH4NqDYzDXUcIujMfM0G64Rl2ai/POZX kYaElfrQxriG3lBNP3iJoWADHVvXw0xpLq3RIL1mBm5J0zd9/Pd8kNy06/mRTehgFVkA ksPUVkneSNQXqRdk+9R96z3iLNlN6/DwTAdxIilhcmxYNunIpA0YQ9sVUGW238FmLMGF RDgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745226865; x=1745831665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C7mT3KrK1rUUgtVlbM9yHGXwYTpp6cBRIH33dYCoAPI=; b=s77v6N+s0p6bg5/y97MvwqVhK6W+eYu3HjSFXuROYCWQ2vq3gm/v5uOtaX/nfgTkJ5 DiMp4DH5lD/vaCJ165Ip79wxx/K05qekqtkP2ZV8wZhmskUpY45gWhrk7PVJ4ztg4KfR tnCd1j36dVx0aIbMBnCj2Ug3CB0Z0c/UzeKcuF3g6lUpP7S4jFZ4x7+HkEosq/6F4RJ0 ahjdOJWa+hib9QuEPps4MF5G5o+W+I8sX4l4ZxAJsy371+H2WtjZrT/C7bQT5JCH9VAv POM1cjTsamvEpDfkiv4EHORd9u6GSuFzP14kytcfwv569d85FyAk2JaNs23fBeYocv9v XhNQ== X-Forwarded-Encrypted: i=1; AJvYcCUuUQWoweEjQLULXmSfUxCXip3lT5F1hl7eIrW3Se7TtNwQ+VzEOuQXH444Ti+1cfdPyAUoKjeexL72YUo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7gWjPDMtB41lxy8HC/xxgrvVe7Z+ndxoZzJQCPu2KwQeeVGk7 ng8wixemWox/1grVJlGkBQMKR+6WHjB/61OygCeGbg6zQ1YpNm/90mqdEAc8FYE= X-Gm-Gg: ASbGncuhUNi0ab+o/eVtXf4vnZ1PWjrEcD86APWBfYFL8oRlNf0C5rjFK8ira5hJR6d OVhpt4CIFYW+oQlt9OBjy1JT630act2kykWWXDp6gefxPQTgoeMUk4gtfRJ+6o3ph8CRMPCap14 V0qCVjXtomflS3QDFUz9jCe/TgLJ1MR9AP3dThO92BSBUYYqbUbN1kWj1kN4CCtZWqoi5u1Lj0h 9cWBr1EJDxyxpTkhzcP2MH1GD8G6LpOoCK2IpdvvrAHt/rwqi0ZqVH830qexVDNbwFZAC1JpPzf Q1uA71xhqKFLPzqlSUbvSILFLMkDhS29G/9Sk/4KDeU+Zm8sKK6CJDms3cS2K6CXLw== X-Google-Smtp-Source: AGHT+IFTmd0T/HXcu3yr2Ci4KMu0d+MmV6LaN3s7vDoYiMpjU3LbXIkbvNPBpWNjBROg83Yrfdjvwg== X-Received: by 2002:a05:6a21:4002:b0:1f3:194b:30ae with SMTP id adf61e73a8af0-203cbc0a836mr17787188637.1.1745226864958; Mon, 21 Apr 2025 02:14:24 -0700 (PDT) Received: from n37-069-081.byted.org ([115.190.40.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b0db157be12sm5246285a12.64.2025.04.21.02.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Apr 2025 02:14:24 -0700 (PDT) From: Zhongkun He To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, mhocko@suse.com, yosry.ahmed@linux.dev, muchun.song@linux.dev, yuzhao@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Subject: [PATCH V4 4/4] mm: using SWAPPINESS_ANON_ONLY in MGLRU Date: Mon, 21 Apr 2025 17:13:31 +0800 Message-Id: <529db7ae6098ee712b81e4df290622e4e64ac50c.1745225696.git.hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using SWAPPINESS_ANON_ONLY instead of MAX_SWAPPINESS + 1 to indicate reclaiming only from anonymous pages makes the code more readable and explicit. Add some comment in the SWAPPINESS_ANON_ONLY context. Signed-off-by: Zhongkun He suggested-by: Yosry Ahmed --- mm/vmscan.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index b442c20d1168..24e959881ada 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2698,8 +2698,12 @@ static bool should_clear_pmd_young(void) READ_ONCE((lruvec)->lrugen.min_seq[LRU_GEN_FILE]), \ } =20 +/* Get the min/max evictable type based on swappiness */ +#define min_type(swappiness) (!(swappiness)) +#define max_type(swappiness) ((swappiness) < SWAPPINESS_ANON_ONLY) + #define evictable_min_seq(min_seq, swappiness) \ - min((min_seq)[!(swappiness)], (min_seq)[(swappiness) <=3D MAX_SWAPPINESS]) + min((min_seq)[min_type(swappiness)], (min_seq)[max_type(swappiness)]) =20 #define for_each_gen_type_zone(gen, type, zone) \ for ((gen) =3D 0; (gen) < MAX_NR_GENS; (gen)++) \ @@ -2707,7 +2711,7 @@ static bool should_clear_pmd_young(void) for ((zone) =3D 0; (zone) < MAX_NR_ZONES; (zone)++) =20 #define for_each_evictable_type(type, swappiness) \ - for ((type) =3D !(swappiness); (type) <=3D ((swappiness) <=3D MAX_SWAPPIN= ESS); (type)++) + for ((type) =3D min_type(swappiness); (type) <=3D max_type(swappiness); (= type)++) =20 #define get_memcg_gen(seq) ((seq) % MEMCG_NR_GENS) #define get_memcg_bin(bin) ((bin) % MEMCG_NR_BINS) @@ -3858,7 +3862,12 @@ static bool inc_min_seq(struct lruvec *lruvec, int t= ype, int swappiness) int hist =3D lru_hist_from_seq(lrugen->min_seq[type]); int new_gen, old_gen =3D lru_gen_from_seq(lrugen->min_seq[type]); =20 - if (type ? swappiness > MAX_SWAPPINESS : !swappiness) + /* For file type, skip the check if swappiness is anon only */ + if (type && (swappiness =3D=3D SWAPPINESS_ANON_ONLY)) + goto done; + + /* For anon type, skip the check if swappiness is zero (file only) */ + if (!type && !swappiness) goto done; =20 /* prevent cold/hot inversion if the type is evictable */ @@ -5524,7 +5533,7 @@ static int run_cmd(char cmd, int memcg_id, int nid, u= nsigned long seq, =20 if (swappiness < MIN_SWAPPINESS) swappiness =3D get_swappiness(lruvec, sc); - else if (swappiness > MAX_SWAPPINESS + 1) + else if (swappiness > SWAPPINESS_ANON_ONLY) goto done; =20 switch (cmd) { --=20 2.39.5