From nobody Thu Nov 6 20:31:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487735386022561.0100874784185; Tue, 21 Feb 2017 19:49:46 -0800 (PST) Received: from localhost ([::1]:49669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgNw0-0001wH-Nd for importer@patchew.org; Tue, 21 Feb 2017 22:49:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgNpO-0004i6-4o for qemu-devel@nongnu.org; Tue, 21 Feb 2017 22:42:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgNpJ-0002tL-E9 for qemu-devel@nongnu.org; Tue, 21 Feb 2017 22:42:54 -0500 Received: from [45.249.212.189] (port=2398 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cgNpI-0002pa-Qb for qemu-devel@nongnu.org; Tue, 21 Feb 2017 22:42:49 -0500 Received: from 172.30.72.53 (EHLO DGGEMM403-HUB.china.huawei.com) ([172.30.72.53]) by dggrg03-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AIX52738; Wed, 22 Feb 2017 11:42:41 +0800 (CST) Received: from DGGEML401-HUB.china.huawei.com (10.3.17.32) by DGGEMM403-HUB.china.huawei.com (10.3.20.211) with Microsoft SMTP Server (TLS) id 14.3.301.0; Wed, 22 Feb 2017 11:42:40 +0800 Received: from localhost (10.177.24.212) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server id 14.3.301.0; Wed, 22 Feb 2017 11:42:33 +0800 From: zhanghailiang To: , , Date: Wed, 22 Feb 2017 11:42:12 +0800 Message-ID: <1487734936-43472-12-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487734936-43472-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487734936-43472-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.58AD08B3.0022, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 35196897032f94d7bd429c45c29385b6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.189 Subject: [Qemu-devel] [PATCH 11/15] savevm: split save/find loadvm_handlers entry into two helper functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xiecl.fnst@cn.fujitsu.com, zhanghailiang , lizhijian@cn.fujitsu.com, Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" COLO's checkpoint process is based on migration process, everytime we do checkpoint we will repeat the process of savevm and loadvm. So we will call qemu_loadvm_section_start_full() repeatedly, It will add all migration sections information into loadvm_handlers list everytime, which will lead to memory leak. To fix it, we split the process of saving and finding section entry into two helper functions, we will check if section info was exist in loadvm_handlers list before save it. This modifications have no side effect for normal migration. Cc: Juan Quintela Signed-off-by: zhanghailiang Reviewed-by: Dr. David Alan Gilbert --- migration/savevm.c | 55 +++++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 5ecd264..9c2d239 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1821,6 +1821,37 @@ void loadvm_free_handlers(MigrationIncomingState *mi= s) } } =20 +static LoadStateEntry *loadvm_add_section_entry(MigrationIncomingState *mi= s, + SaveStateEntry *se, + uint32_t section_id, + uint32_t version_id) +{ + LoadStateEntry *le; + + /* Add entry */ + le =3D g_malloc0(sizeof(*le)); + + le->se =3D se; + le->section_id =3D section_id; + le->version_id =3D version_id; + QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry); + return le; +} + +static LoadStateEntry *loadvm_find_section_entry(MigrationIncomingState *m= is, + uint32_t section_id) +{ + LoadStateEntry *le; + + QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { + if (le->section_id =3D=3D section_id) { + break; + } + } + + return le; +} + static int qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) { @@ -1863,15 +1894,12 @@ qemu_loadvm_section_start_full(QEMUFile *f, Migrati= onIncomingState *mis) return -EINVAL; } =20 - /* Add entry */ - le =3D g_malloc0(sizeof(*le)); - - le->se =3D se; - le->section_id =3D section_id; - le->version_id =3D version_id; - QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry); - - ret =3D vmstate_load(f, le->se, le->version_id); + /* Check if we have saved this section info before, if not, save it */ + le =3D loadvm_find_section_entry(mis, section_id); + if (!le) { + le =3D loadvm_add_section_entry(mis, se, section_id, version_id); + } + ret =3D vmstate_load(f, se, version_id); if (ret < 0) { error_report("error while loading state for instance 0x%x of" " device '%s'", instance_id, idstr); @@ -1894,12 +1922,9 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationI= ncomingState *mis) section_id =3D qemu_get_be32(f); =20 trace_qemu_loadvm_state_section_partend(section_id); - QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { - if (le->section_id =3D=3D section_id) { - break; - } - } - if (le =3D=3D NULL) { + + le =3D loadvm_find_section_entry(mis, section_id); + if (!le) { error_report("Unknown savevm section %d", section_id); return -EINVAL; } --=20 1.8.3.1