From mboxrd@z Thu Jan 1 00:00:00 1970 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 B72B6CCA481 for ; Sun, 10 Jul 2022 02:20:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA576940007; Sat, 9 Jul 2022 22:20:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A30AC6B0073; Sat, 9 Jul 2022 22:20:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A8CD940007; Sat, 9 Jul 2022 22:20:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 758F46B0072 for ; Sat, 9 Jul 2022 22:20:18 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3A63B60570 for ; Sun, 10 Jul 2022 02:20:18 +0000 (UTC) X-FDA: 79669585716.26.E013F5A Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf12.hostedemail.com (Postfix) with ESMTP id C93DD40056 for ; Sun, 10 Jul 2022 02:20:16 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id g4so2092543pgc.1 for ; Sat, 09 Jul 2022 19:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=wX3dLYovPqvcyaF+fwNCYWsC056jAjNyoNmTlmS8iW0=; b=Fl5FCM+pGOAju0nqPaLwlLQRU3DgIn2U3VjWbrKUgfZNasnd8+3wJB2GSCasxbzHPt BgqW0HYecXPR9ONL1bsDWWH8qEffILRvUoodJ6fmVcQsoQGKMcz0GMsn7FRsS/nSDbEC nhI18OgpQbarufSB4YvZra8eU6tNyjhk4Ojy7eOnZgCpQWVdbSz2WkJfVcnXCtv7gdka P2AdeBN7TOhBoHLuuL6WYycvPAoThV6sDmtdpPO+de00As4TgQp7ibrDfdZFLawcmwO1 Jbvls1bojQ586hbBCkJqccW2lXmiD9bNvasjdFtaEkvQRfeYYEwjA61jOKIUNAulWS0p sbPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=wX3dLYovPqvcyaF+fwNCYWsC056jAjNyoNmTlmS8iW0=; b=TYacN1SpsIUgMV5OoHulYWrB3aOMvzX4U2gE6AjZxqcpUMhSECaLyOKXrIkL2XO5D8 KaQa6hFczMciMSkfPzDwOOccWEYojGVdAZlolr4C9mJTmKholkiWofThgnLPg5DjMWS/ QIyG8dlczuxKO/sCyEIGjCyx5t+d7Ao6jeKPhJn6nfmBeH3pEf8RcEdzKyVXQXSBusKL DVCAE3g+Ia82qwkgPRWxGnoGrSAqED6JKZgP8OigOZwJFueiqYwbPAR4eTkdkWdh0vLG fJJ9xK57olx8gaEtxRVzEP7Gm1WcnglHzqHkpKA/FISAZ4MhVJYO9jBL4pvZe6DgVBVK wejA== X-Gm-Message-State: AJIora87J4whi9vGuMluOORJJb9SgdQNoPyNNApqBn422EUYfb0u54el iUJITfw0algZ8VtmZTHFPcg= X-Google-Smtp-Source: AGRyM1v4U8y46pN2FJKMAahBzHzOqEiA1OvGWb+6E+WV/4gA21PixpT9UD1eGmwQQVQbgyJDxcphRA== X-Received: by 2002:a63:ec03:0:b0:40d:e79d:e22e with SMTP id j3-20020a63ec03000000b0040de79de22emr10315114pgh.53.1657419615561; Sat, 09 Jul 2022 19:20:15 -0700 (PDT) Received: from [192.168.43.80] (subs09a-223-255-225-73.three.co.id. [223.255.225.73]) by smtp.gmail.com with ESMTPSA id d9-20020a170902f14900b0016405375132sm1965706plb.25.2022.07.09.19.20.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 Jul 2022 19:20:14 -0700 (PDT) Message-ID: Date: Sun, 10 Jul 2022 09:20:04 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v13 13/14] mm: multi-gen LRU: admin guide Content-Language: en-US To: Yu Zhao , Andrew Morton Cc: Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Johannes Weiner , Jonathan Corbet , Linus Torvalds , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Peter Zijlstra , Tejun Heo , Vlastimil Babka , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, page-reclaim@google.com, Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , =?UTF-8?Q?Holger_Hoffst=c3=a4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain References: <20220706220022.968789-1-yuzhao@google.com> <20220706220022.968789-14-yuzhao@google.com> From: Bagas Sanjaya In-Reply-To: <20220706220022.968789-14-yuzhao@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657419616; a=rsa-sha256; cv=none; b=y1C5tPLDekc0hP9p4essa0KzvImm0T3qijZHfq4clhuR4Ks7KYUnakHSU5MuFXoBk9ZO5D Lu4bhgURdriFlEPOoFg+zXi7RuSZTudFZ8JGXse+kc5Fn2RnSWPcQ84E3mECKbD2Li5Ds5 FO7ii31z616yJfs62fsXP0wOM1NZ1W4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657419616; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wX3dLYovPqvcyaF+fwNCYWsC056jAjNyoNmTlmS8iW0=; b=oFHFkDIIaU1y+13exleZonHhHf1SAv1Qdo/WvHumNFiKaZ/naQWnBggcbVV+xDn+JryMAm HpcGceVr1h3r4YEey9olcJQtT/9HKojflrT2x/BDkdjGqgEqVapf9OayiDH3W59/Bu+xmY aNYQBMgqpq+0jhod45qEYJ+jmjErY4A= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Fl5FCM+p; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of bagasdotme@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=bagasdotme@gmail.com Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Fl5FCM+p; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of bagasdotme@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=bagasdotme@gmail.com X-Rspamd-Server: rspam03 X-Stat-Signature: 8mon934ou5h5uh8rjs11is7trge7ktg9 X-Rspamd-Queue-Id: C93DD40056 X-Rspam-User: X-HE-Tag: 1657419616-52973 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: On 7/7/22 05:00, Yu Zhao wrote: > Add an admin guide. > > Signed-off-by: Yu Zhao > Acked-by: Brian Geffon > Acked-by: Jan Alexander Steffens (heftig) > Acked-by: Oleksandr Natalenko > Acked-by: Steven Barrett > Acked-by: Suleiman Souhlal > Tested-by: Daniel Byrne > Tested-by: Donald Carr > Tested-by: Holger Hoffstätte > Tested-by: Konstantin Kharlamov > Tested-by: Shuang Zhai > Tested-by: Sofia Trinh > Tested-by: Vaibhav Jain > --- > Documentation/admin-guide/mm/index.rst | 1 + > Documentation/admin-guide/mm/multigen_lru.rst | 156 ++++++++++++++++++ > mm/Kconfig | 3 +- > mm/vmscan.c | 4 + > 4 files changed, 163 insertions(+), 1 deletion(-) > create mode 100644 Documentation/admin-guide/mm/multigen_lru.rst > > diff --git a/Documentation/admin-guide/mm/index.rst b/Documentation/admin-guide/mm/index.rst > index c21b5823f126..2cf5bae62036 100644 > --- a/Documentation/admin-guide/mm/index.rst > +++ b/Documentation/admin-guide/mm/index.rst > @@ -32,6 +32,7 @@ the Linux memory management. > idle_page_tracking > ksm > memory-hotplug > + multigen_lru > nommu-mmap > numa_memory_policy > numaperf > diff --git a/Documentation/admin-guide/mm/multigen_lru.rst b/Documentation/admin-guide/mm/multigen_lru.rst > new file mode 100644 > index 000000000000..6355f2b5019d > --- /dev/null > +++ b/Documentation/admin-guide/mm/multigen_lru.rst > @@ -0,0 +1,156 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +============= > +Multi-Gen LRU > +============= > +The multi-gen LRU is an alternative LRU implementation that optimizes > +page reclaim and improves performance under memory pressure. Page > +reclaim decides the kernel's caching policy and ability to overcommit > +memory. It directly impacts the kswapd CPU usage and RAM efficiency. > + > +Quick start > +=========== > +Build the kernel with the following configurations. > + > +* ``CONFIG_LRU_GEN=y`` > +* ``CONFIG_LRU_GEN_ENABLED=y`` > + > +All set! > + > +Runtime options > +=============== > +``/sys/kernel/mm/lru_gen/`` contains stable ABIs described in the > +following subsections. > + > +Kill switch > +----------- > +``enabled`` accepts different values to enable or disable the > +following components. Its default value depends on > +``CONFIG_LRU_GEN_ENABLED``. All the components should be enabled > +unless some of them have unforeseen side effects. Writing to > +``enabled`` has no effect when a component is not supported by the > +hardware, and valid values will be accepted even when the main switch > +is off. > + > +====== =============================================================== > +Values Components > +====== =============================================================== > +0x0001 The main switch for the multi-gen LRU. > +0x0002 Clearing the accessed bit in leaf page table entries in large > + batches, when MMU sets it (e.g., on x86). This behavior can > + theoretically worsen lock contention (mmap_lock). If it is > + disabled, the multi-gen LRU will suffer a minor performance > + degradation for workloads that contiguously map hot pages, > + whose accessed bits can be otherwise cleared by fewer larger > + batches. > +0x0004 Clearing the accessed bit in non-leaf page table entries as > + well, when MMU sets it (e.g., on x86). This behavior was not > + verified on x86 varieties other than Intel and AMD. If it is > + disabled, the multi-gen LRU will suffer a negligible > + performance degradation. > +[yYnN] Apply to all the components above. > +====== =============================================================== > + > +E.g., > +:: In this case, it would be better to say "For example". > + > + echo y >/sys/kernel/mm/lru_gen/enabled > + cat /sys/kernel/mm/lru_gen/enabled > + 0x0007 > + echo 5 >/sys/kernel/mm/lru_gen/enabled > + cat /sys/kernel/mm/lru_gen/enabled > + 0x0005 > + > +Thrashing prevention > +-------------------- > +Personal computers are more sensitive to thrashing because it can > +cause janks (lags when rendering UI) and negatively impact user > +experience. The multi-gen LRU offers thrashing prevention to the > +majority of laptop and desktop users who do not have ``oomd``. > + > +Users can write ``N`` to ``min_ttl_ms`` to prevent the working set of > +``N`` milliseconds from getting evicted. The OOM killer is triggered > +if this working set cannot be kept in memory. In other words, this > +option works as an adjustable pressure relief valve, and when open, it > +terminates applications that are hopefully not being used. > + > +Based on the average human detectable lag (~100ms), ``N=1000`` usually > +eliminates intolerable janks due to thrashing. Larger values like > +``N=3000`` make janks less noticeable at the risk of premature OOM > +kills. > + > +The default value ``0`` means disabled. > + > +Experimental features > +===================== > +``/sys/kernel/debug/lru_gen`` accepts commands described in the > +following subsections. Multiple command lines are supported, so does > +concatenation with delimiters ``,`` and ``;``. > + > +``/sys/kernel/debug/lru_gen_full`` provides additional stats for > +debugging. ``CONFIG_LRU_GEN_STATS=y`` keeps historical stats from > +evicted generations in this file. > + > +Working set estimation > +---------------------- > +Working set estimation measures how much memory an application needs > +in a given time interval, and it is usually done with little impact on > +the performance of the application. E.g., data centers want to > +optimize job scheduling (bin packing) to improve memory utilizations. > +When a new job comes in, the job scheduler needs to find out whether > +each server it manages can allocate a certain amount of memory for > +this new job before it can pick a candidate. To do so, the job > +scheduler needs to estimate the working sets of the existing jobs. > + > +When it is read, ``lru_gen`` returns a histogram of numbers of pages > +accessed over different time intervals for each memcg and node. > +``MAX_NR_GENS`` decides the number of bins for each histogram. The > +histograms are noncumulative. > +:: > + > + memcg memcg_id memcg_path > + node node_id > + min_gen_nr age_in_ms nr_anon_pages nr_file_pages > + ... > + max_gen_nr age_in_ms nr_anon_pages nr_file_pages > + > +Each bin contains an estimated number of pages that have been accessed > +within ``age_in_ms``. E.g., ``min_gen_nr`` contains the coldest pages > +and ``max_gen_nr`` contains the hottest pages, since ``age_in_ms`` of > +the former is the largest and that of the latter is the smallest. > + > +Users can write ``+ memcg_id node_id max_gen_nr > +[can_swap [force_scan]]`` to ``lru_gen`` to create a new generation > +``max_gen_nr+1``. ``can_swap`` defaults to the swap setting and, if it > +is set to ``1``, it forces the scan of anon pages when swap is off, > +and vice versa. ``force_scan`` defaults to ``1`` and, if it is set to > +``0``, it employs heuristics to reduce the overhead, which is likely > +to reduce the coverage as well. > + > +A typical use case is that a job scheduler writes to ``lru_gen`` at a > +certain time interval to create new generations, and it ranks the > +servers it manages based on the sizes of their cold pages defined by > +this time interval. > + > +Proactive reclaim > +----------------- > +Proactive reclaim induces page reclaim when there is no memory > +pressure. It usually targets cold pages only. E.g., when a new job > +comes in, the job scheduler wants to proactively reclaim cold pages on > +the server it selected to improve the chance of successfully landing > +this new job. > + > +Users can write ``- memcg_id node_id min_gen_nr [swappiness > +[nr_to_reclaim]]`` to ``lru_gen`` to evict generations less than or > +equal to ``min_gen_nr``. Note that ``min_gen_nr`` should be less than > +``max_gen_nr-1`` as ``max_gen_nr`` and ``max_gen_nr-1`` are not fully > +aged 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. > + > +A typical use case is that a job scheduler writes to ``lru_gen`` > +before it tries to land a new job on a server. If it fails to > +materialize enough cold pages because of the overestimation, it > +retries on the next server according to the ranking result obtained > +from the working set estimation step. This less forceful approach > +limits the impacts on the existing jobs. > diff --git a/mm/Kconfig b/mm/Kconfig > index 0c2ef0af0036..a0f7b6e66410 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -1137,7 +1137,8 @@ config LRU_GEN > # make sure folio->flags has enough spare bits > depends on 64BIT || !SPARSEMEM || SPARSEMEM_VMEMMAP > help > - A high performance LRU implementation to overcommit memory. > + A high performance LRU implementation to overcommit memory. See > + Documentation/admin-guide/mm/multigen_lru.rst for details. > > config LRU_GEN_ENABLED > bool "Enable by default" > diff --git a/mm/vmscan.c b/mm/vmscan.c > index fbcd298adca7..7096ff7836db 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -5209,6 +5209,7 @@ static ssize_t show_min_ttl(struct kobject *kobj, struct kobj_attribute *attr, c > return sprintf(buf, "%u\n", jiffies_to_msecs(READ_ONCE(lru_gen_min_ttl))); > } > > +/* see Documentation/admin-guide/mm/multigen_lru.rst for details */ > static ssize_t store_min_ttl(struct kobject *kobj, struct kobj_attribute *attr, > const char *buf, size_t len) > { > @@ -5242,6 +5243,7 @@ static ssize_t show_enabled(struct kobject *kobj, struct kobj_attribute *attr, c > return snprintf(buf, PAGE_SIZE, "0x%04x\n", caps); > } > > +/* see Documentation/admin-guide/mm/multigen_lru.rst for details */ > static ssize_t store_enabled(struct kobject *kobj, struct kobj_attribute *attr, > const char *buf, size_t len) > { > @@ -5389,6 +5391,7 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec, > seq_putc(m, '\n'); > } > > +/* see Documentation/admin-guide/mm/multigen_lru.rst for details */ > static int lru_gen_seq_show(struct seq_file *m, void *v) > { > unsigned long seq; > @@ -5547,6 +5550,7 @@ static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq, > return err; > } > > +/* see Documentation/admin-guide/mm/multigen_lru.rst for details */ > static ssize_t lru_gen_seq_write(struct file *file, const char __user *src, > size_t len, loff_t *pos) > { Otherwise looks good (no new warnings). Reviewed-by: Bagas Sanjaya -- An old man doll... just what I always wanted! - Clara