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 C8B8EC4332F for ; Wed, 13 Dec 2023 03:03:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6357E6B0413; Tue, 12 Dec 2023 22:03:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E5586B0414; Tue, 12 Dec 2023 22:03:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4ACE56B0416; Tue, 12 Dec 2023 22:03:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 34AAA6B0413 for ; Tue, 12 Dec 2023 22:03:15 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0F573160B17 for ; Wed, 13 Dec 2023 03:03:15 +0000 (UTC) X-FDA: 81560298750.22.69854D8 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by imf26.hostedemail.com (Postfix) with ESMTP id 27A1B140013 for ; Wed, 13 Dec 2023 03:03:12 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DtzOCAfX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702436593; 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=hmdVgMNTGQhlO8xslqjDOun90RL8Cnjj+IZGL+fIg18=; b=g3ICRmJw4g3ndR6VqxDIf3/UCSZSlC7+sljv3oj35rRnFPgMxcDfSQZXVvSpb6X4OjHmze Zu8kXI07ifkbUIni/C7qtojEKRmZLplMdmr+rl92tmBTVCY0Ml6t7lgcGrxZ6N3c2iSxXG rYdyq5pDpRqMdvE9pm7IWRULZALTIhw= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DtzOCAfX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702436593; a=rsa-sha256; cv=none; b=SNjyAFqVuVGCQa31URlcqeQUW70/qnxM2Z6Ex8pBIVYXFG8OeeqHWl+J0Mjd3Ajko+vNvH o4eHmqgegyDoESCvcpXpi1uqVFsMRrbwDAD6o6TFzyBr41CLN+ffN97nSYkV0yaiUSGAUz xtHiKPkh3FeIKq8HKwgRSCgYAOMZVHs= Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2c9fe0b5b28so82791371fa.1 for ; Tue, 12 Dec 2023 19:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702436591; x=1703041391; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hmdVgMNTGQhlO8xslqjDOun90RL8Cnjj+IZGL+fIg18=; b=DtzOCAfXyUTMbwKSAfnW9FMAZQNjo5A0nZ+NQLJUjhcvZ+CTAJ9j2ZB2fyNfHHTgkw TUHMvIjiX9XrqfAAXCiJYlFLK8INUyAMg9GcIQcCHAae/zTH3FGif3EMfx9Y64sejBdM pRtw9Dxfk9IVdFADo5LUsNvDGQjk44SXYEUS+9fHpFKUyzR4GXlcLnbZWArnPZV+L9TG LSHhR0N5xlkoOFhh+5osZYevPH17hZ9TAXA9E16RCvsGgTl4gCji+kzL1Nl7S8Nx7BG/ OSA2z5sdJ4k30MFVUivhsbM4QpDvEV9HEDQp1jka/8DPXAFkJIMkp6OH+C5q3QDAtzqe bB0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702436591; x=1703041391; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hmdVgMNTGQhlO8xslqjDOun90RL8Cnjj+IZGL+fIg18=; b=FRGFbI077EFl/9zeDD3/Y4F3F/NTY1em3Y22MjsU/Frmzxj/AWL5Xlat/s44Tgu//r 2+mq1MM+4UyYoTqvAw3ehUKP1HsiXpPx28kKCpEMyrRjy2NGy2e9X8Xeb2MFZtX0pxVC 1o/KpBOxpiRvUBZ+zQveO2AEi64qJ3QA7gGweD1cjDNAlEl1j55J8uLIoDlsG7mV/W1A co1L8HoTBYGYMjT75/jPxR0Rid6CVX3Jhf2b2hAKhkV5RfnNl1E6qlMt7H5E5xi+ChDn rcNHBCbpr6iTfoOQesARExeEz0JePjKbkM5z6Ni/U9aZj/TJF1RzDk8GwZE/aQ9YSmf9 eq2g== X-Gm-Message-State: AOJu0YwJN7AYTaRdiXKuRV/GVUx+6SHevc1miC5oQo/OoTIZb0w/0P++ 7az5v9KW6oMp5sBX/zOUoWqwkELVm6p9g4pKAug= X-Google-Smtp-Source: AGHT+IEGHNPRMT1y4DbpNigFLxiTDz6QwrOyHzSEklbz1RugyR56UDijbMNGVrIcXyVVOmf/+R7EXkXBZtUAvRLFNrs= X-Received: by 2002:a05:651c:894:b0:2cc:321d:8654 with SMTP id d20-20020a05651c089400b002cc321d8654mr917030ljq.8.1702436590921; Tue, 12 Dec 2023 19:03:10 -0800 (PST) MIME-Version: 1.0 References: <20231208061407.2125867-1-yuzhao@google.com> In-Reply-To: From: Kairui Song Date: Wed, 13 Dec 2023 11:02:53 +0800 Message-ID: Subject: Re: [PATCH mm-unstable v1 1/4] mm/mglru: fix underprotected page cache To: Yu Zhao Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Charan Teja Kalla , Kalesh Singh , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 27A1B140013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: rac7jf7xqkzo4gm8gd1wjztwnuxdhyef X-HE-Tag: 1702436592-783284 X-HE-Meta: U2FsdGVkX1/2YRH4nbQEfj/+t3l2ejRBxTuslmg24Ujbbo9ZawLu4MSnCZzgaejDE23Dv46WdbgrdVAiHQInJOTiTvONLDmo3ZcmKRgqOyBLFMHqEEpB8vUhRVwV318dS8j2UgGewMCCFbYbVZxVTE3nodsU+FkrAUpAxMmaZfJNfG0hIzM6ttXGypV570S9TdsXbHvhYhJs6M2JmxQHRgUlqds9Hp2NP7vmAnIl+mZGcrJ3KGoTnaTXdGGdKxxye8LKZc2Wx6tC00wgnhTWo8zT+MHH+G8GREU/vdIswtY3h7fk1ZfCvsEhU0AFFY5ZEVsZXtjcv5sjAAGyOo8UHznxuDp8ALM4JE+PKdCAmI8owi0FcwIejLLmG9WL/T4Nn6EGx0vUEux4KYwNEX0WSXdBtvHMW62YQ/0Bo7Tv6TYiVxWOFvoBzMM73I4MDgoHZ7tWNUtBaVADwFpVwsPpAwpiqp2eo/u55TQcrrZipRKUo6qVC/+NBpGce+ACsLKnSfbggzrdOiwZ42EBmIQrVzwYFE0HMRMj5EeVm/No9aJTgC5jgrlcd6by+mq392jXJFr/CfDLCSY6gRcUPdK24zM74YZR0pUX9a/NwcMgI9EXwiKWWZHXV2kEeJtNHNYEC5PkgRHeOxmRMPzCmvsN2afoC0HS7LdiHWKNBP4S9QxQy3L4hlOqG0rl9tguxUEIB2wqTwcSVXhC+0kS6p0S6cj7WUaDGEzxLn+xpJ88d/PVSgOeGD3NE17zSPkBbD484GFZz9HzvjlzlJSVQxlKRlWR/1R6Lie24YbkUnZVYrV9gkR6CFgZT3tTdU0+l7p6y+aDiPnP2mCoCKwkrNQ7MPCkIVDap/xtoyDBmZozxXM6CT/65c4g6gClo0lk1qCLV+5Xbg/bRWagfJhTnnzTGeO8/ruYpHFH4GEozAIPmQ4wNzNXaxTtd9s4LbIXfYcqkdRwihnj5FW15ZoKG9k rz+p61mb N+ZQ1XQmQ7iPMBu3azkHxPim18ZfI8VOn+B8UR4dt4R9F+Eu1XvJE5YTHrOJlM3799bL92DCXV8I/XKiGHuSgNa+p+TrZ4SK4BPkH0IITAHFJiMSFcw8aC85Roi0WmQLILnhYXp5QjsXF06Zpi5j8fkcv3xaVX3kdvI/Te/1XqeL/2K1b8jKK5544qYU21PsblWlu/dw9zuAeEG1fHF1//rs+J6/+ziPF/ZkRaQQPu1eRUfQuumFEuMjniSeGgRDQxivM/wo0F7Lwog1HWMtv9o6oc5WF7MEEaL5IXUACZNaATzx5NituFmbPkNeTb0oJRmI5hJgHMPb7ghowADSOmE43+lWHSYtn+jA9U90420GfIEnlBpBfqhK0OgA0TRICEwKGKxMYjrSywxzrjskVyG6/fkwT0UweCo5wf12JOOlsSCkI2HVEvwndHFtBrGLbEzlOgKHZhr7kDjA= 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: List-Subscribe: List-Unsubscribe: Kairui Song =E4=BA=8E2023=E5=B9=B412=E6=9C=8812=E6=97=A5= =E5=91=A8=E4=BA=8C 14:52=E5=86=99=E9=81=93=EF=BC=9A > > Yu Zhao =E4=BA=8E2023=E5=B9=B412=E6=9C=8812=E6=97=A5= =E5=91=A8=E4=BA=8C 06:07=E5=86=99=E9=81=93=EF=BC=9A > > > > On Fri, Dec 8, 2023 at 1:24=E2=80=AFAM Kairui Song w= rote: > > > > > > Yu Zhao =E4=BA=8E2023=E5=B9=B412=E6=9C=888=E6=97= =A5=E5=91=A8=E4=BA=94 14:14=E5=86=99=E9=81=93=EF=BC=9A > > > > > > > > Unmapped folios accessed through file descriptors can be > > > > underprotected. Those folios are added to the oldest generation bas= ed > > > > on: > > > > 1. The fact that they are less costly to reclaim (no need to walk t= he > > > > rmap and flush the TLB) and have less impact on performance (don= 't > > > > cause major PFs and can be non-blocking if needed again). > > > > 2. The observation that they are likely to be single-use. E.g., for > > > > client use cases like Android, its apps parse configuration file= s > > > > and store the data in heap (anon); for server use cases like MyS= QL, > > > > it reads from InnoDB files and holds the cached data for tables = in > > > > buffer pools (anon). > > > > > > > > However, the oldest generation can be very short lived, and if so, = it > > > > doesn't provide the PID controller with enough time to respond to a > > > > surge of refaults. (Note that the PID controller uses weighted > > > > refaults and those from evicted generations only take a half of the > > > > whole weight.) In other words, for a short lived generation, the > > > > moving average smooths out the spike quickly. > > > > > > > > To fix the problem: > > > > 1. For folios that are already on LRU, if they can be beyond the > > > > tracking range of tiers, i.e., five accesses through file > > > > descriptors, move them to the second oldest generation to give t= hem > > > > more time to age. (Note that tiers are used by the PID controlle= r > > > > to statistically determine whether folios accessed multiple time= s > > > > through file descriptors are worth protecting.) > > > > 2. When adding unmapped folios to LRU, adjust the placement of them= so > > > > that they are not too close to the tail. The effect of this is > > > > similar to the above. > > > > > > > > On Android, launching 55 apps sequentially: > > > > Before After Change > > > > workingset_refault_anon 25641024 25598972 0% > > > > workingset_refault_file 115016834 106178438 -8% > > > > > > Hi Yu, > > > > > > Thanks you for your amazing works on MGLRU. > > > > > > I believe this is the similar issue I was trying to resolve previousl= y: > > > https://lwn.net/Articles/945266/ > > > The idea is to use refault distance to decide if the page should be > > > place in oldest generation or some other gen, which per my test, > > > worked very well, and we have been using refault distance for MGLRU i= n > > > multiple workloads. > > > > > > There are a few issues left in my previous RFC series, like anon page= s > > > in MGLRU shouldn't be considered, I wanted to collect feedback or tes= t > > > cases, but unfortunately it seems didn't get too much attention > > > upstream. > > > > > > I think both this patch and my previous series are for solving the > > > file pages underpertected issue, and I did a quick test using this > > > series, for mongodb test, refault distance seems still a better > > > solution (I'm not saying these two optimization are mutually exclusiv= e > > > though, just they do have some conflicts in implementation and solvin= g > > > similar problem): > > > > > > Previous result: > > > =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 > > > Execution Results after 905 seconds > > > ------------------------------------------------------------------ > > > Executed Time (=C2=B5s) Rate > > > STOCK_LEVEL 2542 27121571486.2 0.09 txn/s > > > ------------------------------------------------------------------ > > > TOTAL 2542 27121571486.2 0.09 txn/s > > > > > > This patch: > > > =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 > > > Execution Results after 900 seconds > > > ------------------------------------------------------------------ > > > Executed Time (=C2=B5s) Rate > > > STOCK_LEVEL 1594 27061522574.4 0.06 txn/s > > > ------------------------------------------------------------------ > > > TOTAL 1594 27061522574.4 0.06 txn/s > > > > > > Unpatched version is always around ~500. > > > > Thanks for the test results! > > > > > I think there are a few points here: > > > - Refault distance make use of page shadow so it can better > > > distinguish evicted pages of different access pattern (re-access > > > distance). > > > - Throttled refault distance can help hold part of workingset when > > > memory is too small to hold the whole workingset. > > > > > > So maybe part of this patch and the bits of previous series can be > > > combined to work better on this issue, how do you think? > > > > I'll try to find some time this week to look at your RFC. It'd be a Hi Yu, I'm working on V4 of the RFC now, which just update some comments, and skip anon page re-activation in refault path for mglru which was not very helpful, only some tiny adjustment. And I found it easier to test with fio, using following test script: #!/bin/bash swapoff -a modprobe brd rd_nr=3D1 rd_size=3D16777216 mkfs.ext4 /dev/ram0 mount /dev/ram0 /mnt mkdir -p /sys/fs/cgroup/benchmark cd /sys/fs/cgroup/benchmark echo 4G > memory.max echo $$ > cgroup.procs echo 3 > /proc/sys/vm/drop_caches fio -name=3Dmglru --numjobs=3D12 --directory=3D/mnt --size=3D1024m \ --buffered=3D1 --ioengine=3Dio_uring --iodepth=3D128 \ --iodepth_batch_submit=3D32 --iodepth_batch_complete=3D32 \ --rw=3Drandread --random_distribution=3Dzipf:0.5 --norandommap \ --time_based --ramp_time=3D5m --runtime=3D5m --group_reporting zipf:0.5 is used here to simulate a cached read with slight bias towards certain pages. Unpatched 6.7-rc4: Run status group 0 (all jobs): READ: bw=3D6548MiB/s (6866MB/s), 6548MiB/s-6548MiB/s (6866MB/s-6866MB/s), io=3D1918GiB (2060GB), run=3D300001-300001msec Patched with RFC v4: Run status group 0 (all jobs): READ: bw=3D7270MiB/s (7623MB/s), 7270MiB/s-7270MiB/s (7623MB/s-7623MB/s), io=3D2130GiB (2287GB), run=3D300001-300001msec Patched with this series: Run status group 0 (all jobs): READ: bw=3D7098MiB/s (7442MB/s), 7098MiB/s-7098MiB/s (7442MB/s-7442MB/s), io=3D2079GiB (2233GB), run=3D300002-300002msec MGLRU off: Run status group 0 (all jobs): READ: bw=3D6525MiB/s (6842MB/s), 6525MiB/s-6525MiB/s (6842MB/s-6842MB/s), io=3D1912GiB (2052GB), run=3D300002-300002msec - If I change zipf:0.5 to random: Unpatched 6.7-rc4: Patched with this series: Run status group 0 (all jobs): READ: bw=3D5975MiB/s (6265MB/s), 5975MiB/s-5975MiB/s (6265MB/s-6265MB/s), io=3D1750GiB (1879GB), run=3D300002-300002msec Patched with RFC v4: Run status group 0 (all jobs): READ: bw=3D5987MiB/s (6278MB/s), 5987MiB/s-5987MiB/s (6278MB/s-6278MB/s), io=3D1754GiB (1883GB), run=3D300001-300001msec Patched with this series: Run status group 0 (all jobs): READ: bw=3D5839MiB/s (6123MB/s), 5839MiB/s-5839MiB/s (6123MB/s-6123MB/s), io=3D1711GiB (1837GB), run=3D300001-300001msec MGLRU off: Run status group 0 (all jobs): READ: bw=3D5689MiB/s (5965MB/s), 5689MiB/s-5689MiB/s (5965MB/s-5965MB/s), io=3D1667GiB (1790GB), run=3D300003-300003msec fio uses ramdisk so LRU accuracy will have smaller impact. The Mongodb test I provided before uses a SATA SSD so it will have a much higher impact. I'll provides a script to setup the test case and run it, it's more complex to setup than fio since involving setting up multiple replicas and auth and hundreds of GB of test fixtures, I'm currently occupied by some other tasks but will try best to send them out as soon as possible.