Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: add max swappiness arg to lru_gen for anonymous memory only

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>

authored by

Zhongkun He and committed by
Andrew Morton
b4059993 aded729f

+18 -6
+3 -2
Documentation/admin-guide/mm/multigen_lru.rst
··· 151 151 ``min_gen_nr`` should be less than ``max_gen_nr-1``, since 152 152 ``max_gen_nr`` and ``max_gen_nr-1`` are not fully aged (equivalent to 153 153 the active list) and therefore cannot be evicted. ``swappiness`` 154 - overrides the default value in ``/proc/sys/vm/swappiness``. 155 - ``nr_to_reclaim`` limits the number of pages to evict. 154 + overrides the default value in ``/proc/sys/vm/swappiness`` and the valid 155 + range is [0-200, max], with max being exclusively used for the reclamation 156 + of anonymous memory. ``nr_to_reclaim`` limits the number of pages to evict. 156 157 157 158 A typical use case is that a job scheduler runs this command before it 158 159 tries to land a new job on a server. If it fails to materialize enough
+15 -4
mm/vmscan.c
··· 5588 5588 while ((cur = strsep(&next, ",;\n"))) { 5589 5589 int n; 5590 5590 int end; 5591 - char cmd; 5591 + char cmd, swap_string[5]; 5592 5592 unsigned int memcg_id; 5593 5593 unsigned int nid; 5594 5594 unsigned long seq; 5595 - unsigned int swappiness = -1; 5595 + unsigned int swappiness; 5596 5596 unsigned long opt = -1; 5597 5597 5598 5598 cur = skip_spaces(cur); 5599 5599 if (!*cur) 5600 5600 continue; 5601 5601 5602 - n = sscanf(cur, "%c %u %u %lu %n %u %n %lu %n", &cmd, &memcg_id, &nid, 5603 - &seq, &end, &swappiness, &end, &opt, &end); 5602 + n = sscanf(cur, "%c %u %u %lu %n %4s %n %lu %n", &cmd, &memcg_id, &nid, 5603 + &seq, &end, swap_string, &end, &opt, &end); 5604 5604 if (n < 4 || cur[end]) { 5605 5605 err = -EINVAL; 5606 5606 break; 5607 + } 5608 + 5609 + if (n == 4) { 5610 + swappiness = -1; 5611 + } else if (!strcmp("max", swap_string)) { 5612 + /* set by userspace for anonymous memory only */ 5613 + swappiness = SWAPPINESS_ANON_ONLY; 5614 + } else { 5615 + err = kstrtouint(swap_string, 0, &swappiness); 5616 + if (err) 5617 + break; 5607 5618 } 5608 5619 5609 5620 err = run_cmd(cmd, memcg_id, nid, seq, &sc, swappiness, opt);