From patchwork Tue Feb 13 09:37:06 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: 13554788 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 DD155C4829A for ; Tue, 13 Feb 2024 09:37:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 685648D0006; Tue, 13 Feb 2024 04:37:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 634888D0001; Tue, 13 Feb 2024 04:37:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D6628D0006; Tue, 13 Feb 2024 04:37:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3A0578D0001 for ; Tue, 13 Feb 2024 04:37:49 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 157FD40284 for ; Tue, 13 Feb 2024 09:37:49 +0000 (UTC) X-FDA: 81786278658.30.DA754CD Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 4E73240015 for ; Tue, 13 Feb 2024 09:37:47 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=iOQgIoOS; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817067; 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=+mCWMwP5wq3JUiJEv3CmIbOYWUCSLRs7oy3y/VAxBqA=; b=iA6T+t/DPYBWjikAsxGZjuyNfrW7PN0qeo30rCOekwVmRZk/O00NKkz/ncS6LZ+aAQummp NGdFealjLdElu/vvaGhv8u5t8c2Stib7XJITePF+FY2hH8BofU/Z9VSRylqNNRJJ4oC9CZ BMR1pCVmfRkeG0CxoaBMlnM43BmiVkg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817067; a=rsa-sha256; cv=none; b=wG76VfyU7sAUZTy3t2TinZJWAtzNj07n3LuMkj3xulDy796UIVeyMJgn4fJu+0kX1pmoMz lotVzstfxYNh5TbVxInnKZ4BE5oKbYXIyAgkusxVJ+MvIG8w+CRtej7r8cYB0DRSTOE3vo YBN6An9b96QChYqC45QEhBFyOQl+xlY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=iOQgIoOS; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.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 4TYx7q6TR8z9sQ6; Tue, 13 Feb 2024 10:37:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817063; 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=+mCWMwP5wq3JUiJEv3CmIbOYWUCSLRs7oy3y/VAxBqA=; b=iOQgIoOS6MNE5AoCAkHWB9G4sH1HUqNrseAIr0UHMHOFKgN7X/i+sSLh14ZYjJ2VfVFoVD xEnCZpOimSmqDL3bsXvjRAwCjcpL4t0fpM7v0+a7NpzQ42OVb5XKUPN4Pe1yuaQzlQg510 9+GAiYGfjY4aRVJ8IhjdFc1qFraRZoin7df2vI6gb5P7s9bDaqDLapMAqTGaNHPabkP8jG 9EDznjuSuLHv8D6U3BuOBiHgpe9P5VKhmdvy9UShqKWr+81MrlafvnKcCyxnZS7ekoFiTv AsIwPvDH6bnGLovC6E5hxc34cSXEfFiEBW/VvDrEK/Um/6t5hMDmGu+a5nYQnw== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 07/14] readahead: allocate folios with mapping_min_order in ra_(unbounded|order) Date: Tue, 13 Feb 2024 10:37:06 +0100 Message-ID: <20240213093713.1753368-8-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4E73240015 X-Rspam-User: X-Stat-Signature: bt1wwsuzihyrauaecxeu9bw8zp93hqo9 X-Rspamd-Server: rspam03 X-HE-Tag: 1707817067-114063 X-HE-Meta: U2FsdGVkX18EOxMF//dp7hU1jvlNHxXahIqFl/Tk2Rub3T6vHyPzhbroCyk1he+WJ8X1J3qunRIpWJR04PPW0cZ44QK2TprJAdLRVt5+ZGqLshoJZZD8DUjWt1gcmYkCLIJ2SSQtvPqIQKn8yjB/nhuaY56lw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xdk5ZFc19sqJzbwHI1jsY3/vYQHprpOeXnnwjhEHH3Uc2F7JHlyhta5q+FJ1pbNVzlY9qjtpjvqv/faTca8nwFf/QHZq6iE8KY+M/117ZB60fpAP7WEDEDNuOJZnjYNrtfl18Fq7tJiiW8I035a5lI/E03NULBeAgbzMd2 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: Pankaj Raghav Allocate folios with at least mapping_min_order in page_cache_ra_unbounded() and page_cache_ra_order() as we need to guarantee a minimum order in the page cache. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/readahead.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 13b62cbd3b79..a361fba18674 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -214,6 +214,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); unsigned long i = 0; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); /* * Partway through the readahead operation, we will have added @@ -235,6 +236,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { + long nr_pages = folio_nr_pages(folio); + /* * Page already present? Kick off the current batch * of contiguous pages before continuing with the @@ -244,19 +247,31 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index += folio_nr_pages(folio); + + /* + * Move the ractl->_index by at least min_pages + * if the folio got truncated to respect the + * alignment constraint in the page cache. + * + */ + if (mapping != folio->mapping) + nr_pages = min_nrpages; + + VM_BUG_ON_FOLIO(nr_pages < min_nrpages, folio); + ractl->_index += nr_pages; i = ractl->_index + ractl->_nr_pages - index; continue; } - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, + mapping_min_folio_order(mapping)); if (!folio) break; if (filemap_add_folio(mapping, folio, index + i, gfp_mask) < 0) { folio_put(folio); read_pages(ractl); - ractl->_index++; + ractl->_index += min_nrpages; i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -516,6 +531,7 @@ void page_cache_ra_order(struct readahead_control *ractl, { struct address_space *mapping = ractl->mapping; pgoff_t index = readahead_index(ractl); + unsigned int min_order = mapping_min_folio_order(mapping); pgoff_t limit = (i_size_read(mapping->host) - 1) >> PAGE_SHIFT; pgoff_t mark = index + ra->size - ra->async_size; int err = 0; @@ -542,11 +558,17 @@ void page_cache_ra_order(struct readahead_control *ractl, if (index & ((1UL << order) - 1)) order = __ffs(index); /* Don't allocate pages past EOF */ - while (index + (1UL << order) - 1 > limit) + while (order > min_order && index + (1UL << order) - 1 > limit) order--; /* THP machinery does not support order-1 */ if (order == 1) order = 0; + + if (order < min_order) + order = min_order; + + VM_BUG_ON(index & ((1UL << order) - 1)); + err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) break;