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 85A33C4332F for ; Thu, 14 Dec 2023 23:51:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D55D78D00F8; Thu, 14 Dec 2023 18:51:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CDEDB8D00C7; Thu, 14 Dec 2023 18:51:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B59298D00F8; Thu, 14 Dec 2023 18:51:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9FC208D00C7 for ; Thu, 14 Dec 2023 18:51:41 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6ACE280473 for ; Thu, 14 Dec 2023 23:51:41 +0000 (UTC) X-FDA: 81567073602.13.3F2DFAA Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf27.hostedemail.com (Postfix) with ESMTP id 8936A40005 for ; Thu, 14 Dec 2023 23:51:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PT0r74vO; spf=pass (imf27.hostedemail.com: domain of yuzhao@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702597899; 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=fp/I7DMT70xgZqvYPb/pR7anfyQRttZJnBDn8rEZYag=; b=syblOXxAH68hV9cfswcWRJkmwZxmUbpBGwYaZB4xZzjApfUvDhLvKSNP59Y+T9xyAXXaNT N9FMPPeK+vqzTuUYmtUHFtj90aRU3LwcSPs230+XjGXaCNTRrOLvS+LXcCjjyTGp7JWSyZ BS+1e+lOcgbpm7vjrCHQnN1FGHCNQ4Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702597899; a=rsa-sha256; cv=none; b=O7c6apC93GMzkVYDcuAQF5oCG4LmQmiYz5rDDce6DSuc/kYNh0E95rsM6p7FL8tHsefdI7 DiGdik9KFUSgpbNTWKlMMU8okH/pQAP0IPQAHPFQRAmB402NwZKwFpvS9HX35uLp6wwetU nWFDyfKXAakIo8tn2pmMBFohCfcOeZA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PT0r74vO; spf=pass (imf27.hostedemail.com: domain of yuzhao@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-54744e66d27so5661a12.0 for ; Thu, 14 Dec 2023 15:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702597898; x=1703202698; 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=fp/I7DMT70xgZqvYPb/pR7anfyQRttZJnBDn8rEZYag=; b=PT0r74vOtCsk3yHjvPzZwnqlp1bbApUqcoeQVDog0NSbxX63zGWv3JJc7oO2pJIqPp 6MDWO1KY2U5WmfDpeNCTytSccj/vjWQZo68SVb7YZSi/6181ZdgtAwcNCApw3UqtgBXA 0gFPkdYYpRyI/Lxz+mG/Nv144byAiPU+e50hRqM+YVf9rCfNKbyp9medel0mRRugpjqg 86fFKx2YoCOKMcfH6ZyovbVkrXJ/gtnhBUU2gTW+azPiUeBn9O+JumoELxUmucR6GFRD 9y6iwwF7dRlFpLoyW31hiS3NcIRbWDwphxp5zpN4Z1+hOpa+c880bcr+uk0+m8wyLczo Aykw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702597898; x=1703202698; 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=fp/I7DMT70xgZqvYPb/pR7anfyQRttZJnBDn8rEZYag=; b=X2HTBnLU7WnYF4cEPGwLroSZ5fDOufKNfSIwc+Rdrhjd1t+/Ve84XwHskkQ09i8Psc /hKSBftM7Vw+1u3k0IwrHcNBcEjq2AXXZFLBnjzY3N+NNgd2c46PyH1CNnDQNctedGoB SZHAB/48dWRaQme/K2v4ddrXRJmnK2uTcK8vj093BfXBpMAZALuBbG0iNCRnACvvYNmi jOVdGXUF82EaDqmH5RBIV1jw5m4WPmXuj7IFGImDgwzYSZe51FtH5uTIiYM005vzY8Ec qoxaK8lzCAeX7uQm/qiTfx3uZMetkTRQIWldDpiTwzECsuE6UpqLzn2+J1zB606Ner1B 43IA== X-Gm-Message-State: AOJu0YyRCrGDIz4/siICTEP90Y/aTUfiq3KxlO1Jbu3sF+UC6Khevx0c sGEnWMGIHYHunnNP1ME5F1WqgD2ufH4WTPfuWTzesg== X-Google-Smtp-Source: AGHT+IHfBFCtoShuRoZ+56vAPMWpQr9j8KC1Gh2PsHr/GVH4O6e4S4cKgYI3j38AwMEOc2XuC/1Cb732xXahrHATO+M= X-Received: by 2002:a50:d601:0:b0:551:f450:752a with SMTP id x1-20020a50d601000000b00551f450752amr305174edi.6.1702597897781; Thu, 14 Dec 2023 15:51:37 -0800 (PST) MIME-Version: 1.0 References: <20231208061407.2125867-1-yuzhao@google.com> In-Reply-To: From: Yu Zhao Date: Thu, 14 Dec 2023 16:51:00 -0700 Message-ID: Subject: Re: [PATCH mm-unstable v1 1/4] mm/mglru: fix underprotected page cache To: Kairui Song 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: 8936A40005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 66u8qmjx6i8fd4ddczmy3btsae14tanp X-HE-Tag: 1702597899-754775 X-HE-Meta: U2FsdGVkX1+q8f6R5GuWTSmv/9bDQYr1caSfqQwT+g8IKKYrAs0AexBpBQnEWP2WF5ZFnaNpWhU9zPvoJBqlmCsW9j1mqLDws/U5tNGMpjy2MkEQ3lUdGCd3XaIuCzPUKDL1oxCIzdm6Ju1zmfrL+oIys156IJ6g8pQQIJbp6EQTAAhnBhD52GagSYSMbFpdpsjZuo8/I4nrDeKKfDVPEPPovv2Ju6HmL6Calty6wY6HsdJFQzKegx2/iEjdWN9vW8KxsMkxWXKznK2aS9COAD7KpUsTSX0/5e0QFmNptHrVvxF+rom4FsOw6lwfgMkbx3X9jy2+340iy/788qQS7lk7DUGvNYUVkCJpOdRrZcBZs9UbJHj7h2dbKeV5L1Qr2K7xjqWCB1c5TGIAJikMafVxzP/PcOx2xPDq1GUW36fa03i98FZNNwuW6lkah7nMe2mlU1VpjAjkLLT1YW24sBWnvDkHh71RBOWfm7saAzvpPl8bSKsjKu2aORNG6t8jt+pNpZLTaKZpvlZDnVtxD3rDBAgieK/7nQVbfFnnW82w07IWX+LpSD+bfyejvCRbaT9tYwwpiM+QrozWpz5Ku0Z9MC/wLsVvHa4OHK/RjQvG6kBcJDuj0zhgipPxzzvQHpHz0T1BAuXmYOmx48EUL99QJ+bU8F9SI5i/OVpNfzzXxoIGNAJQIGbyMu+zoDFkJRnopbPyFIKoYHZ4FudhgpP0jsZX2ouREt4ptoPOu0uKih+BSlo5ppvWn/F5uzITKKU5K4t8w2KHxz6LD7xVl8OEMKzL7lvfTDyYFOEOwcXrZLlzydnSidfaem7pZee6pVuacpUUv/6CZmxCFD634RQqR13/yRfCCNyQrcjMtOUTabzZfk5PyRSaTpxHWxl30c55hJBMy8PN/lVz4ai+/3u8ecUMo55e/0rmg+mz2daMYjxJTlQE+K2s9VxWQ9iXFtmCW7eAFASf4o3w5BD TOO06hmK t3q9bjypd4/DFw2BLC1Kc0CUlBZ4yRfDIUH7xeJdRYseO203DzARtRv1lkNRUgOntEZViaWLMWR7clsvKyk+NmDFcTiWyWnD+XVEmpbhq01Fgps3h0CzV/QdbflownbLr2I32la/WQWIs2+pX4AQthsaAEK4xE9ShIj5vC13bnkHb+QXbrpXyO/yeUAbxAi5N8Go4Lcl5pceB/RHrsdQMwFMmfgSOz6ph+IYKHAaOTYQkXj2jXE1c4Ea/XTISu8oUFzp7U7vVOHvBRZGYIG2BjzaYLdij4U4uzX4eobEUo2KKB6y3u+if3AYHCF+FMT/hSg7/2B+pq3NqN6g= 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: On Thu, Dec 14, 2023 at 11:38=E2=80=AFAM Kairui Song wro= te: > > Yu Zhao =E4=BA=8E2023=E5=B9=B412=E6=9C=8814=E6=97=A5= =E5=91=A8=E5=9B=9B 11:09=E5=86=99=E9=81=93=EF=BC=9A > > On Wed, Dec 13, 2023 at 12:59:14AM -0700, Yu Zhao wrote: > > > On Tue, Dec 12, 2023 at 8:03=E2=80=AFPM Kairui Song wrote: > > > > > > > > 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 wrote: > > > > > > > > > > > > > > Yu Zhao =E4=BA=8E2023=E5=B9=B412=E6=9C=88= 8=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 genera= tion based > > > > > > > > on: > > > > > > > > 1. The fact that they are less costly to reclaim (no need t= o walk the > > > > > > > > rmap and flush the TLB) and have less impact on performa= nce (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 configurat= ion files > > > > > > > > and store the data in heap (anon); for server use cases = like MySQL, > > > > > > > > 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 resp= ond to a > > > > > > > > surge of refaults. (Note that the PID controller uses weigh= ted > > > > > > > > refaults and those from evicted generations only take a hal= f 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 beyon= d the > > > > > > > > tracking range of tiers, i.e., five accesses through fil= e > > > > > > > > descriptors, move them to the second oldest generation t= o give them > > > > > > > > more time to age. (Note that tiers are used by the PID c= ontroller > > > > > > > > to statistically determine whether folios accessed multi= ple times > > > > > > > > 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 t= his 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 p= reviously: > > > > > > > https://lwn.net/Articles/945266/ > > > > > > > The idea is to use refault distance to decide if the page sho= uld be > > > > > > > place in oldest generation or some other gen, which per my te= st, > > > > > > > worked very well, and we have been using refault distance for= MGLRU in > > > > > > > multiple workloads. > > > > > > > > > > > > > > There are a few issues left in my previous RFC series, like a= non pages > > > > > > > in MGLRU shouldn't be considered, I wanted to collect feedbac= k or test > > > > > > > cases, but unfortunately it seems didn't get too much attenti= on > > > > > > > upstream. > > > > > > > > > > > > > > I think both this patch and my previous series are for solvin= g the > > > > > > > file pages underpertected issue, and I did a quick test using= this > > > > > > > series, for mongodb test, refault distance seems still a bett= er > > > > > > > solution (I'm not saying these two optimization are mutually = exclusive > > > > > > > though, just they do have some conflicts in implementation an= d solving > > > > > > > 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-acc= ess > > > > > > > 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 c= an 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 no= t > > > > 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 --norand= ommap \ > > > > --time_based --ramp_time=3D5m --runtime=3D5m --group_repo= rting > > > > > > > > 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 Mong= odb > > > > test I provided before uses a SATA SSD so it will have a much highe= r > > > > impact. I'll provides a script to setup the test case and run it, i= t's > > > > more complex to setup than fio since involving setting up multiple > > > > replicas and auth and hundreds of GB of test fixtures, I'm currentl= y > > > > occupied by some other tasks but will try best to send them out as > > > > soon as possible. > > > > > > Thanks! Apparently your RFC did show better IOPS with both access > > > patterns, which was a surprise to me because it had higher refaults > > > and usually higher refautls result in worse performance. > > > > > > So I'm still trying to figure out why it turned out the opposite. My > > > current guess is that: > > > 1. It had a very small but stable inactive LRU list, which was able t= o > > > fit into the L3 cache entirely. > > > 2. It counted few folios as workingset and therefore incurred less > > > overhead from CONFIG_PSI and/or CONFIG_TASK_DELAY_ACCT. > > > > > > Did you save workingset_refault_file when you ran the test? If so, ca= n > > > you check the difference between this series and your RFC? > > > > > > It seems I was right about #1 above. After I scaled your test up by 20x= , > > I saw my series performed ~5% faster with zipf and ~9% faster with rand= om > > accesses. > > Hi Yu, > > Thank you so much for testing and sharing this result. > > I'm not sure about #1, the ramdisk size, access data, are far larger > than L3 (16M on my CPU) even in down scaled test, and both random/zipf > shows similar result. It's the LRU list not pages. IOW, the kernel data structure, not the content in LRU pages. Does it make sense? > > IOW, I made rd_size from 16GB to 320GB, memory.max from 4GB to 80GB, > > --numjobs from 12 to 60 and --size from 1GB to 4GB. Would you be able to try a larger configuration like above instead?