This patch also enhances this test to make it support running
with ZFS mounted from non-root.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 bsd/sys/cddl/compat/opensolaris/sys/mman.h    |  1 +
 .../opensolaris/uts/common/fs/zfs/arc.c       |  4 +-
 modules/tests/Makefile                        | 11 +--
 tests/misc-zfs-arc.cc                         | 86 ++++++++++++-------
 4 files changed, 63 insertions(+), 39 deletions(-)

diff --git a/bsd/sys/cddl/compat/opensolaris/sys/mman.h 
b/bsd/sys/cddl/compat/opensolaris/sys/mman.h
index ca746898..ec1f17ac 100644
--- a/bsd/sys/cddl/compat/opensolaris/sys/mman.h
+++ b/bsd/sys/cddl/compat/opensolaris/sys/mman.h
@@ -32,6 +32,7 @@
 
 #include_next <sys/mman.h>
 
+#undef mmap64
 #define        mmap64(_a,_b,_c,_d,_e,_f)       mmap(_a,_b,_c,_d,_e,_f)
 
 #endif
diff --git a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c 
b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
index 15b7a59d..ba339ed1 100644
--- a/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
+++ b/bsd/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
@@ -134,6 +134,7 @@
 #include <sys/sdt.h>
 
 #include <bsd/porting/mmu.h>
+#include <osv/export.h>
 
 #ifdef illumos
 #ifndef _KERNEL
@@ -444,6 +445,7 @@ static arc_stats_t arc_stats = {
                }                                                       \
        }
 
+OSV_LIB_SOLARIS_API
 kstat_t                        *arc_ksp;
 static arc_state_t     *arc_anon;
 static arc_state_t     *arc_mru;
@@ -2328,7 +2330,7 @@ arc_flush(spa_t *spa)
        ASSERT(spa || arc_eviction_list == NULL);
 }
 
-void
+OSV_LIB_SOLARIS_API void
 arc_shrink(void)
 {
        if (arc_c > arc_c_min) {
diff --git a/modules/tests/Makefile b/modules/tests/Makefile
index d1732e75..d084e357 100644
--- a/modules/tests/Makefile
+++ b/modules/tests/Makefile
@@ -134,13 +134,9 @@ tests := tst-pthread.so misc-ramdisk.so tst-vblk.so 
tst-bsd-evh.so \
        tst-elf-init.so tst-realloc.so tst-setjmp.so \
        libtls.so libtls_gold.so tst-tls.so tst-tls-gold.so tst-tls-pie.so \
        tst-sigaction.so tst-syscall.so tst-ifaddrs.so tst-getdents.so \
-       tst-netlink.so misc-zfs-io.so
+       tst-netlink.so misc-zfs-io.so misc-zfs-arc.so
 #      libstatic-thread-variable.so tst-static-thread-variable.so \
 
-#TODO For now let us disable these tests for aarch64 until
-# we support floating point numbers, TLS and correct syscall handling
-# The tst-ifaddrs.so is an exception and it does not compile due to some
-# missing headers
 ifeq ($(arch),x64)
 tests += tst-mmx-fpu.so
 endif
@@ -222,10 +218,9 @@ tests += $(boost-tests)
 
 solaris-tests := tst-solaris-taskq.so
 
-# FIXME: two of the test below can't compile now because of include path
-# (BSD and OSv header files get mixed up, etc.).
+#FIXME: the misc-zfs-disk.c does not compile due to some header issues
 #zfs-tests := misc-zfs-disk.so misc-zfs-io.so misc-zfs-arc.so
-zfs-tests := misc-zfs-io.so
+zfs-tests := misc-zfs-io.so misc-zfs-arc.so
 solaris-tests += $(zfs-tests)
 
 $(zfs-tests:%=$(out)/tests/%): COMMON+= \
diff --git a/tests/misc-zfs-arc.cc b/tests/misc-zfs-arc.cc
index b24dd56b..24ce2e26 100644
--- a/tests/misc-zfs-arc.cc
+++ b/tests/misc-zfs-arc.cc
@@ -5,9 +5,6 @@
  * BSD license as described in the LICENSE file in the top-level directory.
  */
 
-#include <osv/mutex.h>
-#include <osv/mempool.hh>
-#include <osv/run.hh>
 #include <osv/debug.hh>
 
 #include "stat.hh"
@@ -19,6 +16,7 @@
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <sys/mman.h>
+#include <sys/sysinfo.h>
 #include <boost/program_options.hpp>
 #include <chrono>
 #include <unordered_map>
@@ -31,6 +29,9 @@ typedef u_long ulong_t;
 #include <machine/atomic.h>
 #include <bsd/porting/netport.h>
 
+#include <osv/osv_c_wrappers.h>
+#include <pthread.h>
+
 #define MB (1024 * 1024)
 
 using namespace std;
@@ -52,7 +53,7 @@ struct arc_data {
     uint64_t size;
 };
 
-static mutex_t kstat_map_mutex;
+static pthread_mutex_t kstat_map_mutex;
 static unordered_map<const char *, struct kstat_named *> kstat_map;
 
 static struct kstat_named *kstat_map_lookup(const char *name)
@@ -86,18 +87,20 @@ static uint64_t *get_kstat_by_name(const kstat_t *ksp, 
const char *name)
 
     assert(ksp && ksp->ks_data);
 
-    WITH_LOCK(kstat_map_mutex) {
-        knp = kstat_map_lookup(name);
+    pthread_mutex_lock(&kstat_map_mutex);
+    knp = kstat_map_lookup(name);
 
-        /* If knp is NULL, kstat_named wasn't found in the hash */
+    /* If knp is NULL, kstat_named wasn't found in the hash */
+    if (!knp) {
+        /* Then do the manual search and insert it into the hash */
+        knp = kstat_map_insert(ksp, name);
         if (!knp) {
-            /* Then do the manual search and insert it into the hash */
-            knp = kstat_map_insert(ksp, name);
-            if (!knp) {
-                return 0;
-            }
+            pthread_mutex_unlock(&kstat_map_mutex);
+            return 0;
         }
     }
+    pthread_mutex_unlock(&kstat_map_mutex);
+
     assert(knp->data_type == KSTAT_DATA_UINT64);
 
     return &(knp->value.ui64);
@@ -297,7 +300,6 @@ static int run_test(const kstat_t *ksp, int argc, char 
**argv)
     struct arc_data data;
     struct stat st;
     char path[PATH_MAX];
-    int ret;
 
     snprintf(path, PATH_MAX, "%s/%s", TESTDIR, argv[0]);
     printf("Running %s", path);
@@ -318,7 +320,7 @@ static int run_test(const kstat_t *ksp, int argc, char 
**argv)
 
     create_arc_data(ksp, data);
 
-    osv::run(path, argc, argv, &ret);
+    int ret = osv_run_app(path, (const char**)argv, argc);
 
     report_arc_data(ksp, data);
 
@@ -353,36 +355,44 @@ static void memory_pressure_scenario(const kstat_t *ksp)
 /*
  * Test used to check performance on linear workloads.
  */
-static int arc_linear_test(const kstat_t *ksp, bool all_cached)
+static int arc_linear_test(const kstat_t *ksp, bool all_cached, const char 
*test_file)
 {
-    char *args[3] = { 0 };
+    char *args[5] = { 0 };
     int argc, ret = 0;
 
     args[0] = strdup("misc-zfs-io.so");
     args[1] = strdup("--no-unlink");
-    argc = 2;
+    args[2] = strdup("--file-path");
+    args[3] = strdup(test_file);
+    argc = 4;
     if (all_cached) {
-        args[2] = strdup("--all-cached");
-        argc = 3;
+        args[4] = strdup("--all-cached");
+        argc = 5;
     }
     ret = run_test(ksp, argc, args);
 
     free(args[0]);
     free(args[1]);
     free(args[2]);
+    free(args[3]);
+    free(args[4]);
 
     args[0] = strdup("misc-zfs-io.so");
     args[1] = strdup("--rdonly");
-    argc = 2;
+    args[2] = strdup("--file-path");
+    args[3] = strdup(test_file);
+    argc = 4;
     if (all_cached) {
-        args[2] = strdup("--all-cached");
-        argc = 3;
+        args[4] = strdup("--all-cached");
+        argc = 5;
     }
     ret = run_test(ksp, argc, args);
 
     free(args[0]);
     free(args[1]);
     free(args[2]);
+    free(args[3]);
+    free(args[4]);
 
     zfs_arc_statistics(ksp);
 
@@ -392,16 +402,20 @@ static int arc_linear_test(const kstat_t *ksp, bool 
all_cached)
 /*
  * Test used to check performance on non-linear workloads.
  */
-static int arc_nonlinear_test(const kstat_t *ksp)
+static int arc_nonlinear_test(const kstat_t *ksp, const char *test_file)
 {
-    char *args[2];
+    char *args[4];
     int ret = 0;
 
     args[0] = strdup("misc-zfs-io.so");
     args[1] = strdup("--random");
-    ret = run_test(ksp, 2, args);
+    args[2] = strdup("--file-path");
+    args[3] = strdup(test_file);
+    ret = run_test(ksp, 4, args);
     free(args[0]);
     free(args[1]);
+    free(args[2]);
+    free(args[3]);
 
     zfs_arc_statistics(ksp);
 
@@ -424,7 +438,9 @@ int main(int argc, char **argv)
         ("check-arc-shrink",
             "check ARC shrink functionality")
         ("test", po::value<std::string>(),
-            "analyze ARC performance on a given testcase, e.g. --test 
tst-001.so");
+            "analyze ARC performance on a given testcase, e.g. --test 
tst-001.so")
+        ("test-file", po::value<std::string>(),
+            "path to a test file, defaults to /zfs-io-file");
 
     po::variables_map vm;
     po::store(po::parse_command_line(argc, argv, desc), vm);
@@ -443,7 +459,12 @@ int main(int argc, char **argv)
     }
 
     printf("System Memory:        %luMB\n", kmem_size() / MB);
-    printf("\tFree: %luMB\n", memory::stats::free() / MB);
+    struct sysinfo info;
+    if (sysinfo(&info)) {
+        fprintf(stderr, "Error: Could not retrieve free memory information\n");
+        return -1;
+    }
+    printf("\tFree: %luMB\n", info.freeram / MB);
     printf("\tUsed: %luMB\n", kmem_used() / MB);
     zfs_arc_statistics(arc_kstat_p);
 
@@ -458,6 +479,11 @@ int main(int argc, char **argv)
             new_arc_target / MB);
     }
 
+    const char *test_file = "/zfs-io-file";
+    if (vm.count("test-file")) {
+        test_file = strdup(vm["test-file"].as<std::string>().c_str());
+    }
+
     if (vm.count("check-arc-shrink")) {
         ret = check_arc_shrink(arc_kstat_p);
         printf("Result: ARC shrink %s.\n", ret == 0 ? "worked" : "didn't 
work");
@@ -467,11 +493,11 @@ int main(int argc, char **argv)
         free(arg0);
     } else {
         printf("\n*** NON-LINEAR WORKLOAD; PREFETCH SHOULDN'T BE EFFECTIVE 
***\n");
-        ret = arc_nonlinear_test(arc_kstat_p);
+        ret = arc_nonlinear_test(arc_kstat_p, test_file);
         printf("\n*** CHECK ARC PERFORMANCE WHEN DATA IS ALL CACHED ***\n");
-        ret |= arc_linear_test(arc_kstat_p, true);
+        ret |= arc_linear_test(arc_kstat_p, true, test_file);
         printf("\n*** READAHEAD AND PAGE REPLACEMENT SCENARIO ***\n");
-        ret |= arc_linear_test(arc_kstat_p, false);
+        ret |= arc_linear_test(arc_kstat_p, false, test_file);
         printf("\n*** MEMORY PRESSURE SCENARIO ***\n");
         memory_pressure_scenario(arc_kstat_p);
     }
-- 
2.35.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20220717053818.96144-1-jwkozaczuk%40gmail.com.

Reply via email to