qemu-e2k/hw/i386
Laurent Vivier 3bfe57165b numa: equally distribute memory on nodes
When there are more nodes than available memory to put the minimum
allowed memory by node, all the memory is put on the last node.

This is because we put (ram_size / nb_numa_nodes) &
~((1 << mc->numa_mem_align_shift) - 1); on each node, and in this
case the value is 0. This is particularly true with pseries,
as the memory must be aligned to 256MB.

To avoid this problem, this patch uses an error diffusion algorithm [1]
to distribute equally the memory on nodes.

We introduce numa_auto_assign_ram() function in MachineClass
to keep compatibility between machine type versions.
The legacy function is used with pseries-2.9, pc-q35-2.9 and
pc-i440fx-2.9 (and previous), the new one with all others.

Example:

qemu-system-ppc64 -S -nographic  -nodefaults -monitor stdio -m 1G -smp 8 \
                  -numa node -numa node -numa node \
                  -numa node -numa node -numa node

Before:

(qemu) info numa
6 nodes
node 0 cpus: 0 6
node 0 size: 0 MB
node 1 cpus: 1 7
node 1 size: 0 MB
node 2 cpus: 2
node 2 size: 0 MB
node 3 cpus: 3
node 3 size: 0 MB
node 4 cpus: 4
node 4 size: 0 MB
node 5 cpus: 5
node 5 size: 1024 MB

After:
(qemu) info numa
6 nodes
node 0 cpus: 0 6
node 0 size: 0 MB
node 1 cpus: 1 7
node 1 size: 256 MB
node 2 cpus: 2
node 2 size: 0 MB
node 3 cpus: 3
node 3 size: 256 MB
node 4 cpus: 4
node 4 size: 256 MB
node 5 cpus: 5
node 5 size: 256 MB

[1] https://en.wikipedia.org/wiki/Error_diffusion

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20170502162955.1610-2-lvivier@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
[ehabkost: s/ram_size/size/ at numa_default_auto_assign_ram()]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2017-05-11 16:08:47 -03:00
..
kvm kvmclock: Don't crash QEMU if KVM is disabled 2017-03-14 13:26:36 +01:00
xen move xen-mapcache.c to hw/i386/xen/ 2017-04-25 11:04:34 -07:00
Makefile.objs hw/i386: Introduce AMD IOMMU 2016-09-24 01:02:00 +03:00
acpi-build.c numa: Allow setting NUMA distance for different NUMA nodes 2017-05-11 16:08:37 -03:00
acpi-build.h Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00
amd_iommu.c trace: Avoid abuse of amdvi_mmio_read 2017-03-24 09:21:42 +00:00
amd_iommu.h i386: amd_iommu: fix MMIO register count and access 2016-12-16 01:14:38 +02:00
intel_iommu.c intel_iommu: enable remote IOTLB 2017-04-20 15:22:41 -03:00
intel_iommu_internal.h intel_iommu: enable remote IOTLB 2017-04-20 15:22:41 -03:00
kvmvapic.c tcg: drop global lock during TCG code execution 2017-02-24 10:32:45 +00:00
multiboot.c multiboot: copy the cmdline verbatim, unescape module strings 2016-12-22 16:00:26 +01:00
multiboot.h refer to FWCfgState explicitly 2013-06-02 18:14:02 +03:00
pc.c error: Apply error_propagate_null.cocci again 2017-04-24 09:13:45 +02:00
pc_piix.c numa: equally distribute memory on nodes 2017-05-11 16:08:47 -03:00
pc_q35.c numa: equally distribute memory on nodes 2017-05-11 16:08:47 -03:00
pc_sysfw.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
pci-assign-load-rom.c pci-assign: avoid pointless stat 2017-01-24 23:26:53 +03:00
trace-events intel_iommu: enable remote IOTLB 2017-04-20 15:22:41 -03:00
x86-iommu.c intel_iommu: support device iotlb descriptor 2017-01-10 05:56:58 +02:00