From nobody Tue May 14 12:58:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1677554883; cv=none; d=zohomail.com; s=zohoarc; b=WNDVxr8hjBCAzS3Ex9GHxYlOCW6X4RqorX9mubw5c7R9ROTyCyIFyyqxwYZudPaugRYWSJGOLUNpNRizNtqSW0AQUxV/8qgIFBXVoZyxxbOQRNUt1ecl/uYKLn0PJ7Xala0CeV8t4ZJHkqD2IMdiaDX65DF3qxZBemm2pHiTIuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677554883; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=79Q6EsQf75DX5YPOd0XN4AM3TecZ1PwpSoeUNiAXTAE=; b=EuKO6t7uKBld1KnJ4vjMGTZ3mIltkq1D3rOzoS2rXppJb0ckwndsFxFB9AkySSZjrhbVqRXTbJZPjx3/tXDcqi4a3Rv8193oDOGnjy4JN77uL3PewDYDCTurwbV1fhEZanWRoChgHrnhIxDgOzDXW+V6Xni7FxUDEakIlU5H85U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677554883111239.59364123288776; Mon, 27 Feb 2023 19:28:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWqeC-0000jL-KP; Mon, 27 Feb 2023 22:27:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWqeA-0000j9-JR for qemu-devel@nongnu.org; Mon, 27 Feb 2023 22:27:22 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWqe6-000399-RD for qemu-devel@nongnu.org; Mon, 27 Feb 2023 22:27:22 -0500 Received: from dggpemm100002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PQjQD2Qb7zRs7D; Tue, 28 Feb 2023 11:24:04 +0800 (CST) Received: from dggpemm500010.china.huawei.com (7.185.36.134) by dggpemm100002.china.huawei.com (7.185.36.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 28 Feb 2023 11:26:56 +0800 Received: from dggpemm500010.china.huawei.com ([7.185.36.134]) by dggpemm500010.china.huawei.com ([7.185.36.134]) with mapi id 15.01.2507.021; Tue, 28 Feb 2023 11:26:56 +0800 To: David Hildenbrand , "Michael S. Tsirkin" , "qemu-devel@nongnu.org" CC: "wangzhigang (O)" , "zhangliang (AG)" , xiqi Subject: [PATCH] virtio-balloon: optimize the virtio-balloon on the ARM platform. Thread-Topic: [PATCH] virtio-balloon: optimize the virtio-balloon on the ARM platform. Thread-Index: AdlLJCk3Wfz4uKhKSM+62zmLrlFVzA== Date: Tue, 28 Feb 2023 03:26:56 +0000 Message-ID: <264b6cc6a74945c3b5214fa4e8f099fe@huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.184.140] Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.188; envelope-from=yangming73@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yangming From: Yangming via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1677554884931100003 > > Optimize the virtio-balloon feature on the ARM platform by adding a > > variable to keep track of the current hot-plugged pc-dimm size, > > instead of traversing the virtual machine's memory modules to count > > the current RAM size during the balloon inflation or deflation > > process. This variable can be updated only when plugging or unplugging > > the device, which will result in an increase of approximately 60% > > efficiency of balloon process on the ARM platform. > > > > We tested the total amount of time required for the balloon inflation > process on ARM: > > inflate the balloon to 64GB of a 128GB guest under stress. > > Before: 102 seconds > > After: 42 seconds > > > > Signed-off-by: Qi Xi > > Signed-off-by: Ming Yang yangming73@huawei.com > > --- > > hw/mem/pc-dimm.c | 2 ++ > > hw/virtio/virtio-balloon.c | 33 +++++---------------------------- > > include/hw/boards.h | 1 + > > 3 files changed, 8 insertions(+), 28 deletions(-) > > > > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index > > 50ef83215c..192fc7922c 100644 > > --- a/hw/mem/pc-dimm.c > > +++ b/hw/mem/pc-dimm.c > > @@ -81,6 +81,7 @@ void pc_dimm_plug(PCDIMMDevice *dimm, > MachineState > > *machine) > > > > memory_device_plug(MEMORY_DEVICE(dimm), machine); > > vmstate_register_ram(vmstate_mr, DEVICE(dimm)); > > + machine->device_memory->dimm_size +=3D vmstate_mr->size; > > } > > > > void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine) > @@ > > -90,6 +91,7 @@ void pc_dimm_unplug(PCDIMMDevice *dimm, > MachineState > > *machine) > > > > memory_device_unplug(MEMORY_DEVICE(dimm), machine); > > vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); > > + machine->device_memory->dimm_size -=3D vmstate_mr->size; > > } >=20 > Ahh, missed that my previous comment was not addressed: we only want to > track "real" DIMMs, not NVDIMMs. >=20 > -- > Thanks, >=20 > David / dhildenb Optimize the virtio-balloon feature on the ARM platform by adding a variable to keep track of the current hot-plugged pc-dimm size, instead of traversing the virtual machine's memory modules to count the current RAM size during the balloon inflation or deflation process. This variable can be updated only when plugging or unplugging the device, which will result in an increase of approximately 60% efficiency of balloon process on the ARM platform. We tested the total amount of time required for the balloon inflation proce= ss on ARM: inflate the balloon to 64GB of a 128GB guest under stress. Before: 102 seconds After: 42 seconds Signed-off-by: Qi Xi Signed-off-by: Ming Yang yangming73@huawei.com Acked-by: David Hildenbrand --- hw/mem/pc-dimm.c | 8 ++++++++ hw/virtio/virtio-balloon.c | 33 +++++---------------------------- include/hw/boards.h | 1 + 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 50ef83215c..2107615016 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -81,6 +81,10 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *mach= ine) =20 memory_device_plug(MEMORY_DEVICE(dimm), machine); vmstate_register_ram(vmstate_mr, DEVICE(dimm)); + bool is_nvdimm =3D object_dynamic_cast(OBJECT(dimm), TYPE_NVDIMM); + if (!is_nvdimm) { + machine->device_memory->dimm_size +=3D vmstate_mr->size; + } } =20 void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine) @@ -90,6 +94,10 @@ void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *ma= chine) =20 memory_device_unplug(MEMORY_DEVICE(dimm), machine); vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); + bool is_nvdimm =3D object_dynamic_cast(OBJECT(dimm), TYPE_NVDIMM); + if (!is_nvdimm) { + machine->device_memory->dimm_size -=3D vmstate_mr->size; + } } =20 static int pc_dimm_slot2bitmap(Object *obj, void *opaque) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 746f07c4d2..80bbb59132 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -729,37 +729,14 @@ static void virtio_balloon_get_config(VirtIODevice *v= dev, uint8_t *config_data) memcpy(config_data, &config, virtio_balloon_config_size(dev)); } =20 -static int build_dimm_list(Object *obj, void *opaque) -{ - GSList **list =3D opaque; - - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - DeviceState *dev =3D DEVICE(obj); - if (dev->realized) { /* only realized DIMMs matter */ - *list =3D g_slist_prepend(*list, dev); - } - } - - object_child_foreach(obj, build_dimm_list, opaque); - return 0; -} - static ram_addr_t get_current_ram_size(void) { - GSList *list =3D NULL, *item; - ram_addr_t size =3D current_machine->ram_size; - - build_dimm_list(qdev_get_machine(), &list); - for (item =3D list; item; item =3D g_slist_next(item)) { - Object *obj =3D OBJECT(item->data); - if (!strcmp(object_get_typename(obj), TYPE_PC_DIMM)) { - size +=3D object_property_get_int(obj, PC_DIMM_SIZE_PROP, - &error_abort); - } + MachineState *machine =3D MACHINE(qdev_get_machine()); + if (machine->device_memory !=3D NULL) { + return machine->ram_size + machine->device_memory->dimm_size; + } else { + return machine->ram_size; } - g_slist_free(list); - - return size; } =20 static bool virtio_balloon_page_poison_support(void *opaque) diff --git a/include/hw/boards.h b/include/hw/boards.h index 6fbbfd56c8..551b4b419e 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -296,6 +296,7 @@ struct MachineClass { typedef struct DeviceMemoryState { hwaddr base; MemoryRegion mr; + ram_addr_t dimm_size; } DeviceMemoryState; =20 /** --=20 2.33.0