From owner-svn-src-head@FreeBSD.ORG Mon Oct 27 06:25:02 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B5DAB106567C; Mon, 27 Oct 2008 06:25:02 +0000 (UTC) (envelope-from sobomax@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A4C308FC1C; Mon, 27 Oct 2008 06:25:02 +0000 (UTC) (envelope-from sobomax@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9R6P2i9029702; Mon, 27 Oct 2008 06:25:02 GMT (envelope-from sobomax@svn.freebsd.org) Received: (from sobomax@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9R6P2a8029701; Mon, 27 Oct 2008 06:25:02 GMT (envelope-from sobomax@svn.freebsd.org) Message-Id: <200810270625.m9R6P2a8029701@svn.freebsd.org> From: Maxim Sobolev Date: Mon, 27 Oct 2008 06:25:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184323 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Oct 2008 06:25:02 -0000 Author: sobomax Date: Mon Oct 27 06:25:02 2008 New Revision: 184323 URL: http://svn.freebsd.org/changeset/base/184323 Log: 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 Modified: head/sys/kern/subr_param.c Modified: head/sys/kern/subr_param.c ============================================================================== --- head/sys/kern/subr_param.c Mon Oct 27 05:28:08 2008 (r184322) +++ head/sys/kern/subr_param.c Mon Oct 27 06:25:02 2008 (r184323) @@ -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, */ 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