From patchwork Tue Jun 18 11:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Peng X-Patchwork-Id: 13702138 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 CC48CC2BA1A for ; Tue, 18 Jun 2024 11:50:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4708F8D0026; Tue, 18 Jun 2024 07:50:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 420676B034E; Tue, 18 Jun 2024 07:50:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30F308D0026; Tue, 18 Jun 2024 07:50:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0F71C6B034D for ; Tue, 18 Jun 2024 07:50:44 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 749861A082E for ; Tue, 18 Jun 2024 11:50:43 +0000 (UTC) X-FDA: 82243842366.05.470C06C Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf21.hostedemail.com (Postfix) with ESMTP id C18751C0008 for ; Tue, 18 Jun 2024 11:50:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YjzJ6vtx; spf=pass (imf21.hostedemail.com: domain of zhangpengpeng0808@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhangpengpeng0808@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718711438; a=rsa-sha256; cv=none; b=PHrh5UkeYpFMgcZQo4f0rV+w1fK1dl+AKB69/gqQvIu3uq08wHHwV4TkC3dONSI2qKT3Ya R3RqygkKCl883QMgbw9yj/Bdkz2PrFuelc4zELGq7obQYfIQ025pcQAvHxwLKwFTZtCmwZ h+L7F8gvZazQM582WzCDJVO3nN20P9c= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YjzJ6vtx; spf=pass (imf21.hostedemail.com: domain of zhangpengpeng0808@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhangpengpeng0808@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=1718711438; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=5s6/LFX8WRrd2o/jtRmvisL1C8048AZKiXldCA8XPv8=; b=Gp59hT1QTHmhoi2FdtLizll2F/BxwO6mTu1l4LURE5HH0gUyjFvWxD0nVeoh5WWZeMJHND GxJlGODvmOj673PXuxJ/Qbi4AJus/v2bQOI4vJhojQ0HMlFCQvGYbZfCjaQ3gnEPiuk+UT cjOwnEoW0nvghzTzqiwo+HCuCjlx438= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f6559668e1so43330685ad.3 for ; Tue, 18 Jun 2024 04:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718711440; x=1719316240; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5s6/LFX8WRrd2o/jtRmvisL1C8048AZKiXldCA8XPv8=; b=YjzJ6vtxNb75NGMEdnH9arAEK8Oz2a+2IqzshLeZ9nL59wbS1pXjISpq06wIdiqfVr rgGRQ2HSTwgHY99ohC0TcjR/KAiaMVeiRr720lf3MDf6jhlJPAuLczMBk820Lrc9Wt9W dQwErIHz6raC8HpM1cKAnx5d4/SpZF8h0kQVajwWt6MtQgFz9vdC/QgzWR1gZv0cU6Ul qTMLjDhr4TP0cJ6BjkpLXQu7jvf5lePbStSDXGsk1g61wEra0gF2zBH3vZVAtrn++cmo 4mayAc8mY7ctmdYuNWqmLgYMEJAQwlKarrcD6HjKefkirAivsuM7upGcvvq6gaYCOSwc lhLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718711440; x=1719316240; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5s6/LFX8WRrd2o/jtRmvisL1C8048AZKiXldCA8XPv8=; b=j2dliJvPOBv72J2Is4SAnEGT4NUD9uzNJPP02bnTkaM6WP3Kev1OWp1VGYRts+OZFj oRtvWr3tJME3dWvs6ieyJLtZgazHcW98Y0xMVwaxsFOun973D5kRHH9DwyWE2BxvEBlE dsOuKZ5kQztYzhiacKiC7oyg1QcbsWP8WHWSNLGySXdf4CkuxBtJjRFOaIbI5YMuHPlM Cqc3BsGaXwFFeC8s56/Zl2bXpRnttowBVvJUQ7Dt8RnSbDqLOyMBaPbbfLGY2UeQGxLw ex451svplMnlOGLnfw2WE9KMgV+0NL0cRzmRaexKbQmXUxTNZ1pD+1Zid2HWnGyapSTm pQwA== X-Forwarded-Encrypted: i=1; AJvYcCW7H4RaB1o+1ba4hxxBzOuEDXAOvcgAjF5uyA1fOLH/eJc+dWQkaqRFPdt70T97KbYrEQxYBQ5CwVxJZs54sNxwnkM= X-Gm-Message-State: AOJu0YxU5GlKoQwPq8g5G5lKNYlUyNeQ/SenWhL2arSkKEMMrzhOBRwG 1Nr0bTkASmG2SpTGacWdSleBRuvl91gJ3kFt4ORdrKF+Nle7iPG6 X-Google-Smtp-Source: AGHT+IH6Z3j/b0LjFf0GkWIaBhwNo56mHqUE9EsvTcdnjzrbDUZk8I1kDyLDNVWXU4Yb1P3z7Mag0g== X-Received: by 2002:a17:902:d50a:b0:1f7:23d9:f530 with SMTP id d9443c01a7336-1f862a0eadfmr139727715ad.66.1718711440120; Tue, 18 Jun 2024 04:50:40 -0700 (PDT) Received: from BRUZZHANG-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855ee7ce5sm95643995ad.129.2024.06.18.04.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 04:50:39 -0700 (PDT) From: Peng Zhang To: willy@infradead.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: bruzzhang , Rongwei Wang , Vern Hao Subject: [PATCH RFC] mm/readahead: Fix repeat initial_readahead Date: Tue, 18 Jun 2024 19:49:41 +0800 Message-Id: <20240618114941.5935-1-zhangpengpeng0808@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Stat-Signature: zw3mz3p6ipb1mbbw99pwuptfchtqpxze X-Rspamd-Queue-Id: C18751C0008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718711441-537678 X-HE-Meta: U2FsdGVkX18eOTQSTGqeO4682kxq+GU/MWyIXfJ/aXuq6z/r8oncjFeLnpBFA3PzAsk6CL/SXFoaFnXPedqrus2Nz41APL1lNLS20FQDWgjW3XUthA/eVbvjfTznIGx3UrixJ+U9JvP/uokrCqjuFHlQrwAej6tIg9eFQjywP9n0qcztwapB6S4hsl1qzmERtKZlt5CW5INr9V8MLn8slqow9zBO+//6liyjz8nM5HjzIp66BvrnvIPfyMlRIAIF/MQC2LiZupqJbAspNr/qrg5wS5345q+MGd9krYBWygC4wpiM2fum524/RX8KQdydFK7lRAEt5thC4gKeeDIvZeZn+VrLiYu22NmvhFFwK35WZ9V9ttBO/Cm6DnDApVfKzHcQDbf7P0PuJSRGubq2aEph466LBekYy+NFDnxr0Tu4JmiHMy+uCEEROr7t/cZJh0TOM02yj7x/dRvyMUGmutVxUeuUkB7s7zOVcFpFxbGr0BgYb4YdysIvZM5XRd5w40hLYC6FKnm0cfyMhSVIvN8XcyehzKoctHux0I3Wmo70c+66Tuea7LHrLv2c7KHqzjw9/CZS97aKFbgW4dgvAEC2p35Xelq7voVToUDxqpK+LRk2nPA+VpenjVklelTRr8xuWveP1hL636DjjGlv6XzCkhpeuu+3jzE3kQVc2UF0bAGbf2z9CRfAVgc8rkfACiTnVnoC3axDt+rAz4H33AKOj67x3nBrazDpAUKYLO/aw9Rrk11MJm8UzKlOe1IKHbPB1jW6uKecpfgQTlGF3clW+yE5PNO4Vx5V4Qx6Dy3iWwq+KV+LovrBiZyVspO9TXyOGEDRIQbmD/Zj2kXLe94OqyDA+dOnUYY5bDkzLbaV87RycUYlSB9PpK3IA572iewncMk+ekP0s4wJ7UzC/YwVhXYyrcJcR+vdBxEcxp5g3MKtjfKirSfiubUgZN1gUqX+cQnqIvjE3yuuHxF 4KRroyc2 OUGMmIp4FQItiHqSvaS8eXUZZbocS4uyREXBisLW1q+z2JzJx5QnTrLMWpWDKt9oRva1EgX70eu5omQ6m8p8mpJSGguRf4vAcNNsTFHSgoJInaJvxe+oeaBxGamAFVFZBWouG2TodYaGZx7HkUghtm40FzYsFae8dp0zW9LCOGz4TvJ8Ugrj17CKkVnMyY4KtUiUovSwDQWVJ2QcBEX0qlWR5mXGMfmkd+3LbaW6sBs9SKlgMiOXzDA4sX9N71uQRA7x4bgLIxekavrDoh02FS/qycDUhTGSZkPOt7KKKbSzT2lQmDARm4cAi7MG7p6mjD4sBGlTyWFA8uL4eK/a1EWID5pgs1IQC6b1q/wODpIIuUufMX1Ev0ABLddV8eHbQqEL6SxGj/vPFVJI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000923, 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: bruzzhang Now, if read from start of file, readahead state will be repeatly initialized when first time async readahead after sync one. This case likes: sequence read page_cache_sync_readahead() --> ondemand_readahead() <-- initial ra --> folio ready <-- order=2, readahead flags folio_test_readahead(folio) filemap_readahead() <-- async readahead --> ondemand_readahead() <-- initial ra again The second initialization of ra seems a mistake, and right ra window (start, size, async_size) should be (4,8,8) instead of (0,4,3) after async readahead. What's more, this patch can improve sequence read greatly, the result of test as following: case name upstream upstream+fix speedup ---------- -------- ------------ -------- randread-4k-sync 48981.00 48948.0000 -0.0674% seqread-4k-sync 1162630.00 1334915.00 14.8186% randread-4k-libaio 47561.00 49910.00 4.9389% seqread-4k-libaio 1058526.00 1257134.00 18.7627% seqread-1024k-libaio 1365866.00 1411463.00 3.3383% Signed-off-by: bruzzhang Signed-off-by: Rongwei Wang Signed-off-by: Vern Hao --- mm/readahead.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/readahead.c b/mm/readahead.c index c1b23989d..498708b4b 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -571,7 +571,7 @@ static void ondemand_readahead(struct readahead_control *ractl, /* * start of file */ - if (!index) + if (!folio && !index) goto initial_readahead; /*