From patchwork Sat Apr 22 08:35:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9694287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0266E601E9 for ; Sat, 22 Apr 2017 08:40:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE3E22860E for ; Sat, 22 Apr 2017 08:40:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1FDF28621; Sat, 22 Apr 2017 08:40:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 291822860E for ; Sat, 22 Apr 2017 08:40:41 +0000 (UTC) Received: from localhost ([::1]:34742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1qau-0003Ua-B6 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 22 Apr 2017 04:40:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1qXF-00013h-Oa for qemu-devel@nongnu.org; Sat, 22 Apr 2017 04:36:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1qXC-0003tM-Is for qemu-devel@nongnu.org; Sat, 22 Apr 2017 04:36:53 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3511 helo=dggrg01-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1qXB-0003ri-Vx for qemu-devel@nongnu.org; Sat, 22 Apr 2017 04:36:50 -0400 Received: from 172.30.72.53 (EHLO DGGEML401-HUB.china.huawei.com) ([172.30.72.53]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id ANE70252; Sat, 22 Apr 2017 16:36:42 +0800 (CST) 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; Sat, 22 Apr 2017 16:36:32 +0800 From: zhanghailiang To: , Date: Sat, 22 Apr 2017 16:35:21 +0800 Message-ID: <1492850128-17472-12-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1492850128-17472-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1492850128-17472-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.0A020202.58FB161A.0066, 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: 83b2617821d6d67304e386e2ced5cfd3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.187 Subject: [Qemu-devel] [PATCH RESEND v2 11/18] 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: zhanghailiang , zhangchen.fnst@cn.fujitsu.com, quintela@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 03ae1bd..f87cd8d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1836,6 +1836,37 @@ void loadvm_free_handlers(MigrationIncomingState *mis) } } +static LoadStateEntry *loadvm_add_section_entry(MigrationIncomingState *mis, + SaveStateEntry *se, + uint32_t section_id, + uint32_t version_id) +{ + LoadStateEntry *le; + + /* Add entry */ + le = g_malloc0(sizeof(*le)); + + le->se = se; + le->section_id = section_id; + le->version_id = version_id; + QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry); + return le; +} + +static LoadStateEntry *loadvm_find_section_entry(MigrationIncomingState *mis, + uint32_t section_id) +{ + LoadStateEntry *le; + + QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { + if (le->section_id == section_id) { + break; + } + } + + return le; +} + static int qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) { @@ -1878,15 +1909,12 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) return -EINVAL; } - /* Add entry */ - le = g_malloc0(sizeof(*le)); - - le->se = se; - le->section_id = section_id; - le->version_id = version_id; - QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry); - - ret = vmstate_load(f, le->se, le->version_id); + /* Check if we have saved this section info before, if not, save it */ + le = loadvm_find_section_entry(mis, section_id); + if (!le) { + le = loadvm_add_section_entry(mis, se, section_id, version_id); + } + ret = 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); @@ -1909,12 +1937,9 @@ qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) section_id = qemu_get_be32(f); trace_qemu_loadvm_state_section_partend(section_id); - QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { - if (le->section_id == section_id) { - break; - } - } - if (le == NULL) { + + le = loadvm_find_section_entry(mis, section_id); + if (!le) { error_report("Unknown savevm section %d", section_id); return -EINVAL; }