From patchwork Tue Nov 12 07:45:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13871826 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 A8288D41D5F for ; Tue, 12 Nov 2024 07:46:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF3F06B00DC; Tue, 12 Nov 2024 02:46:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA3676B00E1; Tue, 12 Nov 2024 02:46:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6A5A6B00E3; Tue, 12 Nov 2024 02:46:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 831BD6B00E1 for ; Tue, 12 Nov 2024 02:46:02 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1F43240D61 for ; Tue, 12 Nov 2024 07:46:02 +0000 (UTC) X-FDA: 82776658482.18.27AF650 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by imf03.hostedemail.com (Postfix) with ESMTP id 0D6B720004 for ; Tue, 12 Nov 2024 07:45:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=wYjKhkeq; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 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=1731397472; 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=1SJuihJYAFsIthe48Yp7PlQqFbbRscF0mbHdHErE/Xs=; b=7sZJeEu89V+qhbHeYJ8fboGhX7cGHXe7LR7Ruj8qaKbcNZz15AYnucnHAC8owOE7j7tZxC lnL0H4SlX3eD8bslwE0fYAY9m+Jo7HeUPIl2lutJ6fWG0G+q0z01WxMRQQ1GXu4JcCHpmO 7D+8BULB4tEgDJweLz2cJ7bmqlHZQdI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731397473; a=rsa-sha256; cv=none; b=d17UI8/DmcM/ZUgcHx48CPRHTyvvXa1ebQEV4h6FS377c6MULF1NAe0zMA6B392pllykS0 rN0ws0JIjDc5m0lODhJdZSvSFWZ9haFGn3XjHC6iF9hdCgWdQY7r1e5ifhEiAUVgzQyioM swg/pEQ9G9CqY39XEvNakP8qlhnNOz8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=wYjKhkeq; spf=pass (imf03.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.112 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731397557; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=1SJuihJYAFsIthe48Yp7PlQqFbbRscF0mbHdHErE/Xs=; b=wYjKhkeq8/+I1kjCLIVs9e/KnVLWp+PFKid+1SqkOdru0vsvHQdI2XOSxJaf/rG3AjwVbw05Iq4LZfIIY2NAdZHt/U8Gn63pbKFwkHTtghmgATm7oPg/toqZX4w6JbwSgbd21mkiIJOxkVAs+rANKHyDzJDuA+0sTKzm92eQqWo= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WJGDWme_1731397555 cluster:ay36) by smtp.aliyun-inc.com; Tue, 12 Nov 2024 15:45: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 v2 1/5] mm: factor out the order calculation into a new helper Date: Tue, 12 Nov 2024 15:45:48 +0800 Message-Id: <582997bd09b17a292124ea47dabc2ea5642daade.1731397290.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: rspam10 X-Stat-Signature: u7h316d93eazjt6cyrh13jnxngd9kdne X-Rspamd-Queue-Id: 0D6B720004 X-Rspam-User: X-HE-Tag: 1731397540-806025 X-HE-Meta: U2FsdGVkX1+cBQye1WIi+xMNehklLbEY4hGG2J32H2M3pMF0SkzVSESfwx6ESGE7iGoRSoee/ShRn3wueIvGHfShm5NqgYghUc498ob73ZwSVXrECkOT7ikS0Hd0tZmbuUn/N+LvC80OJFS/1CAdlgiBWxWsCzdH1nzt2YH2wJz81JmjdEYsnxn82HRi/n0Eg55a1jcUzkObnmnfG0QUQUjJLfauad9QMt1INjclYt2XrhqSluyaqrhV3eSdByueDQTICURcR5Da+ueoesWAIM8MYDnyCvqIvbXHWEefYXUkBL0/0Yo8auHXq81IjPiVArViW0ds4TI5fJLv6t41YOvgjEjYgAR/nrGvXTb7TLdWpizWaCuOMz9NuE6m+hkWAAD7NUQuB+5KiJWLtggYnofaVxSne1IA2jYJOei0YcC9T0ojBczwjxn9n6LV2BXpSSI617UodjBMJP836d5ntCdNqE0ZM3+8KEBSMYjgsT5ETmL/QheMtNJFPWDXwMnUhCmEAKXEpjc7tmTS5p8znIOnH0ujFgUJ/AjacyilwTzoTboy11JEt3V5SL4G79+O0BT734FHjdWewf/dNYvg4A8TUc8Vx6V/V/P0ZMeRMwtKnd12M/xpteujWP0t4w8LMUSsqnAROgkPMLiUvdMFm//pt2BMy7/d0cgEJgYbOehBJfpwq4bZ2sIrUxKYY4LIKF01iW0bJ1hT7DvCUu2TNM/cq8ZfbPHjxzSg4SulvMO/c1vQz2WkrQl3Tb3bz/UYaZNYjvvTPoAYi3baK85wCn+qPwbGQykn/qsvM0HlgKMKtFTNnz7PK875jmsFT/CQ0eRhEy/WeOVaDioLZtQ/MP8WDO2KBDkn4W2h2gahWTSXCFPtYsj6SwEaJe6uWTQyeAzHsv25DQnf964M0Z+uck943HXva1SBaH38uAU3kFTPbjiGpSzJB3RMqIqkCJhTtshzasPOqB+TzVjV4sb NkQ3W5D4 1oa9S6gysn/xN+kMpQtu9x6SJltLxxsyGp5/F5o60Ul066KZxmpdCGwqfdOojehDc37cLEKn9EvBxduXH8KAyZ3FTTfzpaS7xxbWPsCB+ohkWqlBLxBalrNIavgk2Nf3GWfEEjma9p6ygsejyY25G9vS83niCuBrj8Lw73kgK34P2yFRhcEvBQ4W3EI1bu9PhcxC/H8ljE9ktDtWL1P/pmpptW5XlW1CQkcAxR0UbSjql5Riy7c6L5bDa6ZIWkixnPErrKw1dZ2o620L8QJXNAhqZxjpzjMBkIa11elCI7FBVkK4pPJL8bQtpR8QZUHzYNSy9z66sJFa9ohE= 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);