]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm: add max swappiness arg to lru_gen for anonymous memory only
authorZhongkun He <hezhongkun.hzk@bytedance.com>
Mon, 21 Apr 2025 09:13:30 +0000 (17:13 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 13 May 2025 06:50:36 +0000 (23:50 -0700)
The MGLRU already supports reclaiming only from anonymous memory via the
/sys/kernel/debug/lru_gen interface.  Now, memory.reclaim also supports
the swappiness=max parameter to enable reclaiming solely from anonymous
memory.  To unify the semantics of proactive reclaiming from anonymous
folios, the max parameter is introduced.

[hezhongkun.hzk@bytedance.com: use strcmp instead of strncmp, if swappiness is not set, use the default value]
Link: https://lkml.kernel.org/r/20250507071057.3184240-1-hezhongkun.hzk@bytedance.com
[akpm@linux-foundation.org: tweak coding style]
Link: https://lkml.kernel.org/r/65181f7745d657d664d833c26d8a94cae40538b9.1745225696.git.hezhongkun.hzk@bytedance.com
Signed-off-by: Zhongkun He <hezhongkun.hzk@bytedance.com>
Acked-by: Muchun Song <muchun.song@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/admin-guide/mm/multigen_lru.rst
mm/vmscan.c

index 33e068830497e742a0d91081fc84dcf8661d9fde..9cb54b4ff5d9d6e964d11f875118174e64652937 100644 (file)
@@ -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.
 
 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
index ca786575b6c2e67f33c6d72a7be7253ae85a3d8e..d1ad528186dd81b25b81ca05ac553cba95d5ae3e 100644 (file)
@@ -5588,24 +5588,35 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src,
        while ((cur = strsep(&next, ",;\n"))) {
                int n;
                int end;
-               char cmd;
+               char cmd, swap_string[5];
                unsigned int memcg_id;
                unsigned int nid;
                unsigned long seq;
-               unsigned int swappiness = -1;
+               unsigned int swappiness;
                unsigned long opt = -1;
 
                cur = skip_spaces(cur);
                if (!*cur)
                        continue;
 
-               n = sscanf(cur, "%c %u %u %lu %n %u %n %lu %n", &cmd, &memcg_id, &nid,
-                          &seq, &end, &swappiness, &end, &opt, &end);
+               n = 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 = -EINVAL;
                        break;
                }
 
+               if (n == 4) {
+                       swappiness = -1;
+               } else if (!strcmp("max", swap_string)) {
+                       /* set by userspace for anonymous memory only */
+                       swappiness = SWAPPINESS_ANON_ONLY;
+               } else {
+                       err = kstrtouint(swap_string, 0, &swappiness);
+                       if (err)
+                               break;
+               }
+
                err = run_cmd(cmd, memcg_id, nid, seq, &sc, swappiness, opt);
                if (err)
                        break;