[PATCH] percpu: explain quick paths in pcpu_[de]populate_chunk()

From: Tejun Heo
Date: Mon Nov 30 2009 - 19:01:58 EST


pcpu_[de]populate_chunk() check whether there's actually any work to
do at the beginning and exit early if not. This checking is done by
seeing whether the first iteration of pcpu_for_each_[un]pop_region()
covers the whole requested region. The resulting code is a bit
unusual in that it's loop-like but never loops which apparently
confuses people. Add comments to explain it.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
Reported-by: Amerigo Wang <amwang@xxxxxxxxxx>
Cc: Christoph Lameter <cl@xxxxxxxxxxxxxxxxxxxx>
---
Added to percpu#for-next. This should be clear enough, right?

mm/percpu.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/mm/percpu.c b/mm/percpu.c
index 442010c..c264315 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -912,10 +912,15 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size)
unsigned long *populated;
int rs, re;

- /* quick path, check whether it's empty already */
+ /*
+ * Quick path, check whether it's already empty. If the
+ * region is completely empty, the first iteration will cover
+ * the whole region.
+ */
pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
if (rs == page_start && re == page_end)
return;
+ /* it didn't cover the whole thing, break to slow path */
break;
}

@@ -967,10 +972,15 @@ static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
unsigned int cpu;
int rs, re, rc;

- /* quick path, check whether all pages are already there */
+ /*
+ * Quick path, check whether all pages are already there. If
+ * the region is fully populated, the first iteration will
+ * cover the whole region.
+ */
pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end) {
if (rs == page_start && re == page_end)
goto clear;
+ /* it didn't cover the whole thing, break to slow path */
break;
}

--
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/