linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slab_common: use helper function is_power_of_2()
@ 2022-02-17  9:16 Miaohe Lin
  2022-02-17  9:23 ` Vlastimil Babka
  0 siblings, 1 reply; 5+ messages in thread
From: Miaohe Lin @ 2022-02-17  9:16 UTC (permalink / raw)
  To: akpm, cl, penberg, rientjes, iamjoonsoo.kim, vbabka
  Cc: linux-mm, linux-kernel, linmiaohe

Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power
of two. Minor readability improvement.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/slab_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index 23f2ab0713b7..6ee64d6208b3 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -807,7 +807,7 @@ void __init setup_kmalloc_cache_index_table(void)
 	unsigned int i;
 
 	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
-		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
+		!is_power_of_2(KMALLOC_MIN_SIZE));
 
 	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
 		unsigned int elem = size_index_elem(i);
-- 
2.23.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slab_common: use helper function is_power_of_2()
  2022-02-17  9:16 [PATCH] mm/slab_common: use helper function is_power_of_2() Miaohe Lin
@ 2022-02-17  9:23 ` Vlastimil Babka
  2022-02-17 10:44   ` Miaohe Lin
  0 siblings, 1 reply; 5+ messages in thread
From: Vlastimil Babka @ 2022-02-17  9:23 UTC (permalink / raw)
  To: Miaohe Lin, akpm, cl, penberg, rientjes, iamjoonsoo.kim
  Cc: linux-mm, linux-kernel

On 2/17/22 10:16, Miaohe Lin wrote:
> Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power
> of two. Minor readability improvement.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

We can try, but in case some compiler will no longer able to perform the
check at build-time (although is_power_of_2() looks sufficiently trivial
too), we'll have to revert it.

> ---
>  mm/slab_common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 23f2ab0713b7..6ee64d6208b3 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -807,7 +807,7 @@ void __init setup_kmalloc_cache_index_table(void)
>  	unsigned int i;
>  
>  	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
> -		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
> +		!is_power_of_2(KMALLOC_MIN_SIZE));
>  
>  	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
>  		unsigned int elem = size_index_elem(i);



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slab_common: use helper function is_power_of_2()
  2022-02-17  9:23 ` Vlastimil Babka
@ 2022-02-17 10:44   ` Miaohe Lin
  2022-02-17 17:04     ` Vlastimil Babka
  0 siblings, 1 reply; 5+ messages in thread
From: Miaohe Lin @ 2022-02-17 10:44 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: linux-mm, linux-kernel, Andrew Morton, Christoph Lameter,
	penberg, rientjes, iamjoonsoo.kim

On 2022/2/17 17:23, Vlastimil Babka wrote:
> On 2/17/22 10:16, Miaohe Lin wrote:
>> Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power
>> of two. Minor readability improvement.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> 
> We can try, but in case some compiler will no longer able to perform the
> check at build-time (although is_power_of_2() looks sufficiently trivial
> too), we'll have to revert it.

I see. I checked the compiler in my env but there might be some compilers can't
perform the check at build-time.

Many thanks for your reply.

> 
>> ---
>>  mm/slab_common.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/slab_common.c b/mm/slab_common.c
>> index 23f2ab0713b7..6ee64d6208b3 100644
>> --- a/mm/slab_common.c
>> +++ b/mm/slab_common.c
>> @@ -807,7 +807,7 @@ void __init setup_kmalloc_cache_index_table(void)
>>  	unsigned int i;
>>  
>>  	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
>> -		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
>> +		!is_power_of_2(KMALLOC_MIN_SIZE));
>>  
>>  	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
>>  		unsigned int elem = size_index_elem(i);
> 
> .
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slab_common: use helper function is_power_of_2()
  2022-02-17 10:44   ` Miaohe Lin
@ 2022-02-17 17:04     ` Vlastimil Babka
  2022-02-18  1:15       ` Miaohe Lin
  0 siblings, 1 reply; 5+ messages in thread
From: Vlastimil Babka @ 2022-02-17 17:04 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: linux-mm, linux-kernel, Andrew Morton, Christoph Lameter,
	penberg, rientjes, iamjoonsoo.kim

On 2/17/22 11:44, Miaohe Lin wrote:
> On 2022/2/17 17:23, Vlastimil Babka wrote:
>> On 2/17/22 10:16, Miaohe Lin wrote:
>>> Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power
>>> of two. Minor readability improvement.
>>>
>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> 
>> We can try, but in case some compiler will no longer able to perform the
>> check at build-time (although is_power_of_2() looks sufficiently trivial
>> too), we'll have to revert it.
> 
> I see. I checked the compiler in my env but there might be some compilers can't
> perform the check at build-time.

I'll add this to the slab tree and linux-next and we'll see if wider testing
uncovers such compilers. Should be unlikely.

> Many thanks for your reply.
> 
>> 
>>> ---
>>>  mm/slab_common.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/mm/slab_common.c b/mm/slab_common.c
>>> index 23f2ab0713b7..6ee64d6208b3 100644
>>> --- a/mm/slab_common.c
>>> +++ b/mm/slab_common.c
>>> @@ -807,7 +807,7 @@ void __init setup_kmalloc_cache_index_table(void)
>>>  	unsigned int i;
>>>  
>>>  	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
>>> -		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
>>> +		!is_power_of_2(KMALLOC_MIN_SIZE));
>>>  
>>>  	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
>>>  		unsigned int elem = size_index_elem(i);
>> 
>> .
>> 
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm/slab_common: use helper function is_power_of_2()
  2022-02-17 17:04     ` Vlastimil Babka
@ 2022-02-18  1:15       ` Miaohe Lin
  0 siblings, 0 replies; 5+ messages in thread
From: Miaohe Lin @ 2022-02-18  1:15 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: linux-mm, linux-kernel, Andrew Morton, Christoph Lameter,
	penberg, rientjes, iamjoonsoo.kim

On 2022/2/18 1:04, Vlastimil Babka wrote:
> On 2/17/22 11:44, Miaohe Lin wrote:
>> On 2022/2/17 17:23, Vlastimil Babka wrote:
>>> On 2/17/22 10:16, Miaohe Lin wrote:
>>>> Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power
>>>> of two. Minor readability improvement.
>>>>
>>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>>
>>> We can try, but in case some compiler will no longer able to perform the
>>> check at build-time (although is_power_of_2() looks sufficiently trivial
>>> too), we'll have to revert it.
>>
>> I see. I checked the compiler in my env but there might be some compilers can't
>> perform the check at build-time.
> 
> I'll add this to the slab tree and linux-next and we'll see if wider testing
> uncovers such compilers. Should be unlikely.

Many thanks! :)

> 
>> Many thanks for your reply.
>>
>>>
>>>> ---
>>>>  mm/slab_common.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/mm/slab_common.c b/mm/slab_common.c
>>>> index 23f2ab0713b7..6ee64d6208b3 100644
>>>> --- a/mm/slab_common.c
>>>> +++ b/mm/slab_common.c
>>>> @@ -807,7 +807,7 @@ void __init setup_kmalloc_cache_index_table(void)
>>>>  	unsigned int i;
>>>>  
>>>>  	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
>>>> -		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
>>>> +		!is_power_of_2(KMALLOC_MIN_SIZE));
>>>>  
>>>>  	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
>>>>  		unsigned int elem = size_index_elem(i);
>>>
>>> .
>>>
>>
> 
> .
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-18  1:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17  9:16 [PATCH] mm/slab_common: use helper function is_power_of_2() Miaohe Lin
2022-02-17  9:23 ` Vlastimil Babka
2022-02-17 10:44   ` Miaohe Lin
2022-02-17 17:04     ` Vlastimil Babka
2022-02-18  1:15       ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox