[LTP] [PATCH] syscalls/cachestat01: Fix num_shift calculation

Cyril Hrubis chrubis@suse.cz
Thu Sep 11 10:57:00 CEST 2025


The calculation added in commit 8422d46 works only for 64k page size.
This commit fixes the calculation so that it properly detects maximal
num_shift regardless the page_size.

Closes #1258

Fixes: 8422d4680b21 ("cachestat01: Reduce required space on 64kb page size")
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/cachestat/cachestat01.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/cachestat/cachestat01.c b/testcases/kernel/syscalls/cachestat/cachestat01.c
index e218747d9..aa6f21d41 100644
--- a/testcases/kernel/syscalls/cachestat/cachestat01.c
+++ b/testcases/kernel/syscalls/cachestat/cachestat01.c
@@ -72,7 +72,14 @@ static void run(unsigned int use_sync)
 static void setup(void)
 {
 	page_size = (int)sysconf(_SC_PAGESIZE);
-	num_shift = MIN(tst_device->size*1024*2.5/page_size, 15);
+
+	for (num_shift = 0; num_shift <= 15; num_shift++) {
+		if ((1lu<<num_shift) * page_size / 1024 >= tst_device->size) {
+			tst_res(TINFO, "Limiting num_shift to %i\n", num_shift);
+			break;
+		}
+	}
+
 	page_data = SAFE_MALLOC(page_size);
 	memset(page_data, 'a', page_size);
 }
-- 
2.49.1



More information about the ltp mailing list