From 7892bf808b6f748684af7defa0c0a8611cc4be50 Mon Sep 17 00:00:00 2001 From: xbasel <103044017+xbasel@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:04:27 +0200 Subject: [PATCH] Fix test_reclaimFilePageCache to avoid tmpfs (#1379) Avoid tmpfs as fadvise(FADV_DONTNEED) has no effect on memory-backed filesystems. Fixes https://github.com/valkey-io/valkey/issues/897 --------- Signed-off-by: Ran Shidlansik Signed-off-by: ranshid <88133677+ranshid@users.noreply.github.com> Co-authored-by: ranshid <88133677+ranshid@users.noreply.github.com> Co-authored-by: Ran Shidlansik --- src/unit/test_util.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/unit/test_util.c b/src/unit/test_util.c index 4558c38c3..9858318e0 100644 --- a/src/unit/test_util.c +++ b/src/unit/test_util.c @@ -6,6 +6,11 @@ #include "../util.h" #include "test_help.h" +#if defined(__linux__) +#include +#include +#endif + int test_string2ll(int argc, char **argv, int flags) { UNUSED(argc); UNUSED(argv); @@ -291,6 +296,15 @@ int test_reclaimFilePageCache(int argc, char **argv, int flags) { if (flags & UNIT_TEST_VALGRIND) return 0; #if defined(__linux__) + struct statfs stats; + + /* Check if /tmp is memory-backed (e.g., tmpfs) */ + if (statfs("/tmp", &stats) == 0) { + if (stats.f_type != TMPFS_MAGIC) { // Not tmpfs, use /tmp + return 0; + } + } + char *tmpfile = "/tmp/redis-reclaim-cache-test"; int fd = open(tmpfile, O_RDWR | O_CREAT, 0644); TEST_ASSERT(fd >= 0);