Skip to contentSkip to conversation

hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs

PATCH Superseded Pavithra 2 participants 2 messages Sep 20

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Pavithra

author
#0 lore raw

PATCH v8 1/1 hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs

Stress test fallocate() on hugetlbfs with three concurrent threads:
one continuously punches and fills holes, one faults in hugepages, and one continuously mmaps and munmaps the same file range. Verify no hugepage leak occurs after the stress run.

---
v7 -> v8:
- Document why root privileges are required in the test description.
- Format syscall names with Sphinx :manpage: roles and avoid abbreviations.
- Drop redundant mutexes (fault_addr_lock, mmap_munmap_lock) and make mmap_munmap_addr local.
- Add sigsetjmp/siglongjmp handler to safely recover from concurrent SIGBUS during page faults.
- Use non-fatal mmap() in thread_mmap_munmap to tolerate transient ENOMEM under stress.
- Cast write-back pointer to (volatile char *) to prevent compiler optimization.
- Replace nanosleep() with pthread_testcancel() for thread cancellation points.
- Abort with tst_brk(TBROK) on preallocation failure instead of jumping to cleanup.
- Use TST_EXP_EQ_LU() macros to report hugepage counter assertions.
- Fix format specifiers (%u for seed, %lu for max_hpages) and check (fd != -1) in cleanup(). Link to v7: https://lore.kernel.org/ltp/[email protected]/

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../hugetlb/hugefallocate/hugefallocate03.c   | 220 ++++++++++++++++++
 3 files changed, 222 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c
runtest/hugetlb +1 -0
index 621c9718a..cd1c2794e 100644
@@ -1,5 +1,6 @@
 hugefallocate01 hugefallocate01
 hugefallocate02 hugefallocate02
+hugefallocate03 hugefallocate03
 
 hugefork01 hugefork01
 hugefork02 hugefork02
testcases/kernel/mem/.gitignore +1 -0
index 9e706e1c8..3086d1ac6 100644
@@ -2,6 +2,7 @@
 /cpuset/cpuset02
 /hugetlb/hugefallocate/hugefallocate01
 /hugetlb/hugefallocate/hugefallocate02
+/hugetlb/hugefallocate/hugefallocate03
 /hugetlb/hugefork/hugefork01
 /hugetlb/hugefork/hugefork02
 /hugetlb/hugemmap/hugemmap01
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +220 -0

220 lines not on this page · raw message

Signature · 5 lines
2.55.0


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

Hi Pavithra,

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 26

Quoted 11 lines · Pavithra

hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +9 -0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <signal.h>
+#include <setjmp.h>

Add missing #include <time.h> for time().

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 61

Quoted 9 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +9 -0
+		if (err) {
+			tst_res(TFAIL | TERRNO, "fallocate(PUNCH_HOLE) failed at page %ld:", tpage);
+			thread_err = 1;
+		}
+		err = fallocate(fd, 0, tpage * hpage_size, hpage_size);
+		if (err) {
+			tst_res(TFAIL | TERRNO, "fallocate(fill) failed at page %ld:", tpage);
+			thread_err = 1;
+		}

Drop the trailing colons in the format strings; TERRNO automatically appends ": <errno>". Remove thread_err as tst_res() already records the failure. Break the loop or return early on failure to avoid flooding the test log with thousands of failure messages.

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 82

Quoted 9 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +9 -0
+static void thread_fault_cleanup(void *arg)
+{
+	(void)arg;
+
+	if (fault_mmap_addr) {
+		munmap(fault_mmap_addr, max_hpages * hpage_size);
+		fault_mmap_addr = NULL;
+	}
+}

Use SAFE_MUNMAP() instead of munmap().

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 153

Quoted 3 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +3 -0
+	nr_hpages_free = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
+	max_hpages = MIN(nr_hpages_free, MAX_PAGES_TO_USE);
+	free_before = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);

Assign free_before = nr_hpages_free instead of reading /proc/meminfo twice in consecutive lines.

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 194

Quoted 2 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +2 -0
+	if (thread_err)
+		tst_res(TFAIL, "fallocate() failed during stress, see above");

Remove this check; tst_res() in thread_fallocate() already marks the test as failed.

testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 219

Quoted 1 line
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +1 -0
+	.hugepages = {MAX_PAGES_TO_USE, TST_NEEDS},

Using TST_NEEDS with MAX_PAGES_TO_USE (100) causes unnecessary TCONF on systems where hugepages are large (e.g. 16MB on ppc64le, 512MB on arm64) or where memory is limited. Use TST_REQUEST, or require a smaller minimum in .hugepages to keep the test portable.

Verdict - Needs revision

---
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