[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200330123643.17120-3-richard.weiyang@gmail.com>
Date: Mon, 30 Mar 2020 12:36:36 +0000
From: Wei Yang <richard.weiyang@...il.com>
To: willy@...radead.org
Cc: linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
Wei Yang <richard.weiyang@...il.com>
Subject: [PATCH 2/9] XArray: simplify the calculation of shift
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 <richard.weiyang@...il.com>
---
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);
} else if (xa_is_node(head)) {
node = xa_to_node(head);
shift = node->shift + XA_CHUNK_SHIFT;
--
2.23.0
Powered by blists - more mailing lists