Commit 92eca8fa authored by Takuya Yoshikawa's avatar Takuya Yoshikawa Committed by Avi Kivity

KVM: Separate out dirty_bitmap allocation code as kvm_kvzalloc()

Will be used for lpage_info allocation later.
Signed-off-by: default avatarTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 99becf13
...@@ -516,16 +516,32 @@ static struct kvm *kvm_create_vm(unsigned long type) ...@@ -516,16 +516,32 @@ static struct kvm *kvm_create_vm(unsigned long type)
return ERR_PTR(r); return ERR_PTR(r);
} }
/*
* Avoid using vmalloc for a small buffer.
* Should not be used when the size is statically known.
*/
static void *kvm_kvzalloc(unsigned long size)
{
if (size > PAGE_SIZE)
return vzalloc(size);
else
return kzalloc(size, GFP_KERNEL);
}
static void kvm_kvfree(const void *addr)
{
if (is_vmalloc_addr(addr))
vfree(addr);
else
kfree(addr);
}
static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot) static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot)
{ {
if (!memslot->dirty_bitmap) if (!memslot->dirty_bitmap)
return; return;
if (2 * kvm_dirty_bitmap_bytes(memslot) > PAGE_SIZE) kvm_kvfree(memslot->dirty_bitmap);
vfree(memslot->dirty_bitmap);
else
kfree(memslot->dirty_bitmap);
memslot->dirty_bitmap = NULL; memslot->dirty_bitmap = NULL;
} }
...@@ -617,11 +633,7 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot) ...@@ -617,11 +633,7 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
#ifndef CONFIG_S390 #ifndef CONFIG_S390
unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot); unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot);
if (dirty_bytes > PAGE_SIZE) memslot->dirty_bitmap = kvm_kvzalloc(dirty_bytes);
memslot->dirty_bitmap = vzalloc(dirty_bytes);
else
memslot->dirty_bitmap = kzalloc(dirty_bytes, GFP_KERNEL);
if (!memslot->dirty_bitmap) if (!memslot->dirty_bitmap)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment