From patchwork Fri Mar 1 16:44:37 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: 13578744 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 4902AC5478C for ; Fri, 1 Mar 2024 16:45:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87FD6B0093; Fri, 1 Mar 2024 11:45:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C36F56B0095; Fri, 1 Mar 2024 11:45:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD7906B0096; Fri, 1 Mar 2024 11:45:14 -0500 (EST) 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 9B4656B0093 for ; Fri, 1 Mar 2024 11:45:14 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5B6DD1A0176 for ; Fri, 1 Mar 2024 16:45:14 +0000 (UTC) X-FDA: 81849045348.14.94EB620 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 9D0824001A for ; Fri, 1 Mar 2024 16:45:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=sy87xrj0; spf=pass (imf01.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311512; 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=fyszdUSBCFtEWqaMFYCTrgSY4YVZLc+Vs7TuxxQjQl4=; b=ES1X+j1XZbZFj0SsFP3UahUUAUj5jjauS9XBkY6Abnt3LY5xQrV1RkTFhQh7FvkCTijA8M DkYRbLm7pDsjVqnx8Dp+JZt7kSHxesZVc6xmTq9MpKRy0vLFwn8ucCvgVW+CB0e/pAOjpf a80g3WvqGx/37K6HV9CIoBXUGz1dgIg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311512; a=rsa-sha256; cv=none; b=TIgUtCP6Hx72mRAfk3Ji6fwGqCjXAMYRxqna9GcD1llvJAqf7SOzK1TF7n++a+1TYPrgAp vN/7+ASdmn085fbOGWLsUPRL2hQoA5wpiJ9Wx5GmkqNMcnC9GbziplOq3/Mpgmcu9lquhS Nk6Eao+3L+AXT93jNYBnX3LS7JQ8XjY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=sy87xrj0; spf=pass (imf01.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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 4TmYq94WM6z9t2l; Fri, 1 Mar 2024 17:45:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311509; 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=fyszdUSBCFtEWqaMFYCTrgSY4YVZLc+Vs7TuxxQjQl4=; b=sy87xrj0yXtold9KEo0HbYK8U8fwRqeLzMnk/2gqJnegYhfzQ3WYLFoP+gKh5jVg1lArg7 fdvBQ/UZr6BWq1qkEe8pVninsVe5DywCu19kITPvxIcx9Vack4ssHwRyzuRaD6lB1jC7BQ uTbBKafIzaN4RXOHoJ1rzeP6f4AufeVRjLDYHxKwlvj43YJ6QFoKnvZ+64+iUVUOvlm/8e cWxdREnG6S6nfRUGvJWdO0s95pIgZWmt7I76Q/tgXIulymt3CuLsbAF7hA1QD8/PNc/0PC sqv72BLNDr5q3jgNBxoz2RpihfmZAFSOIg0/3k52B5oukRPUxhIRfIEheiIRow== 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 06/13] readahead: align index to mapping_min_order in ondemand_ra and force_ra Date: Fri, 1 Mar 2024 17:44:37 +0100 Message-ID: <20240301164444.3799288-7-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9D0824001A X-Rspam-User: X-Stat-Signature: zffbkye7jea4k13ku9cm4x9fyzx5bu44 X-Rspamd-Server: rspam03 X-HE-Tag: 1709311512-805928 X-HE-Meta: U2FsdGVkX198vBOSBhJHeapa4ZA6IQefIrCRQ6L+Liu/pscFfIAaQk+t+hrD9XgKhbS5O9lYIlZ1BjDI/WRHm7C2tA72PjLXPCm88KtNb/Gw28UXF1O51CQk3MOO+7Oa4EyHQjfnxk6JkqevfgepV28hBWmgCRameqqkPSRFAAT/dqqSXFYNyzgky7wD+p1OPg9dU6jldcHgUxSPUSwevqqePA4SsIkBVHbjPZZC7TUl7F14ILOQ2MjzWxOhojWVhjv5IVwBhLToIL6Na9Ld4KEgzsVKSjTQDgANXrxYy4qZ2HBcOVPYf9XyrTGsDeNFRnNh9D+9ELJxpFS14y+5oqDyUAFoyi34s5WvvMMmZjFtd/jR/YbJf4YH2cophjHWIt5XJ6K2z0z3MDfPKQqiDFimpeZtbxPPhrUkLjUDlJGlEh+u5fItIcEFrETM9aItMg+MvxDnK+sxX94998mvF1IXZZCRkJtNrXt9LesgQ5xsSFLKxg5CnO5BXQ8IcFolIb25keZWVZoENm5kcSm61emzTUBTlHEN4f3EhY9CKV4t3iSMhi+W9id8VotdhIKDS8nkRI1lLZ+TGeWqwRrUA/n4fwR2Fqd3ClBibudxbXwuCrci4mZsj8MHAYLdoosX9ytjlWzdxXu+OGChh8POLKqP4W3fS/7OguOA8n7GKZj1ZAId1Yf4n2MmIEL0joVfcJIKzHrykNJB2eycce+D8AqSXCDtqtV70Xh096bIiC75i17Z/ykeVq0nMvNAX45SS5tA9bPC7KpwSWGz4KZ7eDcU53cKq7TNOr7s3sghQuuHZSUispSf/OSqnoWyKBEzrW2tb1n7UHhLq34WH6X2p37pyL1I5VdBF/eaPgpo8UWSFD2F9p0itwWVD7OtzwS9hPJw3ga34mAeaYOmHdUnjy5gzmoiwfKMe93rOfL6q39oAPBmJaJ92hDcm7ExO+thJvmXsmrHkqA22QauHbO lB/iV1W5 IB72q0umqRko8Z3zo4G+oxePHaH6TbLPKs0E3GyVi6DHAGOKnNusn7yFu91Lso1xHUAdIt8wrIO184MJAK09vRneo5UoomiB0KefdTWmwdOeOBwif0i74SWR18QDE7Ja69GQ7LTTw2tcsaAw= 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: From: Luis Chamberlain Align the ra->start and ra->size to mapping_min_order in ondemand_readahead(), and align the index to mapping_min_order in force_page_cache_ra(). This will ensure that the folios allocated for readahead that are added to the page cache are aligned to mapping_min_order. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/readahead.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 6336c1736cc9..0197cb91cf85 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -310,7 +310,9 @@ void force_page_cache_ra(struct readahead_control *ractl, 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, index; + unsigned long max_pages; + pgoff_t index, new_index; + unsigned long min_nrpages = mapping_min_folio_nrpages(mapping); if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; @@ -320,7 +322,14 @@ void force_page_cache_ra(struct readahead_control *ractl, * be up to the optimal hardware IO size */ index = readahead_index(ractl); + new_index = mapping_align_start_index(mapping, index); + if (new_index != index) { + nr_to_read += index - new_index; + index = new_index; + } + max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); + max_pages = max_t(unsigned long, max_pages, min_nrpages); nr_to_read = min_t(unsigned long, nr_to_read, max_pages); while (nr_to_read) { unsigned long this_chunk = (2 * 1024 * 1024) / PAGE_SIZE; @@ -328,6 +337,7 @@ void force_page_cache_ra(struct readahead_control *ractl, if (this_chunk > nr_to_read) this_chunk = nr_to_read; ractl->_index = index; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); do_page_cache_ra(ractl, this_chunk, 0); index += this_chunk; @@ -554,8 +564,11 @@ static void ondemand_readahead(struct readahead_control *ractl, unsigned long add_pages; pgoff_t index = readahead_index(ractl); pgoff_t expected, prev_index; - unsigned int order = folio ? folio_order(folio) : 0; + unsigned int min_order = mapping_min_folio_order(ractl->mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(ractl->mapping); + unsigned int order = folio ? folio_order(folio) : min_order; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); /* * If the request exceeds the readahead window, allow the read to * be up to the optimal hardware IO size @@ -577,7 +590,7 @@ static void ondemand_readahead(struct readahead_control *ractl, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = max(get_next_ra_size(ra, max_pages), min_nrpages); ra->async_size = ra->size; goto readit; } @@ -602,7 +615,7 @@ static void ondemand_readahead(struct readahead_control *ractl, ra->start = start; ra->size = start - index; /* old async_size */ ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = max(get_next_ra_size(ra, max_pages), min_nrpages); ra->async_size = ra->size; goto readit; } @@ -639,7 +652,7 @@ static void ondemand_readahead(struct readahead_control *ractl, initial_readahead: ra->start = index; - ra->size = get_init_ra_size(req_size, max_pages); + ra->size = max(min_nrpages, get_init_ra_size(req_size, max_pages)); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; readit: @@ -650,7 +663,7 @@ static void ondemand_readahead(struct readahead_control *ractl, * Take care of maximum IO pages as above. */ if (index == ra->start && ra->size == ra->async_size) { - add_pages = get_next_ra_size(ra, max_pages); + add_pages = max(get_next_ra_size(ra, max_pages), min_nrpages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; @@ -660,7 +673,7 @@ static void ondemand_readahead(struct readahead_control *ractl, } } - ractl->_index = ra->start; + ractl->_index = mapping_align_start_index(ractl->mapping, ra->start); page_cache_ra_order(ractl, ra, order); }