Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2447369ybb; Mon, 30 Mar 2020 06:22:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsjHsU50eGncIW5dXTFk1JukpaeKwJyzEpkkKHlaUDLddQJVUWQn8kxgZBpGWaiifbp0O5a X-Received: by 2002:aca:fcd8:: with SMTP id a207mr3884651oii.56.1585574579058; Mon, 30 Mar 2020 06:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585574579; cv=none; d=google.com; s=arc-20160816; b=C6KA/vQG6qeZgnvbbSTqUoyadqyZrrgBP34ejcNBD2PfbdwDgH59bEaz5T9Q5FB0L8 oOEMyw39gWQPgLzPQDR35WXYKZNem99BX2aXrv1zeZH7D1YU0YA6T9MngNptpFT2R59q /2L4EN4xHO1dLa9xQokLX6tKFjMnZEdpcYSHyLZaLGtTAYoG8n97mEFf4w379s2YmcUv n+A9in5gbGb/lPwroX1eEa9zQqL1vkehlU1fqaFwx2mUy4vOrbjPd5JPoLI/BefQMwzB 7KOrK8IiH+zHqfxPTg7v7xC6AQEmHABjwSExXLnlqr5SmX5WPltkb84KcCXEJ+Paz2x4 qgXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=MJCgOUEW8BzVvh8w7blL/dFDhkt5EMD9LfcMnUWKMzU=; b=aWgdNmsJKzv2A2yBjcqb/0PeI7jvL2/bbnzWkdqcKfAa2395X8poVb77PVZZLKFYuR FUCpF+e/3C60+2lAZ/rcxdMvUiwJXD0Ugybw9U3iGuQ3OTb1YHrhLfP43UUsCZNpwmgC 4X7tXW3wxjkLize0lL2YFea8y3T/FAOPJXnirbCSrL/W2CvbEqHXMpC28keckQB+/2Hw Sh2mkl5XaDteWciKyrAWGPhF/tXVl6mQVdb7CwhjBN5j7/Zw1qeqzhlPY5b2T4kao7sn IlYbCUKX0kCA8gzriHIlEoP26Fq7gtfJvLkO5ec9xAk+crew75JLTYH6QCBkxFr+BscP bVjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qK3lRE+K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z139si6145707ooa.70.2020.03.30.06.22.45; Mon, 30 Mar 2020 06:22:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qK3lRE+K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730340AbgC3NU2 (ORCPT + 99 others); Mon, 30 Mar 2020 09:20:28 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48126 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730304AbgC3NU2 (ORCPT ); Mon, 30 Mar 2020 09:20:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MJCgOUEW8BzVvh8w7blL/dFDhkt5EMD9LfcMnUWKMzU=; b=qK3lRE+KkWFZl8d23RcdBm6dPk N9/utmsRdB0KHKhtqHKigBTfrq2eYhoQgE6+S4QYXcTiGb3QJkHaJbioVMyPfKLUCCa+hlbASrkbH x9eDboHIyCbKPJq/njxYG5XStVBvPPlUMjLkHKXLrsGhdA8xOAoYs7DcoQ5dkGW6xbbtUJ6BPwjSw Px3WKjlYdSQ/+otL63yaS00J9KNcmU2oglHRZhjNVHUZrl10TarvH68UBSLlTWtKUCUPrQH8MTIfO auK+z1ot+e5setANEGV8A+iJH74+T/osThh0OBdxpUIqKiKif4L5zWgjzBtGZbd/dR+cO9kPi0EOS IRNaHGnw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jIuL6-0007Bd-5i; Mon, 30 Mar 2020 13:20:28 +0000 Date: Mon, 30 Mar 2020 06:20:28 -0700 From: Matthew Wilcox To: Wei Yang Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/9] XArray: simplify the calculation of shift Message-ID: <20200330132028.GA22483@bombadil.infradead.org> References: <20200330123643.17120-1-richard.weiyang@gmail.com> <20200330123643.17120-3-richard.weiyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200330123643.17120-3-richard.weiyang@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 30, 2020 at 12:36:36PM +0000, Wei Yang wrote: > When head is NULL, shift is calculated from max. Currently we use a loop > to detect how many XA_CHUNK_SHIFT is need to cover max. > > To achieve this, we can get number of bits max expands and round it up > to XA_CHUNK_SHIFT. > > Signed-off-by: Wei Yang > --- > lib/xarray.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/lib/xarray.c b/lib/xarray.c > index 1d9fab7db8da..6454cf3f5b4c 100644 > --- a/lib/xarray.c > +++ b/lib/xarray.c > @@ -560,11 +560,7 @@ static int xas_expand(struct xa_state *xas, void *head) > unsigned long max = xas_max(xas); > > if (!head) { > - if (max == 0) > - return 0; > - while ((max >> shift) >= XA_CHUNK_SIZE) > - shift += XA_CHUNK_SHIFT; > - return shift + XA_CHUNK_SHIFT; > + return roundup(fls_long(max), XA_CHUNK_SHIFT); This doesn't give the same number. Did you test this? Consider max = 64. The current code does: shift = 0; 64 >> 0 >= 64 (true) shift += 6; 64 >> 6 < 64 return 12 Your replacement does: fls_long(64) = 6 roundup(6, 6) is 6. Please be more careful.