[08/10] mm/slub: Fix MAX_ORDER usage in calculate_order()

Message ID 20230315113133.11326-9-kirill.shutemov@linux.intel.com
State New
Headers
Series Fix confusion around MAX_ORDER |

Commit Message

Kirill A. Shutemov March 15, 2023, 11:31 a.m. UTC
  MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
can deliver is MAX_ORDER-1.

Fix MAX_ORDER usage in calculate_order().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Vlastimil Babka March 16, 2023, 11:18 a.m. UTC | #1
On 3/15/23 12:31, Kirill A. Shutemov wrote:
> MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
> can deliver is MAX_ORDER-1.
> 
> Fix MAX_ORDER usage in calculate_order().
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>

Reviewed-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  mm/slub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 39327e98fce3..32eb6b50fe18 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4171,7 +4171,7 @@ static inline int calculate_order(unsigned int size)
>  	/*
>  	 * Doh this slab cannot be placed using slub_max_order.
>  	 */
> -	order = calc_slab_order(size, 1, MAX_ORDER, 1);
> +	order = calc_slab_order(size, 1, MAX_ORDER - 1, 1);
>  	if (order < MAX_ORDER)
>  		return order;
>  	return -ENOSYS;
  

Patch

diff --git a/mm/slub.c b/mm/slub.c
index 39327e98fce3..32eb6b50fe18 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4171,7 +4171,7 @@  static inline int calculate_order(unsigned int size)
 	/*
 	 * Doh this slab cannot be placed using slub_max_order.
 	 */
-	order = calc_slab_order(size, 1, MAX_ORDER, 1);
+	order = calc_slab_order(size, 1, MAX_ORDER - 1, 1);
 	if (order < MAX_ORDER)
 		return order;
 	return -ENOSYS;