diff mbox

[3/3] balloon: don't use NVDIMM for ballooning

Message ID 1453963872-13549-4-git-send-email-vsementsov@virtuozzo.com
State New
Headers show

Commit Message

Vladimir Sementsov-Ogievskiy Jan. 28, 2016, 6:51 a.m. UTC
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

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
CC: "Michael S. Tsirkin" <mst@redhat.com>
CC: Igor Mammedov <imammedo@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
---
 hw/virtio/virtio-balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Markus Armbruster Feb. 2, 2016, 3:30 p.m. UTC | #1
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> 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
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> CC: "Michael S. Tsirkin" <mst@redhat.com>
> CC: Igor Mammedov <imammedo@redhat.com>
> CC: Eric Blake <eblake@redhat.com>
> CC: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/virtio/virtio-balloon.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index 6a4c4d2..749be25 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -26,6 +26,7 @@
>  #include "qapi/visitor.h"
>  #include "qapi-event.h"
>  #include "trace.h"
> +#include "hw/mem/nvdimm.h"
>  
>  #if defined(__linux__)
>  #include <sys/mman.h>
> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>          if (value) {
>              switch (value->type) {
>              case MEMORY_DEVICE_INFO_KIND_DIMM:
> -                size += value->u.dimm->size;
> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
> +                    size += value->u.dimm->size;
> +                }
>                  break;
>              default:
>                  break;

Should this be a blacklist ("don't count TYPE_NVDIMM") or a whitelist
("count TYPE_PC_DIMM")?  I guess that depends on whether we think future
types are more likely to need counting or not counting.
Eric Blake Feb. 2, 2016, 10:13 p.m. UTC | #2
On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
> 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
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> CC: "Michael S. Tsirkin" <mst@redhat.com>
> CC: Igor Mammedov <imammedo@redhat.com>
> CC: Eric Blake <eblake@redhat.com>
> CC: Markus Armbruster <armbru@redhat.com>
> ---

> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>          if (value) {
>              switch (value->type) {
>              case MEMORY_DEVICE_INFO_KIND_DIMM:
> -                size += value->u.dimm->size;
> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {

If you fix 2/3 to use a QAPI enum, then this will be an integer compare
instead of a strcmp().
Vladimir Sementsov-Ogievskiy Feb. 3, 2016, 12:01 p.m. UTC | #3
On 02.02.2016 18:30, Markus Armbruster wrote:
> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
>
>> 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
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>> CC: Igor Mammedov <imammedo@redhat.com>
>> CC: Eric Blake <eblake@redhat.com>
>> CC: Markus Armbruster <armbru@redhat.com>
>> ---
>>   hw/virtio/virtio-balloon.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
>> index 6a4c4d2..749be25 100644
>> --- a/hw/virtio/virtio-balloon.c
>> +++ b/hw/virtio/virtio-balloon.c
>> @@ -26,6 +26,7 @@
>>   #include "qapi/visitor.h"
>>   #include "qapi-event.h"
>>   #include "trace.h"
>> +#include "hw/mem/nvdimm.h"
>>   
>>   #if defined(__linux__)
>>   #include <sys/mman.h>
>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>           if (value) {
>>               switch (value->type) {
>>               case MEMORY_DEVICE_INFO_KIND_DIMM:
>> -                size += value->u.dimm->size;
>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>> +                    size += value->u.dimm->size;
>> +                }
>>                   break;
>>               default:
>>                   break;
> Should this be a blacklist ("don't count TYPE_NVDIMM") or a whitelist
> ("count TYPE_PC_DIMM")?  I guess that depends on whether we think future
> types are more likely to need counting or not counting.

May be, to avoid such bugs in future, it would be better to make like a 
whitelist.
Markus Armbruster Feb. 3, 2016, 3:42 p.m. UTC | #4
Eric Blake <eblake@redhat.com> writes:

> On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
>> 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
>> 
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>> CC: Igor Mammedov <imammedo@redhat.com>
>> CC: Eric Blake <eblake@redhat.com>
>> CC: Markus Armbruster <armbru@redhat.com>
>> ---
>
>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>          if (value) {
>>              switch (value->type) {
>>              case MEMORY_DEVICE_INFO_KIND_DIMM:
>> -                size += value->u.dimm->size;
>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>
> If you fix 2/3 to use a QAPI enum, then this will be an integer compare
> instead of a strcmp().

Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
for the subtypes that should be counted here, and accumulate the sizes
of devices where the flag is set.  Requires iterating directly over the
devices here (like qmp_pc_dimm_device_list() does under the hood) rather
than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
Igor Mammedov Feb. 3, 2016, 4:23 p.m. UTC | #5
On Wed, 03 Feb 2016 16:42:21 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> Eric Blake <eblake@redhat.com> writes:
> 
> > On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:  
> >> 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
> >> 
> >> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> >> Signed-off-by: Denis V. Lunev <den@openvz.org>
> >> CC: Stefan Hajnoczi <stefanha@redhat.com>
> >> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> >> CC: "Michael S. Tsirkin" <mst@redhat.com>
> >> CC: Igor Mammedov <imammedo@redhat.com>
> >> CC: Eric Blake <eblake@redhat.com>
> >> CC: Markus Armbruster <armbru@redhat.com>
> >> ---  
> >  
> >> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
> >>          if (value) {
> >>              switch (value->type) {
> >>              case MEMORY_DEVICE_INFO_KIND_DIMM:
> >> -                size += value->u.dimm->size;
> >> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {  
> >
> > If you fix 2/3 to use a QAPI enum, then this will be an integer compare
> > instead of a strcmp().  
> 
> Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
> for the subtypes that should be counted here, and accumulate the sizes
> of devices where the flag is set.  Requires iterating directly over the
> devices here (like qmp_pc_dimm_device_list() does under the hood) rather
> than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
I'd rather not add flag to TYPE_PC_DIMM state/class as its purely balloon
qemu/guest driver limit and not related to [pc-|nv]in general.
Lets whitelist balloon supported type here.
Vladimir Sementsov-Ogievskiy Feb. 3, 2016, 5:21 p.m. UTC | #6
On 03.02.2016 18:42, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
>
>> On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
>>> 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
>>>
>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>>> CC: Igor Mammedov <imammedo@redhat.com>
>>> CC: Eric Blake <eblake@redhat.com>
>>> CC: Markus Armbruster <armbru@redhat.com>
>>> ---
>>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>>           if (value) {
>>>               switch (value->type) {
>>>               case MEMORY_DEVICE_INFO_KIND_DIMM:
>>> -                size += value->u.dimm->size;
>>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>> If you fix 2/3 to use a QAPI enum, then this will be an integer compare
>> instead of a strcmp().
> Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
> for the subtypes that should be counted here, and accumulate the sizes
> of devices where the flag is set.  Requires iterating directly over the
> devices here (like qmp_pc_dimm_device_list() does under the hood) rather
> than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
It was my first approach but it was rejected)

As another option I can make a function iterating over the devices and 
return list of them, and then use it instead of 
qmp_pc_dimm_device_list.. Then, I'll have pointers to devices and can 
use object_dynamic_cast.
Markus Armbruster Feb. 4, 2016, 6:20 a.m. UTC | #7
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> On 03.02.2016 18:42, Markus Armbruster wrote:
>> Eric Blake <eblake@redhat.com> writes:
>>
>>> On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
>>>> 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
>>>>
>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>>>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>>>> CC: Igor Mammedov <imammedo@redhat.com>
>>>> CC: Eric Blake <eblake@redhat.com>
>>>> CC: Markus Armbruster <armbru@redhat.com>
>>>> ---
>>>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>>>           if (value) {
>>>>               switch (value->type) {
>>>>               case MEMORY_DEVICE_INFO_KIND_DIMM:
>>>> -                size += value->u.dimm->size;
>>>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>>> If you fix 2/3 to use a QAPI enum, then this will be an integer compare
>>> instead of a strcmp().
>> Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
>> for the subtypes that should be counted here, and accumulate the sizes
>> of devices where the flag is set.  Requires iterating directly over the
>> devices here (like qmp_pc_dimm_device_list() does under the hood) rather
>> than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
> It was my first approach but it was rejected)
>
> As another option I can make a function iterating over the devices and
> return list of them, and then use it instead of
> qmp_pc_dimm_device_list.. Then, I'll have pointers to devices and can
> use object_dynamic_cast.

I fail to see how splitting a tree walk doing stuff into a tree walk
creating a list and a list walk doing stuff makes things better :)

Anyway, you guys figure it out.  The only part where I get involved is
QAPI design.
Vladimir Sementsov-Ogievskiy Feb. 4, 2016, 10:21 a.m. UTC | #8
On 04.02.2016 09:20, Markus Armbruster wrote:
> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
>
>> On 03.02.2016 18:42, Markus Armbruster wrote:
>>> Eric Blake <eblake@redhat.com> writes:
>>>
>>>> On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
>>>>> 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
>>>>>
>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>>>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>>>>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>>>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>>>>> CC: Igor Mammedov <imammedo@redhat.com>
>>>>> CC: Eric Blake <eblake@redhat.com>
>>>>> CC: Markus Armbruster <armbru@redhat.com>
>>>>> ---
>>>>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>>>>            if (value) {
>>>>>                switch (value->type) {
>>>>>                case MEMORY_DEVICE_INFO_KIND_DIMM:
>>>>> -                size += value->u.dimm->size;
>>>>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>>>> If you fix 2/3 to use a QAPI enum, then this will be an integer compare
>>>> instead of a strcmp().
>>> Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
>>> for the subtypes that should be counted here, and accumulate the sizes
>>> of devices where the flag is set.  Requires iterating directly over the
>>> devices here (like qmp_pc_dimm_device_list() does under the hood) rather
>>> than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
>> It was my first approach but it was rejected)
>>
>> As another option I can make a function iterating over the devices and
>> return list of them, and then use it instead of
>> qmp_pc_dimm_device_list.. Then, I'll have pointers to devices and can
>> use object_dynamic_cast.
> I fail to see how splitting a tree walk doing stuff into a tree walk
> creating a list and a list walk doing stuff makes things better :)

It will allow me not touch qapi)

>
> Anyway, you guys figure it out.  The only part where I get involved is
> QAPI design.
Markus Armbruster Feb. 5, 2016, 9:53 a.m. UTC | #9
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> On 04.02.2016 09:20, Markus Armbruster wrote:
>> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
>>
>>> On 03.02.2016 18:42, Markus Armbruster wrote:
>>>> Eric Blake <eblake@redhat.com> writes:
>>>>
>>>>> On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
>>>>>> 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
>>>>>>
>>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>>>>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>>>>>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>>>>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>>>>>> CC: Igor Mammedov <imammedo@redhat.com>
>>>>>> CC: Eric Blake <eblake@redhat.com>
>>>>>> CC: Markus Armbruster <armbru@redhat.com>
>>>>>> ---
>>>>>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>>>>>            if (value) {
>>>>>>                switch (value->type) {
>>>>>>                case MEMORY_DEVICE_INFO_KIND_DIMM:
>>>>>> -                size += value->u.dimm->size;
>>>>>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>>>>> If you fix 2/3 to use a QAPI enum, then this will be an integer compare
>>>>> instead of a strcmp().
>>>> Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
>>>> for the subtypes that should be counted here, and accumulate the sizes
>>>> of devices where the flag is set.  Requires iterating directly over the
>>>> devices here (like qmp_pc_dimm_device_list() does under the hood) rather
>>>> than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
>>> It was my first approach but it was rejected)

Sounds like your first approach was the right approach.

>>> As another option I can make a function iterating over the devices and
>>> return list of them, and then use it instead of
>>> qmp_pc_dimm_device_list.. Then, I'll have pointers to devices and can
>>> use object_dynamic_cast.
>> I fail to see how splitting a tree walk doing stuff into a tree walk
>> creating a list and a list walk doing stuff makes things better :)
>
> It will allow me not touch qapi)

Whatever it takes to get this fix past the gaggle of maintainers (I can
relate to that).

[...]
Vladimir Sementsov-Ogievskiy Feb. 5, 2016, noon UTC | #10
On 05.02.2016 12:53, Markus Armbruster wrote:
> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
>
>> On 04.02.2016 09:20, Markus Armbruster wrote:
>>> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
>>>
>>>> On 03.02.2016 18:42, Markus Armbruster wrote:
>>>>> Eric Blake <eblake@redhat.com> writes:
>>>>>
>>>>>> On 01/27/2016 11:51 PM, Vladimir Sementsov-Ogievskiy wrote:
>>>>>>> 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
>>>>>>>
>>>>>>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>>>>>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>>>>>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>>>>>>> CC: Xiao Guangrong <guangrong.xiao@linux.intel.com>
>>>>>>> CC: "Michael S. Tsirkin" <mst@redhat.com>
>>>>>>> CC: Igor Mammedov <imammedo@redhat.com>
>>>>>>> CC: Eric Blake <eblake@redhat.com>
>>>>>>> CC: Markus Armbruster <armbru@redhat.com>
>>>>>>> ---
>>>>>>> @@ -308,7 +309,9 @@ static ram_addr_t get_current_ram_size(void)
>>>>>>>             if (value) {
>>>>>>>                 switch (value->type) {
>>>>>>>                 case MEMORY_DEVICE_INFO_KIND_DIMM:
>>>>>>> -                size += value->u.dimm->size;
>>>>>>> +                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
>>>>>> If you fix 2/3 to use a QAPI enum, then this will be an integer compare
>>>>>> instead of a strcmp().
>>>>> Another option is to add a flag to the subtypes of TYPE_PC_DIMM, set it
>>>>> for the subtypes that should be counted here, and accumulate the sizes
>>>>> of devices where the flag is set.  Requires iterating directly over the
>>>>> devices here (like qmp_pc_dimm_device_list() does under the hood) rather
>>>>> than the MemoryDeviceInfoList returned by qmp_pc_dimm_device_list(),
>>>> It was my first approach but it was rejected)
> Sounds like your first approach was the right approach.
>
>>>> As another option I can make a function iterating over the devices and
>>>> return list of them, and then use it instead of
>>>> qmp_pc_dimm_device_list.. Then, I'll have pointers to devices and can
>>>> use object_dynamic_cast.
>>> I fail to see how splitting a tree walk doing stuff into a tree walk
>>> creating a list and a list walk doing stuff makes things better :)
>> It will allow me not touch qapi)
> Whatever it takes to get this fix past the gaggle of maintainers (I can
> relate to that).
>
> [...]

Everything is in your hands). I'm not mind if someone take any of this 
series versions, tune it as he wants and merge. It is a bug fix, but the 
discussion looks like I'm trying to add a new feature)
diff mbox

Patch

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 6a4c4d2..749be25 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -26,6 +26,7 @@ 
 #include "qapi/visitor.h"
 #include "qapi-event.h"
 #include "trace.h"
+#include "hw/mem/nvdimm.h"
 
 #if defined(__linux__)
 #include <sys/mman.h>
@@ -308,7 +309,9 @@  static ram_addr_t get_current_ram_size(void)
         if (value) {
             switch (value->type) {
             case MEMORY_DEVICE_INFO_KIND_DIMM:
-                size += value->u.dimm->size;
+                if (strcmp(value->u.dimm->type, TYPE_NVDIMM)) {
+                    size += value->u.dimm->size;
+                }
                 break;
             default:
                 break;