From patchwork Fri Mar 1 16:44:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 209289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp844203dyc; Sun, 3 Mar 2024 01:50:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqADk+aFDi5YTGo5ggWm5gYWrdEXBz6m83q7FfuqYQaVCCK56pg0V3wmhcMBNyxGltKfCS29Mrrd7KmZSYosQqxZ1ImA== X-Google-Smtp-Source: AGHT+IFfrv2dK0H6aIS9jqZ9RZlz1iWybxwbm7Mktwkqu3j3Iv+oNbqrBghwPiQF26XoAa74IONc X-Received: by 2002:a05:620a:5755:b0:788:21c3:be3a with SMTP id wj21-20020a05620a575500b0078821c3be3amr2503872qkn.16.1709459435552; Sun, 03 Mar 2024 01:50:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709459435; cv=pass; d=google.com; s=arc-20160816; b=RvCE1YVdVnDbBf2dpQvfekneINLh++vyNjq6HAgWnhmKL674MrAFmOx5gjw/nBnvvK UErmBEULuParrt9HgOXqtkA878SFUZSugnuD+3XJD1U93REAt3H5NC/ToDZpRIoQMvi/ 8fiEnHJwhYjPlyVIgjQEP0QLLrKZUtSb9lQG2KdiVN5+TVvbago4XPm6oEjre61gX8cF SMrO6b1BS3RxXLFU1IovcYezofi7nbPQcPl0X7Q18mmp139970KF304uGDdxtZe9pos8 gDnl1ffhF+zffM83Y6Q2lBevMS4BCt+pkats6isy/GqAZEMFh9ALU5zpOotxaTBZ4Roj HN9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=467JnvYp6xZwSrqHVz6JwGG/B+XhREWQAJ9IMIxeQus=; fh=XNSrRUwVTzpEiSup2LruPjXnnBE4qDGoPoS5h6R7xQ4=; b=SonDGusmgsKAsZzlFtW8tVIY5Fvphb4P4WGrCxZD+vyNMxhde8ZckGbMaAj7BUrhlQ RG9P2BQtf7nVr4S/pAdQgNHuLwidTBdOTM+Zze3GrVwck89uB7XOnsHb/UwhRaRmh6oq PTE0/IPHoaTOSje8kKEPVrR831BD9/L4TM1sUPD5ZLRFkQLGnMtLGrTytWJs8q2lt6ia ptMDNLPNL3eSnQ6Yif2+fLubxVcUUJwULW965CfIsAGdZGahDatc14jQf8PvDb9ClD52 /bUWutUfIKoafKSvgqLV3eUUxrK2lAhAN5GiioIIpmXreL9A7OMySlJz1n0oCBfYS4Li JPsw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=VkAMxpfa; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-88762-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88762-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l24-20020a05620a0c1800b00788214aea18si1552109qki.78.2024.03.03.01.50.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 01:50:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88762-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=VkAMxpfa; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-88762-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88762-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ABEA41C24339 for ; Fri, 1 Mar 2024 16:53:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DED217317E; Fri, 1 Mar 2024 16:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="VkAMxpfa" Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (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 922133EA89; Fri, 1 Mar 2024 16:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709311518; cv=none; b=g1APcb90TJ0eEIwdJsvIs/huAYN8bn5hLkZf10SF2jpurPZcm0WYKQ9RBO1wkINuf68DO/3vlqqQKQN+d3IstOHshDgJetUKRaThYLDMcCLvFeGn9fArQFDrpbHmKzDSb+w9QtWZylwhQ2k+MWDqbxSx8iQVJheVqMcV36QjQiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709311518; c=relaxed/simple; bh=ZTzrN3PfzOk7uvp85ZEBavNp8FF3Rm3QXyiQCAXrJco=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EgHNvuUmvRDxYMqUmoYsX8lrV95XHIJwqwp1+VnzoOKEvKTj2mtS76zDAmTY/QaLfajgvkPJpy43CKmbQdz2rRCX4erLxKpqsYH9kBhssRxRjX7AvkCV0khsIqrPJ+4K4P30Y4MTJhNDKBsIqYEPR4Pk34Zw4qJjQeSeYJAlcwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=VkAMxpfa; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4TmYqF1lVsz9tWG; Fri, 1 Mar 2024 17:45:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311513; h=from:from:reply-to:subject:subject: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=467JnvYp6xZwSrqHVz6JwGG/B+XhREWQAJ9IMIxeQus=; b=VkAMxpfaEVmgbBcyuWtw1txdyYcbaIt4sqlGeJGp4avK/yPIQcy8to9fJZZ3qScgjLTMG0 zZ9hNEFp/oojel/WDhiyAb0dUct7HpNi+jJfzLbKNIueuEmbxVJyZbUht4rQxyC5lh8sMS HT6uu3rN9e8yCRwtkb60yJuBlBx8yoAQTlAbKLMMQDdxFUhoa6mKOfD0v3iZ/6pYAYxmVe Lb60kYjxTwQ5MKjEw4kbxCiUHOFuNB1Ojc9L6Jm6wAx5rq7lhFCLV8t0rmZZF8lVDx9g6W 5GNu5Ozk7Sxh5HXX22l8nX0Ko7gEP5moqmlTnADLEs0uHQPFY4rDTa4vNBGg7A== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 07/13] readahead: rework loop in page_cache_ra_unbounded() Date: Fri, 1 Mar 2024 17:44:38 +0100 Message-ID: <20240301164444.3799288-8-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4TmYqF1lVsz9tWG X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792498137387362889 X-GMAIL-MSGID: 1792498137387362889 From: Hannes Reinecke Rework the loop in page_cache_ra_unbounded() to advance with the number of pages in a folio instead of just one page at a time. Signed-off-by: Hannes Reinecke Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav Acked-by: Darrick J. Wong --- mm/readahead.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 0197cb91cf85..65fbb9e78615 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -209,7 +209,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i = 0; /* * Partway through the readahead operation, we will have added @@ -227,7 +227,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, /* * Preallocate as many pages as we will need. */ - for (i = 0; i < nr_to_read; i++) { + while (i < nr_to_read) { struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { @@ -240,8 +240,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -253,13 +253,14 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, folio_put(folio); read_pages(ractl); ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + i = ractl->_index + ractl->_nr_pages - index; continue; } if (i == nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; + ractl->_nr_pages += folio_nr_pages(folio); + i += folio_nr_pages(folio); } /*