qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Bug?]When close VM the hugepage not freed
@ 2014-10-14 12:02 Linhaifeng
  2014-10-14 12:08 ` Daniel P. Berrange
  2014-10-15  7:39 ` Linhaifeng
  0 siblings, 2 replies; 6+ messages in thread
From: Linhaifeng @ 2014-10-14 12:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: lilijun, Michael S. Tsirkin

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();

}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-15  7:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-14 12:02 [Qemu-devel] [Bug?]When close VM the hugepage not freed Linhaifeng
2014-10-14 12:08 ` Daniel P. Berrange
2014-10-14 16:28   ` Michael S. Tsirkin
2014-10-15  7:03     ` Daniel P. Berrange
2014-10-15  1:32   ` Linhaifeng
2014-10-15  7:39 ` Linhaifeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).