summaryrefslogtreecommitdiffstats
path: root/lib/libspl/include
diff options
context:
space:
mode:
authorAlexander Motin <[email protected]>2021-05-27 16:27:29 -0400
committerGitHub <[email protected]>2021-05-27 14:27:29 -0600
commit86706441a86d6e947610046bc8fc08c0618e9eaa (patch)
tree5becb19632d5ea76c9f3463d991de8354c3bc8cc /lib/libspl/include
parent2041d6eecd5e88fadf7a8f0d755d3dda938a3127 (diff)
Introduce write-mostly sums
wmsum counters are a reduced version of aggsum counters, optimized for write-mostly scenarios. They do not provide optimized read functions, but instead allow much cheaper add function. The primary usage is infrequently read statistic counters, not requiring exact precision. The Linux implementation is directly mapped into percpu_counter KPI. The FreeBSD implementation is directly mapped into counter(9) KPI. In user-space due to lack of better implementation mapped to aggsum. Unfortunately neither Linux percpu_counter nor FreeBSD counter(9) provide sufficient functionality to completelly replace aggsum, so it still remains to be used for several hot counters. Reviewed-by: Paul Dagnelie <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored-By: iXsystems, Inc. Closes #12114
Diffstat (limited to 'lib/libspl/include')
-rw-r--r--lib/libspl/include/sys/Makefile.am1
-rw-r--r--lib/libspl/include/sys/wmsum.h68
2 files changed, 69 insertions, 0 deletions
diff --git a/lib/libspl/include/sys/Makefile.am b/lib/libspl/include/sys/Makefile.am
index 53a36f6bf..6816a0125 100644
--- a/lib/libspl/include/sys/Makefile.am
+++ b/lib/libspl/include/sys/Makefile.am
@@ -44,4 +44,5 @@ libspl_HEADERS = \
varargs.h \
vnode.h \
vtoc.h \
+ wmsum.h \
zone.h
diff --git a/lib/libspl/include/sys/wmsum.h b/lib/libspl/include/sys/wmsum.h
new file mode 100644
index 000000000..0679af73c
--- /dev/null
+++ b/lib/libspl/include/sys/wmsum.h
@@ -0,0 +1,68 @@
+/*
+ * CDDL HEADER START
+ *
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * wmsum counters are a reduced version of aggsum counters, optimized for
+ * write-mostly scenarios. They do not provide optimized read functions,
+ * but instead allow much cheaper add function. The primary usage is
+ * infrequently read statistic counters, not requiring exact precision.
+ *
+ * In user-space due to lack of better implementation mapped to aggsum.
+ */
+
+#ifndef _SYS_WMSUM_H
+#define _SYS_WMSUM_H
+
+#include <sys/aggsum.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define wmsum_t aggsum_t
+
+static inline void
+wmsum_init(wmsum_t *ws, uint64_t value)
+{
+
+ aggsum_init(ws, value);
+}
+
+static inline void
+wmsum_fini(wmsum_t *ws)
+{
+
+ aggsum_fini(ws);
+}
+
+static inline uint64_t
+wmsum_value(wmsum_t *ws)
+{
+
+ return (aggsum_value(ws));
+}
+
+static inline void
+wmsum_add(wmsum_t *ws, int64_t delta)
+{
+
+ aggsum_add(ws, delta);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_WMSUM_H */