From patchwork Thu Oct 10 09:58:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13829875 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 9E1F7CF11C3 for ; Thu, 10 Oct 2024 09:58:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 128426B0083; Thu, 10 Oct 2024 05:58:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C0F76B0088; Thu, 10 Oct 2024 05:58:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D343B6B0085; Thu, 10 Oct 2024 05:58:25 -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 AA8816B0083 for ; Thu, 10 Oct 2024 05:58:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5146CA0A5E for ; Thu, 10 Oct 2024 09:58:19 +0000 (UTC) X-FDA: 82657242570.24.A61545D Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf07.hostedemail.com (Postfix) with ESMTP id 802C340010 for ; Thu, 10 Oct 2024 09:58:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Xy+jETAc; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728554202; a=rsa-sha256; cv=none; b=GbYLAPhEEwnaQJQel4AURmKldr2a46na9ADNowoF0rqsZCJsokVA6Y4qBptAuDlWwxyhJM wqwF9cgk6zBa41NjWFXcRmYjysTFxjNoSNLGwsDTmJ0aOzUcAgOskz3nxiROr6r4HIi7tf Ub6jvlvdS0E30hS1QO0Lu1NOIFbP634= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Xy+jETAc; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf07.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728554202; 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=GjeDj7oC1iiZ/gkwEo4XJZE2Kubqr3JwCuLq6Y0HOAU=; b=DzPvgDLNAGSo9K1CE5RZ3zEeWgjJmw8yo5cK1imQUK9xKEqFP4WWnn2apBATrALqJLVOfa 9yo1wB2QWvIGiJgpsbMLhUW+RejLU283t5Qc+mHyvABrGgG111GLzr42DrDxKneLmjslGN I5fimtRexI4EvVRp+1OrTPa0JtnoceA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1728554300; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=GjeDj7oC1iiZ/gkwEo4XJZE2Kubqr3JwCuLq6Y0HOAU=; b=Xy+jETAcI31K/++s8bwE1Q96Nr06WGfscMPMiMRzKj5dO9zg2qeAWkOqhF2frMQYp1zojA9Pavh/WBGSZ+jrDwA0siqKNCxghp5D0iFByplhyIK3J3j8Cl9Mh0dSdFKEHOnft+Ng6fEHgYsOm/sQlLr3JC4gcSq416/OjWHk1kc= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WGm1Wg-_1728554298 cluster:ay36) by smtp.aliyun-inc.com; Thu, 10 Oct 2024 17:58:19 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ioworker0@gmail.com, da.gomez@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v3 1/4] mm: factor out the order calculation into a new helper Date: Thu, 10 Oct 2024 17:58:11 +0800 Message-Id: <382e820c4805dcac80723d8f1707088dbcea2e85.1728548374.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 802C340010 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: aejjbsu6k1hykjyuqnoxikpg736mioa5 X-HE-Tag: 1728554301-562202 X-HE-Meta: U2FsdGVkX193zkD9aS5pJTpF4yFtP0chlBZW+v9MVASKrYXeIK8Lxf5rUu+sHMJzPvDy8n9+qHn/Dh2PwMHPFsANci1c+8ZO/XB1wis+KZS/WX7W+52PYRdI9D9CdOCcnAeu7Prbrr0dokjwf8Dh4KF64gzI3BvIOcmXYBlbUnctln/2QRsgjtZUK/54URsM0T8hcQXVIbGHP4rmoQUg363cOk7Q5oi4ghBJluym5+mpACD3M4LxyVEI+Dg8hodbjoaDbYZakXEZ+xjac9bhZhWHFzzFXXF0oacuKbANZ4UDyQ4jMuw2D/IPCCQuoPusfmsSDyvlDdo71F3bM/S4c9G84WWC4VjmMPtfKbzyl3oak53X7n5CCMdSMGYmqeEAyIUNmho4SkXi1rbLugu5y6ldfBjBBTDbLneZZXiF+1udonl4mSyxrERiGsO/BN5T3XYIP0y9j5p7RIdwlONmTVCAFtVn/W6qQb+iH/jmv3LXEYx9EJwgP8xkjUO7z8yhmGK9f0ePjdgLlnnBaIcKreLiAilReo8qiVF7ps0KYAtwacKFHf0idaFzY3HyKszrNXTsJ8V1R4KFGl4sPF1wWBxebJLyS/ws23z9q1F9V5KWNxOMXJ/WMEnbLXlg9QtTmN2zCwtWFlI8Zc4Bdr+OJpl+sxSSfn+zyJB/nY733eL+lo2i8BtGEjydwqVylJsfA+VtUTH153+emLVK1DTlcCEjn47+Ot03ezpC8lu26+G4PWEVQ7lniboDkMTy/JMpyZTbUwbRdkA2hmo4yLMDRIr/IxOfSrBhO6y0XsfTp/cyd0sxDXGz4j0MOEJQYxgkvn2V1VigSNAkQ61QhXSQ4HwvmCrU+yRU9cvSljwwf9iZAP/Qc2npZO4l0v3GbxhlOkoOTkhSDXID6p9rfliJOCc6LByM5fZMYoq8u3kUoIAXF3W1tZkVR2hVies4iOuzDybRFZ0YDttC/TbbwWy ky/h4HRd coGvXKiLwJCl+v6I2mq9BrvnDBkDu7NFHnchFjndBdtTB9k0JFdizlgPMTkxp7x6QlSQlbgV0vT25DUX1zuphpLvHLXGPNein8mwKNG919+saoZ1zFC+dz4DV7J/sF4iQ3wjZT8pTBmhKLAmjahczM69DpoJziYlCSsDlSr4xFN7p41map0goY10qtK9qqLvi6b3UBuDKTcocuaed6Sev0frZxHz0T0mPlvP8CgZXs/23nCKcrUWbTkfZayMuw9cI0+M90c+bwb7ylJQOpSeJU12gELDa4s94x+WW 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: Factor out the order calculation into a new helper, which can be reused by shmem in the following patch. Suggested-by: Matthew Wilcox Signed-off-by: Baolin Wang --- include/linux/pagemap.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index bcf0865a38ae..d796c8a33647 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -727,6 +727,16 @@ typedef unsigned int __bitwise fgf_t; #define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) +static inline unsigned int filemap_get_order(size_t size) +{ + unsigned int shift = ilog2(size); + + if (shift <= PAGE_SHIFT) + return 0; + + return shift - PAGE_SHIFT; +} + /** * fgf_set_order - Encode a length in the fgf_t flags. * @size: The suggested size of the folio to create. @@ -740,11 +750,11 @@ typedef unsigned int __bitwise fgf_t; */ static inline fgf_t fgf_set_order(size_t size) { - unsigned int shift = ilog2(size); + unsigned int order = filemap_get_order(size); - if (shift <= PAGE_SHIFT) + if (!order) return 0; - return (__force fgf_t)((shift - PAGE_SHIFT) << 26); + return (__force fgf_t)(order << 26); } void *filemap_get_entry(struct address_space *mapping, pgoff_t index);