Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1043215lqd; Thu, 25 Apr 2024 04:38:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUK19l3mZcNsa8PJAECNETaM9tsx4Lxqxcvih/fNCtZF+fzJLYcHgB0mT62fbMLi3eMXmm1oFTYw6HZ8sfYyVSw205BDQGuh6c4AyMBgg== X-Google-Smtp-Source: AGHT+IEPaAB/MF8tfOoia1u77+NU7WNyppz6j1UKEnlYW6oE4vW6Xj77FN9CmW0bFr0CXtf7Xsd0 X-Received: by 2002:a17:906:4353:b0:a52:33b0:fcb1 with SMTP id z19-20020a170906435300b00a5233b0fcb1mr3189839ejm.32.1714045118007; Thu, 25 Apr 2024 04:38:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714045117; cv=pass; d=google.com; s=arc-20160816; b=WHbVK1Ku+QQz+YQ+HlngJzvQ0hr2nAbjuHdkfpnOxZRlPZOe5Q7SzaFMCMZuVCYOJm 2WTC3ACyXhhaX3REFt8JgbQpI+AW/yIw7KohLqmSm81sgFDoLSA6GpImOHiSlZWNJq41 Q6I5En9oLHHLiOiFD6NhVHBO6FuazPRYhSchVZpWDrc8mZu8CmSjrNiMBYgP8T6UXAm3 y1DpP6lfEbeIDh8wmrLGemCUh3B1ZYhFIGs6s+i3lYppSP/ipiu/N3H70A9HJsolEY0X 4fwIbG9AdYgvoKT0WIVNBagKrN/UPt2ucFyHDLwqZK1KzpG9vGYy9IpoNx2UWWpxtLJj teZg== 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=fe/EkxT/4tbsQ0E/aktsfNPPVKoCmEm9S5NSTYBj3tk=; fh=AC6j17aBHSL5HsK8cY4ELsf/ZPirpNG+gef8M2C/TAc=; b=v0fLo7Za0jy2wtuDxB74BI7rVxN4LeF7kzTrb2XnZOJ+40bElU6gEKMgp9TB/KAlf4 ru2D6J98Ds73ofV07RQz4Rc6SPAd7Mmc06XCNjPdRs6cq+g/0dy7JchBh0qt+3ZWAp2/ I5MIT7Q7eg427hUixysT33Z+xt5U699+Tv1Q1ARxgEQKD20kzmCjVJEaeMjXKSYVoezG zPOtsmw01SYHmYRUh+2QaOVm47afNXsFHbDpMHzhSrWksum4KClekquxMhkrENgX5BQu k9osEwQd5aWmg5OfX3QJVs7CQ4HG4aCakat1GXmKnLSSyT7FpiL0SKjF74TD9UGLWIRi IFLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=cQcJGDBL; 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-158457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158457-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a2-20020a1709062b0200b00a55af41acd2si5636028ejg.3.2024.04.25.04.38.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 04:38:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=cQcJGDBL; 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-158457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158457-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id B5EEB1F22C1F for ; Thu, 25 Apr 2024 11:38:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47DC012BF1D; Thu, 25 Apr 2024 11:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="cQcJGDBL" Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (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 B5EB512AAE8; Thu, 25 Apr 2024 11:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714045087; cv=none; b=iKlwQpllIw+ZNYDUXshhA1ln0YArN9L9g7fVCKc3s7PCa7Z4nAUcGxdTVpJ73PjIIqvKRkFwVMRqGflld8c+inribQkS3KW1iEkSrEZHTb1kRjN5O9F3SS4peGfQ76IZd/urQ1etqbepFSQljJIVIzF15WhsiB0OnAK6Oq2Y0xk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714045087; c=relaxed/simple; bh=dAb52hpNjJqYCkHB6e1HLiI7yzESYqD4M929IAgDDoQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m5KmBE2T6Ph/g5o2EA3WLNbZoH1fviB9inESCB4fZNaSccaRqdFNG034aWaXFpSqNn+O2HpEdIR298WMtQrgrNop00eb6s04x3/bpms7Jt8Esjzp0twEWuBgalZZntR5ZbTQJHnk9NXyXW/bW/5jU1KQEhW6Mdn2IzOPnzV0N1s= 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=cQcJGDBL; arc=none smtp.client-ip=80.241.56.151 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 smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.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-101.mailbox.org (Postfix) with ESMTPS id 4VQDPJ23mVz9sPv; Thu, 25 Apr 2024 13:37:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1714045076; 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=fe/EkxT/4tbsQ0E/aktsfNPPVKoCmEm9S5NSTYBj3tk=; b=cQcJGDBLAl1dtJxy2kvDsF3al40H5eNmF+KJhBHUl9EJFN42VOJQ+eT0kKwRT7JcFsKb93 X650sGma4M8zKkqAEZvRZSU/z8fEza1NcUiq8h6r+Lw2TlOS/Al7Uxk92R+ziwxPd8KTFr 8GwuqK1plMMpyev89NoAiITarFI/PiKOaT5bsa4J8u4QrCVuK/6Db1KadTwqtE7ZGCU69j SEkRtAo4DoUk3WNvBQgnHOsP+o/CSH7V/HAZ1szftyz1TLk8iQuaVgBdm524Lhsrr4fBuD hDmfrjD8Lai7/Ufz7ZtNtkaGft4Ejr4EMY/v2vMTfonhZKN0sPYlHF5tSw8ctg== From: "Pankaj Raghav (Samsung)" To: willy@infradead.org, djwong@kernel.org, brauner@kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, hare@suse.de, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, p.raghav@samsung.com Subject: [PATCH v4 01/11] readahead: rework loop in page_cache_ra_unbounded() Date: Thu, 25 Apr 2024 13:37:36 +0200 Message-Id: <20240425113746.335530-2-kernel@pankajraghav.com> In-Reply-To: <20240425113746.335530-1-kernel@pankajraghav.com> References: <20240425113746.335530-1-kernel@pankajraghav.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Note that the index is incremented by 1 if filemap_add_folio() fails because the size of the folio we are trying to add is 1 (order 0). 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 130c0e7df99f..2361634a84fd 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -208,7 +208,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 @@ -226,7 +226,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)) { @@ -239,8 +239,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; } @@ -252,13 +252,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); } /* -- 2.34.1