Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1316177rwj; Sat, 29 Oct 2022 21:34:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7oNyefYgbU+baVktthwmAkvRtPAffWATqyNtzMViFnEO0xu3ZpqTHy9piXGt1siEcbSxJE X-Received: by 2002:a05:6a00:2187:b0:56d:4d02:5776 with SMTP id h7-20020a056a00218700b0056d4d025776mr1087242pfi.4.1667104444427; Sat, 29 Oct 2022 21:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667104444; cv=none; d=google.com; s=arc-20160816; b=FhldpkAnCE+daiaOseHLx+7yYpBQYM4kSoTYkxHAV1sVO0f3FVKj6mGSv4a9JRwXD9 +TdnBTvLr8ZiIHs8O5mhXx9ApEvcmt1G0nodom+7FT5wNRJ2JR1JuHKRvVB1fpJoi4JI ocFdG6fac41QNyGTYJuTSNgBOY/Gg8A7Wj67Al+RqyNpMiunDUD0fQlX4y+ncfREx1aC BZ+MZxbFnZwtyHlucvgwbjMBkWmY62A+i3ZxpYrmBhrGejoCXKzE1J19cCQhETNBarVy o/XcqBg7xvsiBdJUm20HAHOzqmzIueB8B+wO6oWveVEnfzAjMcPzlJ1rEcQI+ToqYyRB GMUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=pS7AZ/Tfdzwte7j4jjsc2iqCeEjErFBQNVNROTsodAU=; b=K+gFj680fIcEbs7cytBKWNjGaZrO1W5Br98I6ez0wbfdA1Tq6KQQLpgDLL/XgT0N4U Mz8cX+OPPC6yVOhRiiyTvKGgCJmRGIhlXA3ywN1e55rQDpb0R/ebTDjISqxKOMUMUb+b ExWR2k+h4xBpRU0VDagb0LGyyOnrfgiIrKiGRqEa0DxdyhJvybmxKoupKmfrqhE4omMv S4c/nbm53NRYM55dui/5//9B79QzkXN94PFM0tGsT9ebPyEVjru9h8Udm4FrLx5ew4f0 zTS4uZPp2kYsX82rsGY5SThIF0WMqyg5ww9rNB4/NRTq/OcraUSveaOtER+rxb5PpNX+ E8KQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=acm.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 188-20020a6309c5000000b0043c5fa4c118si4127137pgj.814.2022.10.29.21.33.51; Sat, 29 Oct 2022 21:34:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=acm.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbiJ3Dd3 (ORCPT + 99 others); Sat, 29 Oct 2022 23:33:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbiJ3Dd0 (ORCPT ); Sat, 29 Oct 2022 23:33:26 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68D86476D5; Sat, 29 Oct 2022 20:33:25 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id d24so8099215pls.4; Sat, 29 Oct 2022 20:33:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pS7AZ/Tfdzwte7j4jjsc2iqCeEjErFBQNVNROTsodAU=; b=pPrR0QNR8mH+0ZJCRHO29bYOoN7n0ue4L3m6Wf2LJ79HAGyKL3dklDhSVFk1Ucy7iT DPsrxFNney55zCNVV7bkjo+2QUZ8GFXGQd27kThbb+4DYdQAWHoB+QaAYsxRenGeyS1o 0dznYftmT3zG7wt0CO5N/U7zrpJqmeyiYJQe11xGGJevsQ1Dotqknp3Xh0dKOUCq1QWb SPdj1ZRGLN8++KK+FXrUprQ4Mc0O8RhlrFJGjwmfPnrUvz95+hbOrdZEWROJLhR/xTfd 6eJ4yopmHEpQoB/vDt6ZCHZhjQEq3UkG0ncnjmSB80LzwuTCOcWfvkre93BMc9AyCmqK qJSg== X-Gm-Message-State: ACrzQf2n0DmDfDVdcOdp1lyHGtPeQ4rGY6ho0CCkdJkuUMPBYtNOlWjN +IrOEsd6pi5mQ0U/au4ZWnIuOheUpNc= X-Received: by 2002:a17:90a:6043:b0:213:8043:4b85 with SMTP id h3-20020a17090a604300b0021380434b85mr7504475pjm.135.1667100804466; Sat, 29 Oct 2022 20:33:24 -0700 (PDT) Received: from [192.168.3.219] ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id u12-20020a170902714c00b00186881688f2sm234240plm.220.2022.10.29.20.33.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Oct 2022 20:33:23 -0700 (PDT) Message-ID: Date: Sat, 29 Oct 2022 20:33:22 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH v2] block: simplify blksize_bits() implementation Content-Language: en-US To: Dawei Li Cc: axboe@kernel.dk, hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <8ccaabc1-2834-dad6-7d46-19bfc2adcc9a@acm.org> From: Bart Van Assche In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no 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 On 10/29/22 20:25, Dawei Li wrote: > On Sat, Oct 29, 2022 at 08:00:58PM -0700, Bart Van Assche wrote: >> On 10/29/22 19:17, Dawei Li wrote: >>> 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; >>> } >> >> Why the rounding ("+ SECTOR_SIZE - 1")? The blksize_bits() argument should >> be an argument of two. > > Yeah, that's what's supposed to be. > But I thought maybe a "just in case" is more robust? > Should we consider these corner cases(!is_power_of_2())? I don't think that the Linux kernel supports block sizes that are not a power of two. Hence my request to leave out the rounding code. Keeping that code would be misleading because it would suggest that the blksize_bits() argument can be something else than a power of two. Thanks, Bart.