YetAnotherMod / qemu

QEMU with PowerPC 476 core
Other
2 stars 2 forks source link

Host RAM usage #14

Closed vit9696 closed 9 months ago

vit9696 commented 9 months ago

Currently it is not possible to run qemu on Linux machines with less than 8 GB of RAM. They fail with an error: cannot set up guest memory 'EM0': Cannot allocate memory. Is it intended given that the emulated board itself uses far less?

nia40m commented 9 months ago

Updated memory tree of a MB115.01 board. Added support of -m option. Now you can set available RAM size using it, but please note that the value you set will be divided equally into two DDR memory slots.

Also resized a bit memory usage of MT174.04 board but without a dynamical change with an -m option.

The commit with the fix 0503056. Please test it whenever you can.

vit9696 commented 9 months ago

Thank you! This seems to partially work. I rebased the patch on top of 8.1.3, and was able to launch QEMU with much less RAM assigned to the virtual machine (namely 4G).

However, guest RAM is now allocated in sparse regions (EM0 and EM1) with EM0 being low (0x0) and EM1 being pretty high (0x200000000). This is rather uncommon for QEMU boards, which usually allocate RAM in a physically contiguous region, and somewhat inconvenient for us.

We can change this downstream, but perhaps you might also find it more convenient to map first 4G at EM0, and then the rest at EM1 if any? Something like:

    MemoryRegion *EM0 = g_new(MemoryRegion, 1);
    uint32_t em0_ram = MIN(machine->ram_size, 4 * GiB);
    memory_region_init_ram(EM0, NULL, "EM0", em0_ram, &error_fatal);
    memory_region_add_subregion(get_system_memory(), 0x0, EM0);
vit9696 commented 9 months ago

On the other side, I checked the MB115 board we have, and it seems to have 2GB in each slot. Yet we are only using the lower 2 GB :) So whatever exists in QEMU code actually matches the physical hardware and helps us to find bugs in the BSP code. Perhaps better for us to adapt for sparse memory allocation. After all, it is not that problematic and we need it for MB115 anyway.

UPD: We fixed sparse memory allocation support on our side, and it now works perfectly. So the issue is pretty much resolved for me now. Shall I close the issue?