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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA350C32771 for ; Sun, 18 Sep 2022 08:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RDAJEM7e2FVlgTgZD0w7qCsTg9Jfuky7Epn0eGvDzkw=; b=SJShYWQ8UILeOE Tb8RKBomuIzTWIp8zyW0xv8bYnKupU5K1L42qVJRxSGV18gDgcPFJvZV0Ka+PInUbvxfek95Cnq7f nXjVgfcFj+X0Wp7nA3PrCRGaZ8XpyQ/WNpIoOdgYzwj0w5wKBMoeMI2PJFT64g4vVe/iuA638HR/J 5v9qJ7ScBY2fMBgTVaBzEBGu1ZvZONkZ+Hjo/p2gjIRMqFDwBMrOX9TZDBhIAJ+EIP2QdKGfjiQH5 dfHGiYXktr1Bd0Z+A40C1XXf1o55KDPPCm6irq68tHNzF+1de7p7VEUxTU8MxBUkoHVIp7SEFsPPT fbTzx0lvMPqZkEno65qw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oZpe0-00DnKL-Un; Sun, 18 Sep 2022 08:27:17 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oZpdr-00DnFy-9Y for linux-arm-kernel@lists.infradead.org; Sun, 18 Sep 2022 08:27:09 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED57F60AE6; Sun, 18 Sep 2022 08:27:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C2BAC433D6; Sun, 18 Sep 2022 08:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663489625; bh=i8tFUE7hDPArKjgc1xuA8u0fkfuNBAfI3ufw4PO6CLE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Nw5dmO/QbXNSgt3XVC89A1FpRP5jtJOvsNJOrMCOMW5yNZhv11rdA7q1UdSGYesYO k28IUPJrjzepazAErWH40fBkEITt5pBcc6RYJ2gwxfd8jFGQ/wdR+6WqObD33QOwlk qazGVrtG89vh3r3yWuG0C7GGqECE9SdCGnFUS+ihBh4UPzCw2HyyJtZmtAMqVRnN+d ujcGNkQ3SxughcIh0680OoaVOVkkKB9MnrIJFZ2G9NurxMZ9sxm5d09Fgwv1X1tB7x xboGnI13OA9I7KxfhsBLBUZ4tCy+ucL6sbCClmHGWca7Sbf9SedtRvk1qHksEKtSqq 8ja52oUEXDj4w== Date: Sun, 18 Sep 2022 11:26:42 +0300 From: Mike Rapoport To: Yu Zhao Cc: Andrew Morton , 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 , 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 , Holger =?iso-8859-1?Q?Hoffst=E4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain Subject: Re: [PATCH mm-unstable v15 13/14] mm: multi-gen LRU: admin guide Message-ID: References: <20220918080010.2920238-1-yuzhao@google.com> <20220918080010.2920238-14-yuzhao@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220918080010.2920238-14-yuzhao@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220918_012707_468090_67FD9A9E X-CRM114-Status: GOOD ( 48.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, Sep 18, 2022 at 02:00:10AM -0600, 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=E4tte > 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 | 162 ++++++++++++++++++ > mm/Kconfig | 3 +- > mm/vmscan.c | 4 + > 4 files changed, 169 insertions(+), 1 deletion(-) > create mode 100644 Documentation/admin-guide/mm/multigen_lru.rst I have a feeling I already did this, but whatever. Acked-by: Mike Rapoport > = > diff --git a/Documentation/admin-guide/mm/index.rst b/Documentation/admin= -guide/mm/index.rst > index 1bd11118dfb1..d1064e0ba34a 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/Documentatio= n/admin-guide/mm/multigen_lru.rst > new file mode 100644 > index 000000000000..33e068830497 > --- /dev/null > +++ b/Documentation/admin-guide/mm/multigen_lru.rst > @@ -0,0 +1,162 @@ > +.. SPDX-License-Identifier: GPL-2.0 > + > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +Multi-Gen LRU > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +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 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +Build the kernel with the following configurations. > + > +* ``CONFIG_LRU_GEN=3Dy`` > +* ``CONFIG_LRU_GEN_ENABLED=3Dy`` > + > +All set! > + > +Runtime options > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +``/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. > + > +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +Values Components > +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +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. > +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +E.g., > +:: > + > + 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=3D1000`` usually > +eliminates intolerable janks due to thrashing. Larger values like > +``N=3D3000`` make janks less noticeable at the risk of premature OOM > +kills. > + > +The default value ``0`` means disabled. > + > +Experimental features > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > +``/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=3Dy`` 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 the following command to ``lru_gen`` to create a new > +generation ``max_gen_nr+1``: > + > + ``+ memcg_id node_id max_gen_nr [can_swap [force_scan]]`` > + > +``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 runs this command 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 the following command to ``lru_gen`` to evict > +generations less than or equal to ``min_gen_nr``. > + > + ``- memcg_id node_id min_gen_nr [swappiness [nr_to_reclaim]]`` > + > +``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. > + > +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 > +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 ab6ef5115eb8..ceec438c0741 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -1125,7 +1125,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 7657d54c9c42..1456f133f256 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -5310,6 +5310,7 @@ static ssize_t show_min_ttl(struct kobject *kobj, s= truct 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) > { > @@ -5343,6 +5344,7 @@ static ssize_t show_enabled(struct kobject *kobj, s= truct 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) > { > @@ -5490,6 +5492,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; > @@ -5648,6 +5651,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 *s= rc, > size_t len, loff_t *pos) > { > -- = > 2.37.3.968.ga6b4b080e4-goog > = -- = Sincerely yours, Mike. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel