login
Header Space

 
 

Re: [PATCH] scsi: fix sense_slab/bio swapping livelock

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: Hugh Dickins <hugh@...>, Peter Zijlstra <a.p.zijlstra@...>, Christoph Lameter <clameter@...>, James Bottomley <James.Bottomley@...>, Andrew Morton <akpm@...>, FUJITA Tomonori <fujita.tomonori@...>, Jens Axboe <jens.axboe@...>, Rafael J. Wysocki <rjw@...>, <linux-kernel@...>
Date: Tuesday, April 8, 2008 - 4:42 pm

On Tue, 8 Apr 2008, Pekka J Enberg wrote:

On Mon, 7 Apr 2008, Linus Torvalds wrote:

So something like this fugly patch on top of the SLUB variable order 
patches that let the allocator fall-back to smaller page orders. Survives 
OOM in my testing and the box seems to be bit more responsive even under X 
with this.

		Pekka

---
 mm/slub.c |   93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 92 insertions(+), 1 deletion(-)

Index: slab-2.6/mm/slub.c
===================================================================
--- slab-2.6.orig/mm/slub.c	2008-04-08 22:52:02.000000000 +0300
+++ slab-2.6/mm/slub.c	2008-04-08 23:27:27.000000000 +0300
@@ -1549,6 +1549,88 @@
 }
 
 /*
+ * Emergency caches are reserved for GFP_TEMPORARY allocations on OOM.
+ */
+
+#define MIN_EMERGENCY_SIZE 32
+#define NR_EMERGENCY_CACHES 4
+
+struct kmem_cache *emergency_caches[NR_EMERGENCY_CACHES];
+
+static void pre_alloc_cpu_slabs(struct kmem_cache *s)
+{
+	int cpu;
+
+	/*
+	 * FIXME: CPU hot-plug, stats, debug?
+	 */
+	for_each_online_cpu(cpu) {
+		struct kmem_cache_cpu *c;
+		struct page *new;
+		void **object;
+		int node;
+
+		c = get_cpu_slab(s, cpu);
+		node = cpu_to_node(cpu);
+
+		new = new_slab(s, GFP_KERNEL, node);
+		BUG_ON(!new);
+
+		slab_lock(new);
+		SetSlabFrozen(new);
+		c->page = new;
+		object = c->page->freelist;
+		c->freelist = object[c->offset];
+		c->page->inuse = c->page->objects;
+		c->page->freelist = NULL;
+		c->node = page_to_nid(c->page);
+		slab_unlock(c->page);
+	}
+}
+
+static void init_emergency_caches(void)
+{
+	unsigned long size = MIN_EMERGENCY_SIZE;
+	int i;
+
+	for (i = 0; i < NR_EMERGENCY_CACHES; i++) {
+		struct kmem_cache *cache;
+		char *name;
+
+		name = kasprintf(GFP_KERNEL, "kmalloc-%d", 1 << i);
+		BUG_ON(!name);
+
+		cache = kmem_cache_create(name, size, 0, 0, NULL);
+		BUG_ON(!cache);
+		kfree(name);
+
+		pre_alloc_cpu_slabs(cache);
+		emergency_caches[i] = cache;
+
+		size *= 2;
+	}
+}
+
+static void *emergency_alloc(struct kmem_cache *cache, gfp_t gfp)
+{
+	unsigned long cache_size = MIN_EMERGENCY_SIZE;
+	void *p = NULL;
+	int i;
+
+	for (i = 0; i < NR_EMERGENCY_CACHES; i++) {
+		if (cache->objsize < cache_size) {
+			p = kmem_cache_alloc(emergency_caches[i], gfp);
+			if (p)
+				break;
+		}
+		cache_size *= 2;
+	}
+	if (p && cache->ctor)
+		cache->ctor(cache, p);
+	return p;
+}
+
+/*
  * Slow path. The lockless freelist is empty or we need to perform
  * debugging duties.
  *
@@ -1626,6 +1708,14 @@
 		c->page = new;
 		goto load_freelist;
 	}
+
+	/*
+	 * We are really OOM. Let short-lived allocations dip into the reserves
+	 * to ensure writeback makes progress.
+	 */
+	if ((gfpflags & GFP_TEMPORARY) == GFP_TEMPORARY)
+		return emergency_alloc(s, gfpflags);
+
 	return NULL;
 debug:
 	if (!alloc_debug_processing(s, c->page, object, addr))
@@ -1791,7 +1881,7 @@
 
 	page = virt_to_head_page(x);
 
-	slab_free(s, page, x, __builtin_return_address(0));
+	slab_free(page->slab, page, x, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(kmem_cache_free);
 
@@ -3225,6 +3315,7 @@
 #else
 	kmem_size = sizeof(struct kmem_cache);
 #endif
+	init_emergency_caches();
 
 	printk(KERN_INFO
 		"SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Sun Apr 6, 6:56 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Christoph Lameter, (Mon Apr 7, 1:26 am)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Mon Apr 7, 3:40 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Christoph Lameter, (Tue Apr 8, 4:43 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Peter Zijlstra, (Mon Apr 7, 3:55 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Mon Apr 7, 4:31 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Mon Apr 7, 5:00 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Mon Apr 7, 5:05 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Mon Apr 7, 5:30 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Mon Apr 7, 5:36 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Linus Torvalds, (Mon Apr 7, 5:15 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Mon Apr 7, 5:34 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Mon Apr 7, 5:39 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka J Enberg, (Mon Apr 7, 6:05 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Linus Torvalds, (Mon Apr 7, 6:17 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka J Enberg, (Tue Apr 8, 4:42 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Christoph Lameter, (Tue Apr 8, 4:45 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Tue Apr 8, 5:11 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Peter Zijlstra, (Tue Apr 8, 5:40 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Tue Apr 8, 4:44 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Pekka Enberg, (Mon Apr 7, 6:42 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Peter Zijlstra, (Mon Apr 7, 4:47 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, FUJITA Tomonori, (Sun Apr 6, 10:48 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Mon Apr 7, 2:07 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, FUJITA Tomonori, (Tue Apr 8, 10:04 am)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, James Bottomley, (Sun Apr 6, 7:35 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Sun Apr 6, 9:01 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Mon Apr 7, 1:51 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, James Bottomley, (Mon Apr 7, 2:04 pm)
Re: [PATCH] scsi: fix sense_slab/bio swapping livelock, Hugh Dickins, (Mon Apr 7, 2:26 pm)
speck-geostationary