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 59E4AD1AD3B for ; Wed, 16 Oct 2024 10:06:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D16D76B0082; Wed, 16 Oct 2024 06:06:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9DC36B0083; Wed, 16 Oct 2024 06:06:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3EA86B0088; Wed, 16 Oct 2024 06:06:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9227B6B0082 for ; Wed, 16 Oct 2024 06:06:54 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4BF5CA1B38 for ; Wed, 16 Oct 2024 10:06:36 +0000 (UTC) X-FDA: 82679036496.23.A513B74 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf16.hostedemail.com (Postfix) with ESMTP id A6523180009 for ; Wed, 16 Oct 2024 10:06:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=hVNs7IMv; spf=pass (imf16.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729073068; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sOzG0cX3sai5dakTTrL0FJHVbrUqwT6b+G39uDNzeQc=; b=QpwtAuKCamUrqJbwSoyvkVYb+xz5nVY0Opvt4LMKd7lAQdh4lV5ROhbDuS/jgIbFpQ77g7 c65DtvO8JgrY6SC6YS9qYtqdksO/m+3BmRv5Tf1qdMPHJsOCn6JSygwX6PSsxJu925aXpA 50IoACGDpG9xuu5IB3kvua3IpW/lFkY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729073068; a=rsa-sha256; cv=none; b=rrFCXotSjd1yNIxJL3MYrqBLeI8zIoZiaURH4qlxd/tbjPY60nIgEkWxyVnohqR7NyEUVs Z2h+vSWhAJaemBWmY3iH4ZEg+IDh274HaB28IBdPEmtx3LBdXHhtKWJrH8KT/4voHaZt9k MU+b42VzEJIW/2U9JnPNbkUilBSFjVw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=hVNs7IMv; spf=pass (imf16.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4XT67q19ZYz9tSH; Wed, 16 Oct 2024 12:06:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1729073207; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sOzG0cX3sai5dakTTrL0FJHVbrUqwT6b+G39uDNzeQc=; b=hVNs7IMvyZxZVObgylgjWNpB2G4SBMa/ka4yRUBmpRzK1FazRa6rDaq6xdI+llHB2cCURi CHCYxfnQCfPvAL3Sx/eoEG5VhDIOWbWLbq4MTBgkLnI+wO/yP3KULWxJB3LaDkLeE1HO4T ShGpTjDdyHECSUMZuyYgfe37UTz/w4hLq8SnZsAL/Ezo/l6L6onwLU8s+MAVyOWxnNTtk0 tU6ZvWX/pBCAeGOVgpQnnmcJ1XZk1z7lrEfeJ9Ojdo8/3t/nxE9BzWCLayRZ/zDzrWcHPw LiIfwoVbUmbhxodqdH0mSud5w5HxqVoN6oKeA4H/FvBzB+Ltd+eZTfaVeO3cEA== Date: Wed, 16 Oct 2024 15:35:27 +0530 From: "Pankaj Raghav (Samsung)" To: Matthew Wilcox Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, Pankaj Raghav Subject: Re: Re: [PATCH v14] mm: don't set readahead flag on a folio when lookahead_size > nr_to_read Message-ID: References: <20241015164106.465253-1-kernel@pankajraghav.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A6523180009 X-Stat-Signature: 8rjt9gw3qtyfnhmzzdw1xf33xnxk7wxx X-HE-Tag: 1729073203-502971 X-HE-Meta: U2FsdGVkX1+QpfFqM12wvmvFV+SCro4adOyzhbHVqJYRtMF7iRj38dEUnC64rx8W35fuFhKIktGHZX64L1sybsfgUe0Gb+rVcc28gkxB5Ok3nlxAA+BZ+gXQ4UA4MUJZ2cPGG/z9365Kyxu6I/naHnWvV6mxhj67ckbj3OfJ8JGrEsH8POUidWORsgLp6HywFK9O0MPdWlFFV9VGQS1q/6nUyqS2sJp5MRANfsgrlc4OSDP8t2nNJTIISfP1tG8GPKHRuk/hSUuv0ta/qERGdUPaME5HT2fa9vJ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precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Oct 15, 2024 at 06:33:11PM +0100, Matthew Wilcox wrote: > On Tue, Oct 15, 2024 at 06:41:06PM +0200, Pankaj Raghav (Samsung) wrote: > > v14? Where are v1..13 of this patch? It's the first time I've seen it. Sorry for the confusion. My git send script messed up the version number. It is v1 :) > > > The readahead flag is set on a folio based on the lookahead_size and > > nr_to_read. For example, when the readahead happens from index to index > > + nr_to_read, then the readahead `mark` offset from index is set at > > nr_to_read - lookahead_size. > > > > There are some scenarios where the lookahead_size > nr_to_read. If this > > happens, readahead flag is not set on any folio on the current > > readahead window. > > Please describe those scenarios, as that's the important bit. > Yes. I will do that in the next version. do_page_cache_ra() can clamp the nr_to_read if the readahead window extends beyond EOF. I think this probably happens when readahead window was created and the file was truncated before the readahead starts. > > There are two problems at the moment in the way `mark` is calculated > > when lookahead_size > nr_to_read: > > > > - unsigned long `mark` will be assigned a negative value which can lead > > to unexpected results in extreme cases due to wrap around. > > Can such an extreme case happen? > I think this is highly unlikely. I will probably remove this reason from the commit message. It was just a bit weird to me that we are assigning a negative number to an unsigned value which is supposed to be the offset. > > - The current calculation for `mark` with mapping_min_order > 0 gives > > incorrect results when lookahead_size > nr_to_read due to rounding > > up operation. > > > > Explicitly initialize `mark` to be ULONG_MAX and only calculate it > > when lookahead_size is within the readahead window. > > You haven't really spelled out the consequences of this properly. > Perhaps a worked example would help. > Got it. I saw this while running generic/476 on XFS with 64k block size. Let's assume the following values: index = 128 nr_to_read = 16 lookahead_size = 28 mapping_min_order = 4 (16 pages) The lookahead_size is actually lying outside the current readahead window. The calculation without this patch will result in incorrect mark as follows: ra_folio_index = round_up(128 + 16 - 28, 16) = 128; mark = 128 - 128 = 0; So we will be marking the folio on 0th index with RA flag, even though we shouldn't have. Does that make sense? > I think the worst case scenario is that we set the flag on the wrong > folio, causing readahead to occur when it should not. But maybe I'm > wrong? You are right. We might unnecessarily trigger a readahead where we should not. I think it is good to mention this consequence as well in the commit message to be clear. -- Pankaj