Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Oct 2021 12:50:36 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f2069331e582 - main - libutil: add kinfo_getswapvmobject(3)
Message-ID:  <202110261250.19QCoa7f060559@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=f2069331e5821f4c2b65d82af2809946a34158d2

commit f2069331e5821f4c2b65d82af2809946a34158d2
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-10-26 08:40:10 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-10-26 12:50:29 +0000

    libutil: add kinfo_getswapvmobject(3)
    
    which is the wrapper around the vm.swap_objects sysctl, same as
    kinfo_getvmobject(3) wraps vm.objects.
    
    Submitted by:   Yoshihiro Ota
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D29754
---
 lib/libutil/kinfo_getvmobject.c | 20 ++++++++++++++++----
 lib/libutil/libutil.h           |  2 ++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/libutil/kinfo_getvmobject.c b/lib/libutil/kinfo_getvmobject.c
index de55650a518b..4bf666fd7f3b 100644
--- a/lib/libutil/kinfo_getvmobject.c
+++ b/lib/libutil/kinfo_getvmobject.c
@@ -36,8 +36,8 @@ __FBSDID("$FreeBSD$");
 
 #include "libutil.h"
 
-struct kinfo_vmobject *
-kinfo_getvmobject(int *cntp)
+static struct kinfo_vmobject *
+kinfo_getvmobject_impl(int *cntp, const char *vmobjsysctl)
 {
 	char *buf, *bp, *ep;
 	struct kinfo_vmobject *kvo, *list, *kp;
@@ -46,14 +46,14 @@ kinfo_getvmobject(int *cntp)
 
 	buf = NULL;
 	for (i = 0; i < 3; i++) {
-		if (sysctlbyname("vm.objects", NULL, &len, NULL, 0) < 0) {
+		if (sysctlbyname(vmobjsysctl, NULL, &len, NULL, 0) < 0) {
 			free(buf);
 			return (NULL);
 		}
 		buf = reallocf(buf, len);
 		if (buf == NULL)
 			return (NULL);
-		if (sysctlbyname("vm.objects", buf, &len, NULL, 0) == 0)
+		if (sysctlbyname(vmobjsysctl, buf, &len, NULL, 0) == 0)
 			goto unpack;
 		if (errno != ENOMEM) {
 			free(buf);
@@ -94,3 +94,15 @@ unpack:
 	*cntp = cnt;
 	return (list);
 }
+
+struct kinfo_vmobject *
+kinfo_getvmobject(int *cntp)
+{
+	return (kinfo_getvmobject_impl(cntp, "vm.objects"));
+}
+
+struct kinfo_vmobject *
+kinfo_getswapvmobject(int *cntp)
+{
+	return (kinfo_getvmobject_impl(cntp, "vm.swap_objects"));
+}
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index bb96b2caa502..17c44de0fce7 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -109,6 +109,8 @@ struct kinfo_vmentry *
 	kinfo_getvmmap(pid_t _pid, int *_cntp);
 struct kinfo_vmobject *
 	kinfo_getvmobject(int *_cntp);
+struct kinfo_vmobject *
+	kinfo_getswapvmobject(int *_cntp);
 struct kinfo_proc *
 	kinfo_getallproc(int *_cntp);
 struct kinfo_proc *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110261250.19QCoa7f060559>