[LTP] [PATCH v2 2/3] swapon04: Add test for discard flags

Li Wang li.wang@linux.dev
Fri Aug 28 11:37:49 CEST 2026


Andrea Cervesato wrote:

> +static void verify_swapon(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +	int fd;
> +	struct stat st;
> +	blkcnt_t blocks_before, blocks_after;
> +	const char *const mkswap_argv[] = {"mkswap", loop_dev, NULL};
> +
> +	tst_res(TINFO, "Testing swapon(%s, %s)", loop_dev, tc->desc);
> +
> +	tst_fill_file(BACKING_FILE, 'A', TST_MB, SWAP_SIZE_MB);
> +

Or, we need to confirm with an XFS developer/expert whether this
should be treated as a minor bug or is worth fixing on 6.6.

If not, then the code comment below is needed.

	/*
	 * Flush the backing file to disk before formatting it with mkswap.

	 * XFS uses delayed allocation, and without fsync the blocks written
	 * by tst_fill_file() may remain as unwritten extents in page cache.
	 * If swapon(2) with SWAP_FLAG_DISCARD is called while such extents
	 * are still pending, the discard request may not cover the whole
	 * swap area, causing the test to fail spuriously.
	 *
	 * This is especially visible on kernel 6.6, where the XFS/swap
	 * discard path does not force delalloc extents to be resolved.
	 */

> +	fd = SAFE_OPEN(BACKING_FILE, O_RDONLY);
> +	SAFE_FSYNC(fd);
> +	SAFE_CLOSE(fd);

-- 
Regards,
Li Wang


More information about the ltp mailing list