Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp118810rdb; Thu, 25 Jan 2024 09:52:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFz54sChzmfNHRwsAORXHX0Ip4yYmiQyDlKLtgmRgnRp8dAha7bzYxFArgmiPp2y91o5L+W X-Received: by 2002:a05:6a00:bf0:b0:6db:a0e5:7ec3 with SMTP id x48-20020a056a000bf000b006dba0e57ec3mr76477pfu.22.1706205175039; Thu, 25 Jan 2024 09:52:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706205175; cv=pass; d=google.com; s=arc-20160816; b=0RxG/nzaSg+OpSKTp3uc1JFaOMQPPVK8JvYdWj1YlVgoaysNoT/8rsUjySLAPE0AN1 FC0PwtohcL+C7eA5RoCqacnPR80CfBgbABD2TiijpXp4APoFwk/QhECnt0/fnRDHIjIx kwDJPZ27P/IqRPDepiVEJRXUZmhepQHkmTtMN7UNi+Ygd4rjzQh5/iVddLii/KQmUYMs WLrJqA6YkaeHLMsojrTkM9lHzHgrn69PjzlPnkcMSRGMbNdMyeTUbqli4BTbCGjPFLSc E/iGz6w2sPVfqyjMBVQDMecc43gygjCmba8yOGmpM0uZ7n16xQNz3ue/w2rOdbSnu4oD gsGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=58AAw59QVEkmC52O5LxYTi+CX/9Jh0etyAUz49wdjuc=; fh=XHmWkL5PCShsM5cQlhNBTGJaARZCqUgwU4lraLL0gPo=; b=AjG0XWHFkOLzZwW+3oaSQT+NI295ZkPsdGuxadLJnAB7VW0bxDupP8Z3wKXDFw/IWP oSkohf8I0ZQPPPf5DVhUbFDPviEGuzfKk9LoilsfP+kwLm8le9he6t+27Rkrj20LhuDY JqLrbOnkf6VwBQod27dwIZH9JZVNvAxBSJGHvenHPUOlSvVlfRsts4R717bSa/JW0mid LmGcZ/O3rGcOLJz1cgehZ5JQ94A37AWK8CsJzswg20FvWbVt573/Yu/XUw93dTMqA71w A7RTYktLn6SStuf/Tvk3PtVHGbAFSt1XEJoBEn/17tGHrsFK8eP+HOaP6chcMv6Z91Hv vrnA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GOdaBr8p; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-39056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s23-20020a62e717000000b006dda22fe678si2650430pfh.18.2024.01.25.09.52.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:52:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GOdaBr8p; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-39056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8B704291096 for ; Thu, 25 Jan 2024 17:52:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32B63133414; Thu, 25 Jan 2024 17:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GOdaBr8p" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E0C745C6 for ; Thu, 25 Jan 2024 17:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706205126; cv=none; b=iCVuYtEC+tCyE9GulPhRd14Ntb5SSu/MEKtU7V/jPPCr1ib9Fdp+TaHDq3Kt/3S3QwdNz/KJ3P+veAT1xdNn3d+ZG4eIJrYyRi6/8al1coNvdBk3rqHttndwqxBIjs31fkXahDAJgCNu9L+JHy8BYW6QL2PxIrr4b33wCUvKXnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706205126; c=relaxed/simple; bh=vr/AyOXBh/PfRIcVKSypP8o7xVRseNU4jwIKCJkd2Vg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=C1SvhVMJr43EXaWhvjZbyGhCyjEYuRMM2tLdilpilI47YN5mY/vTpOT+eXJ8T/nto326IQm4c5H+QRuJSYsWQIACfLTcnWMB5vOlq1gpDvpuIn+RRWiJZ0bARZxp2e6y0jJqv0bBcNiO3CGtLa8NdKCY1QGRZQvHhdDfQPu8ceM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GOdaBr8p; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2cf205dc075so25418831fa.2 for ; Thu, 25 Jan 2024 09:52:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706205122; x=1706809922; darn=vger.kernel.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=58AAw59QVEkmC52O5LxYTi+CX/9Jh0etyAUz49wdjuc=; b=GOdaBr8pn9Cvvp48n+QQzlcK+1xC+KjSZtVQ9F91vBfbqCVFN99u8fWGUTYnfqCWSU nRzNwGLYl43d2W+5gFDjcIs6HjiBLA/b1Nk45LBfsZtoMv8ok3wWx5JlAT981xLCxpFa GvQB6oab+kocg3efoEIZpycrHY041xM7foYASjJ02fsCTkaRmRyA6IhPHeSLW5AyIDf4 zhkOW2JB40YJFiEbgHrLOCDjE8oMo0jGp6eQrEn5ARHi+VfFdPsVKM599M3bTvhQEj1j AGzL59PlgzkD9sRW7oTQQhOSA7n+5emqBSNODUA/kF3j/uucH6Srxi4V4NadkegUv2Nr 2iSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706205122; x=1706809922; 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=58AAw59QVEkmC52O5LxYTi+CX/9Jh0etyAUz49wdjuc=; b=wNUrKtXRkLYaqe2IKyB1j5eioSfIqWixYtFC09SJ2MqCTsw8ulRBEtBHIvSZNsUwGs NtxLZEgkeFMKosgAAbVmzxatA8xFqPVLvi5xKXOQk7PW3/aRnUbYrm6UWu8RwRSh5mYg H59c0O9FHv99HcTIItzAo6II2q+4gRwQQr7S5RPDRGkrD1Roxtk4HEso0ORPk2RcPRIo jBM1I9mD9WES9pvHdPX4YRS8pFbmWrffi0loeZSHbrbE+WKf9/uVKpO8zhKHlkAbECIS FauYhwpZyryk8Ile4k4ip+PGcl2qciLxb+EguncG98ym0EaN3q3Pb5IVMw+Aaa/nYgJa Aqrg== X-Gm-Message-State: AOJu0YxOglbKC6FJR8wrGg/U0MS8iTJ/jdLrwbHwqQFTdsYcfBdVnoF3 me1plQ46rCLknXsSynRw9NK87XmsBMo+t9KTo7hUNIqwOXNX2zis+sshGPGgCLVh0Vtusg/guy1 6yMcfziRcscxg+LECxTOOd69goBXCP7pgfVUkxQ== X-Received: by 2002:a2e:9092:0:b0:2cf:433c:b3e with SMTP id l18-20020a2e9092000000b002cf433c0b3emr28412ljg.8.1706205121921; Thu, 25 Jan 2024 09:52:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240123184552.59758-1-ryncsn@gmail.com> <20240123184552.59758-2-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Fri, 26 Jan 2024 01:51:44 +0800 Message-ID: Subject: Re: [PATCH v3 1/3] mm, lru_gen: try to prefetch next page when scanning LRU To: Chris Li Cc: linux-mm@kvack.org, Andrew Morton , Yu Zhao , Wei Xu , Matthew Wilcox , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 25, 2024 at 3:33=E2=80=AFPM Chris Li wrote: > > On Tue, Jan 23, 2024 at 10:46=E2=80=AFAM Kairui Song w= rote: > > > > From: Kairui Song > > > > Prefetch for inactive/active LRU have been long exiting, apply the same > > optimization for MGLRU. > > > > Test 1: Ramdisk fio ro test in a 4G memcg on a EPYC 7K62: > > fio -name=3Dmglru --numjobs=3D16 --directory=3D/mnt --size=3D960m \ > > --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=3D1m --runtime=3D6m --group_reporting > > > > Before this patch: > > bw ( MiB/s): min=3D 7758, max=3D 9239, per=3D100.00%, avg=3D8747.59, s= tdev=3D16.51, samples=3D11488 > > iops : min=3D1986251, max=3D2365323, avg=3D2239380.87, stdev=3D4= 225.93, samples=3D11488 > > > > After this patch (+7.2%): > > bw ( MiB/s): min=3D 8360, max=3D 9771, per=3D100.00%, avg=3D9381.31, s= tdev=3D15.67, samples=3D11488 > > iops : min=3D2140296, max=3D2501385, avg=3D2401613.91, stdev=3D4= 010.41, samples=3D11488 > > > > Test 2: Ramdisk fio hybrid test for 30m in a 4G memcg on a EPYC 7K62 (3= times): > > fio --buffered=3D1 --numjobs=3D8 --size=3D960m --directory=3D/mnt \ > > --time_based --ramp_time=3D1m --runtime=3D30m \ > > --ioengine=3Dio_uring --iodepth=3D128 --iodepth_batch_submit=3D32 \ > > --iodepth_batch_complete=3D32 --norandommap \ > > --name=3Dmglru-ro --rw=3Drandread --random_distribution=3Dzipf:0.7 = \ > > --name=3Dmglru-rw --rw=3Drandrw --random_distribution=3Dzipf:0.7 > > > > Before this patch: > > READ: 6622.0 MiB/s. Stdev: 22.090722 > > WRITE: 1256.3 MiB/s. Stdev: 5.249339 > > > > After this patch (+4.6%, +3.3%): > > READ: 6926.6 MiB/s, Stdev: 37.950260 > > WRITE: 1297.3 MiB/s, Stdev: 7.408704 > > > > Test 3: 30m of MySQL test in 6G memcg (12 times): > > echo 'set GLOBAL innodb_buffer_pool_size=3D16106127360;' | \ > > mysql -u USER -h localhost --password=3DPASS > > > > sysbench /usr/share/sysbench/oltp_read_only.lua \ > > --mysql-user=3DUSER --mysql-password=3DPASS --mysql-db=3DDB \ > > --tables=3D48 --table-size=3D2000000 --threads=3D16 --time=3D1800 r= un > > > > Before this patch > > Avg: 134743.714545 qps. Stdev: 582.242189 > > > > After this patch (+0.2%): > > Avg: 135005.779091 qps. Stdev: 295.299027 > > > > Test 4: Build linux kernel in 2G memcg with make -j48 with SSD swap > > (for memory stress, 18 times): > > > > Before this patch: > > Avg: 1456.768899 s. Stdev: 20.106973 > > > > After this patch (+0.0%): > > Avg: 1455.659254 s. Stdev: 15.274481 > > > > Test 5: Memtier test in a 4G cgroup using brd as swap (18 times): > > memcached -u nobody -m 16384 -s /tmp/memcached.socket \ > > -a 0766 -t 16 -B binary & > > memtier_benchmark -S /tmp/memcached.socket \ > > -P memcache_binary -n allkeys \ > > --key-minimum=3D1 --key-maximum=3D16000000 -d 1024 \ > > --ratio=3D1:0 --key-pattern=3DP:P -c 1 -t 16 --pipeline 8 -x 3 > > > > Before this patch: > > Avg: 50317.984000 Ops/sec. Stdev: 2568.965458 > > > > After this patch (-5.7%): > > Avg: 47691.343500 Ops/sec. Stdev: 3925.772473 > > > > It seems prefetch is helpful in most cases, but the memtier test is > > either hitting a case where prefetch causes higher cache miss or it's > > just too noisy (high stdev). > > > > Signed-off-by: Kairui Song > > --- > > mm/vmscan.c | 30 ++++++++++++++++++++++++++---- > > 1 file changed, 26 insertions(+), 4 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index 4f9c854ce6cc..03631cedb3ab 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -3681,15 +3681,26 @@ static bool inc_min_seq(struct lruvec *lruvec, = int type, bool can_swap) > > /* prevent cold/hot inversion if force_scan is true */ > > for (zone =3D 0; zone < MAX_NR_ZONES; zone++) { > > struct list_head *head =3D &lrugen->folios[old_gen][typ= e][zone]; > > + struct folio *prev =3D NULL; > > > > - while (!list_empty(head)) { > > - struct folio *folio =3D lru_to_folio(head); > > + if (!list_empty(head)) > > + prev =3D lru_to_folio(head); > > + > > + while (prev) { > > + struct folio *folio =3D prev; > > > > VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(fo= lio), folio); > > VM_WARN_ON_ONCE_FOLIO(folio_test_active(folio),= folio); > > VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) = !=3D type, folio); > > VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) !=3D= zone, folio); > > > > + if (unlikely(list_is_first(&folio->lru, head)))= { > > + prev =3D NULL; > > + } else { > > + prev =3D lru_to_folio(&folio->lru); > > + prefetchw(&prev->flags); > > + } > > This makes the code flow much harder to follow. Also for architecture > that does not support prefetch, this will be a net loss. > > Can you use refetchw_prev_lru_folio() instead? It will make the code > much easier to follow. It also turns into no-op when prefetch is not > supported. > > Chris > Hi Chris, Thanks for the suggestion. Yes, that's doable, I made it this way because in previous series (V1 & V2) I applied the bulk move patch first which needed and introduced the `prev` variable here, so the prefetch logic just used it. For V3 I did a rebase and moved the prefetch commit to be the first one, since it seems to be the most effective one, and just kept the code style to avoid redundant change between patches. I can update in V4 to make this individual patch better with your suggestio= n.