aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/mmu.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-04-16 04:53:17 -0400
committerAvi Kivity <avi@qumranet.com>2007-05-03 03:52:29 -0400
commit8c4385024d31cb909ad84a2cafa5c83a4c5fab61 (patch)
tree9c6df8e13bf475985b682704cbe0b587072cc087 /drivers/kvm/mmu.c
parentb5a33a75720c03d58d8281a72b45ffd214f00ed7 (diff)
KVM: Retry sleeping allocation if atomic allocation fails
This avoids -ENOMEM under memory pressure. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/mmu.c')
-rw-r--r--drivers/kvm/mmu.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index a368ea8297f3..c814394a966d 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -199,14 +199,15 @@ static int is_rmap_pte(u64 pte)
199} 199}
200 200
201static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache, 201static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
202 struct kmem_cache *base_cache, int min) 202 struct kmem_cache *base_cache, int min,
203 gfp_t gfp_flags)
203{ 204{
204 void *obj; 205 void *obj;
205 206
206 if (cache->nobjs >= min) 207 if (cache->nobjs >= min)
207 return 0; 208 return 0;
208 while (cache->nobjs < ARRAY_SIZE(cache->objects)) { 209 while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
209 obj = kmem_cache_zalloc(base_cache, GFP_NOWAIT); 210 obj = kmem_cache_zalloc(base_cache, gfp_flags);
210 if (!obj) 211 if (!obj)
211 return -ENOMEM; 212 return -ENOMEM;
212 cache->objects[cache->nobjs++] = obj; 213 cache->objects[cache->nobjs++] = obj;
@@ -220,20 +221,35 @@ static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc)
220 kfree(mc->objects[--mc->nobjs]); 221 kfree(mc->objects[--mc->nobjs]);
221} 222}
222 223
223static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu) 224static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags)
224{ 225{
225 int r; 226 int r;
226 227
227 r = mmu_topup_memory_cache(&vcpu->mmu_pte_chain_cache, 228 r = mmu_topup_memory_cache(&vcpu->mmu_pte_chain_cache,
228 pte_chain_cache, 4); 229 pte_chain_cache, 4, gfp_flags);
229 if (r) 230 if (r)
230 goto out; 231 goto out;
231 r = mmu_topup_memory_cache(&vcpu->mmu_rmap_desc_cache, 232 r = mmu_topup_memory_cache(&vcpu->mmu_rmap_desc_cache,
232 rmap_desc_cache, 1); 233 rmap_desc_cache, 1, gfp_flags);
233out: 234out:
234 return r; 235 return r;
235} 236}
236 237
238static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
239{
240 int r;
241
242 r = __mmu_topup_memory_caches(vcpu, GFP_NOWAIT);
243 if (r < 0) {
244 spin_unlock(&vcpu->kvm->lock);
245 kvm_arch_ops->vcpu_put(vcpu);
246 r = __mmu_topup_memory_caches(vcpu, GFP_KERNEL);
247 kvm_arch_ops->vcpu_load(vcpu);
248 spin_lock(&vcpu->kvm->lock);
249 }
250 return r;
251}
252
237static void mmu_free_memory_caches(struct kvm_vcpu *vcpu) 253static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
238{ 254{
239 mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache); 255 mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache);