Skip to contentSkip to conversation

kernel/pid.c: Improve flow of a loop inside alloc_pidmap.

PATCH New Raphael S.Carvalho 1 participant 1 message Mar 8, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/pid.c: Improve flow of a loop inside alloc_pidmap.

Notes: find_next_offset searches for an available "cleaned bit" in the respective pid bitmap (page), so returns the offset if found, otherwise it returns a value equals to BITS_PER_PAGE (invalid offset).

For example, suppose find_next_offset didn't find any available bit, so there's no purpose to call mk_pid (Wasteful Cpu Cycles) since it only computes a new PID based on a *valid* offset of the current map.

Therefore, I found it could be better to call mk_pid after the checking (offset < BITS_PER_PAGE) returned sucessfully!

---
 kernel/pid.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/pid.c +2 -2
index 047dc62..7ecb09a 100644
@@ -190,8 +190,8 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
 					return pid;
 				}
 				offset = find_next_offset(map, offset);
-				pid = mk_pid(pid_ns, map, offset);
-			} while (offset < BITS_PER_PAGE && pid < pid_max);
+			} while (offset < BITS_PER_PAGE &&
+				(pid = mk_pid(pid_ns, map, offset)) < pid_max);
 		}
 		if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
 			++map;
Signature · 1 line
1.7.2.5