Re: [PATCH resend] cpumask: don't perform while loop in cpumask_next_and()

From: Sergey Senozhatsky
Date: Mon Jun 15 2015 - 10:27:56 EST


Hello,

On (06/15/15 15:12), Peter Zijlstra wrote:
> > +++ b/lib/cpumask.c
> > @@ -37,10 +37,11 @@ EXPORT_SYMBOL(__next_cpu_nr);
> > int cpumask_next_and(int n, const struct cpumask *src1p,
> > const struct cpumask *src2p)
> > {
> > + struct cpumask tmp;
> > +
> > + if (cpumask_and(&tmp, src1p, src2p))
> > + return cpumask_next(n, &tmp);
> > + return nr_cpu_ids;
> > }
> > EXPORT_SYMBOL(cpumask_next_and);
>
> Just ran into this; I though we were not supposed to put cpumasks on the
> stack because $BIG. ?!

Gosh, I didn't think $BIG enough. So, on a _big_ 4096 x86_64 it's like...
64 bytes on stack. That's bad. alloc_cpumask_var()/free_cpumask_var()
version just doesn't look like a win (inlined below) so I guess I'll
ask to revert. It makes sense on smaller systems, but loses on huge
ones.

---

lib/cpumask.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/cpumask.c b/lib/cpumask.c
index 5f62708..95ce89a 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -16,11 +16,17 @@
int cpumask_next_and(int n, const struct cpumask *src1p,
const struct cpumask *src2p)
{
- struct cpumask tmp;
+ int ret = nr_cpu_ids;
+ cpumask_var_t tmp;

- if (cpumask_and(&tmp, src1p, src2p))
- return cpumask_next(n, &tmp);
- return nr_cpu_ids;
+ if (!alloc_cpumask_var(&tmp, GFP_KERNEL))
+ return ret;
+
+ if (cpumask_and(tmp, src1p, src2p))
+ ret = cpumask_next(n, tmp);
+
+ free_cpumask_var(tmp);
+ return ret;
}
EXPORT_SYMBOL(cpumask_next_and);

--
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/