]> git.proxmox.com Git - pve-qemu-kvm.git/blob - debian/patches/virtio-balloon-dimmfix2.patch
fix ballooning with memory hotplug
[pve-qemu-kvm.git] / debian / patches / virtio-balloon-dimmfix2.patch
1 From patchwork Wed Mar 4 19:13:31 2015
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 Subject: [PULL, 1/5] pc-dimm: add a function to calculate VM's current RAM size
6 From: Luiz Capitulino <lcapitulino@redhat.com>
7 X-Patchwork-Id: 446386
8 Message-Id: <1425496415-6161-2-git-send-email-lcapitulino@redhat.com>
9 To: peter.maydell@linaro.org
10 Cc: qemu-devel@nongnu.org
11 Date: Wed, 4 Mar 2015 14:13:31 -0500
12
13 From: zhanghailiang <zhang.zhanghailiang@huawei.com>
14
15 The global parameter 'ram_size' does not take into account
16 the hotplugged memory.
17
18 In some codes, we use 'ram_size' as current VM's real RAM size,
19 which is not correct.
20
21 Add function 'get_current_ram_size' to calculate VM's current RAM size,
22 it will enumerate present memory devices and also plus ram_size.
23
24 Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
25 Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
26 ---
27 hw/mem/pc-dimm.c | 26 ++++++++++++++++++++++++++
28 include/exec/cpu-common.h | 1 +
29 stubs/qmp_pc_dimm_device_list.c | 5 +++++
30 3 files changed, 32 insertions(+)
31
32 diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
33 index f27a087..de81b9c 100644
34 --- a/hw/mem/pc-dimm.c
35 +++ b/hw/mem/pc-dimm.c
36 @@ -100,6 +100,32 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
37 return 0;
38 }
39
40 +ram_addr_t get_current_ram_size(void)
41 +{
42 + MemoryDeviceInfoList *info_list = NULL;
43 + MemoryDeviceInfoList **prev = &info_list;
44 + MemoryDeviceInfoList *info;
45 + ram_addr_t size = ram_size;
46 +
47 + qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
48 + for (info = info_list; info; info = info->next) {
49 + MemoryDeviceInfo *value = info->value;
50 +
51 + if (value) {
52 + switch (value->kind) {
53 + case MEMORY_DEVICE_INFO_KIND_DIMM:
54 + size += value->dimm->size;
55 + break;
56 + default:
57 + break;
58 + }
59 + }
60 + }
61 + qapi_free_MemoryDeviceInfoList(info_list);
62 +
63 + return size;
64 +}
65 +
66 static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
67 {
68 unsigned long *bitmap = opaque;
69 diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
70 index 427b851..fcc3162 100644
71 --- a/include/exec/cpu-common.h
72 +++ b/include/exec/cpu-common.h
73 @@ -52,6 +52,7 @@ typedef uintptr_t ram_addr_t;
74 #endif
75
76 extern ram_addr_t ram_size;
77 +ram_addr_t get_current_ram_size(void);
78
79 /* memory API */
80
81 diff --git a/stubs/qmp_pc_dimm_device_list.c b/stubs/qmp_pc_dimm_device_list.c
82 index 5cb220c..b584bd8 100644
83 --- a/stubs/qmp_pc_dimm_device_list.c
84 +++ b/stubs/qmp_pc_dimm_device_list.c
85 @@ -5,3 +5,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
86 {
87 return 0;
88 }
89 +
90 +ram_addr_t get_current_ram_size(void)
91 +{
92 + return ram_size;
93 +}