mm/slab_common: use helper function is_power_of_2()
Subsystems (2)
PATCH 1/1 mm/slab_common: use helper function is_power_of_2()
Use helper function is_power_of_2() to check if KMALLOC_MIN_SIZE is power of two. Minor readability improvement.
--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slab_common.c +1 -1
@@ -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);
Signature · 1 line
2.23.0
Quoted 4 lines · Miaohe Lin
Use helper function
is_power_of_2()to check ifKMALLOC_MIN_SIZEis power of two. Minor readability improvement.Signed-off-by Miaohe Lin <[email protected]>
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.
Quoted 17 lines
--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slab_common.c +1
-1@@ -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);
Quoted 9 lines · Vlastimil Babka
Quoted 4 lines · Miaohe Lin
Use helper function
is_power_of_2()to check ifKMALLOC_MIN_SIZEis power of two. Minor readability improvement.Signed-off-by Miaohe Lin <[email protected]>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.
Quoted 21 lines
Quoted 10 lines
--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slab_common.c +0
-0mm/slab_common.c void __init setup_kmalloc_cache_index_table(void) · line 813
Quoted 8 lines
mm/slab_common.c +1
-1@@ -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);.
Quoted 5 lines · Miaohe Lin
Quoted 4 lines · Vlastimil Babka
Quoted 3 lines · Miaohe Lin
Use helper function
is_power_of_2()to check ifKMALLOC_MIN_SIZEis power of two. Minor readability improvement.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Miaohe Lin <[email protected]>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.
Quoted 24 lines
Many thanks for your reply.
Quoted 21 lines
Quoted 10 lines
--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slab_common.c +0
-0mm/slab_common.c void __init setup_kmalloc_cache_index_table(void) · line 813
Quoted 8 lines
mm/slab_common.c +1
-1@@ -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);.
Quoted 12 lines · Vlastimil Babka
Quoted 11 lines · Miaohe Lin
Quoted 9 lines · Vlastimil Babka
Quoted 4 lines · Miaohe Lin
Use helper function
is_power_of_2()to check ifKMALLOC_MIN_SIZEis power of two. Minor readability improvement.Signed-off-by Miaohe Lin <[email protected]>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.
Quoted 5 lines
Quoted 2 lines
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! :)
Quoted 28 lines
Quoted 25 lines
Many thanks for your reply.
Quoted 21 lines
Quoted 10 lines
--- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/slab_common.c +0
-0mm/slab_common.c void __init setup_kmalloc_cache_index_table(void) · line 813
Quoted 8 lines
mm/slab_common.c +1
-1@@ -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);.
.