From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23F0F18732E for ; Wed, 6 Nov 2024 01:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730854824; cv=none; b=Pl2LNVvKhe5T5ahdKghLuxghg7EZ8yfY0EVq5D7F0sMjlI0ZEMpLlcxdl3C6vj6K0MHLa28fl1gGClaMA8JNparlo593dhsr1+jFi8qJaid2Kf22jciFTG5l4YQtpEDEEXxB3LJoK4yEZDX+JvnqT8QDpzNJ+q97A1DvyTsOZIk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730854824; c=relaxed/simple; bh=PdLbj+fEMLoq0Vl2bWyFvgz6y03sYJzEzrPL7nes2yM=; h=Date:To:From:Subject:Message-Id; b=NdKhHdVBmu+VmwKRl+Ln6qug3BnqDkshtZExfeOiZKwBbJD5+3OoPF84nhmXUzreS18cyV9JLAbrIXl/Ol97QGPM5HeFoQ7FyauvW1KV5FV3JzqdonHho3ulQn5SviMAjmif53zO3GCET/WaGLV0tL3IFv++kYIO/UPoDxxWaoU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=mZXAIJcl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="mZXAIJcl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F88DC4CECF; Wed, 6 Nov 2024 01:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1730854823; bh=PdLbj+fEMLoq0Vl2bWyFvgz6y03sYJzEzrPL7nes2yM=; h=Date:To:From:Subject:From; b=mZXAIJclnRmS0hbCDbyT9PhNyfRS0R4icr3nigyX+U+oIasW7SSFnRdrhP5oxA436 3aGhilSrzUtckTNnNJzgAUgaCmACHCeXV4IuWdejg7FSh+oLdW9tcRlAwgzUD8TFab Q45SrG+fYy/BmVoEiOvqchLjOYkoDGSjFnXDWLrM= Date: Tue, 05 Nov 2024 17:00:23 -0800 To: mm-commits@vger.kernel.org,willy@infradead.org,mcgrof@kernel.org,p.raghav@samsung.com,akpm@linux-foundation.org From: Andrew Morton Subject: [merged mm-stable] mm-dont-set-readahead-flag-on-a-folio-when-lookahead_size-nr_to_read.patch removed from -mm tree Message-Id: <20241106010023.9F88DC4CECF@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The quilt patch titled Subject: mm: don't set readahead flag on a folio when lookahead_size > nr_to_read has been removed from the -mm tree. Its filename was mm-dont-set-readahead-flag-on-a-folio-when-lookahead_size-nr_to_read.patch This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: Pankaj Raghav Subject: mm: don't set readahead flag on a folio when lookahead_size > nr_to_read Date: Thu, 17 Oct 2024 08:23:42 +0200 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. For example, readahead window was created, but the file was truncated before the readahead starts. do_page_cache_ra() will clamp the nr_to_read if the readahead window extends beyond EOF after truncation. If this happens, readahead flag should not be set on any folio on the current readahead window. The current calculation for `mark` with mapping_min_order > 0 gives incorrect results when lookahead_size > nr_to_read due to rounding up operation: index = 128 nr_to_read = 16 lookahead_size = 28 mapping_min_order = 4 (16 pages) ra_folio_index = round_up(128 + 16 - 28, 16) = 128; mark = 128 - 128 = 0; # offset from index to set RA flag In the above example, the lookahead_size is actually lying outside the current readahead window. Without this patch, RA flag will be set incorrectly on the folio at index 128. This can lead to marking the readahead flag on the wrong folio, therefore, triggering a readahead when it is not necessary. Explicitly initialize `mark` to be ULONG_MAX and only calculate it when lookahead_size is within the readahead window. Link: https://lkml.kernel.org/r/20241017062342.478973-1-kernel@pankajraghav.com Fixes: 26cfdb395eef ("readahead: allocate folios with mapping_min_order in readahead") Signed-off-by: Pankaj Raghav Cc: Luis Chamberlain Cc: Matthew Wilcox Signed-off-by: Andrew Morton --- mm/readahead.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/mm/readahead.c~mm-dont-set-readahead-flag-on-a-folio-when-lookahead_size-nr_to_read +++ a/mm/readahead.c @@ -206,9 +206,9 @@ void page_cache_ra_unbounded(struct read unsigned long nr_to_read, unsigned long lookahead_size) { struct address_space *mapping = ractl->mapping; - unsigned long ra_folio_index, index = readahead_index(ractl); + unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long mark, i = 0; + unsigned long mark = ULONG_MAX, i = 0; unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); /* @@ -232,9 +232,14 @@ void page_cache_ra_unbounded(struct read * index that only has lookahead or "async_region" to set the * readahead flag. */ - ra_folio_index = round_up(readahead_index(ractl) + nr_to_read - lookahead_size, - min_nrpages); - mark = ra_folio_index - index; + if (lookahead_size <= nr_to_read) { + unsigned long ra_folio_index; + + ra_folio_index = round_up(readahead_index(ractl) + + nr_to_read - lookahead_size, + min_nrpages); + mark = ra_folio_index - index; + } nr_to_read += readahead_index(ractl) - index; ractl->_index = index; _ Patches currently in -mm which might be from p.raghav@samsung.com are