Re: [patch 01/28] cpu alloc: The allocator

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Christoph Lameter
Date: Thursday, November 8, 2007 - 11:50 am

On Thu, 8 Nov 2007, Christoph Lameter wrote:


Well I went the other way and made it work like the slab allocators.


cpu_alloc: Make it irq safe

Use the same method as used in SLAB/SLUB to make the allocator interrupt safe.
disable interrupts when allocator metadata is processed. Reenable interrupts
during page allocator calls if __GFP_WAIT is set in the flags passed to the
allocator.

Signed-off-by: Christoph Lameter <clameter@sgi.com>

---
 mm/cpu_alloc.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Index: linux-2.6/mm/cpu_alloc.c
===================================================================
--- linux-2.6.orig/mm/cpu_alloc.c	2007-11-07 16:49:40.069701326 -0800
+++ linux-2.6/mm/cpu_alloc.c	2007-11-08 10:45:43.172294260 -0800
@@ -186,6 +186,8 @@ static int expand_cpu_area(gfp_t flags)
 		goto out;
 
 	spin_unlock(&cpu_alloc_map_lock);
+	if (flags & __GFP_WAIT)
+		local_irq_enable();
 
 	/*
 	 * Determine the size of the bit map needed
@@ -212,6 +214,8 @@ static int expand_cpu_area(gfp_t flags)
 			goto out;
 	}
 
+	if (flags & __GFP_WAIT)
+		local_irq_disable();
 	spin_lock(&cpu_alloc_map_lock);
 
 	/*
@@ -312,10 +316,11 @@ void *cpu_alloc(unsigned long size, gfp_
 	void *ptr;
 	int first;
 	unsigned long map_size;
+	unsigned long flags;
 
 	BUG_ON(gfpflags & ~(GFP_RECLAIM_MASK | __GFP_ZERO));
 
-	spin_lock(&cpu_alloc_map_lock);
+	spin_lock_irqsave(&cpu_alloc_map_lock, flags);
 
 restart:
 	map_size = PAGE_SIZE << cpu_alloc_map_order;
@@ -358,7 +363,7 @@ restart:
 	units_free -= units;
 	__count_vm_events(CPU_BYTES, units * UNIT_SIZE);
 
-	spin_unlock(&cpu_alloc_map_lock);
+	spin_unlock_irqrestore(&cpu_alloc_map_lock, flags);
 
 	ptr = cpu_area + start * UNIT_SIZE;
 
@@ -372,7 +377,7 @@ restart:
 	return ptr;
 
 out_of_memory:
-	spin_unlock(&cpu_alloc_map_lock);
+	spin_unlock_irqrestore(&cpu_alloc_map_lock, flags);
 	return NULL;
 }
 EXPORT_SYMBOL(cpu_alloc);
@@ -386,13 +391,14 @@ void cpu_free(void *start, unsigned long
 	int units = size_to_units(size);
 	int index;
 	u8 *p = start;
+	unsigned long flags;
 
 	BUG_ON(p < cpu_area);
 	index = (p - cpu_area) / UNIT_SIZE;
 	BUG_ON(!test_bit(index, cpu_alloc_map) ||
 			index >= units_total);
 
-	spin_lock(&cpu_alloc_map_lock);
+	spin_lock_irqsave(&cpu_alloc_map_lock, flags);
 
 	clear_map(index, units);
 	units_free += units;
@@ -400,6 +406,6 @@ void cpu_free(void *start, unsigned long
 	if (index < first_free)
 		first_free = index;
 
-	spin_unlock(&cpu_alloc_map_lock);
+	spin_unlock_irqrestore(&cpu_alloc_map_lock, flags);
 }
 EXPORT_SYMBOL(cpu_free);
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 6, 12:51 pm)
Re: [patch 01/28] cpu alloc: The allocator, Peter Zijlstra, (Thu Nov 8, 5:34 am)
Re: [patch 01/28] cpu alloc: The allocator, Peter Zijlstra, (Thu Nov 8, 5:37 am)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 8, 11:33 am)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 8, 11:50 am)
Re: [patch 01/28] cpu alloc: The allocator, Peter Zijlstra, (Thu Nov 8, 1:19 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 4:15 am)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 2:40 pm)
Re: [patch 01/28] cpu alloc: The allocator, Eric Dumazet, (Tue Nov 13, 2:58 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 3:00 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 3:02 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 3:20 pm)
Re: [patch 01/28] cpu alloc: The allocator, Andi Kleen, (Tue Nov 13, 6:06 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 6:30 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 6:33 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 6:36 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 6:37 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 6:48 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 6:50 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 6:52 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 6:57 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 7:00 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 7:01 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 7:03 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 7:05 pm)
Re: [patch 01/28] cpu alloc: The allocator, Andi Kleen, (Tue Nov 13, 7:28 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 8:48 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 8:49 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 9:15 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 9:18 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 9:21 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Tue Nov 13, 9:26 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Tue Nov 13, 10:53 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 15, 11:49 am)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 15, 7:19 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Thu Nov 15, 7:50 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 15, 7:55 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 15, 8:10 pm)
Re: [patch 01/28] cpu alloc: The allocator, David Miller, (Thu Nov 15, 8:17 pm)
Re: [patch 01/28] cpu alloc: The allocator, Christoph Lameter, (Thu Nov 15, 8:19 pm)