From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfKbI-0004g5-3D for qemu-devel@nongnu.org; Fri, 17 Oct 2014 23:22:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfKbD-0004IM-8J for qemu-devel@nongnu.org; Fri, 17 Oct 2014 23:22:40 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:1838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfKbC-0004AN-Ip for qemu-devel@nongnu.org; Fri, 17 Oct 2014 23:22:35 -0400 Message-ID: <5441DCE9.6000202@huawei.com> Date: Sat, 18 Oct 2014 11:22:17 +0800 From: Linhaifeng MIME-Version: 1.0 References: <1413534437-13516-1-git-send-email-haifeng.lin@huawei.com> <5440D6BA.2040801@huawei.com> In-Reply-To: <5440D6BA.2040801@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] fix the memory leak for share hugepage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: zhanghailiang , qemu-devel@nongnu.org Cc: jerry.lilijun@huawei.com, mst@redhat.com On 2014/10/17 16:43, zhanghailiang wrote: > On 2014/10/17 16:27, haifeng.lin@huawei.com wrote: >> From: linhaifeng >> >> The VM start with share hugepage should close the hugefile fd >> when exit.Because the hugepage fd may be send to other process >> e.g vhost-user If qemu not close the fd the other process can >> not free the hugepage otherwise exit process,this is ugly,so >> qemu should close all shared fd when exit. >> >> Signed-off-by: linhaifeng >> --- >> exec.c | 12 ++++++++++++ >> vl.c | 7 +++++++ >> 2 files changed, 19 insertions(+) >> >> diff --git a/exec.c b/exec.c >> index 759055d..d120b73 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -1535,6 +1535,18 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) >> } >> } >> } >> + >> +void qemu_close_all_ram_fd(void) >> +{ >> + RAMBlock *block; >> + >> + qemu_mutex_lock_ramlist(); >> + QTAILQ_FOREACH(block, &ram_list.blocks, next) { >> + close(block->fd); >> + } >> + qemu_mutex_unlock_ramlist(); >> +} >> + >> #endif /* !_WIN32 */ >> >> int qemu_get_ram_fd(ram_addr_t addr) >> diff --git a/vl.c b/vl.c >> index aee73e1..0b78f3f 100644 >> --- a/vl.c >> +++ b/vl.c >> @@ -1658,6 +1658,7 @@ static int qemu_shutdown_requested(void) >> return r; >> } >> >> +extern void qemu_close_all_ram_fd(void); >> static void qemu_kill_report(void) >> { >> if (!qtest_driver() && shutdown_signal != -1) { >> @@ -1671,6 +1672,12 @@ static void qemu_kill_report(void) >> fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); >> } >> shutdown_signal = -1; >> + >> + /* Close all ram fd when exit. If the ram is shared by othter process > > s/othter/other/ > OK.thank you. >> + * e.g vhost-user, it can free the hugepage by close fd after qemu exit, >> + * otherwise the process have to exit to free hugepage. >> + */ >> + qemu_close_all_ram_fd(); >> } >> } >> >> > > > > . > -- Regards, Haifeng