Skip to contentSkip to conversation

kvm: don not fail when cache is sufficient

PATCH In review Lai Jiangshan 2 participants 2 messages Apr 17, 2010 – Apr 21, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: don not fail when cache is sufficient

cleanup: don not fail when cache is sufficient

---

arch/x86/kvm/mmu.c +2 -2
index c8c074c..90f666e 100644
@@ -304,7 +304,7 @@ static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
 	while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
 		obj = kmem_cache_zalloc(base_cache, GFP_KERNEL);
 		if (!obj)
-			return -ENOMEM;
+			return cache->nobjs >= min ? 0 : -ENOMEM;
 		cache->objects[cache->nobjs++] = obj;
 	}
 	return 0;
@@ -326,7 +326,7 @@ static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache,
 	while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
 		page = alloc_page(GFP_KERNEL);
 		if (!page)
-			return -ENOMEM;
+			return  cache->nobjs >= min ? 0 : -ENOMEM;
 		set_page_private(page, 0);
 		cache->objects[cache->nobjs++] = page_address(page);
 	}
#1 lore raw
Quoted 20 lines · Lai Jiangshan

cleanup: don not fail when cache is sufficient

---

arch/x86/kvm/mmu.c +1 -1
index c8c074c..90f666e 100644
@@ -304,7 +304,7 @@ static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
  	while (cache->nobjs<  ARRAY_SIZE(cache->objects)) {
  		obj = kmem_cache_zalloc(base_cache, GFP_KERNEL);
  		if (!obj)
-			return -ENOMEM;
+			return cache->nobjs>= min ? 0 : -ENOMEM;
  		cache->objects[cache->nobjs++] = obj;
  	}
  	return 0;

arch/x86/kvm/mmu.c static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache, · line 332

Quoted 8 lines
arch/x86/kvm/mmu.c +1 -1
@@ -326,7 +326,7 @@ static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache,
  	while (cache->nobjs<  ARRAY_SIZE(cache->objects)) {
  		page = alloc_page(GFP_KERNEL);
  		if (!page)
-			return -ENOMEM;
+			return  cache->nobjs>= min ? 0 : -ENOMEM;
  		set_page_private(page, 0);
  		cache->objects[cache->nobjs++] = page_address(page);
  	}

Have you ever observed this? My feeling is that if we're a few pages from -ENOMEM, it doesn't really matter if we die now or a few calls away. Note alloc_page() can call back into kvm via the shrinker to free pages, so an OOM will be external to kvm and we won't really be able to handle it.

Signature · 1 line
error compiling committee.c: too many arguments to function