Skip to contentSkip to conversation

percpu: simplify the pcpu_alloc()

PATCH In review Huang Shijie 2 participants 2 messages Aug 10, 2010

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

PATCH 1/1 percpu: simplify the pcpu_alloc()

The while' is not needed, replaced it with if' to reduce an unnecessary check.

---
 mm/percpu.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
mm/percpu.c +2 -1
index e61dc2c..2e50004 100644
@@ -724,7 +724,8 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved)
 			goto fail_unlock;
 		}
 
-		while ((new_alloc = pcpu_need_to_extend(chunk))) {
+		new_alloc = pcpu_need_to_extend(chunk);
+		if (new_alloc) {
 			spin_unlock_irqrestore(&pcpu_lock, flags);
 			if (pcpu_extend_area_map(chunk, new_alloc) < 0) {
 				err = "failed to extend area map of reserved chunk";
Signature · 7 lines
1.6.6.1

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw
Quoted 13 lines · Huang Shijie

The while' is not needed, replaced it with if' to reduce an unnecessary check.

---
 mm/percpu.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
mm/percpu.c +0 -0
index e61dc2c..2e50004 100644

mm/percpu.c static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved) · line 731

Quoted 9 lines
mm/percpu.c +2 -1
@@ -724,7 +724,8 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved)
 			goto fail_unlock;
 		}
 
-		while ((new_alloc = pcpu_need_to_extend(chunk))) {
+		new_alloc = pcpu_need_to_extend(chunk);
+		if (new_alloc) {
 			spin_unlock_irqrestore(&pcpu_lock, flags);
 			if (pcpu_extend_area_map(chunk, new_alloc) < 0) {
 				err = "failed to extend area map of reserved chunk";

I'd leave it as is. The check may be spurious now but if we ever end up updating locking there to allow allocations from atomic contexts, that while loop will be needed to check whether race hasn't happened while the lock was dropped. This change would just make the code more fragile without actually gaining anything.

Thanks.

Signature · 7 lines
tejun

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>