summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_param.c
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2008-10-27 06:25:02 +0000
committersobomax <sobomax@FreeBSD.org>2008-10-27 06:25:02 +0000
commit6b076dc6038583c6d220060fdb70629f5b6a3ed6 (patch)
treeb15e493185ed0490d0a96ca598132e78d10afca8 /sys/kern/subr_param.c
parent322737440fd171cacbb47d30fecc6537604f25ed (diff)
downloadFreeBSD-src-6b076dc6038583c6d220060fdb70629f5b6a3ed6.zip
FreeBSD-src-6b076dc6038583c6d220060fdb70629f5b6a3ed6.tar.gz
Default HZ value (1,000) on i386/amd64 is not very virtual machine friendly.
Due to the nature of the beast it causes lot of unproductive overhead. This is especially bad when running SMP kernel on VMWare with several virtual processors - idle FreeBSD guest with SMP kernel takes 150% host CPU time on my dual-core MacBook Pro when I am enabling two virtual CPUs, making even host not very usable. Detect when we are running in the sandbox and reduce HZ to 10 (can be adjusted via VM_HZ in the kernel config) in such cases. This brings host CPU usage of idle FreeBSD/SMP on two virtual processors down to 10%. Detect most popular VM platforms out there - VMWare, Parallels, VirtualBox and VirtualPC. MFC after: 2 weeks
Diffstat (limited to 'sys/kern/subr_param.c')
-rw-r--r--sys/kern/subr_param.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c
index 89150ac..138ccbc 100644
--- a/sys/kern/subr_param.c
+++ b/sys/kern/subr_param.c
@@ -57,6 +57,13 @@ __FBSDID("$FreeBSD$");
# else
# define HZ 100
# endif
+# ifndef HZ_VM
+# define HZ_VM 10
+# endif
+#else
+# ifndef HZ_VM
+# define HZ_VM HZ
+# endif
#endif
#define NPROC (20 + 16 * maxusers)
#ifndef NBUF
@@ -111,6 +118,30 @@ SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RDTUN, &sgrowsiz, 0,
*/
struct buf *swbuf;
+char *vm_pnames[] = {
+ "VMware Virtual Platform", /* VMWare VM */
+ "Virtual Machine", /* Microsoft VirtualPC */
+ "VirtualBox", /* Sun xVM VirtualBox */
+ "Parallels Virtual Platform", /* Parallels VM */
+ NULL
+};
+
+static int
+detect_virtual(void)
+{
+ char *sysenv;
+ int i;
+
+ sysenv = getenv("smbios.system.product");
+ if (sysenv != NULL) {
+ for (i = 0; vm_pnames[i] != NULL; i++) {
+ if (strcmp(sysenv, vm_pnames[i]) == 0)
+ return 1;
+ }
+ }
+ return 0;
+}
+
/*
* Boot time overrides that are not scaled against main memory
*/
@@ -118,8 +149,15 @@ void
init_param1(void)
{
- hz = HZ;
+ hz = -1;
TUNABLE_INT_FETCH("kern.hz", &hz);
+ if (hz == -1) {
+ if (detect_virtual()) {
+ hz = HZ_VM;
+ } else {
+ hz = HZ;
+ }
+ }
tick = 1000000 / hz;
#ifdef VM_SWZONE_SIZE_MAX
OpenPOWER on IntegriCloud