From patchwork Thu Jan 11 18:33:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13517708 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 3F9D8C47077 for ; Thu, 11 Jan 2024 18:33:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D09216B00A4; Thu, 11 Jan 2024 13:33:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C69DA6B00A5; Thu, 11 Jan 2024 13:33:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A96AD6B00A6; Thu, 11 Jan 2024 13:33:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8EA056B00A4 for ; Thu, 11 Jan 2024 13:33:48 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DDEBB140D16 for ; Thu, 11 Jan 2024 18:33:47 +0000 (UTC) X-FDA: 81667878894.25.F46F932 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf28.hostedemail.com (Postfix) with ESMTP id DD732C001A for ; Thu, 11 Jan 2024 18:33:45 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WNFNOKmH; spf=pass (imf28.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704998025; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FtBGRSINF6KI+RQqf15dVUHoZl7wlhzwJWjlp3npicI=; b=vTXLrNoPUevJcG3/eyrk7eR3V9XpafK5acwgYMYHZ7rEPHaTfjTREp/KmE5l8k48UjzZ7B tjEt1j08uO44IEZ+TluDF73VMHsXMB1NoRH813lvA6wkDS6QbMZ/9Ig4aCip4Nx3Uo+o3f tQha+SeNnIKpQY5Zj7u8PRdLjeDIlos= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WNFNOKmH; spf=pass (imf28.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704998025; a=rsa-sha256; cv=none; b=iY3QoEYrLG3W+0uzYbN9ZS1kJaGaOe9kkPCP7w8zyIUf2xSMt2mHohGICBNQp3Wh2IAPKb 50jUXll2LYXdbhyYWq/NH2hR+eLtpLNHhxiYG56/MqPtBa9Fe/GkaJ02mQw7O4gSLqK8ji HitwpNMWlgt8jghr8tM0O70eiP7NKFI= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d54b86538aso28936355ad.0 for ; Thu, 11 Jan 2024 10:33:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704998024; x=1705602824; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=FtBGRSINF6KI+RQqf15dVUHoZl7wlhzwJWjlp3npicI=; b=WNFNOKmHBtz9sgvB/YpUhwCstqKNWZnALcGAofrWrWdVqBsEJJ6jP7Vmqd4HQiCQUR 1v9rfx4jFHF/ZpG2uwoRE2hi96VsDMLT46DwJA/chPU23Y/ucvz4g9Y7OVhNiEbZoYSD NYZiagRFJl1946uAcD809+3rBLUYMH01zbyIhfSO9mcUGOEdXIUl169D7JncR80CYn9t XzgBHH8mWfjKIPg4n0etXVxciCo4gXHM56BLLp4Oc9Lx2uoRTulWQoblWwTgHMA2s/Lg lymbXEp+HF3YmJ5Nbi1WjGo9ZYNPsDgg9vdZl992TngwG+F+/3zKhfnZwI5L/Z8sRaLP MPAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704998024; x=1705602824; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FtBGRSINF6KI+RQqf15dVUHoZl7wlhzwJWjlp3npicI=; b=iBowDl2T724QtpxT02oWL/fhKG2VtHWmaX3Hwvz+31eFRrI6C84PYOGZB4st3pnaY0 qu5fbH9CpWyOOXdI2ENSM1sZDKcBmAYMNBMovvyfVaPGPNvV2K0z3Ytn9F8/WpA2v4MU vqwfrqPCl1qTlkwSZ5ZALW1PthPTBwe5stuk27w6k5nKBm/73nzFKlYazUm1uuRiyibM cKlEg5arJoRQeD1KwvUoxxe0GYAE8eaPbAr0qmSP1SdoLmg5CjYyeFMbnJBNQeWlpwmB vWIEqUgQdnuVWeiWzVaZSb8jLtKI9saZnTM+4WLAL+r6o6WzrKvzskv6eTLCiJvzU19Q hjKg== X-Gm-Message-State: AOJu0YwvLSvR/zW5NcXOI8L2LIelilKCn0X0SZSRAOLyExLYFPDvJVXq rIIgz6mPI+6Lcqnx7+6w15L7RACWDX3/mUBP X-Google-Smtp-Source: AGHT+IFBEjyW6RvYROEJiwKiMLp56a9P4SPF8Qzgo7qO9Q/w+d/Lqk+mkTK5izHiT22OVPgAbeFUzw== X-Received: by 2002:a17:902:ea91:b0:1d4:ca2e:2bfb with SMTP id x17-20020a170902ea9100b001d4ca2e2bfbmr149921plb.42.1704998023664; Thu, 11 Jan 2024 10:33:43 -0800 (PST) Received: from KASONG-MB2.tencent.com ([1.203.117.98]) by smtp.gmail.com with ESMTPSA id mf3-20020a170902fc8300b001d08e080042sm1483267plb.43.2024.01.11.10.33.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Jan 2024 10:33:43 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Yu Zhao , Chris Li , Matthew Wilcox , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 3/3] mm, lru_gen: try to prefetch next page when canning LRU Date: Fri, 12 Jan 2024 02:33:21 +0800 Message-ID: <20240111183321.19984-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111183321.19984-1-ryncsn@gmail.com> References: <20240111183321.19984-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: DD732C001A X-Rspam-User: X-Stat-Signature: y8rdibzddcmcacm9fxc88xe55r1iseja X-Rspamd-Server: rspam01 X-HE-Tag: 1704998025-914538 X-HE-Meta: U2FsdGVkX18Ux/HouFheBplIs06u9Wgd50/p4lIQNZyTRcNHtCl3q89Em52/GtHPOu6ctk1ZGEl8k1kBG8fBYJSynQ1+4/bHB3G0fowL2xy8DHY8YraWi0T0NYbEQLM7VfsIlilBBhzVR2FxTwBbzq+L9IwtDjpS2lhEz/GSjGoooZxt7yMq71UcfIhpE3FI8M/n/OYdqWSifDeLr79KZVc4KqRrZqN3J5iVNlUqDaBwCmkWWyBjouB+D7L54mZXKJO0lcgbx13IdolB/kkoCo7lKlWlEPbxYyoTrVH/FjwSUhHtUe70MwyEztxP9ujkHaoBhPZBkA/MDyk8YY/wUx3Uv6oILe8Eykh6Z9jQ7kQ4y0KIYCMj+4SI92jTqTC3K5e/574Ti/ClO8J2Qei6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jfqgD43WZBunkuox+Myk5hkdTegUzHTeAaMtzVoBadoVEu1cohrqoSN+/dBIqUdTPrGEuBa3ghxU9uKDQbLHyGH66JXSYvVZGk1+U0L1RGspDf6k1lG95joWkmQ2SXybIwc8yV9hluq3SPDDfw6n8hXqZ0dlfcMoxdkhw+fkLi+Lfo42hPamDwWDPqxCG420gZB6fds6KgfA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song Prefetch for inactive/active LRU have been long exiting, apply the same optimization for MGLRU. Ramdisk based swap test in a 4G memcg on a EPYC 7K62 with: 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=1 --key-maximum=16000000 -d 1024 \ --ratio=1:0 --key-pattern=P:P -c 2 -t 16 --pipeline 8 -x 6 Average result of 18 test runs: Before: 44017.78 Ops/sec After patch 1-3: 44890.50 Ops/sec (+1.8%) Ramdisk fio test in a 4G memcg on a EPYC 7K62 with: fio -name=mglru --numjobs=16 --directory=/mnt --size=960m \ --buffered=1 --ioengine=io_uring --iodepth=128 \ --iodepth_batch_submit=32 --iodepth_batch_complete=32 \ --rw=randread --random_distribution=zipf:0.5 --norandommap \ --time_based --ramp_time=1m --runtime=5m --group_reporting Before this patch: bw ( MiB/s): min= 7644, max= 9293, per=100.00%, avg=8777.77, stdev=16.59, samples=9568 iops : min=1956954, max=2379053, avg=2247108.51, stdev=4247.22, samples=9568 After this patch (+7.5%): bw ( MiB/s): min= 8462, max= 9902, per=100.00%, avg=9444.77, stdev=16.43, samples=9568 iops : min=2166433, max=2535135, avg=2417858.23, stdev=4205.15, samples=9568 Prefetch is highly related to timing and architecture so it may only help in certain cases, some extra test showed at least no regression here for the series: Ramdisk memtier test above in a 8G memcg on an Intel i7-9700: memtier_benchmark -S /tmp/memcached.socket \ -P memcache_binary -n allkeys --key-minimum=1 \ --key-maximum=36000000 --key-pattern=P:P -c 1 -t 12 \ --ratio 1:0 --pipeline 8 -d 1024 -x 4 Average result of 12 test runs: Before: 61241.96 Ops/sec After patch 1-3: 61268.53 Ops/sec (+0.0%) Signed-off-by: Kairui Song --- mm/vmscan.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 57b6549946c3..4ef83db40adb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3773,10 +3773,12 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, bool can_swap) VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) != type, folio); VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) != zone, folio); - if (unlikely(list_is_first(&folio->lru, head))) + if (unlikely(list_is_first(&folio->lru, head))) { prev = NULL; - else + } else { prev = lru_to_folio(&folio->lru); + prefetchw(&prev->flags); + } new_gen = folio_inc_gen(lruvec, folio, false, &batch); lru_gen_try_inc_bulk(lrugen, folio, bulk_gen, new_gen, type, zone, &batch); @@ -4452,10 +4454,12 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) != zone, folio); scanned += delta; - if (unlikely(list_is_first(&folio->lru, head))) + if (unlikely(list_is_first(&folio->lru, head))) { prev = NULL; - else + } else { prev = lru_to_folio(&folio->lru); + prefetchw(&prev->flags); + } if (sort_folio(lruvec, folio, sc, tier, bulk_gen, &batch)) sorted += delta;