* [PATCH] quota: code cleanup for hash bits calculation
@ 2019-09-21 1:56 Chengguang Xu
2019-09-23 10:02 ` Jan Kara
0 siblings, 1 reply; 3+ messages in thread
From: Chengguang Xu @ 2019-09-21 1:56 UTC (permalink / raw)
To: jack; +Cc: linux-kernel, Chengguang Xu
Code cleanup for hash bits calculation by
calling rounddown_pow_of_two() and ilog2()
Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
---
fs/quota/dquot.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 6e826b454082..679dd3b5db70 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -2983,13 +2983,9 @@ static int __init dquot_init(void)
/* Find power-of-two hlist_heads which can fit into allocation */
nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
- dq_hash_bits = 0;
- do {
- dq_hash_bits++;
- } while (nr_hash >> dq_hash_bits);
- dq_hash_bits--;
+ nr_hash = rounddown_pow_of_two(nr_hash);
+ dq_hash_bits = ilog2(nr_hash);
- nr_hash = 1UL << dq_hash_bits;
dq_hash_mask = nr_hash - 1;
for (i = 0; i < nr_hash; i++)
INIT_HLIST_HEAD(dquot_hash + i);
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] quota: code cleanup for hash bits calculation
2019-09-21 1:56 [PATCH] quota: code cleanup for hash bits calculation Chengguang Xu
@ 2019-09-23 10:02 ` Jan Kara
2019-09-23 13:36 ` admin
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2019-09-23 10:02 UTC (permalink / raw)
To: Chengguang Xu; +Cc: Jan Kara, linux-kernel
On Sat 21-09-19 09:56:28, Chengguang Xu wrote:
> Code cleanup for hash bits calculation by
> calling rounddown_pow_of_two() and ilog2()
>
> Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
Thanks for the patch! One comment below:
> diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
> index 6e826b454082..679dd3b5db70 100644
> --- a/fs/quota/dquot.c
> +++ b/fs/quota/dquot.c
> @@ -2983,13 +2983,9 @@ static int __init dquot_init(void)
>
> /* Find power-of-two hlist_heads which can fit into allocation */
> nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
> - dq_hash_bits = 0;
> - do {
> - dq_hash_bits++;
> - } while (nr_hash >> dq_hash_bits);
> - dq_hash_bits--;
> + nr_hash = rounddown_pow_of_two(nr_hash);
> + dq_hash_bits = ilog2(nr_hash);
>
> - nr_hash = 1UL << dq_hash_bits;
Why not just:
dq_hash_bits = ilog2(nr_hash);
nr_hash = 1UL << dq_hash_bits;
That way we need to compute fls() only once...
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] quota: code cleanup for hash bits calculation
2019-09-23 10:02 ` Jan Kara
@ 2019-09-23 13:36 ` admin
0 siblings, 0 replies; 3+ messages in thread
From: admin @ 2019-09-23 13:36 UTC (permalink / raw)
To: Jan Kara; +Cc: Jan Kara, linux-kernel
---- 在 星期一, 2019-09-23 18:02:53 Jan Kara <jack@suse.cz> 撰写 ----
> On Sat 21-09-19 09:56:28, Chengguang Xu wrote:
> > Code cleanup for hash bits calculation by
> > calling rounddown_pow_of_two() and ilog2()
> >
> > Signed-off-by: Chengguang Xu <cgxu519@zoho.com.cn>
>
> Thanks for the patch! One comment below:
>
> > diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
> > index 6e826b454082..679dd3b5db70 100644
> > --- a/fs/quota/dquot.c
> > +++ b/fs/quota/dquot.c
> > @@ -2983,13 +2983,9 @@ static int __init dquot_init(void)
> >
> > /* Find power-of-two hlist_heads which can fit into allocation */
> > nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head);
> > - dq_hash_bits = 0;
> > - do {
> > - dq_hash_bits++;
> > - } while (nr_hash >> dq_hash_bits);
> > - dq_hash_bits--;
> > + nr_hash = rounddown_pow_of_two(nr_hash);
> > + dq_hash_bits = ilog2(nr_hash);
> >
> > - nr_hash = 1UL << dq_hash_bits;
>
> Why not just:
> dq_hash_bits = ilog2(nr_hash);
> nr_hash = 1UL << dq_hash_bits;
>
> That way we need to compute fls() only once...
Yeah, you are right, I'll update in v2.
Thanks,
Chengguang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-23 13:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-21 1:56 [PATCH] quota: code cleanup for hash bits calculation Chengguang Xu
2019-09-23 10:02 ` Jan Kara
2019-09-23 13:36 ` admin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox