Skip to contentSkip to conversation

vm patch for highmem

PATCH Arjan van de Ven 1 participant 1 message Aug 28, 2001

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

Hi

The patch below changes the highmem bouncebuffers to increase performance. Initial reports are that it matters A LOT.

What it does: it 1) increases the emergemcy pool and 2) it tries to grab a page from the pool for EVERY bounce first, until the pool is half empty, and only THEN does it try to get a page from the VM.
While this penalizes the low zone by making it have less pages, it also leaves the VM totally alone for normal loads; only under more extreme loads does the vm get involved.

Comments?

Greetings,
Arjan van de Ven

mm/highmem.c renamed from mm/highmem.c.org +38 -5
@@ -159,7 +159,11 @@
 	spin_unlock(&kmap_lock);
 }
 
-#define POOL_SIZE 32
+#ifdef CONFIG_HIGHMEM64G
+#define POOL_SIZE 256
+#else
+#define POOL_SIZE 64
+#endif
 
 /*
  * This lock gets no contention at all, normally.
@@ -306,10 +310,24 @@
 struct page *alloc_bounce_page (void)
 {
 	struct list_head *tmp;
-	struct page *page;
+	struct page *page = NULL;
+	int estimated_left;
+	int iteration=0;
 
 repeat_alloc:
-	page = alloc_page(GFP_NOIO);
+
+	spin_lock_irq(&emergency_lock);
+	estimated_left = nr_emergency_pages;
+	spin_unlock_irq(&emergency_lock);
+
+	/* If there are plenty of spare pages, use some of them first. If the
+	   pool is at least half depleted, use the VM to allocate memory.
+	   This allows moderate loads to continue without blocking here,
+	   while higher loads get throttled by the VM.
+        */
+	if ((estimated_left<=POOL_SIZE/2)&&(!iteration))
+		page = alloc_page(GFP_NOIO);
+	
 	if (page)
 		return page;
 	/*
@@ -338,16 +356,30 @@
 	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
 	schedule();
+	iteration++;
 	goto repeat_alloc;
 }
 
 struct buffer_head *alloc_bounce_bh (void)
 {
 	struct list_head *tmp;
-	struct buffer_head *bh;
+	struct buffer_head *bh = NULL;
+	int estimated_left;
+	int iteration=0;
 
 repeat_alloc:
-	bh = kmem_cache_alloc(bh_cachep, SLAB_NOIO);
+
+	spin_lock_irq(&emergency_lock);
+	estimated_left = nr_emergency_bhs;
+	spin_unlock_irq(&emergency_lock);
+
+	/* If there are plenty of spare bh's, use some of them first. If the
+	   pool is at least half depleted, use the VM to allocate memory.
+	   This allows moderate loads to continue without blocking here,
+	   while higher loads get throttled by the VM.
+        */
+	if ((estimated_left<=POOL_SIZE/2)&&(!iteration))
+		bh = kmem_cache_alloc(bh_cachep, SLAB_NOIO);
 	if (bh)
 		return bh;
 	/*
@@ -376,6 +408,7 @@
 	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
 	schedule();
+	iteration++;
 	goto repeat_alloc;
 }
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/