[LTP] hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Sat Nov 7 11:51:45 CET 2026
Hi Pavithra,
On Sat Nov 7, 2026, Pavithra <pavrampu@linux.ibm.com> wrote:
> hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
> +#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.
> + 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);
> + 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.
> + 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
More information about the ltp
mailing list