Skip to contentSkip to conversation

mem/min_free_kbytes: fix comment typo and whitespace alignment

PATCH Applied Sachin Sant 3 participants 7 messages Jul 10 – Jul 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mem/min_free_kbytes: fix comment typo and whitespace alignment

Fix the typo '%2 MemTotal' -> '2% MemTotal' in the file header comment. Remove spurious leading spaces from continuation lines in tst_res() calls and remove unnecessary braces around a single-statement if body, bringing the file in line with LTP coding style.

---
 testcases/kernel/mem/tunable/min_free_kbytes.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
testcases/kernel/mem/tunable/min_free_kbytes.c +6 -7
index bdc9126c2..b1d00e453 100644
@@ -17,7 +17,7 @@
  *
  * 1. default min_free_kbytes with all ``overcommit_memory`` policy
  * 2. 2x default value with all ``overcommit_memory`` policy
- * 3. 5% of MemFree or %2 MemTotal with all ``overcommit_memory`` policy
+ * 3. 5% of MemFree or 2% MemTotal with all ``overcommit_memory`` policy
  *
  * [References]
  *
@@ -114,7 +114,7 @@ static void test_tune(unsigned long overcommit_policy)
 		if (overcommit_policy == 2) {
 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				tst_res(TFAIL, "child unexpectedly failed: %s",
-					 tst_strstatus(status));
+					tst_strstatus(status));
 		} else if (overcommit_policy == 1) {
 			if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL)
 #ifdef TST_ABI32
@@ -122,20 +122,19 @@ static void test_tune(unsigned long overcommit_policy)
 				if (total_mem < 3145728UL)
 #endif
 					tst_res(TFAIL, "child unexpectedly failed: %s",
-						 tst_strstatus(status));
+						tst_strstatus(status));
 #ifdef TST_ABI32
 				/* in 32-bit system, a process allocate about 3Gb memory at most */
 				else
 					tst_res(TINFO, "Child can't allocate "
-						 ">3Gb memory in 32bit system");
+						">3Gb memory in 32bit system");
 			}
 #endif
 		} else {
 			if (WIFEXITED(status)) {
-				if (WEXITSTATUS(status) != 0) {
+				if (WEXITSTATUS(status) != 0)
 					tst_res(TFAIL, "child unexpectedly failed: %s",
 						tst_strstatus(status));
-				}
 			} else if (!WIFSIGNALED(status) ||
 				   WTERMSIG(status) != SIGKILL) {
 				tst_res(TFAIL, "child unexpectedly failed: %s",
@@ -182,7 +181,7 @@ static void check_monitor(void)
 
 		if (memfree < tune) {
 			tst_res(TINFO, "MemFree is %lu kB, "
-				 "min_free_kbytes is %lu kB", memfree, tune);
+				"min_free_kbytes is %lu kB", memfree, tune);
 			tst_res(TFAIL, "MemFree < min_free_kbytes");
 		}
 
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v3 2/2 mem/min_free_kbytes: refactor to use SAFE_FORK and simplify tune logic

The test mixed old bare-fork patterns with the newer LTP API, making it hard to follow and easy to miscount pass/fail results. Extract the tune selection into set_min_free_kbytes(), replace raw fork() with SAFE_FORK() throughout, and drop the manual SAFE_WAITPID on the monitor child — the framework's tst_reap_children() handles it after test_all() returns.

---
v2 -> v3:
- Extracted tune selection into a new set_min_free_kbytes() helper, replacing the open-coded if/else chain in test_tune().
- Replaced raw fork() with SAFE_FORK() in test_tune(); pid array collapsed to a single pid_t since each child is waited inline.
- Dropped SAFE_WAITPID on the monitor child from min_free_kbytes_test(); tst_reap_children() called by the framework after test_all() returns handles it instead.
- Replaced bare MIN() open-code in tune selection with the MIN() macro.
- Dropped leftover TPASS/TFAIL from the parent's wait block; result reporting stays solely in check_monitor().

v1 -> v2:
- Addressed review comments by moving TPASS/TFAIL reporting into check_monitor() in the child process.

---
 .../kernel/mem/tunable/min_free_kbytes.c      | 67 ++++++++++---------
 1 file changed, 34 insertions(+), 33 deletions(-)
testcases/kernel/mem/tunable/min_free_kbytes.c +34 -33
index b1d00e453..4f991025a 100644
@@ -44,9 +44,30 @@ static int eatup_mem(unsigned long overcommit_policy);
 static void check_monitor(void);
 static void sighandler(int signo LTP_ATTRIBUTE_UNUSED);
 
+static void set_min_free_kbytes(int i)
+{
+	unsigned long memfree, memtotal, tune;
+
+	switch (i) {
+	case 0:
+		tune = default_tune;
+		break;
+	case 1:
+		tune = 2 * default_tune;
+		break;
+	default:
+		memfree = SAFE_READ_MEMINFO("MemFree:");
+		memtotal = SAFE_READ_MEMINFO("MemTotal:");
+		tune = MIN(memfree / 20, memtotal / 50);
+		break;
+	}
+
+	TST_SYS_CONF_LONG_SET(PATH_VM_MIN_FREE_KBYTES, tune, 1);
+}
+
 static void min_free_kbytes_test(void)
 {
-	int pid, status;
+	pid_t pid;
 	struct sigaction sa;
 
 	sa.sa_handler = sighandler;
@@ -56,7 +77,6 @@ static void min_free_kbytes_test(void)
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		/* startup the check monitor */
 		check_monitor();
 		exit(0);
 	}
@@ -66,50 +86,26 @@ static void min_free_kbytes_test(void)
 	test_tune(1);
 
 	SAFE_KILL(pid, SIGUSR1);
-	SAFE_WAITPID(pid, &status, WUNTRACED | WCONTINUED);
-
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
-		tst_res(TFAIL, "check_monitor child exit with status: %s",
-			tst_strstatus(status));
-
-	tst_res(TPASS, "min_free_kbytes test pass");
 }
 
 static void test_tune(unsigned long overcommit_policy)
 {
 	int status;
-	int pid[3];
-	int ret, i;
-	unsigned long tune, memfree, memtotal;
+	pid_t pid;
+	int i;
 
 	TST_SYS_CONF_LONG_SET(PATH_VM_OVERCOMMIT_MEMORY, overcommit_policy, 1);
 
 	for (i = 0; i < 3; i++) {
-		if (i == 0)
-			TST_SYS_CONF_LONG_SET(PATH_VM_MIN_FREE_KBYTES, default_tune, 1);
-		else if (i == 1) {
-			TST_SYS_CONF_LONG_SET(PATH_VM_MIN_FREE_KBYTES, 2 * default_tune, 1);
-		} else {
-			memfree = SAFE_READ_MEMINFO("MemFree:");
-			memtotal = SAFE_READ_MEMINFO("MemTotal:");
-			tune = memfree / 20;
-			if (tune > (memtotal / 50))
-				tune = memtotal / 50;
-
-			TST_SYS_CONF_LONG_SET(PATH_VM_MIN_FREE_KBYTES, tune, 1);
-		}
+		set_min_free_kbytes(i);
 
 		fflush(stdout);
-		switch (pid[i] = fork()) {
-		case -1:
-			tst_brk(TBROK | TERRNO, "fork");
-			break;
-		case 0:
-			ret = eatup_mem(overcommit_policy);
-			exit(ret);
+		pid = SAFE_FORK();
+		if (pid == 0) {
+			exit(eatup_mem(overcommit_policy));
 		}
 
-		SAFE_WAITPID(pid[i], &status, WUNTRACED | WCONTINUED);
+		SAFE_WAITPID(pid, &status, WUNTRACED | WCONTINUED);
 
 		if (overcommit_policy == 2) {
 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
@@ -172,6 +168,7 @@ static int eatup_mem(unsigned long overcommit_policy)
 
 static void check_monitor(void)
 {
+	int violated = 0;
 	unsigned long tune;
 	unsigned long memfree;
 
@@ -183,10 +180,14 @@ static void check_monitor(void)
 			tst_res(TINFO, "MemFree is %lu kB, "
 				"min_free_kbytes is %lu kB", memfree, tune);
 			tst_res(TFAIL, "MemFree < min_free_kbytes");
+			violated = 1;
 		}
 
 		sleep(2);
 	}
+
+	if (!violated)
+		tst_res(TPASS, "min_free_kbytes test pass");
 }
 
 static void sighandler(int signo LTP_ATTRIBUTE_UNUSED)
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Andrea Cervesato on v3 2/2
#2 lore raw

Re: [LTP] [PATCH v3 2/2] mem/min_free_kbytes: refactor to use SAFE_FORK and simplify tune logic

LGTM, but next time please follow the patch-set convention of having

[PATCH <version> <number>/<total>] <subject>

The v3 1/2 is missing the right version tag and it's not linked to the second patch in this way.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Sachin Sant

Hi Sachin,

Quoted 1 line · Sachin Sant

mem/min_free_kbytes: fix comment typo and whitespace alignment

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp