From: Chris Gellermann <christian.gellermann@codasip.com>
To: shuah@kernel.org, linux-kselftest@vger.kernel.org
Cc: reddybalavignesh9979@gmail.com, richard.weiyang@gmail.com,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Chris Gellermann <christian.gellermann@codasip.com>
Subject: [PATCH 2/2] selftests/dma-buf: Skip some tests if not enough free huge pages
Date: Thu, 3 Sep 2026 12:50:18 +0200 [thread overview]
Message-ID: <20260903105018.565425-3-christian.gellermann@codasip.com> (raw)
In-Reply-To: <20260903105018.565425-1-christian.gellermann@codasip.com>
Subtests 6 and 7 of the udmabuf test require free huge pages. If there
are not enough huge pages available, the entire test fails on an mmap:
ok 4 drivers/dma-buf/udmabuf: [PASS,test-4]
ok 5 drivers/dma-buf/udmabuf: [PASS,test-5]
drivers/dma-buf/udmabuf: ubuf_fd mmap fail
Instead of failing, check if there are enough huge pages available
beforehand and potentially skip the subtests 6 and 7.
Signed-off-by: Chris Gellermann <christian.gellermann@codasip.com>
---
.../selftests/drivers/dma-buf/udmabuf.c | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/tools/testing/selftests/drivers/dma-buf/udmabuf.c b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
index 2def04ed3451..daa2fc6c2c27 100644
--- a/tools/testing/selftests/drivers/dma-buf/udmabuf.c
+++ b/tools/testing/selftests/drivers/dma-buf/udmabuf.c
@@ -25,6 +25,34 @@
static unsigned int page_size;
+static bool enough_free_huge_pages(off_t size)
+{
+ unsigned long free_pages = 0, hpage_size_kb = 0;
+ bool found_free = false, found_size = false;
+ char line[256];
+ FILE *f;
+
+ f = fopen("/proc/meminfo", "r");
+ if (!f)
+ return false;
+
+ while (fgets(line, sizeof(line), f)) {
+ if (sscanf(line, "HugePages_Free: %lu", &free_pages) == 1)
+ found_free = true;
+ if (sscanf(line, "Hugepagesize: %lu kB", &hpage_size_kb) == 1)
+ found_size = true;
+ if (found_free && found_size)
+ break;
+ }
+ fclose(f);
+
+ if (!found_free || !found_size)
+ return false;
+
+ return ((unsigned long long)free_pages * hpage_size_kb * 1024ULL) >=
+ (unsigned long long)size;
+}
+
static int create_memfd_with_seals(off_t size, bool hpage)
{
int memfd, ret;
@@ -236,6 +264,13 @@ int main(int argc, char *argv[])
/* should work (migration of 2MB size huge pages)*/
page_size = getpagesize() * 512; /* 2 MB */
size = MEMFD_SIZE * page_size;
+ if (!enough_free_huge_pages(size)) {
+ ksft_test_result_skip("%s: [SKIP,test-6] not enough huge pages\n",
+ TEST_PREFIX);
+ ksft_test_result_skip("%s: [SKIP,test-7] not enough huge pages\n",
+ TEST_PREFIX);
+ goto out;
+ }
memfd = create_memfd_with_seals(size, true);
addr1 = mmap_fd(memfd, size);
write_to_memfd(addr1, size, 'a');
@@ -268,6 +303,7 @@ int main(int argc, char *argv[])
close(buf);
close(memfd);
+out:
close(devfd);
ksft_print_msg("%s: ok\n", TEST_PREFIX);
--
2.47.3
prev parent reply other threads:[~2026-09-03 10:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 10:50 [PATCH 0/2] selftests/dma-buf: Minor improvements to udmabuf selftest Chris Gellermann
2026-09-03 10:50 ` [PATCH 1/2] selftests/dma-buf: Convert off64_t to off_t for portability Chris Gellermann
2026-09-03 10:50 ` Chris Gellermann [this message]
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=20260903105018.565425-3-christian.gellermann@codasip.com \
--to=christian.gellermann@codasip.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=reddybalavignesh9979@gmail.com \
--cc=richard.weiyang@gmail.com \
--cc=shuah@kernel.org \
/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