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 E9B7B1B424F for ; Tue, 2 Dec 2025 01:32:16 +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=1764639137; cv=none; b=D3P9BTSSS3aN1e42QWAAtRGXdV7xYqE7bHmau9BYC8eF7lEfDr0lwmSz4u/r2xC7nnE6u+AeitPY9JCFAR9Gp0qTIf97e5FJ2ruzj1SIrwChOLIcR6o9wRGF0rzzhnLYbTDwNV47sTyoBuTePOAvAhi6YsQN3DOZlaLgYmEEvZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764639137; c=relaxed/simple; bh=z6z126FwDohXSBIi//EiTH/Ua9V8Bx+8xe2h++oSC/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WLon457VpM9byPJ6rjmm9JNdaP8+CYx6gS5YeNH/EiC4jYUI+cf4q+yMc3jpoXy8hrAcgdiVpfmUULzCuqPgVC5dwBGnX+x0s/Vs7HIPHVDpgAiAQwFsqy0rPCGw5+ZSR2PIgBD4v7jZNQ1jQVdOTrYpQ0EPif6M4AiSsw9tZEs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BMdF5Nvq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BMdF5Nvq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8BEEC4CEF1; Tue, 2 Dec 2025 01:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764639136; bh=z6z126FwDohXSBIi//EiTH/Ua9V8Bx+8xe2h++oSC/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BMdF5NvqRQkK+ZJ0ZjCy1m6t6TvoYZOVzc4ugrFnriNRhJSKdHn487GhC1afnkTVw IBcD2j8tohMqJnyCo+2V443u+tIACDE5iGt9sos1gYQBwGnzQQaGEKMz0eowUIacyx vREAcGpa3Zge8LmKIeQDw9BRV+ORe6IVaHkwzGu/+BAPnXjSB5cD2Qw49LGMcACSJs SUBV3IfHXWUxQOruHghEareLoVTbBN3Iwg2nrfe/jeeP4lpXFJFla3OkEmGTToqivj TWwsSeYa/0inI9n1Hp0eVmBx/2el8JNXDmXyC3jgvQjetbnGueVQKyclGbJvp0URzM KrA99eL5jxlSA== From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mm@kvack.org, Matthew Wilcox Cc: Jaegeuk Kim Subject: [PATCH 1/3] mm/readahead: fix the broken readahead for POSIX_FADV_WILLNEED Date: Tue, 2 Dec 2025 01:30:11 +0000 Message-ID: <20251202013212.964298-2-jaegeuk@kernel.org> X-Mailer: git-send-email 2.52.0.107.ga0afd4fd5b-goog In-Reply-To: <20251202013212.964298-1-jaegeuk@kernel.org> References: <20251202013212.964298-1-jaegeuk@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch fixes the broken readahead flow for POSIX_FADV_WILLNEED, where the problem is, in force_page_cache_ra(nr_to_read), nr_to_read is cut by the below code. max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); nr_to_read = min_t(unsigned long, nr_to_read, max_pages); IOWs, we are not able to read ahead larger than the above max_pages which is most likely the range of 2MB and 16MB. Note, it doesn't make sense to set ra->ra_pages to the entire file size. Instead, let's fix this logic. Before: f2fs_fadvise: dev = (252,16), ino = 14, i_size = 4294967296 offset:0, len:4294967296, advise:3 page_cache_ra_unbounded: dev=252:16 ino=e index=0 nr_to_read=512 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=512 nr_to_read=512 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=1024 nr_to_read=512 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=1536 nr_to_read=512 lookahead_size=0 After: f2fs_fadvise: dev = (252,16), ino = 14, i_size = 4294967296 offset:0, len:4294967296, advise:3 page_cache_ra_unbounded: dev=252:16 ino=e index=0 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=2048 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=4096 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=6144 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=8192 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=10240 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=12288 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=14336 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=16384 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=18432 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=20480 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=22528 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=24576 nr_to_read=2048 lookahead_size=0 ... page_cache_ra_unbounded: dev=252:16 ino=e index=1042432 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=1044480 nr_to_read=2048 lookahead_size=0 page_cache_ra_unbounded: dev=252:16 ino=e index=1046528 nr_to_read=2048 lookahead_size=0 Cc: linux-mm@kvack.org Cc: Matthew Wilcox (Oracle) Signed-off-by: Jaegeuk Kim --- mm/readahead.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 3a4b5d58eeb6..e88425ce06f7 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -311,7 +311,7 @@ EXPORT_SYMBOL_GPL(page_cache_ra_unbounded); * behaviour which would occur if page allocations are causing VM writeback. * We really don't want to intermingle reads and writes like that. */ -static void do_page_cache_ra(struct readahead_control *ractl, +static int do_page_cache_ra(struct readahead_control *ractl, unsigned long nr_to_read, unsigned long lookahead_size) { struct inode *inode = ractl->mapping->host; @@ -320,45 +320,42 @@ static void do_page_cache_ra(struct readahead_control *ractl, pgoff_t end_index; /* The last page we want to read */ if (isize == 0) - return; + return -EINVAL; end_index = (isize - 1) >> PAGE_SHIFT; if (index > end_index) - return; + return -EINVAL; /* Don't read past the page containing the last byte of the file */ if (nr_to_read > end_index - index) nr_to_read = end_index - index + 1; page_cache_ra_unbounded(ractl, nr_to_read, lookahead_size); + return 0; } /* - * Chunk the readahead into 2 megabyte units, so that we don't pin too much - * memory at once. + * Chunk the readahead per the block device capacity, and read all nr_to_read. */ void force_page_cache_ra(struct readahead_control *ractl, unsigned long nr_to_read) { struct address_space *mapping = ractl->mapping; - struct file_ra_state *ra = ractl->ra; struct backing_dev_info *bdi = inode_to_bdi(mapping->host); - unsigned long max_pages; + unsigned long this_chunk; if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; /* - * If the request exceeds the readahead window, allow the read to - * be up to the optimal hardware IO size + * Consider the optimal hardware IO size for readahead chunk. */ - max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); - nr_to_read = min_t(unsigned long, nr_to_read, max_pages); + this_chunk = max_t(unsigned long, bdi->io_pages, ractl->ra->ra_pages); + while (nr_to_read) { - unsigned long this_chunk = (2 * 1024 * 1024) / PAGE_SIZE; + this_chunk = min_t(unsigned long, this_chunk, nr_to_read); - if (this_chunk > nr_to_read) - this_chunk = nr_to_read; - do_page_cache_ra(ractl, this_chunk, 0); + if (do_page_cache_ra(ractl, this_chunk, 0)) + break; nr_to_read -= this_chunk; } -- 2.52.0.107.ga0afd4fd5b-goog