From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeJBu-0007As-7j for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:40:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeJBo-0008S6-3C for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:40:14 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:50624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeJBm-00089c-Jy for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:40:08 -0400 Message-ID: <543E24BD.6030804@huawei.com> Date: Wed, 15 Oct 2014 15:39:42 +0800 From: Linhaifeng MIME-Version: 1.0 References: <543D10DE.2080109@huawei.com> In-Reply-To: <543D10DE.2080109@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [Bug?]When close VM the hugepage not freed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lilijun , "Michael S. Tsirkin" On 2014/10/14 20:02, Linhaifeng wrote: > Hi,all > > I was trying to use hugepage with VM and found that the hugepage not freed when close VM. > > > 1.Before start VM the /proc/meminfo is: > AnonHugePages: 124928 kB > HugePages_Total: 4096 > HugePages_Free: 3072 > HugePages_Rsvd: 0 > HugePages_Surp: 0 > Hugepagesize: 2048 kB > > 2.Start VM the /proc/meminfo is: > AnonHugePages: 139264 kB > HugePages_Total: 4096 > HugePages_Free: 2048 > HugePages_Rsvd: 0 > HugePages_Surp: 0 > Hugepagesize: 2048 kB > > 3.Close VM the /proc/meminfo is: > AnonHugePages: 124928 kB > HugePages_Total: 4096 > HugePages_Free: 2048 > HugePages_Rsvd: 0 > HugePages_Surp: 0 > Hugepagesize: 2048 kB > > We can see there are 1024 hugepage leak! > > I try to found which function used to free hugepage but i'm not sure where the qemu_ram_free is the function to free hugepage. > I found that the qemu_ram_free function not call unlink and we know unlink is used to free hugepage(see example of hugepage-mmap.c in kernel source). > > void qemu_ram_free(ram_addr_t addr) > { > RAMBlock *block; > > /* This assumes the iothread lock is taken here too. */ > qemu_mutex_lock_ramlist(); > QTAILQ_FOREACH(block, &ram_list.blocks, next) { > if (addr == block->offset) { > QTAILQ_REMOVE(&ram_list.blocks, block, next); > ram_list.mru_block = NULL; > ram_list.version++; > if (block->flags & RAM_PREALLOC) { > ; > } else if (xen_enabled()) { > xen_invalidate_map_cache_entry(block->host); > #ifndef _WIN32 > } else if (block->fd >= 0) { > munmap(block->host, block->length); > close(block->fd); > // should we add unlink here to free hugepage? > #endif > } else { > qemu_anon_ram_free(block->host, block->length); > } > g_free(block); > break; > } > } > qemu_mutex_unlock_ramlist(); > > } > > > > When i run the QEMU with tap backend the hugepage will be freed but not the vhost-user backend. Maybe the vhost-user process should close the hugefile. -- Regards, Haifeng