summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2019-12-18 09:18:27 +0000
committerflorian <florian@openbsd.org>2019-12-18 09:18:27 +0000
commitc071f09071f839d58d840d707112a4e1152c6f24 (patch)
tree9fc34a6e6804ac81f1ff29db55d0edf813f79bde
parentRework unified cache handling to be able to unify key and neg caches. (diff)
downloadwireguard-openbsd-c071f09071f839d58d840d707112a4e1152c6f24.tar.xz
wireguard-openbsd-c071f09071f839d58d840d707112a4e1152c6f24.zip
Implement unwindctl status memory to show chache memory usage.
testing by otto & pamela as part of a larger diff
-rw-r--r--sbin/unwind/control.c3
-rw-r--r--sbin/unwind/frontend.c3
-rw-r--r--sbin/unwind/resolver.c28
-rw-r--r--sbin/unwind/resolver.h13
-rw-r--r--sbin/unwind/unwind.h4
-rw-r--r--usr.sbin/unwindctl/parser.c3
-rw-r--r--usr.sbin/unwindctl/parser.h5
-rw-r--r--usr.sbin/unwindctl/unwindctl.86
-rw-r--r--usr.sbin/unwindctl/unwindctl.c37
9 files changed, 91 insertions, 11 deletions
diff --git a/sbin/unwind/control.c b/sbin/unwind/control.c
index 13a6f340a84..b724eaaa37a 100644
--- a/sbin/unwind/control.c
+++ b/sbin/unwind/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.14 2019/12/08 09:47:50 florian Exp $ */
+/* $OpenBSD: control.c,v 1.15 2019/12/18 09:18:27 florian Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -274,6 +274,7 @@ control_dispatch_imsg(int fd, short event, void *bula)
break;
case IMSG_CTL_STATUS:
case IMSG_CTL_AUTOCONF:
+ case IMSG_CTL_MEM:
if (IMSG_DATA_SIZE(imsg) != 0)
break;
frontend_imsg_compose_resolver(imsg.hdr.type, 0, NULL,
diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c
index b1792efb668..b64036c4332 100644
--- a/sbin/unwind/frontend.c
+++ b/sbin/unwind/frontend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: frontend.c,v 1.48 2019/12/13 14:37:03 otto Exp $ */
+/* $OpenBSD: frontend.c,v 1.49 2019/12/18 09:18:27 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -484,6 +484,7 @@ frontend_dispatch_resolver(int fd, short event, void *bula)
break;
case IMSG_CTL_RESOLVER_INFO:
case IMSG_CTL_AUTOCONF_RESOLVER_INFO:
+ case IMSG_CTL_MEM_INFO:
case IMSG_CTL_END:
control_imsg_relay(&imsg);
break;
diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c
index 2dc9cc3b620..36515c2b570 100644
--- a/sbin/unwind/resolver.c
+++ b/sbin/unwind/resolver.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resolver.c,v 1.116 2019/12/18 09:17:22 florian Exp $ */
+/* $OpenBSD: resolver.c,v 1.117 2019/12/18 09:18:27 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -174,6 +174,7 @@ int resolver_cmp(const void *, const void *);
void restart_ub_resolvers(void);
void show_status(pid_t);
void show_autoconf(pid_t);
+void show_mem(pid_t);
void send_resolver_info(struct uw_resolver *, pid_t);
void send_detailed_resolver_info(struct uw_resolver *,
pid_t);
@@ -513,6 +514,12 @@ resolver_dispatch_frontend(int fd, short event, void *bula)
"%lu", __func__, IMSG_DATA_SIZE(imsg));
show_autoconf(imsg.hdr.pid);
break;
+ case IMSG_CTL_MEM:
+ if (IMSG_DATA_SIZE(imsg) != 0)
+ fatalx("%s: IMSG_CTL_AUTOCONF wrong length: "
+ "%lu", __func__, IMSG_DATA_SIZE(imsg));
+ show_mem(imsg.hdr.pid);
+ break;
case IMSG_NEW_TA:
/* make sure this is a string */
((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
@@ -1698,6 +1705,25 @@ show_autoconf(pid_t pid)
}
void
+show_mem(pid_t pid)
+{
+ struct ctl_mem_info cmi;
+
+ memset(&cmi, 0, sizeof(cmi));
+ cmi.msg_cache_used = slabhash_get_mem(unified_msg_cache);
+ cmi.msg_cache_max = slabhash_get_size(unified_msg_cache);
+ cmi.rrset_cache_used = slabhash_get_mem(&unified_rrset_cache->table);
+ cmi.rrset_cache_max = slabhash_get_size(&unified_rrset_cache->table);
+ cmi.key_cache_used = slabhash_get_mem(unified_key_cache->slab);
+ cmi.key_cache_max = slabhash_get_size(unified_key_cache->slab);
+ cmi.neg_cache_used = unified_neg_cache->use;
+ cmi.neg_cache_max = unified_neg_cache->max;
+ resolver_imsg_compose_frontend(IMSG_CTL_MEM_INFO, pid, &cmi,
+ sizeof(cmi));
+
+}
+
+void
send_resolver_info(struct uw_resolver *res, pid_t pid)
{
struct ctl_resolver_info cri;
diff --git a/sbin/unwind/resolver.h b/sbin/unwind/resolver.h
index 899b493d86c..c8f0b0bb7ac 100644
--- a/sbin/unwind/resolver.h
+++ b/sbin/unwind/resolver.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: resolver.h,v 1.16 2019/12/08 09:47:50 florian Exp $ */
+/* $OpenBSD: resolver.h,v 1.17 2019/12/18 09:18:27 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -60,6 +60,17 @@ struct ctl_forwarder_info {
int src;
};
+struct ctl_mem_info {
+ size_t msg_cache_used;
+ size_t msg_cache_max;
+ size_t rrset_cache_used;
+ size_t rrset_cache_max;
+ size_t key_cache_used;
+ size_t key_cache_max;
+ size_t neg_cache_used;
+ size_t neg_cache_max;
+};
+
void resolver(int, int);
int resolver_imsg_compose_main(int, pid_t, void *, uint16_t);
int resolver_imsg_compose_frontend(int, pid_t, void *, uint16_t);
diff --git a/sbin/unwind/unwind.h b/sbin/unwind/unwind.h
index 7a2fe17d457..5f7f173d350 100644
--- a/sbin/unwind/unwind.h
+++ b/sbin/unwind/unwind.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwind.h,v 1.46 2019/12/08 12:31:07 otto Exp $ */
+/* $OpenBSD: unwind.h,v 1.47 2019/12/18 09:18:27 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -100,6 +100,7 @@ enum imsg_type {
IMSG_CTL_RELOAD,
IMSG_CTL_STATUS,
IMSG_CTL_AUTOCONF,
+ IMSG_CTL_MEM,
IMSG_RECONF_CONF,
IMSG_RECONF_BLOCKLIST_FILE,
IMSG_RECONF_FORWARDER,
@@ -119,6 +120,7 @@ enum imsg_type {
IMSG_ANSWER,
IMSG_CTL_RESOLVER_INFO,
IMSG_CTL_AUTOCONF_RESOLVER_INFO,
+ IMSG_CTL_MEM_INFO,
IMSG_CTL_END,
IMSG_HTTPSOCK,
IMSG_TAFD,
diff --git a/usr.sbin/unwindctl/parser.c b/usr.sbin/unwindctl/parser.c
index c091a4efecb..4cd38865ab6 100644
--- a/usr.sbin/unwindctl/parser.c
+++ b/usr.sbin/unwindctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.10 2019/12/08 09:47:51 florian Exp $ */
+/* $OpenBSD: parser.c,v 1.11 2019/12/18 09:18:28 florian Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -69,6 +69,7 @@ static const struct token t_log[] = {
static const struct token t_status[] = {
{NOTOKEN, "", NONE, NULL},
{KEYWORD, "autoconf", AUTOCONF, NULL},
+ {KEYWORD, "memory", MEM, NULL},
{ENDTOKEN, "", NONE, NULL}
};
diff --git a/usr.sbin/unwindctl/parser.h b/usr.sbin/unwindctl/parser.h
index 7baba5a231a..e979a4c7346 100644
--- a/usr.sbin/unwindctl/parser.h
+++ b/usr.sbin/unwindctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.8 2019/12/08 09:47:51 florian Exp $ */
+/* $OpenBSD: parser.h,v 1.9 2019/12/18 09:18:28 florian Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -25,7 +25,8 @@ enum actions {
RELOAD,
PORTAL,
STATUS,
- AUTOCONF
+ AUTOCONF,
+ MEM
};
struct parse_result {
diff --git a/usr.sbin/unwindctl/unwindctl.8 b/usr.sbin/unwindctl/unwindctl.8
index c27e407536c..48c617d3e75 100644
--- a/usr.sbin/unwindctl/unwindctl.8
+++ b/usr.sbin/unwindctl/unwindctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: unwindctl.8,v 1.9 2019/12/08 09:47:51 florian Exp $
+.\" $OpenBSD: unwindctl.8,v 1.10 2019/12/18 09:18:28 florian Exp $
.\"
.\" Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 8 2019 $
+.Dd $Mdocdate: December 18 2019 $
.Dt UNWINDCTL 8
.Os
.Sh NAME
@@ -60,6 +60,8 @@ Show nameservers learned from
.Xr dhclient 8
or
.Xr slaacd 8 .
+.It Cm status Cm memory
+Show memory consumption.
.El
.Sh FILES
.Bl -tag -width "/dev/unwind.sockXX" -compact
diff --git a/usr.sbin/unwindctl/unwindctl.c b/usr.sbin/unwindctl/unwindctl.c
index 836b1224db5..23f12c4a8aa 100644
--- a/usr.sbin/unwindctl/unwindctl.c
+++ b/usr.sbin/unwindctl/unwindctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwindctl.c,v 1.25 2019/12/08 12:31:07 otto Exp $ */
+/* $OpenBSD: unwindctl.c,v 1.26 2019/12/18 09:18:28 florian Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -46,6 +46,7 @@
__dead void usage(void);
int show_status_msg(struct imsg *);
int show_autoconf_msg(struct imsg *);
+int show_mem_msg(struct imsg *);
void histogram_header(void);
void print_histogram(const char *name, int64_t[], size_t);
@@ -150,6 +151,9 @@ main(int argc, char *argv[])
case AUTOCONF:
imsg_compose(ibuf, IMSG_CTL_AUTOCONF, 0, 0, -1, NULL, 0);
break;
+ case MEM:
+ imsg_compose(ibuf, IMSG_CTL_MEM, 0, 0, -1, NULL, 0);
+ break;
default:
usage();
}
@@ -177,6 +181,9 @@ main(int argc, char *argv[])
case AUTOCONF:
done = show_autoconf_msg(&imsg);
break;
+ case MEM:
+ done = show_mem_msg(&imsg);
+ break;
default:
break;
}
@@ -319,3 +326,31 @@ print_histogram(const char *name, int64_t histogram[], size_t n)
printf("%6lld", histogram[i]);
printf("\n");
}
+
+int
+show_mem_msg(struct imsg *imsg)
+{
+ struct ctl_mem_info *cmi;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_MEM_INFO:
+ cmi = imsg->data;
+ printf("msg-cache: %zu / %zu (%.2f%%)\n", cmi->msg_cache_used,
+ cmi->msg_cache_max, 100.0 * cmi->msg_cache_used /
+ cmi->msg_cache_max);
+ printf("rrset-cache: %zu / %zu (%.2f%%)\n",
+ cmi->rrset_cache_used, cmi->rrset_cache_max, 100.0 *
+ cmi->rrset_cache_used / cmi->rrset_cache_max);
+ printf("key-cache: %zu / %zu (%.2f%%)\n", cmi->key_cache_used,
+ cmi->key_cache_max, 100.0 * cmi->key_cache_used /
+ cmi->key_cache_max);
+ printf("neg-cache: %zu / %zu (%.2f%%)\n", cmi->neg_cache_used,
+ cmi->neg_cache_max, 100.0 * cmi->neg_cache_used /
+ cmi->neg_cache_max);
+ break;
+ default:
+ break;
+ }
+
+ return 1;
+}