From patchwork Tue Jun 25 10:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13710840 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 48B49C2BBCA for ; Tue, 25 Jun 2024 10:19:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C35C6B01F7; Tue, 25 Jun 2024 06:19:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E00B6B01FA; Tue, 25 Jun 2024 06:19:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1FC06B02EF; Tue, 25 Jun 2024 06:19:15 -0400 (EDT) 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 AF2F26B02F3 for ; Tue, 25 Jun 2024 06:19:14 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 600F91417C7 for ; Tue, 25 Jun 2024 10:19:14 +0000 (UTC) X-FDA: 82269013428.04.779A446 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf22.hostedemail.com (Postfix) with ESMTP id 056F5C000D for ; Tue, 25 Jun 2024 10:19:11 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=JmDEVsny; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xWktmHdd; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=JmDEVsny; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xWktmHdd; dmarc=none; spf=pass (imf22.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719310741; a=rsa-sha256; cv=none; b=dr5by6McKMZtGVOOF3lhkTQUYM/2MAedPraVjHbnNIwfsRzVeidX1AYcBLlTltNJz6kY3M o3UAbwR2SQQXHN77arB9l6Bct0oMxaPjcozO0s6febaDkNCV6fm2XqtXDNAZR13NFs3HZb HLmWAAKvXBYHf8D8qOgqt+gaNIQEapU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=JmDEVsny; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xWktmHdd; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=JmDEVsny; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=xWktmHdd; dmarc=none; spf=pass (imf22.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719310741; 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:in-reply-to:references:references:dkim-signature; bh=t1HXAqj4fgZF3IBo1CB4bn3i39dMk3y6JrzdfxQccxs=; b=W2hMry7Ohf9hk2lDERdHTDqKVF6o7c2K1hC+UHdA7VO63bNPWbMrO91u8gUN/jsvdduYi5 R8JT9Z3ndnxe/t9LdDg5+nJimxSAc+CTYo430pob5HkTIJG43OIixASut3Vn/gkQT1ZtKN lD6u9n2u+SCZ2kyPnu8cVXXrZ4aYXkE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 9AA5A1F850; Tue, 25 Jun 2024 10:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1719310750; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t1HXAqj4fgZF3IBo1CB4bn3i39dMk3y6JrzdfxQccxs=; b=JmDEVsnyYknVUA8/3NzWzbdFr1DvMcLwFTk51FWNZUb+5+ubt7ec2MOHPKj+l4uwoR09GG ucPE+ngfD5BDg/AaAyXUUgW2mBsj3Hb6cXwSozaSbXn7VgA0fmvFw+pEVLsZxRo7ZRs1on ltAagy5F+Tf/B8+HZP7UkqoyARUySV0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1719310750; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t1HXAqj4fgZF3IBo1CB4bn3i39dMk3y6JrzdfxQccxs=; b=xWktmHddUmOllDfb/XAwt8UC0TSzeT0lKN1u4Ub0oLuIeaLdYkC0YpAuszw7LfrBFiqCkq YUAW1W26baZgL0AA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1719310750; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t1HXAqj4fgZF3IBo1CB4bn3i39dMk3y6JrzdfxQccxs=; b=JmDEVsnyYknVUA8/3NzWzbdFr1DvMcLwFTk51FWNZUb+5+ubt7ec2MOHPKj+l4uwoR09GG ucPE+ngfD5BDg/AaAyXUUgW2mBsj3Hb6cXwSozaSbXn7VgA0fmvFw+pEVLsZxRo7ZRs1on ltAagy5F+Tf/B8+HZP7UkqoyARUySV0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1719310750; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t1HXAqj4fgZF3IBo1CB4bn3i39dMk3y6JrzdfxQccxs=; b=xWktmHddUmOllDfb/XAwt8UC0TSzeT0lKN1u4Ub0oLuIeaLdYkC0YpAuszw7LfrBFiqCkq YUAW1W26baZgL0AA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8E90213ADB; Tue, 25 Jun 2024 10:19:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2mbNIp6ZemaEWQAAD6G6ig (envelope-from ); Tue, 25 Jun 2024 10:19:10 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 11A80A0959; Tue, 25 Jun 2024 12:19:10 +0200 (CEST) From: Jan Kara To: Cc: Andrew Morton , Matthew Wilcox , , Jan Kara Subject: [PATCH 09/10] readahead: Fold try_context_readahead() into its single caller Date: Tue, 25 Jun 2024 12:18:59 +0200 Message-Id: <20240625101909.12234-9-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240625100859.15507-1-jack@suse.cz> References: <20240625100859.15507-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3529; i=jack@suse.cz; h=from:subject; bh=1E7MXXKYPrw3MTlpAhRlnbE6/sd+3vrz3Oi0fWfrESc=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBmepmTxfL2AnX6xjFCTZIXemzzgVjcZY/mbaACqC9D b7l4ukeJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZnqZkwAKCRCcnaoHP2RA2ULTCA C42Af5j1m3W6QOH/yr7+kHSYKnjj2QgCuJyEAbWwVKxOCcN0N+Olqw/+ZO6BVqISD2Q/SX/2YDQjtg whoRGFB4y2QbNjVofmkB2/cq7eSQ2oapnZf/6pVaZtb7teQuRHR0ID43l53sDCZlzl6YzWvaeEFozi rgrtmGjwY+Ve5HoBGdP6QpWfFuxepgabt5TPSFL2xz3rK5f8hE4VC5kASIC/0OoyjpXzNC0G3lOvcX xcJmK34oh6y2TjAKbnqw+8K/cliMtIvzPshjtC5jKg7HD31j4Y6bpC//o6MZIJdmGOdAK3++or2InK tQsfNhcns6P6G7J+UrQMQRGBFVFtFE X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Rspamd-Action: no action X-Rspamd-Queue-Id: 056F5C000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mc4ousepmctoymmhj8oxhrt75ak11o77 X-HE-Tag: 1719310751-388570 X-HE-Meta: U2FsdGVkX1/0Dq5BLOyBf5vlAcpaBlTqZVTuFleDlooYoddCX0IqBolQUz0xxR2buDuKO9hBnWXJGRZUQs/J/jZ3ZAuFckrHfatvi1FQ0jv+gQqrjh7qAPW6Ui96S5nh55Bp7Rd6CUjHnwhZpGAGbYc3RJBaqxCfe/et5xrjpuR571i1XaSiuVvpWhjZpxM9vT3d0j62OixMKc4EcVJ62S27ws6QiENpAYmaX4D3msH/eZthfO+CBJrbCvRcDyYPRQJ7pIaKjqbQ+Fu/vgZhx/WzLvTjw8HmWUum2lm0ZywMV15hj8qmDJs8Gw9PVTMvNm4BzejV7C7gcr2xbB1r4wa3r8CxZPjnsaA5b1JVqAXecNAJR/PvT5E0+/05YD2ElM6Rjyd/McVpN6mslcGAf/a6vutF+8Iq4OmUDf6zKHh+1SPSF6dcdaGWiX+ojh1QdghLaTqG8lNo2Q5PqKQSg9Z2Mga0CYEabvuJenSSF7yuGhAGm/Sz5zS1MdhI0k1SLvzyJOJXtWL3R2e0LBdjxZ3HYOf49X+J4Sfp2pspU13QHdomcubDVVnYLSZL3ldbomwgp61E3HHQrtRZzN3udkfasVGlv8oaFlKm71Ji4+s9dx2cIAJyYGprVQwZ5fKTqTIWitokD9ZKVMDsay8i7mgYq8LqkhjrFr65g13W2QHPSYpQvU790VUvwCmLejvfAA/8o+h78g69DX0RtkGlOUt/QVtlJKUCzYYQRk0YyzaeTqaZev5GWaoaG+FtttoFOgtWJDSUsdPyZbSkFtvLZYJGjKHshJvQWswYJANqUbiy8S6ykrm5Utdu1Zr+R01rGKqBhyCXclN2pcZsCXadT/xKhh6oAj8t8DVfRbdQ+dLXp4XeDF6Ew1KZteQIhWx55q1idk3ubVGJhHDME5E36MRqNBxBwHuZ2kd8b/C/hQdbvvfFZfH9DETuX5gTG72c6akug0qszmEiyR3W1T0 LUA9ZSDM DcdVJVFNFVvlCoNwNP81EceojovRHweCqr31zoPBlpVbQGDQd4ncOBjDxpJlTVliW7dSwxOTwXNzKUI7aD1j+NvoSHPCAERK/eFcxamPlq6p65XrHdoGSjsfGot9GIFC+t70hR8KoeKZ8XZubMcUIgNr2Zmw8YopJblUIwGX3tXO0J7ZnbkI4cgLuwXxxw1gH+6ZHaG8msDsO74DANHfkasDBVnPpAWOqxPoveX5dO9d4MH8WVdwczVrS82WfAaXWxW1M X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: try_context_readahead() has a single caller page_cache_sync_ra(). Fold the function there to make ra state modifications more obvious. No functional changes. Signed-off-by: Jan Kara --- mm/readahead.c | 84 +++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 62 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index a44daa12ebd2..12c0d2215329 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -410,58 +410,6 @@ static unsigned long get_next_ra_size(struct file_ra_state *ra, * it approaches max_readhead. */ -/* - * Count contiguously cached pages from @index-1 to @index-@max, - * this count is a conservative estimation of - * - length of the sequential read sequence, or - * - thrashing threshold in memory tight systems - */ -static pgoff_t count_history_pages(struct address_space *mapping, - pgoff_t index, unsigned long max) -{ - pgoff_t head; - - rcu_read_lock(); - head = page_cache_prev_miss(mapping, index - 1, max); - rcu_read_unlock(); - - return index - 1 - head; -} - -/* - * page cache context based readahead - */ -static int try_context_readahead(struct address_space *mapping, - struct file_ra_state *ra, - pgoff_t index, - unsigned long req_size, - unsigned long max) -{ - pgoff_t size; - - size = count_history_pages(mapping, index, max); - - /* - * not enough history pages: - * it could be a random read - */ - if (size <= req_size) - return 0; - - /* - * starts from beginning of file: - * it is a strong indication of long-run stream (or whole-file-read) - */ - if (size >= index) - size *= 2; - - ra->start = index; - ra->size = min(size + req_size, max); - ra->async_size = 1; - - return 1; -} - static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index, pgoff_t mark, unsigned int order, gfp_t gfp) { @@ -561,8 +509,8 @@ void page_cache_sync_ra(struct readahead_control *ractl, pgoff_t index = readahead_index(ractl); bool do_forced_ra = ractl->file && (ractl->file->f_mode & FMODE_RANDOM); struct file_ra_state *ra = ractl->ra; - unsigned long max_pages; - pgoff_t prev_index; + unsigned long max_pages, contig_count; + pgoff_t prev_index, miss; /* * Even if readahead is disabled, issue this request as readahead @@ -603,16 +551,28 @@ void page_cache_sync_ra(struct readahead_control *ractl, * Query the page cache and look for the traces(cached history pages) * that a sequential stream would leave behind. */ - if (try_context_readahead(ractl->mapping, ra, index, req_count, - max_pages)) - goto readit; - + rcu_read_lock(); + miss = page_cache_prev_miss(ractl->mapping, index - 1, max_pages); + rcu_read_unlock(); + contig_count = index - miss - 1; /* - * standalone, small random read - * Read as is, and do not pollute the readahead state. + * Standalone, small random read. Read as is, and do not pollute the + * readahead state. */ - do_page_cache_ra(ractl, req_count, 0); - return; + if (contig_count <= req_count) { + do_page_cache_ra(ractl, req_count, 0); + return; + } + /* + * File cached from the beginning: + * it is a strong indication of long-run stream (or whole-file-read) + */ + if (miss == ULONG_MAX) + contig_count *= 2; + ra->start = index; + ra->size = min(contig_count + req_count, max_pages); + ra->async_size = 1; + goto readit; initial_readahead: ra->start = index;