From patchwork Fri Jul 17 14:07:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Ehrhardt X-Patchwork-Id: 11670449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 325771392 for ; Fri, 17 Jul 2020 14:09:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A97022CB2 for ; Fri, 17 Jul 2020 14:09:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A97022CB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwR2q-0007MH-A4 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 17 Jul 2020 10:09:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwR1H-0004xy-Fu for qemu-devel@nongnu.org; Fri, 17 Jul 2020 10:07:23 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:50373) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1jwR1F-0005Pz-50 for qemu-devel@nongnu.org; Fri, 17 Jul 2020 10:07:23 -0400 Received: from 2.general.paelzer.uk.vpn ([10.172.196.173] helo=Keschdeichel.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jwR1C-0001KP-I4; Fri, 17 Jul 2020 14:07:18 +0000 From: Christian Ehrhardt To: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , qemu-devel Subject: [PATCH] accel/tcg: reduce default code gen buffer on small hosts Date: Fri, 17 Jul 2020 16:07:14 +0200 Message-Id: <20200717140714.124263-1-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Received-SPF: none client-ip=91.189.89.112; envelope-from=christian.ehrhardt@canonical.com; helo=youngberry.canonical.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/17 09:40:52 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Christian Ehrhardt Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Since v5.0.0 and 600e17b2 "accel/tcg: increase default code gen buffer size for 64 bit" in particular qemu with TCG regularly gets OOM Killed on small hosts. The former 47a2def4 "accel/tcg: remove link between guest ram and TCG cache size" removed the link to guest size which is right, but at least some connection to the host size needs to be retained to avoid growing out of control on common CI setups which run at 1-2G host sizes. The lower value of 1/8th of the host memory size and the default (of currently 1G) will be taken to initialize the TB. There already is a Min/Max check in place to not reach ridiculously small values. Fixes: 600e17b2 Signed-off-by: Christian Ehrhardt --- accel/tcg/translate-all.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2afa46bd2b..ffcd67060e 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -977,6 +977,29 @@ static inline size_t size_code_gen_buffer(size_t tb_size) /* Size the buffer. */ if (tb_size == 0) { tb_size = DEFAULT_CODE_GEN_BUFFER_SIZE; + /* + * A static default of 1G turned out to break (OOM Kill) many common + * CI setups that run at 1-2G Host memory size. + * At the same time the former default of ram_size/4 wasted performance + * on large host systems when running small guests. + * Common CI guest sizes are 0.5-1G which meant ~128M-256M TB size. + * A Default of 1/8th of the host size will get small hosts a + * similar TB size than they had prior to v5.0 and common bare metal + * systems (>=8G) the new 1G default that was set in v5.0 + */ +#if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE + { + unsigned long max = DEFAULT_CODE_GEN_BUFFER_SIZE; + double pages = (double)sysconf(_SC_PHYS_PAGES); + + if (pages > 0 && pagesize > 0) { + max = (unsigned long)((pages * qemu_real_host_page_size) / 8); + } + if (max < DEFAULT_CODE_GEN_BUFFER_SIZE) { + tb_size = max; + } + } +#endif } if (tb_size < MIN_CODE_GEN_BUFFER_SIZE) { tb_size = MIN_CODE_GEN_BUFFER_SIZE;