Skip to contentSkip to conversation

don't use NVDIMM for balooning

PATCH Superseded Vladimir Sementsov-Ogievskiy 3 participants 10 messages Feb 4, 2016

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover don't use NVDIMM for balooning

v5: do not use qapi
0002-0004: new patches
0005: white list instead of black list

v4:
0001: Reviewed-by: Eric Blake <[email protected]>
second patch is splitted to 0002 and 0003
0002: Add 'type' field instead of 'balloonable' to PCDIMMDeviceInfo 0003: chec 'type' instead of 'balloonable'

v3:
- do not use additional class variable

NVDIMM for now is planned to use as a backing store for DAX filesystem in the guest and thus this memory is excluded from guest memory management and LRUs.

In this case libvirt running QEMU along with configured balloon almost immediately inflates balloon and effectively kill the guest as qemu counts nvdimm as part of the ram.

CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC Denis V. Lunev <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>

Vladimir Sementsov-Ogievskiy (5):
move get_current_ram_size to virtio-balloon.c
pc-dimm: rename pc_dimm_built_list()
pc-dimm: add pc_dimm_build_list()
virtio-balloon: rewrite get_current_ram_size()
balloon: Use only 'pc-dimm' type dimm for ballooning

 hw/mem/pc-dimm.c                | 47 ++++++++++++++++-------------------------
 hw/virtio/virtio-balloon.c      | 19 +++++++++++++++++
 include/exec/cpu-common.h       |  1 -
 include/hw/mem/pc-dimm.h        |  3 +++
 stubs/qmp_pc_dimm_device_list.c |  5 -----
 5 files changed, 40 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v5 1/5 move get_current_ram_size to virtio-balloon.c

get_current_ram_size() is used only in virtio-balloon.c This patch moves it into virtio-balloon and make it static, to allow some balloon-specific tuning.

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
 hw/mem/pc-dimm.c                | 26 --------------------------
 hw/virtio/virtio-balloon.c      | 26 ++++++++++++++++++++++++++
 include/exec/cpu-common.h       |  1 -
 stubs/qmp_pc_dimm_device_list.c |  5 -----
 4 files changed, 26 insertions(+), 32 deletions(-)
hw/mem/pc-dimm.c +0 -26
index d5cdab2..4f30950 100644
@@ -191,32 +191,6 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
     return 0;
 }
 
-ram_addr_t get_current_ram_size(void)
-{
-    MemoryDeviceInfoList *info_list = NULL;
-    MemoryDeviceInfoList **prev = &info_list;
-    MemoryDeviceInfoList *info;
-    ram_addr_t size = ram_size;
-
-    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
-    for (info = info_list; info; info = info->next) {
-        MemoryDeviceInfo *value = info->value;
-
-        if (value) {
-            switch (value->type) {
-            case MEMORY_DEVICE_INFO_KIND_DIMM:
-                size += value->u.dimm->size;
-                break;
-            default:
-                break;
-            }
-        }
-    }
-    qapi_free_MemoryDeviceInfoList(info_list);
-
-    return size;
-}
-
 static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 {
     unsigned long *bitmap = opaque;
hw/virtio/virtio-balloon.c +26 -0
index 9671635..6a4c4d2 100644
@@ -294,6 +294,32 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
     memcpy(config_data, &config, sizeof(struct virtio_balloon_config));
 }
 
+static ram_addr_t get_current_ram_size(void)
+{
+    MemoryDeviceInfoList *info_list = NULL;
+    MemoryDeviceInfoList **prev = &info_list;
+    MemoryDeviceInfoList *info;
+    ram_addr_t size = ram_size;
+
+    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
+    for (info = info_list; info; info = info->next) {
+        MemoryDeviceInfo *value = info->value;
+
+        if (value) {
+            switch (value->type) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                size += value->u.dimm->size;
+                break;
+            default:
+                break;
+            }
+        }
+    }
+    qapi_free_MemoryDeviceInfoList(info_list);
+
+    return size;
+}
+
 static void virtio_balloon_set_config(VirtIODevice *vdev,
                                       const uint8_t *config_data)
 {
include/exec/cpu-common.h +0 -1
index 85aa403..a0ad2ac 100644
@@ -54,7 +54,6 @@ typedef uintptr_t ram_addr_t;
 #endif
 
 extern ram_addr_t ram_size;
-ram_addr_t get_current_ram_size(void);
 
 /* memory API */
 
stubs/qmp_pc_dimm_device_list.c +0 -5
index b584bd8..5cb220c 100644
@@ -5,8 +5,3 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
 {
    return 0;
 }
-
-ram_addr_t get_current_ram_size(void)
-{
-    return ram_size;
-}
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v5 2/5 pc-dimm: rename pc_dimm_built_list()

In reply to Vladimir Sementsov-Ogievskiy

s/pc_dimm_built_list/pc_dimm_build_list_sorted

- need for add pc_dimm_build_list (not sorted) in the next patch
- fix typo (built -> build)

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
 hw/mem/pc-dimm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/mem/pc-dimm.c +3 -3
index 4f30950..4a681bc 100644
@@ -251,7 +251,7 @@ static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b)
     return 0;
 }
 
-static int pc_dimm_built_list(Object *obj, void *opaque)
+static int pc_dimm_build_list_sorted(Object *obj, void *opaque)
 {
     GSList **list = opaque;
 
@@ -262,7 +262,7 @@ static int pc_dimm_built_list(Object *obj, void *opaque)
         }
     }
 
-    object_child_foreach(obj, pc_dimm_built_list, opaque);
+    object_child_foreach(obj, pc_dimm_build_list_sorted, opaque);
     return 0;
 }
 
@@ -296,7 +296,7 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
     }
 
     assert(address_space_end > address_space_start);
-    object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list);
+    object_child_foreach(qdev_get_machine(), pc_dimm_build_list_sorted, &list);
 
     if (hint) {
         new_addr = *hint;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v5 3/5 pc-dimm: add pc_dimm_build_list()

In reply to Vladimir Sementsov-Ogievskiy

Like pc_dimm_build_list_sorted but not sorted - for cases where sorting is not necessary.

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
 hw/mem/pc-dimm.c         | 15 +++++++++++++++
 include/hw/mem/pc-dimm.h |  3 +++
 2 files changed, 18 insertions(+)
hw/mem/pc-dimm.c +15 -0
index 4a681bc..0f102c0 100644
@@ -266,6 +266,21 @@ static int pc_dimm_build_list_sorted(Object *obj, void *opaque)
     return 0;
 }
 
+int pc_dimm_build_list(Object *obj, void *opaque)
+{
+    GSList **list = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+        DeviceState *dev = DEVICE(obj);
+        if (dev->realized) { /* only realized DIMMs matter */
+            *list = g_slist_prepend(*list, dev);
+        }
+    }
+
+    object_child_foreach(obj, pc_dimm_build_list, opaque);
+    return 0;
+}
+
 uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
                                uint64_t address_space_size,
                                uint64_t *hint, uint64_t align, uint64_t size,
include/hw/mem/pc-dimm.h +3 -0
index d83bf30..ab136a3 100644
@@ -94,4 +94,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms,
                          MemoryRegion *mr, uint64_t align, Error **errp);
 void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms,
                            MemoryRegion *mr);
+
+int pc_dimm_build_list(Object *obj, void *opaque);
+
 #endif
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v5 4/5 virtio-balloon: rewrite get_current_ram_size()

In reply to Vladimir Sementsov-Ogievskiy

Use pc_dimm_built_list() instead of qmp_pc_dimm_device_list()

Actually, Qapi is not related to this internal helper.

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
 hw/virtio/virtio-balloon.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
hw/virtio/virtio-balloon.c +6 -17
index 6a4c4d2..b9c1964 100644
@@ -296,26 +296,15 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 
 static ram_addr_t get_current_ram_size(void)
 {
-    MemoryDeviceInfoList *info_list = NULL;
-    MemoryDeviceInfoList **prev = &info_list;
-    MemoryDeviceInfoList *info;
+    GSList *list = NULL, *item;
     ram_addr_t size = ram_size;
 
-    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
-    for (info = info_list; info; info = info->next) {
-        MemoryDeviceInfo *value = info->value;
-
-        if (value) {
-            switch (value->type) {
-            case MEMORY_DEVICE_INFO_KIND_DIMM:
-                size += value->u.dimm->size;
-                break;
-            default:
-                break;
-            }
-        }
+    pc_dimm_build_list(qdev_get_machine(), &list);
+    for (item = list; item; item = g_slist_next(item)) {
+        PCDIMMDevice *dimm = item->data;
+        size += object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, NULL);
     }
-    qapi_free_MemoryDeviceInfoList(info_list);
+    g_slist_free(list);
 
     return size;
 }
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v5 5/5 balloon: Use only 'pc-dimm' type dimm for ballooning

In reply to Vladimir Sementsov-Ogievskiy

For now there are only two dimm's: pc-dimm and nvdimm. This patch is actually needed to disable ballooning on nvdimm. But, to avoid future bugs, instead of disallowing nvdimm, we allow only pc-dimm. So, if someone adds new dimm which should be balloon-able, then this ability should be explicitly specified here.

Why ballooning for nvdimm should be disabled for now:

NVDIMM for now is planned to use as a backing store for DAX filesystem in the guest and thus this memory is excluded from guest memory management and LRUs.

In this case libvirt running QEMU along with configured balloon almost immediately inflates balloon and effectively kill the guest as qemu counts nvdimm as part of the ram.

Counting dimm devices as part of the ram for ballooning was started from commit 463756d03:
virtio-balloon: Fix balloon not working correctly when hotplug memory

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
 hw/virtio/virtio-balloon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +5 -1
index b9c1964..0415e07 100644
@@ -18,6 +18,7 @@
 #include "qemu-common.h"
 #include "hw/virtio/virtio.h"
 #include "hw/i386/pc.h"
+#include "hw/mem/nvdimm.h"
 #include "cpu.h"
 #include "sysemu/balloon.h"
 #include "hw/virtio/virtio-balloon.h"
@@ -302,7 +303,10 @@ static ram_addr_t get_current_ram_size(void)
     pc_dimm_build_list(qdev_get_machine(), &list);
     for (item = list; item; item = g_slist_next(item)) {
         PCDIMMDevice *dimm = item->data;
-        size += object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, NULL);
+        if (!strcmp(object_get_typename(OBJECT(dimm)), TYPE_PC_DIMM)) {
+            size += object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
+                                            NULL);
+        }
     }
     g_slist_free(list);
 
Signature · 1 line
1.8.3.1
#9 lore raw
In reply to Vladimir Sementsov-Ogievskiy

On Thu, 4 Feb 2016 14:37:18 +0300
Vladimir Sementsov-Ogievskiy <[email protected]> wrote:

CCing Luiz as he might be interested in balloon stuff.

Quoted 44 lines

v5: do not use qapi
0002-0004: new patches
0005: white list instead of black list

v4:
0001: Reviewed-by: Eric Blake <[email protected]>
second patch is splitted to 0002 and 0003
0002: Add 'type' field instead of 'balloonable' to PCDIMMDeviceInfo 0003: chec 'type' instead of 'balloonable'

v3:
- do not use additional class variable

NVDIMM for now is planned to use as a backing store for DAX filesystem in the guest and thus this memory is excluded from guest memory management and LRUs.

In this case libvirt running QEMU along with configured balloon almost immediately inflates balloon and effectively kill the guest as qemu counts nvdimm as part of the ram.

CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC Denis V. Lunev <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>

Vladimir Sementsov-Ogievskiy (5):
move get_current_ram_size to virtio-balloon.c
pc-dimm: rename pc_dimm_built_list()
pc-dimm: add pc_dimm_build_list()
virtio-balloon: rewrite get_current_ram_size()
balloon: Use only 'pc-dimm' type dimm for ballooning

 hw/mem/pc-dimm.c                | 47 ++++++++++++++++-------------------------
 hw/virtio/virtio-balloon.c      | 19 +++++++++++++++++
 include/exec/cpu-common.h       |  1 -
 include/hw/mem/pc-dimm.h        |  3 +++
 stubs/qmp_pc_dimm_device_list.c |  5 -----
 5 files changed, 40 insertions(+), 35 deletions(-)
#5 lore raw

Re: [Qemu-devel] [PATCH 4/5] virtio-balloon: rewrite get_current_ram_size()

In reply to Vladimir Sementsov-Ogievskiy
Quoted 34 lines · On Thu, 4 Feb 2016 14:37:22 +0300 Vladimir Sementsov-Ogievskiy…

Use pc_dimm_built_list() instead of qmp_pc_dimm_device_list()

Actually, Qapi is not related to this internal helper.

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
 hw/virtio/virtio-balloon.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
hw/virtio/virtio-balloon.c +1 -7
index 6a4c4d2..b9c1964 100644
@@ -296,26 +296,15 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 
 static ram_addr_t get_current_ram_size(void)
 {
-    MemoryDeviceInfoList *info_list = NULL;
-    MemoryDeviceInfoList **prev = &info_list;
-    MemoryDeviceInfoList *info;
+    GSList *list = NULL, *item;
     ram_addr_t size = ram_size;
 
-    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
-    for (info = info_list; info; info = info->next) {
-        MemoryDeviceInfo *value = info->value;
-

hw/virtio/virtio-balloon.c static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data) · line 302

Quoted 10 lines
hw/virtio/virtio-balloon.c +1 -9
-        if (value) {
-            switch (value->type) {
-            case MEMORY_DEVICE_INFO_KIND_DIMM:
-                size += value->u.dimm->size;
-                break;
-            default:
-                break;
-            }
-        }
+    pc_dimm_build_list(qdev_get_machine(), &list);

This will break the build for !CONFIG_MEM_HOTPLUG, as you didn't provide a stubbed-out version of this function.

Quoted 9 lines
hw/virtio/virtio-balloon.c +4 -1
+    for (item = list; item; item = g_slist_next(item)) {
+        PCDIMMDevice *dimm = item->data;
+        size += object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, NULL);
     }
-    qapi_free_MemoryDeviceInfoList(info_list);
+    g_slist_free(list);
 
     return size;
 }
#6 lore raw

Re: [Qemu-devel] [PATCH 4/5] virtio-balloon: rewrite get_current_ram_size()

Quoted 33 lines · Cornelia Huck
Quoted 30 lines · On Thu, 4 Feb 2016 14:37:22 +0300 Vladimir Sementsov-Ogievskiy…

Use pc_dimm_built_list() instead of qmp_pc_dimm_device_list()

Actually, Qapi is not related to this internal helper.

CC Stefan Hajnoczi <[email protected]>
CC Xiao Guangrong <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Igor Mammedov <[email protected]>
CC Eric Blake <[email protected]>
CC Markus Armbruster <[email protected]>
---
  hw/virtio/virtio-balloon.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
hw/virtio/virtio-balloon.c +1 -3
index 6a4c4d2..b9c1964 100644
@@ -296,26 +296,15 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 
  static ram_addr_t get_current_ram_size(void)
  {
-    MemoryDeviceInfoList *info_list = NULL;
-    MemoryDeviceInfoList **prev = &info_list;
-    MemoryDeviceInfoList *info;
+    GSList *list = NULL, *item;
      ram_addr_t size = ram_size;
 
Quoted 16 lines
Quoted 4 lines
hw/virtio/virtio-balloon.c +0 -4
-    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
-    for (info = info_list; info; info = info->next) {
-        MemoryDeviceInfo *value = info->value;
-

hw/virtio/virtio-balloon.c static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data) · line 302

Quoted 10 lines
hw/virtio/virtio-balloon.c +1 -9
-        if (value) {
-            switch (value->type) {
-            case MEMORY_DEVICE_INFO_KIND_DIMM:
-                size += value->u.dimm->size;
-                break;
-            default:
-                break;
-            }
-        }
+    pc_dimm_build_list(qdev_get_machine(), &list);

This will break the build for !CONFIG_MEM_HOTPLUG, as you didn't provide a stubbed-out version of this function.

Ok, thanks, will add.

Also: it is already broken because of pc_dimm_memory_plug and pc_dimm_memory_unplug

Quoted 10 lines
Quoted 10 lines
hw/virtio/virtio-balloon.c +4 -1
+    for (item = list; item; item = g_slist_next(item)) {
+        PCDIMMDevice *dimm = item->data;
+        size += object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP, NULL);
      }
-    qapi_free_MemoryDeviceInfoList(info_list);
+    g_slist_free(list);
 
      return size;
  }
Signature · 2 lines
Best regards,
Vladimir
#7 lore raw

Re: [Qemu-devel] [PATCH 4/5] virtio-balloon: rewrite get_current_ram_size()

Quoted 4 lines · On Thu, 4 Feb 2016 15:36:05 +0300 Vladimir Sementsov-Ogievskiy…
Quoted 2 lines · Cornelia Huck

On Thu, 4 Feb 2016 14:37:22 +0300
Vladimir Sementsov-Ogievskiy <[email protected]> wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+ pc_dimm_build_list(qdev_get_machine(), &list);

This will break the build for !CONFIG_MEM_HOTPLUG, as you didn't provide a stubbed-out version of this function.

Ok, thanks, will add.

Also: it is already broken because of pc_dimm_memory_plug and pc_dimm_memory_unplug

These are only used by targets that set CONFIG_MEM_HOTPLUG afaics.