Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1224452rwj; Sat, 29 Oct 2022 19:29:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5hL0QwnnLZ6QoMy/zsd77j1nn2DzZZDhLq62yoXD0nmNWTDQViK+9QNJ6Wq0qq0x+EFlsB X-Received: by 2002:a17:90b:4c87:b0:213:5fe0:6700 with SMTP id my7-20020a17090b4c8700b002135fe06700mr22181532pjb.128.1667096951912; Sat, 29 Oct 2022 19:29:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667096951; cv=pass; d=google.com; s=arc-20160816; b=kpXCp1NhIMoa8TfPHhYAGxNpTtJoMSO6XPe/SLNkfRGScNuwuMY1DgMKWSLBgrDyPG 8cmt91VKwY3fsqhTZUF1GeFxuyUo3z7sPbx23VYXOlfGvXU4L2VbNrafEXVPFsbJfV8L I9O+oVZbweEGG2DIq9IEi8KFO36Cuqq4IG9fd+Zp996MTA0RzmOxdhH0rt66I0xosNkv vreDIbd1/sMFoaUV2Q1ub3WR3sGf5NKXuYVrVXcKmOMUkMWcQtNwmimP0n3yQQOaFFUh hREghA+JsqBB85L23a5cXtwiluGCdJX0jPEKGyyC2wI114JnHT2oUi7ucl8xiPt43Tq3 WSMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=IO+84D9jCg0WxptftHfpbztfGm5ak1HXCre0nWNImkk=; b=yj41n57mYQtEHxPSOkLpbWyfXMlZ08fWDoxAode2Xkz4Tj6sAoDCMveio9Pt8wkUIg XQPpAOyLz9BSDkHoLJ/mY/6z49xNcrYbDgCQ2JbpFdZLydy/i/6C8ZFCh8oXte15l+88 /HEGnCn4+154fiSksMIUiTqQMzg2j6wRYIUXeJt46REf4UXvA1j64Nr6EUvtIsxwvJ1U p5w8DtUKt3oo0t6prmYfda/S3RitA1foaCPro7tc8Izw7oUlBw+eA17TDeA0vCYSsb7a +lIxMkk2CV5iaoeBQtG4WYU+xqMmIBk+g3HJWTgfJsuKjH1gRilXrn8+qf3PSXOT+r6w Ov8g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=jeF1j1m4; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m1-20020a655641000000b0046ec91a400asi3907521pgs.70.2022.10.29.19.28.43; Sat, 29 Oct 2022 19:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=jeF1j1m4; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbiJ3CSe (ORCPT + 99 others); Sat, 29 Oct 2022 22:18:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJ3CSc (ORCPT ); Sat, 29 Oct 2022 22:18:32 -0400 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2037.outbound.protection.outlook.com [40.92.99.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C001648C88; Sat, 29 Oct 2022 19:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TWPFMBntAOvp7HGyugY24seknsAIH5eWekYWMlQU+wYclKXioc6Z5tOhz1TacWmow5XKgROy3uFYYSWk1LgG6eK/316kuEJUXoK8mltObzrZV9mLRuT4mSVh/f+yXdUF1wzbPwtRjKdhQ2HixmOyzS+RX7IsupX8bkNCE095Ax6/luYO/ECvfi2JwSupMbsZMWWExvIdkB8h5P9WP0SK8D9etpmPusDBiiQS88NA8bKk9OCG0msJRgcpE+ehOHnswqF7f32DRAEjrWeAUiN8Vz27FdaimFaW2BwWMES2Sa7x2LnX6TVrfakcPZzR5Xo3m9aMG4Ui75nw/QzegLFVpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IO+84D9jCg0WxptftHfpbztfGm5ak1HXCre0nWNImkk=; b=HGdnjJ15Ontv7z7F8GboWzo+6J6vGFQFpH4J7wnfzPL+xRVVdnTteDpAynevcldwvSxYnVVqH/MIwLrRrW5RW/hi0WxQ/eatSMRUCjD5U8bQBT2rvkpsG5G04NfRVQuzRZAs+rPUknJYb3BIiBPGJgfjEYRfsIJXOtfMMgoMyzx5n8BnNMT0DCyZ+yxBuCFC9n5d2KdQlHcrRhM/PpwYZMPT3rJvzlwfDgibJRxrCQFq14Sgph1oTv8SyZUjn5lWvqLzHlB2WMDl43bzJJ4k23wawrNGNc7NTWqR6UnJwTkb17xcFUNI5mGD/dnbHN+Y8xwt9KcJJbXSGdv3bf6Wig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IO+84D9jCg0WxptftHfpbztfGm5ak1HXCre0nWNImkk=; b=jeF1j1m4/a1D+XorYrCnbhuedVgEz8+wBFKPYZDLQQ7Qs7k4bzyrWp2WKvbLqT4+6TsL9KJsW4VlddAVIBC7aOil2ZndFIyo2DqBeDEqdHzO+i1awZrGQWEM0z+DdxQda/Zwizqopx9J866RuTCoCUxWQ5l//GRbqpwGbP1zESSwWO8ErqzLaAPhoRMplUe0EUegfovsLxDuNDx3aibVwVXgY5jh/p6+SqynXH0aPyCptPZs8OJQvB0/b3J/fhlOa35S/deHOPDeXTurKY4TwJj1MoKMmasRzYbIRJwKE7yzo8daPN2H/jXKS/VwXaJ7Fu2WlRrDy1Qx2AMdKURjOQ== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OSZP286MB2425.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:158::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.18; Sun, 30 Oct 2022 02:18:28 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::c90e:cbf3:c23d:43a5%7]) with mapi id 15.20.5769.018; Sun, 30 Oct 2022 02:18:28 +0000 From: Dawei Li To: axboe@kernel.dk Cc: bvanassche@acm.org, hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Dawei Li Subject: [PATCH v2] block: simplify blksize_bits() implementation Date: Sun, 30 Oct 2022 10:17:40 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [9HSdnovjQQHzSqg7rseYfRemzlra+KSE] X-ClientProxiedBy: TYAPR01CA0101.jpnprd01.prod.outlook.com (2603:1096:404:2a::17) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221030021740.37524-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OSZP286MB2425:EE_ X-MS-Office365-Filtering-Correlation-Id: 818c2ad8-76d2-4abf-5d20-08daba1d0811 X-MS-Exchange-SLBlob-MailProps: ZLYX9kf+sFbSGQPCthfGnzMHvcLRKUdKeNqTJvdXx5yW499aUNx3ai3ufwtx6YTCv9APsjdUkxNFRm+W4CDyL0aeCBVTv3RyjB7vn1hOenEwWERvjCSLCT2JpqWnbaxsnjrpOmyBYRSg8ey0WyLZchf38pa8Xs3uX2plGKOS85CfeaiM2syBVokfxxyEO+03Lzig/gjeY0sxeVv2/fe7FArIIMyKtNSLReC9eQriDXqgtegImThOoQiIURaojmJ5mQ29GdOMshnKrj6tIuF5YLheRlaJUZellgObtKTGhB4rh6G5zsb/wZd3NM6RtdihgYH61hA3TgJp9JxknputXr3mwjdNDzkuw8tuw21R4+mvgBPHa0eSQwSdPYQVC3ZWNt97l5JWWjASeoif1CpfwC1ShUZwy92WXJiEhvys/0QeRPSyKT/KAETyDbx33LJmJxeEWPEWhPvv835WQ70u2YDj03uOF+XGMAJY3bx8kcMqTlToJHqgIG9im2HTksWXliANNa1bsb20cP31zWdVX8+kMvjRgIfYISoQkp/ypKPhRUOnOBPQJMRpmQZt0Z/FOyNpJlw8t32SdzDzfriRWFFtlqsrF1uKKTWAORKjwMCKi3PIpzix818OLoZDhEFBPnQZAA/9HC68uE3vtnv3jH47DDoxe3jQvKKaepaWyzUWCYy+LRJGfIlfp5feOw0lwzGZTYXO59tqRDKC3IE9ZLoincrVq8c0wkebMaUHoOi57f3n/OdW5OAdBNj8101JITJFe2RFoGf6LzP6SxliT17Kw/fekDKu/nTv/vt7o6ndsJKqAXz+MA== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message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?= =?us-ascii?Q?GvoTHIJJR2vh0oZowFipTFTiirvvMnHh/9eRZNuqKYSlS2T//JWpKE0skZOD?= =?us-ascii?Q?H9pYwJnVaugCJy21SEJnO8RdreplaktnkN3G4v/2IamJCX2c2PnDLduNX5oj?= =?us-ascii?Q?YgajVSnLAUBzk1/CSEFtwjJ/AouIh4ZfM2rZCJ3Q7A=3D=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 818c2ad8-76d2-4abf-5d20-08daba1d0811 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2022 02:18:28.0238 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZP286MB2425 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert current looping-based implementation into bit operation, which can bring improvement for: 1) bitops is more efficient for its arch-level optimization. 2) Given that blksize_bits() is inline, _if_ @size is compile-time constant, it's possible that order_base_2() _may_ make output compile-time evaluated, depending on code context and compiler behavior. v1: https://lore.kernel.org/all/TYCP286MB2323169D81A806A7C1F7FDF1CA309@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM v2: Remove the ternary operator, based on Bart's suggestion But this may lead to break for corner cases below: BUILD_BUG_ON(blksize_bits(1025) != 11); So make a minor modification by adding (SECTOR_SIZE - 1) before shifting. base-commit: 30209debe98b6f66b13591e59e5272cb65b3945e Signed-off-by: Dawei Li --- include/linux/blkdev.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 57ed49f20d2e..7b537afe8b38 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1349,12 +1349,7 @@ static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, /* assumes size > 256 */ static inline unsigned int blksize_bits(unsigned int size) { - unsigned int bits = 8; - do { - bits++; - size >>= 1; - } while (size > 256); - return bits; + return order_base_2((size + SECTOR_SIZE - 1) >> SECTOR_SHIFT) + SECTOR_SHIFT; } static inline unsigned int block_size(struct block_device *bdev) -- 2.25.1