Linux Test Project
 help / color / mirror / Atom feed
From: linuxtestproject.agent@gmail.com
To: Pavithra <pavrampu@linux.ibm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs
Date: Sat, 19 Sep 2026 20:14:26 +0000	[thread overview]
Message-ID: <20260919201426.9129-1-linuxtestproject.agent@gmail.com> (raw)
In-Reply-To: <20260919174920.1078796-1-pavrampu@linux.ibm.com>

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-09-19 20:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 17:49 [LTP] [PATCH v7] hugetlb/hugefallocate: Add hugefallocate03 to stress test fallocate on hugetlbfs Pavithra
2026-09-19 20:14 ` linuxtestproject.agent [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-09-20 11:35 [LTP] [PATCH v8] " Pavithra
2026-09-20 14:43 ` [LTP] " linuxtestproject.agent
2026-09-23  8:01 [LTP] [PATCH v9] " Pavithra
2026-09-23 10:00 ` [LTP] " linuxtestproject.agent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260919201426.9129-1-linuxtestproject.agent@gmail.com \
    --to=linuxtestproject.agent@gmail.com \
    --cc=ltp@lists.linux.it \
    --cc=pavrampu@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox