From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3E2F521DF808A for ; Mon, 28 Aug 2017 07:37:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 199771F578; Mon, 28 Aug 2017 14:40:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 199771F578 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-67.phx2.redhat.com [10.3.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC0B181890; Mon, 28 Aug 2017 14:39:59 +0000 (UTC) To: "Shi, Steven" , edk2-devel-01 Cc: "Kinney, Michael D" , "Gao, Liming" , Ard Biesheuvel References: <1714bf60-83a1-ce07-1d71-ac729d8e9dc8@redhat.com> <06C8AB66E78EE34A949939824ABE2B313B57604E@shsmsx102.ccr.corp.intel.com> From: Laszlo Ersek Message-ID: <37998be6-89f9-23a7-b1f5-a4527651d708@redhat.com> Date: Mon, 28 Aug 2017 16:39:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <06C8AB66E78EE34A949939824ABE2B313B57604E@shsmsx102.ccr.corp.intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 28 Aug 2017 14:40:01 +0000 (UTC) Subject: Re: "practical" memory allocation limit? X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Aug 2017 14:37:22 -0000 Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/28/17 16:25, Shi, Steven wrote: > Hi Laszlo, > > I happen to have a question about how to correctly get the system memory size on Qemu. > > In the QemuInitializeRam() of OvmfPkg\PlatformPei\MemDetect.c, I add debug info as below to trace the GetSystemMemorySizeBelow4gb() and GetSystemMemorySizeAbove4gb() output. But the output results seems not right if my input memory size > 4GB. See my commands and trace outputs in below. > > > > MemDetect.c Line 602: > > // > > // Determine total memory size available > > // > > LowerMemorySize = GetSystemMemorySizeBelow4gb (); > > UpperMemorySize = GetSystemMemorySizeAbove4gb (); > > DEBUG ((EFI_D_INFO, "LowerMemorySize= 0x%x\n", LowerMemorySize)); > > DEBUG ((EFI_D_INFO, "UpperMemorySize= 0x%x\n", UpperMemorySize)); > > > > My test commands and trace outputs: > > $ /opt/qemu/bin/qemu-system-x86_64 -m 5120 -enable-kvm -hda /home/jshi19/workspace/simics5-project/images/luv-v2.1_diskboot_gpt_x86_64_.img -machine pc-q35-2.9 -bios OVMF.fd -serial file:serial.log > > LowerMemorySize= 0x80000000 //2GB, but should not it be 4GB? > > UpperMemorySize= 0xC0000000 //3GB, but should not it be 1GB? No, this is correct; the values returned are system memory *amounts*. (On the QEMU command line, the "-m" switch says how much system memory you have, not the highest address in system memory.) In the 4GB address space, you don't have *just* system memory, you have a whole bunch of MMIO too. (Most of that is used for 32-bit MMIO PCI BAR allocation, some is used for the pflash chip range, LAPICs, etc.) On Q35 you also have 256MB assigned to the MMCONFIG / ECAM area (which provides direct MMIO access to PCI config space for PCI 256 buses). The physical memory map also depends on the board model; on i440fx, the 32-bit system memory can go up to 3GB, while on Q35, it only goes up to 2GB. So, if you pass 5GB to a Q35 machine, 2GB of that are placed in the address space at [0, 2G), and the other 3GB are placed in the address space at [4G, 7G). > $ /opt/qemu/bin/qemu-system-x86_64 -m 6144 -enable-kvm -hda /home/jshi19/workspace/simics5-project/images/luv-v2.1_diskboot_gpt_x86_64_.img -machine pc-q35-2.9 -bios OVMF.fd -serial file:serial.log > > LowerMemorySize= 0x80000000 //2GB, but should not it be 4GB? > > UpperMemorySize= 0x0 // 0GB, but should not it be 2GB? With 6G DRAM, 2G go low, and 4G go high. (Your output is misleading because you used the %x format specifier in your debug message -- %Lx would be correct, for printing a UINT64 value.) Laszlo