From patchwork Fri Sep 15 18:38:32 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: 13387468 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 B46AAEED61E for ; Fri, 15 Sep 2023 18:39:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6FA36B03BA; Fri, 15 Sep 2023 14:39:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF6F26B03BB; Fri, 15 Sep 2023 14:39:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B97AB6B03BC; Fri, 15 Sep 2023 14:39:14 -0400 (EDT) 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 A5C676B03BA for ; Fri, 15 Sep 2023 14:39:14 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5AE5416075E for ; Fri, 15 Sep 2023 18:39:14 +0000 (UTC) X-FDA: 81239694228.25.B65C19F Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf30.hostedemail.com (Postfix) with ESMTP id B410D80028 for ; Fri, 15 Sep 2023 18:39:12 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=WfMPs8ow; dmarc=none; spf=pass (imf30.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=1694803152; a=rsa-sha256; cv=none; b=3QOAZeRcD+zVg/c7VGEe2PmRnkPKxcEzTeoQxlOk1VuXAk4QTOVEMOcL1U/VQqs63SHL4l aVgJyPEK/D6XDC3n5amdDcgMz/h2gM6EOZaDQbSXJ1A+6fqHuodMDTIa47bGAv0wP+sO97 nSwHrlfrU/7m27F7wglWXxij2jCP/Y8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=WfMPs8ow; dmarc=none; spf=pass (imf30.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=1694803152; 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=fo0VXOu7M+9NKfjAGLZXjFApmoEpRKKJEPK75Mez2cA=; b=P2cLwbqaAnYeFCf6NXgLOC5tqwE1qJy43cvgHFuK6vycJS95PT4DWX66eAAvOF5F2j2iPC fiHj5uBkwJGrrb6BhnagPAk/lGIOpDlKLe+fe77kClIRTU3ATexgzLYt76T/vlCmmpwq0X /JjsL3eKaliDSZIAU3j66UIlcjAT+Lk= 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 ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4RnNJH1Xljz9sQf; Fri, 15 Sep 2023 20:39:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803151; 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=fo0VXOu7M+9NKfjAGLZXjFApmoEpRKKJEPK75Mez2cA=; b=WfMPs8owDY4qNpPNRRBf2P7n6I/k1Vb8R9SOGAa4d0T5FLvv4ZHDjWd9yFS4HA1DKcDXoZ Hs9/Lc7bdPIjyElTcSGwwlLTk8E9vLbEnQREiltl5xwCZxZhmZW2W/MIWqbzt/L0UBGJkL Pg1tzwwKa0ivqVeh/dlhg7mGJoM5RT/rjcmVhwnmzmeYieP7bnYJI0tIsDaZcaMFCiYk9l eQpfZrnKOiSrp4if8lwa+VZrXN/gYt7pEAXj9fNCZan1DgEdMMHsjyF5BcnH2QER2lpu5Q 2yAY1aQhY540+9mUaXvvL33VXZsMEat6/i+Ojfu5vHN2X5uVaD4JlKa3e5Z7bA== 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 07/23] filemap: align the index to mapping_min_order in __filemap_add_folio() Date: Fri, 15 Sep 2023 20:38:32 +0200 Message-Id: <20230915183848.1018717-8-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B410D80028 X-Stat-Signature: c5uzxya9sna5ssrqfao1euxqpw1ztgaj X-HE-Tag: 1694803152-512299 X-HE-Meta: U2FsdGVkX18kRUPcEsHBXEzB7BJNL/N/P+FudYCCHhdfnXR2jqmPVQBUqhFKNUxj84taJo2H8FN+yG6SE6mlbyhpoBpaCjR3wPg6qKLAMhEU84rpDX73xhJHIDkID6ZxjZPom+RbHoGUkA7fdzhPIR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Y1m80Y105MSqoH4ctmj2Q6oXU7cprMcIzTwbf82i0S8kLgS8o0fRfjnxsG6ZKo8u7xmLO1ISUFIahEu2AyhvNddfJ1NRIKbbO64SH/WYTq9t3gXe8WFgjBjx/0lUjyHgzk18BFwjUhcGL+56Cdnw= 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: Luis Chamberlain Align the index to the mapping_min_order number of pages while setting the XA_STATE and xas_set_order(). Signed-off-by: Luis Chamberlain --- mm/filemap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 33de71bfa953..15bc810bfc89 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -859,7 +859,10 @@ EXPORT_SYMBOL_GPL(replace_page_cache_folio); noinline int __filemap_add_folio(struct address_space *mapping, struct folio *folio, pgoff_t index, gfp_t gfp, void **shadowp) { - XA_STATE(xas, &mapping->i_pages, index); + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nr_of_pages = (1U << min_order); + pgoff_t rounded_index = round_down(index, nr_of_pages); + XA_STATE(xas, &mapping->i_pages, rounded_index); int huge = folio_test_hugetlb(folio); bool charged = false; long nr = 1; @@ -875,8 +878,8 @@ noinline int __filemap_add_folio(struct address_space *mapping, charged = true; } - VM_BUG_ON_FOLIO(index & (folio_nr_pages(folio) - 1), folio); - xas_set_order(&xas, index, folio_order(folio)); + VM_BUG_ON_FOLIO(rounded_index & (folio_nr_pages(folio) - 1), folio); + xas_set_order(&xas, rounded_index, folio_order(folio)); nr = folio_nr_pages(folio); gfp &= GFP_RECLAIM_MASK; @@ -913,6 +916,7 @@ noinline int __filemap_add_folio(struct address_space *mapping, } } + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); xas_store(&xas, folio); if (xas_error(&xas)) goto unlock;