Move RAMBlock deallocation to reclaim_ramblock

Backports a minor portion of commit 43771539d4666cba16298fc6b0ea63867425277c from qemu
This commit is contained in:
Lioncash 2018-02-18 19:36:18 -05:00
parent aa0ce52b97
commit 6a7974277a
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -1205,6 +1205,21 @@ ram_addr_t qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz,
return qemu_ram_alloc_internal(size, maxsz, resized, NULL, true, mr, errp);
}
static void reclaim_ramblock(RAMBlock *block)
{
if (block->flags & RAM_PREALLOC) {
;
#ifndef _WIN32
} else if (block->fd >= 0) {
munmap(block->host, block->max_length);
close(block->fd);
#endif
} else {
qemu_anon_ram_free(block->host, block->max_length);
}
g_free(block);
}
void qemu_ram_free(struct uc_struct *uc, ram_addr_t addr)
{
RAMBlock *block;
@ -1213,18 +1228,11 @@ void qemu_ram_free(struct uc_struct *uc, ram_addr_t addr)
if (addr == block->offset) {
QLIST_REMOVE(block, next);
uc->ram_list.mru_block = NULL;
/* Write list before version */
smp_wmb();
uc->ram_list.version++;
if (block->flags & RAM_PREALLOC) {
;
#ifndef _WIN32
} else if (block->fd >= 0) {
munmap(block->host, block->max_length);
close(block->fd);
#endif
} else {
qemu_anon_ram_free(block->host, block->max_length);
}
g_free(block);
// Unicorn: call directly instead of via call_rcu
reclaim_ramblock(block);
break;
}
}