From patchwork Fri Dec 22 10:22:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13503167 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 19C6BC46CD8 for ; Fri, 22 Dec 2023 10:24:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A91B16B0087; Fri, 22 Dec 2023 05:24:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3E2E6B0088; Fri, 22 Dec 2023 05:24:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DF2F6B0089; Fri, 22 Dec 2023 05:24:19 -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 761F26B0087 for ; Fri, 22 Dec 2023 05:24:19 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 497B0407C2 for ; Fri, 22 Dec 2023 10:24:19 +0000 (UTC) X-FDA: 81594069438.24.90B0288 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf07.hostedemail.com (Postfix) with ESMTP id 7603D40005 for ; Fri, 22 Dec 2023 10:24:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RyuoSLFp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.54 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=1703240657; 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=ZVtAklavGTH0ChBjbCr10B7CRN0g8Fxr7pwyrunV9Wg=; b=HT5YOa39raYz3UMFQSvusWZCUh3FIqXVXmJHW792t3uDYxKAxhRWLCNIGTgLu6bVPRmgKk yi+Q68apyf6n00JPNmeQF6Da5EqbjimGiPuPPakbP64k4m/luNbsVUnbzrPBEPxXrWtUnq aZLuFyr0iof/LnZejIxwpI4Obe4Uqyc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RyuoSLFp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703240657; a=rsa-sha256; cv=none; b=JPjLcM36z7uwlqeL4YOlhI7Wocl95FUi13+mx6tAXFaGWrLY3LHjr7rbh6nHhOfZJTOAVr oj5V7aazdOmcYOSpU1rKsshpvYUJRulzZa+2rPeAvAZfKvs458ayP2ol2kZHeOfz+xvVfK fNcv+yLYPTcWe0OP5OmxEvGUVRwaEgA= Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-28bcc273833so1488250a91.1 for ; Fri, 22 Dec 2023 02:24:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703240655; x=1703845455; 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=ZVtAklavGTH0ChBjbCr10B7CRN0g8Fxr7pwyrunV9Wg=; b=RyuoSLFp9suW2h7+RV3rhsukSiuNrv4PxVZ+774QrdAiVF/o9kda1i2ig4dPpAhwwu 47UA7nnOwZYDrsXZ7HgNzaTV5KpvkfaGxWSAwoqsqlYVaTvJlzb0tY3DE4iTkGlACYi2 7BgfH9e5ld/kllA0Fs18pAjRjf7xyOsxeqrTycTy3bYLjbX9CQBnrc2pfL3azpStMwWX KeD0SOLS2pNTs5kOHdNnyLvK5kTKgJ1I792lfuHMSaEXp9JKQugKH5F12iqHEmdiV+YP AXV0oecyo5qAfxreeMT62gsvqO/YcGXFJPO7ZEvxcS8UJLH5pzvrZ5SbHWM6YeDH5iax ndyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703240655; x=1703845455; 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=ZVtAklavGTH0ChBjbCr10B7CRN0g8Fxr7pwyrunV9Wg=; b=Ogc2fAQDQBFB46xLVvVlio8ABHpf/JJR65bi9CM7q2QCgvHNKbnBwWyAW6FsoEPfpf 4fxtWLEy4PMvabHLJcvAq8folEimcUMV00C7uB/wNlOa1AFx38015dVYooUMu4/ajUIC Ytsmx7vJ4AHoxFmtdJyaIZe+oJSnVUEnTy2ZT4cF4B6rUM+cw+LZ6QVS5PN5q8QsqzZC ZiT+yy1Kez7KsU0mZBh6xmsITgQlMxXEfW83GNUtaf+HyQP0PP/0LiiVlk3kNm5qaVlx ycimiJc8qydRxU781Wke1UPg9ngIKl3XhJc6ZoFrNujQ3g96k7Z/S78YrzU2IbsZhgQS wPeQ== X-Gm-Message-State: AOJu0YxWtxkqlcvxOxqDZixzhddBuAQ8h+VwLREhKkESmVBihLNbSDRs K/F4mq3X+gAjlWMH6NLqB2L0/zd3Jy6pW6Nj X-Google-Smtp-Source: AGHT+IFG6ajXG6vALhMWO57ARn52j3Kb6LdriotQIo1jxt6hAcExEanAl4pobD+1sBFGtt0fLivXqg== X-Received: by 2002:a05:6a20:12c9:b0:190:85d9:9d4a with SMTP id v9-20020a056a2012c900b0019085d99d4amr1304221pzg.97.1703240655043; Fri, 22 Dec 2023 02:24:15 -0800 (PST) Received: from KASONG-MB2.tencent.com ([103.7.29.31]) by smtp.gmail.com with ESMTPSA id gx1-20020a056a001e0100b006d9912e9a77sm364074pfb.6.2023.12.22.02.24.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 22 Dec 2023 02:24:14 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Yu Zhao , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 3/3] mm, lru_gen: try to prefetch next page when canning LRU Date: Fri, 22 Dec 2023 18:22:55 +0800 Message-ID: <20231222102255.56993-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231222102255.56993-1-ryncsn@gmail.com> References: <20231222102255.56993-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7603D40005 X-Stat-Signature: 9fueftp8iq8mhnixbxoh9xznku693cw9 X-Rspam-User: X-HE-Tag: 1703240657-17535 X-HE-Meta: U2FsdGVkX1/JiIvKD+M60D9hngq4spDrtOjwdx5GrZbQXy/8KU4wKqPtONB3vSFp2IA11BG1ZI0GjQTJoEa+a5WbHS8fiRANCPMvvWw6z42qP4Sdni0nSxmAY1jnwoZ/0nBT4xegnVm2+d7VDTZS9CnBfqBNuHLLW3lubuKfDH4+kwuTy4P/WtIRZXgr0ZtYkinYcbqQM5fQ3+QaVpl+tJK4fkCuZGh0ufaKoJtO4aUQglBXgPrJQMjLAMFqKhlfdxsz70TmBCfd7/+BmBDSRLXgnaLErMw2QupjLSq05Sqzc1sgjxycLYqgZutGaE5f3kb70+YJt08yJLC6uUeJrqe61TUgWxT7gsP1R7X+3ufL6ryapGN81YLqvW+AKTXR/efvLgvG43rml5QalTHvTu6j7ULIjz3LCnreSKUNR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lP7iwScKbMwI0bB5Qgxlh+1/wcQfZpFTZunqdjxbqZo5SKStcm/AsShQ6lBf0R+zHdGti7dL72JCHHzI1jFl+2g747FowbWTJnVWrL37C1GMk1bEDMwA0iDByAoqehBDTOwfgoUx6lPiN6e0M4xcA30VGYL+Ozni70RNcgvphI07lowmgCTvf+woeo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.013936, 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. Tested 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%) 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 af1266129c1b..1e9d69e18443 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3764,10 +3764,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); @@ -4434,10 +4436,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;