[LTP] [PATCH] lib/tst_test.c: Scale default tmpfs size with filesystem block size

Wake Liu wakel@google.com
Mon Nov 23 13:33:51 CET 2026


When .dev_min_size is not set, limit_tmpfs_mount_size() mounts tmpfs
with a fixed 32MB size limit. Because tmpfs allocates space in whole
filesystem blocks (kernel PAGE_SIZE), 32MB provides 8192 blocks with
4KB pages, but only 2048 blocks with 16KB pages and 512 blocks with
64KB pages.

After commit 3c212bef5d11 ("inode01: Drop redundant 512MB dev_min_size
requirement"), inode01 creates 5460 non-empty files in parallel across
5 workers and fails with ENOSPC on tmpfs when the kernel uses 16KB or
64KB pages.

Query the actual tmpfs block size via memfd_create() and fstatvfs()
(falling back to getpagesize() when unavailable) rather than deriving
it from getpagesize(), as the kernel page size can also differ from the
page size reported to userspace. Scale the default 32MB limit by
MAX(block_size / 4096, 1) to keep a consistent 8192-block budget across
all page configurations.

Fixes: 21c8759f445f ("lib: adjust the tmpfs size according to .dev_min_size and MemAvailable")
Fixes: 3c212bef5d11 ("inode01: Drop redundant 512MB dev_min_size requirement")
Suggested-by: Avinesh Kumar <avinesh.kumar@suse.com>
Signed-off-by: Wake Liu <wakel@google.com>
---
Context: https://lore.kernel.org/ltp/20261117125658.1743505-1-wakel@google.com/

 lib/tst_test.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 10ff73397..957635e02 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1257,6 +1257,31 @@ int tst_creat_unlinked(const char *path, int flags, mode_t mode)
 	return fd;
 }
 
+/*
+ * tmpfs allocates space in filesystem blocks (kernel PAGE_SIZE), which may
+ * exceed 4KB or differ from the page size reported to userspace. Query the
+ * actual tmpfs block size via memfd_create() + fstatvfs() so the default
+ * mount size keeps an 8192-block budget across all page configurations.
+ */
+static unsigned long get_tmpfs_block_size(void)
+{
+	struct statvfs st;
+	int fd = -1;
+
+	if (__NR_memfd_create != __LTP__NR_INVALID_SYSCALL)
+		fd = syscall(__NR_memfd_create, "ltp_tmpfs", 0);
+
+	if (fd >= 0) {
+		int ret = fstatvfs(fd, &st);
+
+		SAFE_CLOSE(fd);
+		if (!ret && st.f_bsize > 0)
+			return st.f_bsize;
+	}
+
+	return getpagesize();
+}
+
 static const char *limit_tmpfs_mount_size(const char *mnt_data,
 		char *buf, size_t buf_size, const char *fs_type)
 {
@@ -1266,7 +1291,7 @@ static const char *limit_tmpfs_mount_size(const char *mnt_data,
 		return mnt_data;
 
 	if (!tst_test->dev_min_size)
-		tmpfs_size = 32;
+		tmpfs_size = 32 * MAX(get_tmpfs_block_size() / 4096, 1UL);
 	else
 		tmpfs_size = tdev.size;
 
-- 
2.56.1.750.gf70dc682cf-goog



More information about the ltp mailing list