From nobody Sat May 4 16:13:21 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1678348402; cv=none; d=zohomail.com; s=zohoarc; b=Ddyy1iqknuYfMLRkdnZygKJOs6ot8QwSzJu10/5na/JKezhu3h4tkopGbhnSmXxiRJG0q2kzORRIPeI0x9R8AcCeiRhEb2RFkB7gMf7XV0NhTQD11Y8RMagsSsCOa/XzLikickkKzaabVcttTFlgYMR0XrKluNxw/Ao/7z20ik0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678348402; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=JzasVa60l3U+fuRLyeyvPpvVE0g2SAB7uUfebemXZXg=; b=eZJ4yX8JONtVmcpZg7+iEtu+MGqc846y2J2VvU2Svn0PbO64VYC+6bDmv+98NqjwuMuyFG+Tyyx675d5F+h1OiCXTn1Rzu+WHxjDCnnRt0If0QrpF12O280QmdBWETbrg2PiwKVkMXcaTuHNO4IMQRRelbApYbqQ5eKXmb17QV4= 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+importer2=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 1678348402862693.3815383566142; Wed, 8 Mar 2023 23:53:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paB5H-0005Lk-Rx; Thu, 09 Mar 2023 02:53:08 -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 1paB5F-0005LV-Nj for qemu-devel@nongnu.org; Thu, 09 Mar 2023 02:53:05 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1paB5C-0000el-Us for qemu-devel@nongnu.org; Thu, 09 Mar 2023 02:53:05 -0500 Received: from dggpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PXLv355xBznWtH; Thu, 9 Mar 2023 15:50:07 +0800 (CST) Received: from dggpemm500010.china.huawei.com (7.185.36.134) by dggpemm500002.china.huawei.com (7.185.36.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 9 Mar 2023 15:52:57 +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; Thu, 9 Mar 2023 15:52:57 +0800 To: David Hildenbrand , "Michael S. Tsirkin" , "qemu-devel@nongnu.org" CC: "wangzhigang (O)" , "zhangliang (AG)" , xiqi Subject: [PATCH v3] virtio-balloon: optimize the virtio-balloon on the ARM platform Thread-Topic: [PATCH v3] virtio-balloon: optimize the virtio-balloon on the ARM platform Thread-Index: AQHZUi7A5PFV5xA+kk+ShXcQSn47C67yE0aw Date: Thu, 9 Mar 2023 07:52:57 +0000 Message-ID: References: <20230309022752.1013-1-xiqi2@huawei.com> In-Reply-To: <20230309022752.1013-1-xiqi2@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-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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.187; envelope-from=yangming73@huawei.com; helo=szxga01-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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1678348403815100001 Content-Type: text/plain; charset="utf-8" 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 | 7 +++++++ hw/virtio/virtio-balloon.c | 33 +++++---------------------------- include/hw/boards.h | 2 ++ 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 50ef83215c..37f1f4ccfd 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)); + /* count only "real" DIMMs, not NVDIMMs */ + if (!object_dynamic_cast(OBJECT(dimm), TYPE_NVDIMM)) { + machine->device_memory->dimm_size +=3D memory_region_size(vmstate_= mr); + } } =20 void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine) @@ -90,6 +94,9 @@ void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *mac= hine) =20 memory_device_unplug(MEMORY_DEVICE(dimm), machine); vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); + if (!object_dynamic_cast(OBJECT(dimm), TYPE_NVDIMM)) { + machine->device_memory->dimm_size -=3D memory_region_size(vmstate_= mr); + } } =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..2814a47cb1 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) { + 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..f840f88d54 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -292,10 +292,12 @@ struct MachineClass { * @base: address in guest physical address space where the memory * address space for memory devices starts * @mr: address space container for memory devices + * @dimm_size: the sum of plugged DIMMs' sizes */ typedef struct DeviceMemoryState { hwaddr base; MemoryRegion mr; + uint64_t dimm_size; } DeviceMemoryState; =20 /** --=20 2.33.0