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

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Wed Sep 23 12:00:43 CEST 2026


Hi Pavithra,

On Wed Sep 23 13:31:50 2026 +0530, Pavithra wrote:
> hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs

> +static int fd = -1;
> +static unsigned long max_hpages;
> +static long hpage_size;
> +static void *thread_fallocate(void *arg)

Add a blank line between variable declarations and function definitions.

> +	SAFE_SIGACTION(SIGBUS, &sa, NULL);
> +
> +	fault_mmap_addr = SAFE_MMAP(NULL, max_hpages * hpage_size,
> +			PROT_READ | PROT_WRITE, MAP_SHARED,
> +			fd, 0);
> +
> +	pthread_cleanup_push(thread_fault_cleanup, NULL);
> +
> +	while (1) {
> +		tpage = ((long long)random()) % (max_hpages);
> +
> +		if (sigsetjmp(fault_jmp, 1) == 0) {
> +			foo = *((char *)(fault_mmap_addr + (tpage * hpage_size)));
> +			*((volatile char *)(fault_mmap_addr + (tpage * hpage_size))) = foo;
> +		}

Save the original SIGBUS handler and restore it upon thread termination or in
cleanup. If SIGBUS is raised after this thread terminates, siglongjmp() jumps
to an invalid stack.

> +	while (1) {
> +		addr = mmap(NULL, max_hpages * hpage_size,
> +				PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> +		if (addr != MAP_FAILED)
> +			SAFE_MUNMAP(addr, max_hpages * hpage_size);
> +
> +		pthread_testcancel();
> +	}

Use SAFE_MMAP() instead of mmap() and drop the MAP_FAILED check.

> +	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);

Because .hugepages uses TST_REQUEST, nr_hpages_free and max_hpages can be 0.
When max_hpages is 0, fallocate() fails with EINVAL (causing TBROK instead of
TCONF), and the worker threads divide by zero. Add a check to abort with
tst_brk(TCONF, ...) when max_hpages is 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