KVM: Retry sleeping allocation if atomic allocation fails
This avoids -ENOMEM under memory pressure. Signed-off-by: Avi Kivity <avi@qumranet.com>
This commit is contained in:
parent
b5a33a7572
commit
8c4385024d
|
@ -199,14 +199,15 @@ static int is_rmap_pte(u64 pte)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
|
static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
|
||||||
struct kmem_cache *base_cache, int min)
|
struct kmem_cache *base_cache, int min,
|
||||||
|
gfp_t gfp_flags)
|
||||||
{
|
{
|
||||||
void *obj;
|
void *obj;
|
||||||
|
|
||||||
if (cache->nobjs >= min)
|
if (cache->nobjs >= min)
|
||||||
return 0;
|
return 0;
|
||||||
while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
|
while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
|
||||||
obj = kmem_cache_zalloc(base_cache, GFP_NOWAIT);
|
obj = kmem_cache_zalloc(base_cache, gfp_flags);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
cache->objects[cache->nobjs++] = obj;
|
cache->objects[cache->nobjs++] = obj;
|
||||||
|
@ -220,20 +221,35 @@ static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc)
|
||||||
kfree(mc->objects[--mc->nobjs]);
|
kfree(mc->objects[--mc->nobjs]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
|
static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = mmu_topup_memory_cache(&vcpu->mmu_pte_chain_cache,
|
r = mmu_topup_memory_cache(&vcpu->mmu_pte_chain_cache,
|
||||||
pte_chain_cache, 4);
|
pte_chain_cache, 4, gfp_flags);
|
||||||
if (r)
|
if (r)
|
||||||
goto out;
|
goto out;
|
||||||
r = mmu_topup_memory_cache(&vcpu->mmu_rmap_desc_cache,
|
r = mmu_topup_memory_cache(&vcpu->mmu_rmap_desc_cache,
|
||||||
rmap_desc_cache, 1);
|
rmap_desc_cache, 1, gfp_flags);
|
||||||
out:
|
out:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = __mmu_topup_memory_caches(vcpu, GFP_NOWAIT);
|
||||||
|
if (r < 0) {
|
||||||
|
spin_unlock(&vcpu->kvm->lock);
|
||||||
|
kvm_arch_ops->vcpu_put(vcpu);
|
||||||
|
r = __mmu_topup_memory_caches(vcpu, GFP_KERNEL);
|
||||||
|
kvm_arch_ops->vcpu_load(vcpu);
|
||||||
|
spin_lock(&vcpu->kvm->lock);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
|
static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
|
||||||
{
|
{
|
||||||
mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache);
|
mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache);
|
||||||
|
|
Loading…
Reference in a new issue