From patchwork Mon Jun 6 17:35:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9158937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A117B60573 for ; Mon, 6 Jun 2016 17:36:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93D961FE95 for ; Mon, 6 Jun 2016 17:36:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 888162834A; Mon, 6 Jun 2016 17:36:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0462C1FE95 for ; Mon, 6 Jun 2016 17:36:05 +0000 (UTC) Received: from localhost ([::1]:44204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9yRY-0002Ce-9A for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jun 2016 13:36:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9yR1-00029q-De for qemu-devel@nongnu.org; Mon, 06 Jun 2016 13:35:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9yQz-0001MO-5N for qemu-devel@nongnu.org; Mon, 06 Jun 2016 13:35:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9yQy-0001MD-ST for qemu-devel@nongnu.org; Mon, 06 Jun 2016 13:35:29 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F0D08E67C for ; Mon, 6 Jun 2016 17:35:28 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u56HZNDi025291; Mon, 6 Jun 2016 13:35:27 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 19:35:11 +0200 Message-Id: <1465234520-11160-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1465234520-11160-1-git-send-email-pbonzini@redhat.com> References: <1465234520-11160-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 06 Jun 2016 17:35:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/11] pc: allow raising low memory via max-ram-below-4g option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Gerd Hoffmann This patch extends the functionality of the max-ram-below-4g option to also allow increasing lowmem. Use case: Give as much memory as possible to legacy non-PAE guests. While being at it also rework the lowmem calculation logic and add a longish comment describing how it works and what the compatibility constrains are. Note: This is a incompatible change. When setting max-ram-below-4g to a value larger than 3.5G (or 3G with gigabyte alignment) it has no effect on older qemu versions: qemu silently ignores it. With the patch applied it actually has an effect and changes the ram layout. Highly unlikely to hit in practive though as there is no reason start old qemu versions that way. Signed-off-by: Gerd Hoffmann Reviewed-by: Eduardo Habkost Message-Id: <1464857305-26675-1-git-send-email-kraxel@redhat.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 2 +- hw/i386/pc_piix.c | 61 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e29ccc8..bfaf5a3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1893,7 +1893,7 @@ static void pc_machine_initfn(Object *obj) pc_machine_get_hotplug_memory_region_size, NULL, NULL, NULL, &error_abort); - pcms->max_ram_below_4g = 1ULL << 32; /* 4G */ + pcms->max_ram_below_4g = 0xe0000000; /* 3.5G */ object_property_add(obj, PC_MACHINE_MAX_RAM_BELOW_4G, "size", pc_machine_get_max_ram_below_4g, pc_machine_set_max_ram_below_4g, diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 24e7042..7b4790f 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -87,29 +87,46 @@ static void pc_init1(MachineState *machine, MemoryRegion *rom_memory; ram_addr_t lowmem; - /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory). - * If it doesn't, we need to split it in chunks below and above 4G. - * In any case, try to make sure that guest addresses aligned at - * 1G boundaries get mapped to host addresses aligned at 1G boundaries. - * For old machine types, use whatever split we used historically to avoid - * breaking migration. - */ - if (machine->ram_size >= 0xe0000000) { - lowmem = pcmc->gigabyte_align ? 0xc0000000 : 0xe0000000; - } else { - lowmem = 0xe0000000; - } - - /* Handle the machine opt max-ram-below-4g. It is basically doing - * min(qemu limit, user limit). + /* + * Calculate ram split, for memory below and above 4G. It's a bit + * complicated for backward compatibility reasons ... + * + * - Traditional split is 3.5G (lowmem = 0xe0000000). This is the + * default value for max_ram_below_4g now. + * + * - Then, to gigabyte align the memory, we move the split to 3G + * (lowmem = 0xc0000000). But only in case we have to split in + * the first place, i.e. ram_size is larger than (traditional) + * lowmem. And for new machine types (gigabyte_align = true) + * only, for live migration compatibility reasons. + * + * - Next the max-ram-below-4g option was added, which allowed to + * reduce lowmem to a smaller value, to allow a larger PCI I/O + * window below 4G. qemu doesn't enforce gigabyte alignment here, + * but prints a warning. + * + * - Finally max-ram-below-4g got updated to also allow raising lowmem, + * so legacy non-PAE guests can get as much memory as possible in + * the 32bit address space below 4G. + * + * Examples: + * qemu -M pc-1.7 -m 4G (old default) -> 3584M low, 512M high + * qemu -M pc -m 4G (new default) -> 3072M low, 1024M high + * qemu -M pc,max-ram-below-4g=2G -m 4G -> 2048M low, 2048M high + * qemu -M pc,max-ram-below-4g=4G -m 3968M -> 3968M low (=4G-128M) */ - if (lowmem > pcms->max_ram_below_4g) { - lowmem = pcms->max_ram_below_4g; - if (machine->ram_size - lowmem > lowmem && - lowmem & ((1ULL << 30) - 1)) { - error_report("Warning: Large machine and max_ram_below_4g(%"PRIu64 - ") not a multiple of 1G; possible bad performance.", - pcms->max_ram_below_4g); + lowmem = pcms->max_ram_below_4g; + if (machine->ram_size >= pcms->max_ram_below_4g) { + if (pcmc->gigabyte_align) { + if (lowmem > 0xc0000000) { + lowmem = 0xc0000000; + } + if (lowmem & ((1ULL << 30) - 1)) { + error_report("Warning: Large machine and max_ram_below_4g " + "(%" PRIu64 ") not a multiple of 1G; " + "possible bad performance.", + pcms->max_ram_below_4g); + } } }