All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Wake Liu <wakel@google.com>, Kalesh Singh <kaleshsingh@google.com>
Subject: [LTP] [PATCH] lib/tst_test.c: Scale default tmpfs size with filesystem block size
Date: Mon, 23 Nov 2026 12:33:51 +0000	[thread overview]
Message-ID: <20261123123351.1496233-1-wakel@google.com> (raw)
In-Reply-To: <20261119134825.294248-1-wakel@google.com>

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


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

  reply	other threads:[~2026-11-23 12:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:56 [LTP] [PATCH] inode01: Drop redundant 512MB dev_min_size requirement Wake Liu via ltp
2026-11-18  9:44 ` Avinesh Kumar via ltp
2026-11-18 10:19 ` Cyril Hrubis
2026-11-19 13:01 ` Avinesh Kumar via ltp
2026-11-19 13:48   ` Wake Liu via ltp
2026-11-23 12:33     ` Wake Liu via ltp [this message]
2026-11-23 20:37       ` [LTP] lib/tst_test.c: Scale default tmpfs size with filesystem block size 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=20261123123351.1496233-1-wakel@google.com \
    --to=ltp@lists.linux.it \
    --cc=kaleshsingh@google.com \
    --cc=wakel@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.