From patchwork Thu Nov 28 07:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13887733 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 16FEBD690E5 for ; Thu, 28 Nov 2024 07:41:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88C086B0088; Thu, 28 Nov 2024 02:41:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 87E936B0092; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A9EB6B0089; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 48AB46B0085 for ; Thu, 28 Nov 2024 02:41:04 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BE1A71C70C4 for ; Thu, 28 Nov 2024 07:41:03 +0000 (UTC) X-FDA: 82834707228.09.CEE5A3E Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf27.hostedemail.com (Postfix) with ESMTP id EDBB140011 for ; Thu, 28 Nov 2024 07:40:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=eYIlcs7R; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf27.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732779655; a=rsa-sha256; cv=none; b=OFVHJHAH//cnqb0odS8D1QfU3JYnD0CEnxjU+muQnZu4SYilphlWNhRmHawSEulJwxdc/a 9CTufX7y2MyIJG4pzgZomEhIfPEJCzNjs3pcqHYsUUUv6w/qa6mJXWzVVULxgMvEUFjaQn HbSkoAmUG8ynArOctcxw6NGc6j+UIks= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=eYIlcs7R; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf27.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.113 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=1732779655; 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=0V6hY79A/2+E7HEAAM4p9j6HrltNCMws+8O8dcahOFU=; b=J7G94qVzy4zhUB0KuSY34A2cnSYAmbzDdpxg5NIH9+45z3WmzLESrTrKpyF/qNNjxvnffG ZSzIQ1bddNpRrrx6VmKOrkDmDNrx3FSCQak2BLq4S+kLzhFqqNbEZs1CWSUJtU+abF1tAR loCQRbFICVCJZiU2TDwEmApt8Ou8JlM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1732779657; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=0V6hY79A/2+E7HEAAM4p9j6HrltNCMws+8O8dcahOFU=; b=eYIlcs7RWD17JIYC1eaHR4T6dRSLr5s1M4+5TP3RRus1/DlSLoksuCswGkJMO9a0sHx/x6hfhUpBLkqLiQVr2UycUzhVGT/Vz1z5cjRZIMHOrNdpQ1D+d24J3CJdVUCy8AYCy9w8SE+mBBi52+ARsoh8iDBoTkBkeoHqM5msCAs= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WKOx1pU_1732779654 cluster:ay36) by smtp.aliyun-inc.com; Thu, 28 Nov 2024 15:40:55 +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 v3 1/6] mm: factor out the order calculation into a new helper Date: Thu, 28 Nov 2024 15:40:39 +0800 Message-Id: <5505f9ea50942820c1924d1803bfdd3a524e54f6.1732779148.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EDBB140011 X-Stat-Signature: oezok6zjrrwxxpp7xzyu6qezkrox6yfo X-Rspam-User: X-HE-Tag: 1732779651-912465 X-HE-Meta: U2FsdGVkX19bqA/rYgsp+ZVMWCkIva9xOFH3NJ66FkRM4/mOgLjG9ACTVMDaLRRMZv8GtKQg30BdkBiY7m8EGXRJzFoKS/czpXNzGvx9ad1nMwQA6V3+gUSxev1qismjhNpizYMlX3ZiNa+0TNybKJBmkoi8YbVdynw28qDHggaoAHp+teo+fgKScFRZRdMwH452EgegeoNfo5M4mLR7YtPbiQQoDxhZn38MC9JXS+KEdE+OOnonb9f2b8a0AI6+o04IeNFDxMDox5wRISBsc84XneSZA15bmmAMNtntmHbbcpx4dqhOJsTbv+4xDyb+W0QANUPLrLG8OhEvE+vhWYdDJv1udO8bI8NfDIfnxxio6L/eKwZyEpxPYAwZA7AV8SyAJcezTNqU1VgUZ9DiJptirE3ZCKcbiRdQ5b5O/nXNE6w0zTSgNOE78nAIAnyD91LnmRIj+bADC8ICj1Zyv7tCNQseyNZVhfTzhnKb5/k3U/KWAavl868MOdDqYud2Z/IAc98dqiWnLKbb6YFIvNC9M5N/suTO5OeyMpDVTrUqqk5WKUKwTrAT4ooioqnUdxmAZTCLFLnQaJHS2deY3D3aAChuFX7gXF9Gbk9wKrFqqLq2r4AhKfOUzUO1iAFt8H2t7MiKM0IjB3FOvbpBLIVQX+tPZVgH5sco6a2yZqwAUoanIwU23NQS/ONBMWaaP5TfBwxX8RRmcUKiy6OxZB2ig9z5pkKMncd0pb2EZgLVCiaezgiz3IyP3rUzKNoeJPfGjaylvTUsx5/IaQQYlzrZiBGjiCnG/ximnNPwzsCU4Ms66oR4/yVCogyoeNzqDk0pxul5zhYy8eLI/MZnJGhCboygkHD6O4mmLTdkVh2hyiJOk3Sa3MkSoBM3t0/jqR6DEYD0e0z0BnrWFFDNxsnhRt+MFc1W+exIDEI3IIOAhx4Iby446CACqHKZ/1uRop8BcPzPOBECIkJ2UNI AdvrjzJD ktOPoQz4j6FKQkIukt27w9gQfyvV1ZEy1J1XGSyHvQx5cOUDtmjRMx9yENJRJzt/3k6joq0g6c95yuBsRQV0n8GNWb9PgfHClANO1yMEvWhuTyPDPzWG/thXMNpQcEFtH/KfDWanH5VQGCHV85QxBBmv9Yh6wTAZxnv7qe/I8pfOc+Wr38hYKvXGbLQsUWSlhWiIoH5ddciotCrsXwreoncFjpyxhesWu+l2iP+gANtjlJiAPj3m1THBniGngOkCAgLzU/FNWZNZ4VkEWA6vQJyZTQWQowKQSW5SEa0qV8AB61on99YcSbyNXtYlnY8fvH+F+N6PgP9YN2kCpOo4bdSsTk9OvU1LPFwd4 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 Reviewed-by: Daniel Gomez --- 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);