From patchwork Fri Nov 8 04:12:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13867518 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 1B26CD5E127 for ; Fri, 8 Nov 2024 04:13:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 163636B00AE; Thu, 7 Nov 2024 23:13:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 102B48D0002; Thu, 7 Nov 2024 23:13:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE5718D0001; Thu, 7 Nov 2024 23:13:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D4D3C6B00AE for ; Thu, 7 Nov 2024 23:13:30 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 51001A0838 for ; Fri, 8 Nov 2024 04:13:30 +0000 (UTC) X-FDA: 82761606732.07.2996AC9 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf24.hostedemail.com (Postfix) with ESMTP id A985A180002 for ; Fri, 8 Nov 2024 04:13:22 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=BLT+bTHW; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731039040; 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=lvG8s9D8o0cFy28PtPxadSIFvRZKnQUoFVqL6CSUd9F/ygViPSg59/zK5ISF5hc7ZZMdAu Cec7a1pmCiRhIz5EQN/4d3FRnN6ZbkzpsetFUiYOfBKt1tjHVFMq6sWa6rmXSg7LwvG4Ki OnNwl+cOaZ7/8vR6ZDfsqNXKxw9oF7o= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=BLT+bTHW; spf=pass (imf24.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731039040; a=rsa-sha256; cv=none; b=SYVljGNAxNvY1itRC213tOjMqU4UwJif3X2c6B72QhxNHwLSPbc3y7y7erFPBj13936Sxw 5pIL8sNvLDdkAhH200vOsBUndREU/8/KvAN01qKwd6BAqDAh5c0X+GKM8sfOtjNu710Z3s AJe4k3NPG4MaRvKHs8wC37x8qA1xigw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731039205; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=GjeDj7oC1iiZ/gkwEo4XJZE2Kubqr3JwCuLq6Y0HOAU=; b=BLT+bTHW3cS/tkPHBwAItgUH4HiKzcYqMyXkO2UGmTrI4NkzHvCenBhi0FMSRFY3kuT8WS4tORB+M+EGw6NKS3mI7t15HlziENqLRZvzzMZc23hYMpTHtrakOLXrEYRFzdOhl2GGY1lWExPYb2U5QQHsfTFW1HJ97nGYvf8bGVw= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WIxXGhc_1731039203 cluster:ay36) by smtp.aliyun-inc.com; Fri, 08 Nov 2024 12:13:23 +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: [PATCH 1/4] mm: factor out the order calculation into a new helper Date: Fri, 8 Nov 2024 12:12:55 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A985A180002 X-Stat-Signature: dfi3fs59inwyrweyqyqbuwqsk1kuqqmy X-Rspam-User: X-HE-Tag: 1731039202-339928 X-HE-Meta: U2FsdGVkX19anpZukiODCTMsPabdAXPZq1qybsG3Wn/w8GssLMVbZBa5OqmvGUsxirF2auUfIJ4JLN1IAbz7Pzx1683Cd6tWchEYpdmzitaI2HJ/fbeSyPtec4pt3szbLMOSZF5zaJseNDVw8iSTFOAdh5iilZscXPvyQJGbV6HjBI3A0pY8Kbbe/8TUSYYd08L/i1f4CjURPOOsLmt9BuJURixGQw9X6PTcPcEVTtZI+SIa7Fjdm6ujIBYUaZeQgNFTmoL0DvLIcdURfDwwTX4YBR7G0R9EoBqlFkK9zYYbRGOgg7SRSdH1tCyrxdoHWnhGMASGNa3Fu32qQG9P9ZbaAI10P70CslcK72dp7pIwULih+K6FUQ+T/Nd2RL0MYAMNYpHedvIVGetjlO3Vwc2AIhhf9Un5lPjiuGjZqh8G3FD8DJYY4POW2LSMS9FjB43Mkaic2zPtJMmwevAh3SboBUl/NjAK0o2xV8219LVpHCBUZESbCaYKKAYDIIwykS7UOpaKD5tP3a1IdD2hwnbLvTEbr7WmlZyV4EnApIczsM1l4Wtaeg8v4IpgTx8j5oILaJEZuMhePXvCW6ynhZw2Uql70/S4q7kmj8Eds4roQ1/2Y3SOvKYdWr+/2pXzo/fhPtLTdDGcHweGAmskYv0GFqvPGnQGyhyTKsBNve7MzqGYaLAQRt9i6zVVjLdsEOH/zR2EI+jstDfsr3hYnN0eQm4G5voAPQ+rqovtzEFK9Q4qTlGXggYJgUt6as8xUN6zdDb2E90s9lGg1cgehOxCNUWlF5+oxUQfWnFTD75Xj6LoHah+5ePPYk67kb6EoJ6shOtL2MQxHQo605u4nbVZO3L549+8ioSvPM/tu+L4np3kaAtKJkxQJUVyuhm2y2dsdyjV8WHnujyYjiW/Vbn2tUusSkC9UDMTgYDAGdirgVCN+O8lGrylzL29fnQ1bR9uYRupUcW0J6CFkNy pOOI00q4 IEqfD65qlFYdghZLCyCLSXoq0CxriDL1jJCw1s8X326n1bglcWFI3h9aew02ubUW3XfpnSpdTzn8CxQAN1Ur1tXouR1G1mL61UsaYEG9Wt1sKzhaa0YCjrCUpPmH7+KvtHaslK/RwNqUXwlz5q4ecCjlJk5S9S4Mj5ZWQ8/6RDfDCuvchsQjrl3u0gcGMNzkV0p9UlL4vO2C1PkpGybEb7UATcpvqe8Kkf09xUw/7yJewy9R83wPdK2qXwjCp3JO1lQ9eIjnnLoBadXmW5hHloUTP/CD6AApdLutH 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 Reviewed-by: Barry Song Reviewed-by: David Hildenbrand --- 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);