[LTP] hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Sat Sep 19 22:14:26 CEST 2026
Hi Pavithra,
On Sat Sep 19 23:19:20 2026 +0530, Pavithra <pavrampu@linux.ibm.com> wrote:
> hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
> +/*\
> + * Stress test fallocate. This test starts three threads.
> + * Thread one will continually punch/fill holes via falloc.
> + * Thread two will continually fault in those same pages.
> + * Thread three will continually mmap/munmap that page range.
> + */
Format syscall names using the `:manpage:` role (e.g.
`:manpage:`fallocate(2)``, `:manpage:`mmap(2)``, `:manpage:`munmap(2)``)
and avoid abbreviations like "falloc". Document why root privileges are
required (.needs_root = 1).
> + while (1) {
> + tpage = ((long long)random()) % (max_hpages);
> + pthread_mutex_lock(&fault_addr_lock);
> + foo = *((char *)(fault_mmap_addr + (tpage * hpage_size)));
> + *((char *)(fault_mmap_addr + (tpage * hpage_size))) = foo;
> + pthread_mutex_unlock(&fault_addr_lock);
> +
> + nanosleep(&ts, NULL); /* thread cancellation point */
> + }
fault_addr_lock is not accessed by any other thread and can be removed.
Cast to volatile char * when writing back to prevent the compiler from
optimizing out the write. Replace nanosleep(&ts, NULL) with
pthread_testcancel() for thread cancellation.
> + while (1) {
> + pthread_mutex_lock(&mmap_munmap_lock);
> + mmap_munmap_addr = SAFE_MMAP(NULL, max_hpages * hpage_size,
> + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> + SAFE_MUNMAP(mmap_munmap_addr, max_hpages * hpage_size);
> + mmap_munmap_addr = NULL;
> + pthread_mutex_unlock(&mmap_munmap_lock);
> +
> + nanosleep(&ts, NULL); /* thread cancellation point */
> + }
mmap_munmap_lock is unnecessary since no other thread accesses this
address; mmap_munmap_addr can be a local variable. Replace
nanosleep(&ts, NULL) with pthread_testcancel().
> + unsigned int seed = (int)getpid() * time(NULL);
> +
> + srandom(seed);
> + tst_res(TINFO, "Seed = %d", seed);
seed is unsigned int; use %u instead of %d.
> + /* 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_res(TFAIL | TERRNO, "fallocate():");
> + goto windup;
> + }
> +
> + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
> + if (free_before - free_after != max_hpages) {
> + tst_res(TFAIL, "fallocate did not preallocate %ld huge pages",
> + max_hpages);
> + goto windup;
> + }
If fallocate or preallocation fails, branching to windup causes the test
to report TPASS in the subsequent check because SAFE_CLOSE(fd) restores
the free counts and thread_err remains 0. Use tst_brk(TBROK | TERRNO, ...)
to abort on preallocation failure. Also use %lu instead of %ld for
max_hpages.
> +windup:
> + SAFE_CLOSE(fd);
> +
> + free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
> + rsvd_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
> +
> + if (thread_err)
> + tst_res(TFAIL, "fallocate() failed during stress, see above");
> + else if (free_after != free_before || rsvd_after != rsvd_before)
> + tst_res(TFAIL, "free or reserve counts incorrect after fallocate stress test");
> + else
> + tst_res(TPASS, "fallocate stress test passed");
Use TST_EXP_EQ_LU(free_after, free_before) and
TST_EXP_EQ_LU(rsvd_after, rsvd_before) to report free and reserve count
comparisons.
> +static void cleanup(void)
> +{
> + if (fd >= 0)
> + SAFE_CLOSE(fd);
> +}
Use if (fd != -1) instead of if (fd >= 0).
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