From owner-freebsd-virtualization@freebsd.org Fri Sep 28 17:47:40 2018 Return-Path: Delivered-To: freebsd-virtualization@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 14D0C10B5C60 for ; Fri, 28 Sep 2018 17:47:40 +0000 (UTC) (envelope-from hicks@cgi.cz) Received: from bsd.cgi.cz (bsd.cgi.cz [178.238.45.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 92D757BD6D for ; Fri, 28 Sep 2018 17:47:39 +0000 (UTC) (envelope-from hicks@cgi.cz) Received: from hel.cgi.cz (hel [192.168.66.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by bsd.cgi.cz (Postfix) with ESMTPS id 70874240D5F for ; Fri, 28 Sep 2018 20:06:33 +0200 (CEST) Received: from localhost (unknown [192.168.66.11]) by hel.cgi.cz (Postfix) with ESMTP id DE9AA14D924 for ; Fri, 28 Sep 2018 19:48:15 +0200 (CEST) Received: from hel.cgi.cz ([192.168.66.6]) by localhost (antispam1.cgi.cz [192.168.66.11]) (amavisd-new, port 10024) with LMTP id 3RMdVTwYWXUH for ; Fri, 28 Sep 2018 19:47:36 +0200 (CEST) Received: from mail2.cgi.cz (hermes [172.17.174.1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by hel.cgi.cz (Postfix) with ESMTPS id 6A83214D919 for ; Fri, 28 Sep 2018 19:48:14 +0200 (CEST) Received: from [192.168.8.136] (unknown [82.100.31.11]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail2.cgi.cz (Postfix) with ESMTPSA id 40F3684AFF for ; Fri, 28 Sep 2018 19:48:14 +0200 (CEST) Subject: Re: New bhyve user To: freebsd-virtualization@freebsd.org References: <201809281630.w8SGUuB4078064@pdx.rh.CN85.dnsmgr.net> From: Jakub Chromy Message-ID: <449d4e47-f4c7-263b-761a-afb634755994@cgi.cz> Date: Fri, 28 Sep 2018 19:47:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <201809281630.w8SGUuB4078064@pdx.rh.CN85.dnsmgr.net> Content-Language: en-GB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Sep 2018 17:47:40 -0000 > You seemed to have heard incorrectly. There is little to no issues > overcommiting CPU's in bhyve, I have a 2 core, 4 thread system with > 6 VM's, each vm using 1 vCPU, this is a 50% overcommit and it my > base line load. No I have not. As far as you stick with 1 vCPU per virtual host, you should be fine. The problem is with multi-core VMs and spinlocks: https://lists.freebsd.org/pipermail/freebsd-virtualization/2018-July/006613.html quote from Alan Somers below: An anonymous BHyve expert has explained things to me off-list. Details below. On Tue, Jul 24, 2018 at 3:30 PM, Alan Somers > wrote: >/What are people's experiences with overcommitting CPUs in BHyve? I have />/an 8-core machine that often runs VMs totalling up to 5 allocated CPUs />/without problems. But today I got greedy. I assigned 8 cores to one VM />/for a big build job. Obviously, some of those were shared with the host. />/I also assigned it 8GB of RAM (out of 16 total). Build performance fell />/through the floor, even though the host was idle. Eventually I killed the />/build and restarted it with a more modest 2 make jobs (but the VM still had />/8 cores). Performance improved. But eventually the system seemed to be />/mostly hung, while I had a build job running on the host as well as in the />/VM. I killed both build jobs, which resolved the hung processes. Then I />/restarted the host's build alone, and my system completely hung, with />/top(1) indicating that many processes were in the pfault state. />//>/So my questions are: />/1) Is it a known problem to overcommit CPUs with BHyve? />// Yes it's a problem, and it's not just BHyve. The problem comes from stuff like spinlocks. Unlike normal userland locks, when two CPUs contend on a spinlock both are running at the same time. When two vCPUs are contending on a spinlock, the host has no idea how to prioritize them. Normally that's not a problem, because physical CPUs are always supposed to be able to run. But when you overcommit vCPUs, some of them must get swapped out at all times. If a spinlock is being contended by both a running vCPU and a swapped out vCPU, then it might be contended for a long time. The host's scheduler simply isn't able to fix that problem. The problem is even worse when you're using hyperthreading (which I am) because those eight logical cores are really only four physical cores, and spinning on a spinlock doesn't generate enough pipeline stalls to cause a hyperthread switch. So it's probably best to stick with the n - 1 rule. Overcommitting is ok if all guests are single-cored because then they won't use spinlocks. But my guests aren't all single-cored. 2) Could this be related to the pfault hang, even though the guest was idle >/at the time? />// The expert suspects the ZFS ARC was competing with the guest for RAM. IIUC, ZFS will sometimes greedily grow its ARC by swapping out idle parts of the guest's RAM. But the guest isn't aware of this behavior, and will happily allocate memory from the swapped-out portion. The result is a battle between the ARC and the guest for physical RAM. The best solution is to limit the maximum amount of RAM used by the ARC with the vfs.zfs.arc_max sysctl. More info:https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222916 Thanks to everyone who commented, especially the Anonymous Coward. -Alan Jakub