From a42e32910ec7aea1d0e6fb493d6666313138962f Mon Sep 17 00:00:00 2001 From: Sergey Senozhatsky Date: Wed, 18 Jan 2023 09:52:08 +0900 Subject: [PATCH] zsmalloc: skip chain size calculation for pow_of_2 classes If a class size is power of 2 then it wastes no memory and the best configuration is 1 physical page per-zspage. Link: https://lkml.kernel.org/r/20230118005210.2814763-3-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky Acked-by: Minchan Kim Cc: Mike Kravetz Signed-off-by: Andrew Morton --- mm/zsmalloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b95be4718ed4..9be92c4257b5 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -2281,6 +2281,9 @@ static int calculate_zspage_chain_size(int class_size) int i, min_waste = INT_MAX; int chain_size = 1; + if (is_power_of_2(class_size)) + return chain_size; + for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) { int waste;