From patchwork Fri Sep 15 18:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13387464 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 798E4EED61E for ; Fri, 15 Sep 2023 18:39:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13A5F6B03B3; Fri, 15 Sep 2023 14:39:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C5A56B03B4; Fri, 15 Sep 2023 14:39:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7F166B03B5; Fri, 15 Sep 2023 14:39:05 -0400 (EDT) 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 D3A5E6B03B3 for ; Fri, 15 Sep 2023 14:39:05 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AA66C40B20 for ; Fri, 15 Sep 2023 18:39:05 +0000 (UTC) X-FDA: 81239693850.04.720598A Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf13.hostedemail.com (Postfix) with ESMTP id EC85B20020 for ; Fri, 15 Sep 2023 18:39:03 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=r+lyXdNh; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 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=1694803144; 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=FLdOtec4vpzZfm3InvylkSWZf3/uIigm2EerkCxMy5w=; b=7Thyhj/kW8t0LHYb1jpSUGiQ2zvsAyjREYcKso3iXBH9kVBs180jBWUTmcGrg/XZZgd7Nk jtbYnu3Vk0cHilUlUBzaF2rZhcjJInojlqRwW9AiwBcRC5fJCW7+xcg8r+qL0G91q1o7Bb uVpaysFmRFFTUdwsQCAX1RqTXsvnDoo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694803144; a=rsa-sha256; cv=none; b=JGO5ldg1gFR/JYGQA3MAb0Zeti639J+4fGUY2JFkFq85C2vX8PjtfNat2Tl7QZUAYs1zXH OhIGJMekqsgCSNR8vLgiwblCjmVSHxIMLRH7rmdEzyndSdtfWVaqQGgfu08HDPnpbwylGr tsJAvfGa+0ZkT+sgiN/eUkj/bEu1Vew= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=r+lyXdNh; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4RnNJ46BJgz9sVy; Fri, 15 Sep 2023 20:39:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803140; 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=FLdOtec4vpzZfm3InvylkSWZf3/uIigm2EerkCxMy5w=; b=r+lyXdNhKhaZUDV6ta1NOOz4t9XIqBsPWGKdpL52UeGGpc0w2l1GrjQoagDyLq1XmHgALR g1EqfgXzxsfYSrEIgCmHV7nHfJUR65ZXBz1qPyVMU38LzQvwBAQfX8hG15HCbnG3RfUlUX iSsWS6wC7+rnNjpeSwf3O99fKY75M5jL78ggnhb2038nR0JjItKOOiGG6wCGGFRnuDZBUU NgPx6r4jz+JR36KDLUuFNvBWQsWENMcB0tcPeeRxQuUQ5ZEuJPrOFCuxxalzPD+24MFPdX zSeo8UqEgsrlR9EtOCgcPXonCPqSD7HdZB8KudYD6ZpQglZJPmDfFUMnntpKfw== From: Pankaj Raghav To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: p.raghav@samsung.com, david@fromorbit.com, da.gomez@samsung.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, djwong@kernel.org, linux-mm@kvack.org, chandan.babu@oracle.com, mcgrof@kernel.org, gost.dev@samsung.com Subject: [RFC 03/23] filemap: add folio with at least mapping_min_order in __filemap_get_folio Date: Fri, 15 Sep 2023 20:38:28 +0200 Message-Id: <20230915183848.1018717-4-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: mfb1973x6a6y84wxtt6zpi78s5ewwg7u X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EC85B20020 X-Rspam-User: X-HE-Tag: 1694803143-793387 X-HE-Meta: U2FsdGVkX1/JE1eXHnZYv+Qw/BVO6Int0VKtVadzRtFBR8X2ZHKvvoFra4vQDSGcv8IWVp0ixNUcBUPNwDKAgJYDyCQ88CfsIFM72m3G6T0j3Fwj1xF91DGdEq30oOnG2Enp+qMiOrqVyLI3l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nlIEOnJLTXzJ5D/H6GeYcmGfdik1ueU4cre33HJheMmLGgcGHPST92Qew1SCbtqJIzpCsgBw3Dygig7hQOUm2e10MBFu+zpHJ8n0TLWC5frALcrCVycpMJGPtND9gHt/86OJvU8+Ej23 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: From: Pankaj Raghav __filemap_get_folio() with FGP_CREAT should allocate at least folio of filemap's min_order set using folio_set_mapping_orders(). A higher order folio than min_order by definition is a multiple of the min_order. If an index is aligned to an order higher than a min_order, it will also be aligned to the min order. Signed-off-by: Pankaj Raghav --- mm/filemap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 8962d1255905..b1ce63143df5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1862,6 +1862,10 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, fgf_t fgp_flags, gfp_t gfp) { struct folio *folio; + int min_order = mapping_min_folio_order(mapping); + int nr_of_pages = (1U << min_order); + + index = round_down(index, nr_of_pages); repeat: folio = filemap_get_entry(mapping, index); @@ -1929,8 +1933,14 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, err = -ENOMEM; if (order == 1) order = 0; + if (order < min_order) + order = min_order; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; + + if (min_order) + VM_BUG_ON(index & ((1UL << order) - 1)); + folio = filemap_alloc_folio(alloc_gfp, order); if (!folio) continue; @@ -1944,7 +1954,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, break; folio_put(folio); folio = NULL; - } while (order-- > 0); + } while (order-- > min_order); if (err == -EEXIST) goto repeat;