Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2504451ybb; Mon, 30 Mar 2020 07:27:37 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvKaifNfKqEVvJTzr3GcXuR/8WGd0U0gZ0Tn1DZR3fmYI9cB4FTxc2uV4ocatuXtj/b27iT X-Received: by 2002:a9d:7ccb:: with SMTP id r11mr9752085otn.204.1585578457703; Mon, 30 Mar 2020 07:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585578457; cv=none; d=google.com; s=arc-20160816; b=JqBEcn73P3O7IX8K05LKrdq00+MHIvkpLUv5KBsi8+0TWS8s+9KD5qdYtFHxv49wJZ vcak3udwFTdQ8eDRrEeWS6THxW7pd6RM5P02+soApW0ifJqqYK1+YicFAz1NIL6Ugvkm gZ+h4Ku7vyipXAU6WthcWexejdcGge+i2qWI4XPlGsDVf/VcN6tYP6jlfzLHsrTD9sOg 1cWdt7oQ0r1UDje4pyWHK0GAaAwkp0Y+LjUzGV6Np7qUxUCOmNLnhcMcFUGcFJNsel55 W5NXyfixWXFmQ1rH9UXQd6BMMnvEb+jVJJs7dCdMizv5SqmzM2vmtGDRrbGtVVmK2JPT xdwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=NkzDxDJV1bnIzEyyQHH60q1JMe3S2qaalEpyevgeDjU=; b=BZYGoe4MSQMVu5Qsm2GGRg0gmV8zEbI/WcQlu+RlNiI35iPrR0ulL1YjOAjY9fmcBq 9GQ/U3IXUJRPQH+YDAAxo9z3Nz6vFlWDYPvUKjLt5q/q2qY5FXPa7aKnK6+0xBNbiAWH /396Ax2dchmhFvabpcaQcVQSYiDFirGpTrGh7OUj2NfFeioWmgawpFVjQpDgYC4x22w4 fOQUf4nDQvtHqZW1GOlJEnCiB6OgMHCUAxgOe6pOaFJ6JeeuYIJE6dBW/Yrx/AoVIuci IFCKgXvsCeEWVDFuycncaGPfh8X1Vd7ZR9RagTY7RWLFXY9dI+xhHJ0KcQTNh3sc0MIa 6fXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=l09D8veP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3si5527941oie.6.2020.03.30.07.27.24; Mon, 30 Mar 2020 07:27:37 -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=pass header.i=@gmail.com header.s=20161025 header.b=l09D8veP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728447AbgC3OHP (ORCPT + 99 others); Mon, 30 Mar 2020 10:07:15 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38129 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgC3OHP (ORCPT ); Mon, 30 Mar 2020 10:07:15 -0400 Received: by mail-wm1-f66.google.com with SMTP id f6so15466477wmj.3; Mon, 30 Mar 2020 07:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=NkzDxDJV1bnIzEyyQHH60q1JMe3S2qaalEpyevgeDjU=; b=l09D8vePmsTy6YJfx5OBWOTZXcDmZP5AqjJZZ2/1V3JxhHYaHl0Ng7dBXXkGqvkbNO 70Gny56xP33iDCFXLwqULkq+3yPJva9Ww7Zdd8Ud2P7Gl5mvKuT+WXIQW/eGwOW5uthm zxw4Dm10afQz6D2RrJbiELMAeI1+bHF32zI8K9wEwL9dgvy452c/UeATCmoOeyG1QwTQ wKasux9fjj7o0Ws3dHATmouJhcROWFRLaPwolcR5qYqd7RcLsmFGDsICAQHN2JIo/DMH DFre0geNYld5cX4Kzxj8bSNs8iYyKDext4OttK9wmN5UQyxn1fDhEvLZxESD9C0fEcDZ ANNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=NkzDxDJV1bnIzEyyQHH60q1JMe3S2qaalEpyevgeDjU=; b=tJqlxP1PmW2LzdAyn77F0pQtuXE7yw66CbIKDB7rtHUFvhQ9ZOzf8agJ2wsULFyuwi jTU2tvVglWEFgVGAvyVxCVcQ1pS171BhKwa1Eu1v93E4CtKCz+O5S9Z6/+TprcwBEvsM /qhN56ciJL4SIN4AulpxlRtT1nbJqh1Du32UW0kBehsAtWCgDoXH9yazQjkozl2tnUPE TXeB06KibDqXV02Xp11c+aDRgzXsWzF2ajLYyeEt/qgbpTTxlr/nytBmAIt6OjdAy8Sx //Q2NqHvcfkWy1h7VhX7qv9cDSzyFnT8A2WAnyzL3Gh7MaWngw+dm8m2Ug46M0uULnQJ Po2w== X-Gm-Message-State: ANhLgQ2e7nAEuxgeREKDxG5ZygFdAlzKvLqupZk09ds8Nm5bsdfA4L8w kFpY8gja4Ue2plc2NPV0TeI= X-Received: by 2002:a1c:8108:: with SMTP id c8mr13124272wmd.50.1585577233309; Mon, 30 Mar 2020 07:07:13 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id b203sm21270063wmc.45.2020.03.30.07.07.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Mar 2020 07:07:12 -0700 (PDT) Date: Mon, 30 Mar 2020 14:07:12 +0000 From: Wei Yang To: Matthew Wilcox Cc: Wei Yang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/9] XArray: simplify the calculation of shift Message-ID: <20200330140712.sloduuoqc5jid64m@master> Reply-To: Wei Yang References: <20200330123643.17120-1-richard.weiyang@gmail.com> <20200330123643.17120-3-richard.weiyang@gmail.com> <20200330132028.GA22483@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200330132028.GA22483@bombadil.infradead.org> User-Agent: NeoMutt/20170113 (1.7.2) 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 06:20:28AM -0700, Matthew Wilcox wrote: >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 fls_long(64) = 7 >roundup(6, 6) is 6. > >Please be more careful. -- Wei Yang Help you, Help me