From patchwork Fri Mar 1 16:44:39 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: 13578746 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 D02CEC5475B for ; Fri, 1 Mar 2024 16:45:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FC0A6B0099; Fri, 1 Mar 2024 11:45:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 58094940008; Fri, 1 Mar 2024 11:45:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3E4940007; Fri, 1 Mar 2024 11:45:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 273DD6B0099 for ; Fri, 1 Mar 2024 11:45:21 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ECCB2A1CDC for ; Fri, 1 Mar 2024 16:45:20 +0000 (UTC) X-FDA: 81849045600.23.2C664BA Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 337D540021 for ; Fri, 1 Mar 2024 16:45:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=GTvMRiJf; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 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=1709311519; 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=zvw2rzk11TxuiUv97J3TlgZt9xwdAbT4PmWWnU5r0+0=; b=gSMC3CcqcniaA20VlP5SozhcW9b69bgbFLjYjF7zBbr5p9sFjKKuzrzo4cq/ivO4qbm4TI 8Lvpp7piA7Vyxs3rPj94O4LH410WB7yDwtpk3WheZRC5j/V8yDFO/hiBG3ePLh8egWyqd5 +cp4wum3lPOXrlExeBPqPV+fkuA0Abc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=GTvMRiJf; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311519; a=rsa-sha256; cv=none; b=kSuBcK1bz7W6eVHqKk2N520OUHiQWqIcHaSYf+GdAgDTaFYFIpnKZtWX1yPZzhy/+qh1Ng dXw2rtW+rDMpwJm9aNlmL2zCsdmZpR0+3it7MBhER/fxc7iJYEsYMcHHQK+BZM0OGTeUGG zvDx83dr/tc3xs9/HpuG/fbXfQiRSC0= Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4TmYqJ1Kr0z9tWS; Fri, 1 Mar 2024 17:45:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311516; 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=zvw2rzk11TxuiUv97J3TlgZt9xwdAbT4PmWWnU5r0+0=; b=GTvMRiJfwP1CM9YGAN8fjl3pwLxOZk9Gjl/t9vwy8fr7jW+Wufva3/mOFVv/mPJ1wAqh/X 2XKnWTgFH/VlymrO7JqlRSExaN9oXj2IOFhR7Y6qPalDbQtLS6T/oWq4uXm3kHimID0E7i XfGjXVaUhu6kbuAvHHGrVKvfk7wBZiOMHKUB1jxvSNAGa6OxwxT5bmwHB/hjAmTZLipfiZ pkU2S8yLNWUOZ1HtCb5FiUBq/8oK4BURcysJPANZhPHgBabo3bLhcWu89AgRmDqb0SXsDb wKOCAZ1pTj+fuvYcuMhbu40x5DSNsukW4ZietZo/NSJfFBrXmRMcDA99zOCd2A== 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 08/13] readahead: allocate folios with mapping_min_order in ra_(unbounded|order) Date: Fri, 1 Mar 2024 17:44:39 +0100 Message-ID: <20240301164444.3799288-9-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-Server: rspam09 X-Rspamd-Queue-Id: 337D540021 X-Stat-Signature: wqy7owkqhs6bmux6h1krnw3p44ri16r5 X-Rspam-User: X-HE-Tag: 1709311518-238294 X-HE-Meta: U2FsdGVkX1/HMsnclmxbagEXp86E7ugXMHGJ0GmmWde1XeaxD6ijuysQqAbtR+hvZ20aDiiNwnbeNb4qtl58iVTv917ADhhEw3zuufhdXTHAWLhfZ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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 65fbb9e78615..4e3a6f763f5c 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -210,6 +210,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 @@ -231,6 +232,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 @@ -240,19 +243,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; } @@ -500,6 +515,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; @@ -526,8 +542,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;