From patchwork Mon Feb 26 09:49:31 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: 13571766 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 C070AC48BF6 for ; Mon, 26 Feb 2024 09:50:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F2F9940022; Mon, 26 Feb 2024 04:50:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A279940014; Mon, 26 Feb 2024 04:50:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36A61940022; Mon, 26 Feb 2024 04:50:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 27C26940014 for ; Mon, 26 Feb 2024 04:50:23 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 050874074C for ; Mon, 26 Feb 2024 09:50:22 +0000 (UTC) X-FDA: 81833484726.13.74C43A5 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf19.hostedemail.com (Postfix) with ESMTP id 3D3F81A0013 for ; Mon, 26 Feb 2024 09:50:20 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=KD2XCj9V; dmarc=none; spf=pass (imf19.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708941021; 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=iQD+U8fQrLibnL7zMC26FszgKpFB3C91GewFjdSXc68=; b=qjv/951WTIax7o9YyZ1xraBuDFuyUjsiApaN4PHca4nThqLQGBD1lLzL2QsgFE6xWH70Qj irGYcTCfyzRRveq1VnKlUoty2slefEavkDLlfDiCbgCIqk7hjyKrKG1pp56kUDaEN8nj1b 3bjoNTArRAzEcbpBzFoSEQ97wMuTWV0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=KD2XCj9V; dmarc=none; spf=pass (imf19.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708941021; a=rsa-sha256; cv=none; b=FzWDVRjBuN7wGd8wgi7oYtxS8eyHsnDB12DJ8k5xNBRY2XC+oNVATpdQOPhS6RaLgXl83X SjEmoyCvN36BE73C8+8ZTfcNHeur/+7kg9SacXXSlV+Ae+bhf40cABNJOaL/H31PByAyEX oUdQEYQyW82s5e6CtaW/VkE4h83qmzs= Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.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-201.mailbox.org (Postfix) with ESMTPS id 4TjwpK6z92z9sZG; Mon, 26 Feb 2024 10:50:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708941018; 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=iQD+U8fQrLibnL7zMC26FszgKpFB3C91GewFjdSXc68=; b=KD2XCj9VwH1Vmpc+ALJcr0/VQKCCQPTIil6owvpnHMNdIMgpDQ5W7a/HRkd3U4cOUjMCX0 I4cJnFFlwHSCV4Gbv2el17sDjgFvxM7cdzOZPo6QJ8vgcX2taBay3wltwWNxNcF3U5fNAJ L8WPmXdMxUgfXsQGWdlIcNLiYx0iBLpwGhhhEwubhYtDui7L8T/F+UPO5HJSx9SAcTtUtj FTQyNmAv5jqbNtdJ8Jzm5aGVJPAxwFkT36Nxj00z87HVHNTkqX+nYD5rBwtUg1Tiwon+Z2 YDfHCR6EtjB97Z3JdcRcZz++fzTQZzvFdjIDjH+KLPVowAREtTyhjqfTTaSEJA== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, ziy@nvidia.com, hare@suse.de, djwong@kernel.org, gost.dev@samsung.com, linux-mm@kvack.org, willy@infradead.org, Pankaj Raghav Subject: [PATCH 08/13] readahead: allocate folios with mapping_min_order in ra_(unbounded|order) Date: Mon, 26 Feb 2024 10:49:31 +0100 Message-ID: <20240226094936.2677493-9-kernel@pankajraghav.com> In-Reply-To: <20240226094936.2677493-1-kernel@pankajraghav.com> References: <20240226094936.2677493-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3D3F81A0013 X-Stat-Signature: tqb935amb1p7sh5b6ikq7dik3dp7s1pc X-HE-Tag: 1708941020-682361 X-HE-Meta: U2FsdGVkX18niL311ii1DfNtPHTfxezLQgbQLaL/tbIM3qhjP9dE8G/AI3j+MpRp3bC19BUIFlcnDabV91795OlN0caVOu13pRr42dEBIVdkhQA5zDO6Exjpr10o7yQ4HP8Mcq0WVZFWxJWJnY+vnaDK45Pkg9eVFDI0OCUdX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RtDQ0BLhq693gKXkJp5DCRkS4H07bkVgHTxETgTvPeA+RrZ9g8qvyivax6B/5M5/TML85UoXtX1lRmjviHn/B07DtGHTQWj2GQjzUXEm2oyxjIivDaJWYrxJLVRoasvD3YGtF/aoNuWNYLXlDJAGFMF5aAkiY5OfYc93gY93LClKJS 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 Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- mm/readahead.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index ef0004147952..73aef3f080ba 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -213,6 +213,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 @@ -234,6 +235,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 @@ -243,19 +246,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; } @@ -503,6 +518,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; @@ -529,8 +545,13 @@ 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--; + + 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;