From: Yu Zhao <yuzhao@google.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Andi Kleen" <ak@linux.intel.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Hillf Danton" <hdanton@sina.com>, "Jens Axboe" <axboe@kernel.dk>,
"Jesse Barnes" <jsbarnes@google.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Matthew Wilcox" <willy@infradead.org>,
"Mel Gorman" <mgorman@suse.de>,
"Michael Larabel" <Michael@michaellarabel.com>,
"Michal Hocko" <mhocko@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Rik van Riel" <riel@surriel.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Will Deacon" <will@kernel.org>,
"Ying Huang" <ying.huang@intel.com>,
"Linux ARM" <linux-arm-kernel@lists.infradead.org>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>,
"Kernel Page Reclaim v2" <page-reclaim@google.com>,
"the arch/x86 maintainers" <x86@kernel.org>,
"Brian Geffon" <bgeffon@google.com>,
"Jan Alexander Steffens" <heftig@archlinux.org>,
"Oleksandr Natalenko" <oleksandr@natalenko.name>,
"Steven Barrett" <steven@liquorix.net>,
"Suleiman Souhlal" <suleiman@google.com>,
"Daniel Byrne" <djbyrne@mtu.edu>,
"Donald Carr" <d@chaos-reins.com>,
"Holger Hoffstätte" <holger@applied-asynchrony.com>,
"Konstantin Kharlamov" <Hi-Angel@yandex.ru>,
"Shuang Zhai" <szhai2@cs.rochester.edu>,
"Sofia Trinh" <sofia.trinh@edi.works>,
"Vaibhav Jain" <vaibhav@linux.ibm.com>
Subject: Re: [PATCH v9 06/14] mm: multi-gen LRU: minimal implementation
Date: Mon, 21 Mar 2022 22:39:21 -0600 [thread overview]
Message-ID: <CAOUHufYfpiGdLSdffvzDqaD5oYFG99oDJ2xgQd2Ph77OFR5NAA@mail.gmail.com> (raw)
In-Reply-To: <87a6dj793j.fsf@linux.ibm.com>
On Mon, Mar 21, 2022 at 7:01 AM Aneesh Kumar K.V
<aneesh.kumar@linux.ibm.com> wrote:
>
> Yu Zhao <yuzhao@google.com> writes:
>
> > To avoid confusion, the terms "promotion" and "demotion" will be
> > applied to the multi-gen LRU, as a new convention; the terms
> > "activation" and "deactivation" will be applied to the active/inactive
> > LRU, as usual.
> >
> > The aging produces young generations. Given an lruvec, it increments
> > max_seq when max_seq-min_seq+1 approaches MIN_NR_GENS. The aging
> > promotes hot pages to the youngest generation when it finds them
> > accessed through page tables; the demotion of cold pages happens
> > consequently when it increments max_seq. The aging has the complexity
> > O(nr_hot_pages), since it is only interested in hot pages. Promotion
> > in the aging path does not require any LRU list operations, only the
> > updates of the gen counter and lrugen->nr_pages[]; demotion, unless as
> > the result of the increment of max_seq, requires LRU list operations,
> > e.g., lru_deactivate_fn().
> >
> > The eviction consumes old generations. Given an lruvec, it increments
> > min_seq when the lists indexed by min_seq%MAX_NR_GENS become empty. A
> > feedback loop modeled after the PID controller monitors refaults over
> > anon and file types and decides which type to evict when both types
> > are available from the same generation.
> >
> > Each generation is divided into multiple tiers. Tiers represent
> > different ranges of numbers of accesses through file descriptors. A
> > page accessed N times through file descriptors is in tier
> > order_base_2(N). Tiers do not have dedicated lrugen->lists[], only
> > bits in folio->flags. In contrast to moving across generations, which
> > requires the LRU lock, moving across tiers only involves operations on
> > folio->flags. The feedback loop also monitors refaults over all tiers
> > and decides when to protect pages in which tiers (N>1), using the
> > first tier (N=0,1) as a baseline. The first tier contains single-use
> > unmapped clean pages, which are most likely the best choices. The
> > eviction moves a page to the next generation, i.e., min_seq+1, if the
> > feedback loop decides so. This approach has the following advantages:
> > 1. It removes the cost of activation in the buffered access path by
> > inferring whether pages accessed multiple times through file
> > descriptors are statistically hot and thus worth protecting in the
> > eviction path.
> > 2. It takes pages accessed through page tables into account and avoids
> > overprotecting pages accessed multiple times through file
> > descriptors. (Pages accessed through page tables are in the first
> > tier, since N=0.)
> > 3. More tiers provide better protection for pages accessed more than
> > twice through file descriptors, when under heavy buffered I/O
> > workloads.
> >
> > Server benchmark results:
> > Single workload:
> > fio (buffered I/O): +[47, 49]%
> > IOPS BW
> > 5.17-rc2: 2242k 8759MiB/s
> > patch1-5: 3321k 12.7GiB/s
> >
> > Single workload:
> > memcached (anon): +[101, 105]%
> > Ops/sec KB/sec
> > 5.17-rc2: 476771.79 18544.31
> > patch1-5: 972526.07 37826.95
> >
> > Configurations:
> > CPU: two Xeon 6154
> > Mem: total 256G
> >
> > Node 1 was only used as a ram disk to reduce the variance in the
> > results.
> >
> > patch drivers/block/brd.c <<EOF
> > 99,100c99,100
> > < gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM;
> > < page = alloc_page(gfp_flags);
> > ---
> > > gfp_flags = GFP_NOIO | __GFP_ZERO | __GFP_HIGHMEM | __GFP_THISNODE;
> > > page = alloc_pages_node(1, gfp_flags, 0);
> > EOF
> >
> > cat >>/etc/systemd/system.conf <<EOF
> > CPUAffinity=numa
> > NUMAPolicy=bind
> > NUMAMask=0
> > EOF
> >
> > cat >>/etc/memcached.conf <<EOF
> > -m 184320
> > -s /var/run/memcached/memcached.sock
> > -a 0766
> > -t 36
> > -B binary
> > EOF
> >
> > cat fio.sh
> > modprobe brd rd_nr=1 rd_size=113246208
> > mkfs.ext4 /dev/ram0
> > mount -t ext4 /dev/ram0 /mnt
> >
> > mkdir /sys/fs/cgroup/user.slice/test
> > echo 38654705664 >/sys/fs/cgroup/user.slice/test/memory.max
> > echo $$ >/sys/fs/cgroup/user.slice/test/cgroup.procs
> > fio -name=mglru --numjobs=72 --directory=/mnt --size=1408m \
> > --buffered=1 --ioengine=io_uring --iodepth=128 \
> > --iodepth_batch_submit=32 --iodepth_batch_complete=32 \
> > --rw=randread --random_distribution=random --norandommap \
> > --time_based --ramp_time=10m --runtime=5m --group_reporting
> >
> > cat memcached.sh
> > modprobe brd rd_nr=1 rd_size=113246208
> > swapoff -a
> > mkswap /dev/ram0
> > swapon /dev/ram0
> >
> > memtier_benchmark -S /var/run/memcached/memcached.sock \
> > -P memcache_binary -n allkeys --key-minimum=1 \
> > --key-maximum=65000000 --key-pattern=P:P -c 1 -t 36 \
> > --ratio 1:0 --pipeline 8 -d 2000
> >
> > memtier_benchmark -S /var/run/memcached/memcached.sock \
> > -P memcache_binary -n allkeys --key-minimum=1 \
> > --key-maximum=65000000 --key-pattern=R:R -c 1 -t 36 \
> > --ratio 0:1 --pipeline 8 --randomize --distinct-client-seed
> >
> > Client benchmark results:
> > kswapd profiles:
> > 5.17-rc2
> > 38.05% page_vma_mapped_walk
> > 20.86% lzo1x_1_do_compress (real work)
> > 6.16% do_raw_spin_lock
> > 4.61% _raw_spin_unlock_irq
> > 2.20% vma_interval_tree_iter_next
> > 2.19% vma_interval_tree_subtree_search
> > 2.15% page_referenced_one
> > 1.93% anon_vma_interval_tree_iter_first
> > 1.65% ptep_clear_flush
> > 1.00% __zram_bvec_write
> >
> > patch1-5
> > 39.73% lzo1x_1_do_compress (real work)
> > 14.96% page_vma_mapped_walk
> > 6.97% _raw_spin_unlock_irq
> > 3.07% do_raw_spin_lock
> > 2.53% anon_vma_interval_tree_iter_first
> > 2.04% ptep_clear_flush
> > 1.82% __zram_bvec_write
> > 1.76% __anon_vma_interval_tree_subtree_search
> > 1.57% memmove
> > 1.45% free_unref_page_list
> >
> > Configurations:
> > CPU: single Snapdragon 7c
> > Mem: total 4G
> >
> > Chrome OS MemoryPressure [1]
> >
> > [1] https://chromium.googlesource.com/chromiumos/platform/tast-tests/
> >
>
> In shrink_active_list we do preferential treatment of VM_EXEC pages.
> Do we do similar thing with MGLRU? if not why is that not needed?
No, because MGLRU has a different set of assumptions than the
active/inactive LRU does [1]. It provides mmapped pages with equal
opportunities, and the tradeoff was discussed here [2].
Note that even with this preferential treatment of executable pages,
plus other heuristics added since then, executable pages are still
underprotected for at least desktop workloads [3]. And I can confirm
the problem reported is genuine -- we recently accidentally removed
our private patch that works around the problem for the last 12 years,
and observed immediate consequences on a small portion of devices not
using MGLRU [4].
[1] https://lore.kernel.org/linux-mm/20220309021230.721028-15-yuzhao@google.com/
[2] https://lore.kernel.org/linux-mm/20220208081902.3550911-5-yuzhao@google.com/
[3] https://lore.kernel.org/linux-mm/2dc51fc8-f14e-17ed-a8c6-0ec70423bf54@valdikss.org.ru/
[4] https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3429559
next prev parent reply other threads:[~2022-03-22 4:39 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-09 2:12 [PATCH v9 00/14] Multi-Gen LRU Framework Yu Zhao
2022-03-09 2:12 ` [PATCH v9 01/14] mm: x86, arm64: add arch_has_hw_pte_young() Yu Zhao
2022-03-11 10:55 ` Barry Song
2022-03-11 22:57 ` Yu Zhao
2022-03-09 2:12 ` [PATCH v9 02/14] mm: x86: add CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG Yu Zhao
2022-03-16 22:15 ` Barry Song
2022-03-09 2:12 ` [PATCH v9 03/14] mm/vmscan.c: refactor shrink_node() Yu Zhao
2022-03-18 1:15 ` Barry Song
2022-03-09 2:12 ` [PATCH v9 04/14] Revert "include/linux/mm_inline.h: fold __update_lru_size() into its sole caller" Yu Zhao
2022-03-09 2:12 ` [PATCH v9 05/14] mm: multi-gen LRU: groundwork Yu Zhao
2022-03-14 8:08 ` Huang, Ying
2022-03-14 9:30 ` Yu Zhao
2022-03-15 0:34 ` Huang, Ying
2022-03-15 0:50 ` Yu Zhao
2022-03-21 18:58 ` Justin Forbes
2022-03-21 19:17 ` Prarit Bhargava
2022-03-22 4:52 ` Yu Zhao
2022-03-16 23:25 ` Barry Song
2022-03-21 9:04 ` Yu Zhao
2022-03-21 11:47 ` Barry Song
2022-03-09 2:12 ` [PATCH v9 06/14] mm: multi-gen LRU: minimal implementation Yu Zhao
2022-03-16 5:55 ` Huang, Ying
2022-03-16 7:54 ` Yu Zhao
2022-03-19 3:01 ` Barry Song
2022-03-19 3:11 ` Yu Zhao
2022-03-23 7:47 ` Barry Song
2022-03-24 6:24 ` Yu Zhao
2022-03-24 8:13 ` Barry Song
2022-03-19 10:14 ` Barry Song
2022-03-21 23:51 ` Yu Zhao
2022-03-19 11:15 ` Barry Song
2022-03-22 0:30 ` Yu Zhao
2022-03-21 12:51 ` Aneesh Kumar K.V
2022-03-22 4:02 ` Yu Zhao
2022-03-21 13:01 ` Aneesh Kumar K.V
2022-03-22 4:39 ` Yu Zhao [this message]
2022-03-22 5:26 ` Aneesh Kumar K.V
2022-03-22 5:55 ` Yu Zhao
2022-03-09 2:12 ` [PATCH v9 07/14] mm: multi-gen LRU: exploit locality in rmap Yu Zhao
2022-04-07 2:29 ` Barry Song
2022-04-07 3:04 ` Yu Zhao
2022-04-07 3:46 ` Barry Song
2022-04-07 23:51 ` Yu Zhao
2022-03-09 2:12 ` [PATCH v9 08/14] mm: multi-gen LRU: support page table walks Yu Zhao
2022-03-09 2:12 ` [PATCH v9 09/14] mm: multi-gen LRU: optimize multiple memcgs Yu Zhao
2022-03-09 2:12 ` [PATCH v9 10/14] mm: multi-gen LRU: kill switch Yu Zhao
2022-03-22 7:47 ` Barry Song
2022-03-22 8:20 ` Yu Zhao
2022-03-22 8:45 ` Barry Song
2022-03-22 9:00 ` Yu Zhao
2022-03-09 2:12 ` [PATCH v9 11/14] mm: multi-gen LRU: thrashing prevention Yu Zhao
2022-03-22 7:22 ` Barry Song
2022-03-22 8:14 ` Yu Zhao
2022-03-09 2:12 ` [PATCH v9 12/14] mm: multi-gen LRU: debugfs interface Yu Zhao
2022-03-09 2:12 ` [PATCH v9 13/14] mm: multi-gen LRU: admin guide Yu Zhao
2022-03-10 12:29 ` Mike Rapoport
2022-03-11 0:37 ` Yu Zhao
2022-03-09 2:12 ` [PATCH v9 14/14] mm: multi-gen LRU: design doc Yu Zhao
2022-03-11 8:22 ` Mike Rapoport
2022-03-11 9:38 ` Yu Zhao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOUHufYfpiGdLSdffvzDqaD5oYFG99oDJ2xgQd2Ph77OFR5NAA@mail.gmail.com \
--to=yuzhao@google.com \
--cc=Hi-Angel@yandex.ru \
--cc=Michael@michaellarabel.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=axboe@kernel.dk \
--cc=bgeffon@google.com \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=d@chaos-reins.com \
--cc=dave.hansen@linux.intel.com \
--cc=djbyrne@mtu.edu \
--cc=hannes@cmpxchg.org \
--cc=hdanton@sina.com \
--cc=heftig@archlinux.org \
--cc=holger@applied-asynchrony.com \
--cc=jsbarnes@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@kernel.org \
--cc=oleksandr@natalenko.name \
--cc=page-reclaim@google.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=sofia.trinh@edi.works \
--cc=steven@liquorix.net \
--cc=suleiman@google.com \
--cc=szhai2@cs.rochester.edu \
--cc=torvalds@linux-foundation.org \
--cc=vaibhav@linux.ibm.com \
--cc=vbabka@suse.cz \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=x86@kernel.org \
--cc=ying.huang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).