hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
PATCH v10 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.
---
v9 -> v10:
- Save the original SIGBUS handler in thread_fault() and restore it before the thread exits.
- Replace pthread_cancel()/pthread_testcancel() and the cleanup handler with a volatile "run" flag.
- Drop the unused thread return value variables and the global fault_mmap_addr.
Link to v9: https://lore.kernel.org/ltp/[email protected]/
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../hugetlb/hugefallocate/hugefallocate03.c | 200 ++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c
runtest/hugetlb +1 -0
@@ -1,5 +1,6 @@ hugefallocate01 hugefallocate01 hugefallocate02 hugefallocate02 +hugefallocate03 hugefallocate03 hugefork01 hugefork01 hugefork02 hugefork02
testcases/kernel/mem/.gitignore +1 -0
@@ -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 +200 -0
200 lines not on this page · raw message
Signature · 5 lines
2.56.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Pavithra,
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 29
Quoted 10 lines · Pavithra
hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +8
-0+#include <pthread.h> +#include <signal.h> +#include <setjmp.h> +#include <time.h> + +#include "hugetlb.h" +#include "lapi/fallocate.h" +#include "tst_safe_pthread.h"
testcases/kernel/mem/hugetlb/hugefallocate/Makefile is missing "hugefallocate03: CFLAGS += -pthread" (or "LDLIBS += -lpthread"). On supported distributions with glibc < 2.34, linking fails with undefined references to pthread_create and pthread_join.
Quoted 5 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +5
-0+for (i =0 ; i <FALLOCATE_ITERATIONS ; i++) { + tpage = ((long long )random ()) % (max_hpages); + err =fallocate (fd, +FALLOC_FL_PUNCH_HOLE |FALLOC_FL_KEEP_SIZE , + tpage * hpage_size, hpage_size);
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 59
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +10
-0+if (err) { +tst_res (TFAIL |TERRNO ,"fallocate(PUNCH_HOLE) failed at page %ld" , tpage); +return NULL ; + } + err =fallocate (fd,0 , tpage * hpage_size, hpage_size); +if (err) { +tst_res (TFAIL |TERRNO ,"fallocate(fill) failed at page %ld" , tpage); +return NULL ; + } + }
Each iteration punches and refills a hugepage, which zeroes a full hugepage in the kernel (e.g. 200 GB total for 2 MB hugepages, or 1.6 TB for 16 MB hugepages on ppc64le) and can exceed the default 30s timeout. Set .runtime in struct tst_test and check tst_remaining_runtime() in the loop condition.
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c line 147
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate03.c new file +12
-0+ nr_hpages_free =SAFE_READ_MEMINFO (MEMINFO_HPAGE_FREE ); + max_hpages =MIN (nr_hpages_free,MAX_PAGES_TO_USE ); + free_before = nr_hpages_free; + rsvd_before =SAFE_READ_MEMINFO (MEMINFO_HPAGE_RSVD ); + +/* First preallocate file with max_hpages pages */ + err =fallocate (fd,0 ,0 , hpage_size * max_hpages); +if (err) { +if (errno ==EOPNOTSUPP ) +tst_brk (TCONF ,"fallocate() Operation is not supported" ); +tst_brk (TBROK |TERRNO ,"fallocate() failed to preallocate" ); + }
Because .hugepages uses TST_REQUEST, tst_hugepages and nr_hpages_free can be 0 when the system cannot allocate hugepages. In that case max_hpages is 0 and fallocate(fd, 0, 0, 0) fails with EINVAL, triggering TBROK instead of TCONF; check "if (!tst_hugepages || !nr_hpages_free) tst_brk(TCONF, ...);" first.
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