diff options
author | Edward Tomasz Napierala <trasz@FreeBSD.org> | 2017-10-26 15:55:43 (GMT) |
---|---|---|
committer | David Goldblatt <davidtgoldblatt@gmail.com> | 2017-11-03 15:25:39 (GMT) |
commit | 9f455e2786685b443201c33119765c8093461174 (patch) | |
tree | 6db2a0f19c66bda74e604d716b1434074c3330fb | |
parent | d591df05c86e89c0a5db98274bc7f280f910a0de (diff) | |
download | jemalloc-9f455e2786685b443201c33119765c8093461174.zip jemalloc-9f455e2786685b443201c33119765c8093461174.tar.gz jemalloc-9f455e2786685b443201c33119765c8093461174.tar.bz2 |
Try to use sysctl(3) instead of sysctlbyname(3).
This attempts to use VM_OVERCOMMIT OID - newly introduced in -CURRENT
few days ago, specifically for this purpose - instead of querying the
sysctl by its string name. Due to how syctlbyname(3) works, this means
we do one syscall during binary startup instead of two.
Signed-off-by: Edward Tomasz Napierala <trasz@FreeBSD.org>
-rw-r--r-- | src/pages.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/pages.c b/src/pages.c index 14e63f9..c839471 100644 --- a/src/pages.c +++ b/src/pages.c @@ -10,6 +10,9 @@ #ifdef JEMALLOC_SYSCTL_VM_OVERCOMMIT #include <sys/sysctl.h> +#ifdef __FreeBSD__ +#include <vm/vm_param.h> +#endif #endif /******************************************************************************/ @@ -375,9 +378,19 @@ os_overcommits_sysctl(void) { size_t sz; sz = sizeof(vm_overcommit); +#if defined(__FreeBSD__) && defined(VM_OVERCOMMIT) + int mib[2]; + + mib[0] = CTL_VM; + mib[1] = VM_OVERCOMMIT; + if (sysctl(mib, 2, &vm_overcommit, &sz, NULL, 0) != 0) { + return false; /* Error. */ + } +#else if (sysctlbyname("vm.overcommit", &vm_overcommit, &sz, NULL, 0) != 0) { return false; /* Error. */ } +#endif return ((vm_overcommit & 0x3) == 0); } |