[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.1.10.0911051013080.25718@V090114053VZO-1>
Date: Thu, 5 Nov 2009 10:15:36 -0500 (EST)
From: Christoph Lameter <cl@...ux-foundation.org>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...fujitsu.com>
cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"hugh.dickins@...cali.co.uk" <hugh.dickins@...cali.co.uk>,
akpm@...ux-foundation.org,
"kosaki.motohiro@...fujitsu.com" <kosaki.motohiro@...fujitsu.com>
Subject: Re: [RFC][PATCH] lib: generic percpu counter array
On Thu, 5 Nov 2009, KAMEZAWA Hiroyuki wrote:
> +static inline void
> +counter_array_add(struct counter_array *ca, int idx, int val)
> +{
> + ca->counters[idx] += val;
> +}
This is not a per cpu operation and therefore expensive. The new percpu
this_cpu_inc f.e. generates a single x86 instruction for an increment.
> +void __counter_array_add(struct counter_array *ca, int idx, int val, int batch)
> +{
> + long count, *pcount;
> +
> + preempt_disable();
> +
> + pcount = this_cpu_ptr(ca->v.array);
> + count = pcount[idx] + val;
> + if (!ca->v.nosync && ((count > batch) || (count < -batch))) {
> + atomic_long_add(count, &ca->counters[idx]);
> + pcount[idx] = 0;
> + } else
> + pcount[idx] = count;
> + preempt_enable();
> +}
Too expensive to use in critical VM paths. The percpu operations generate
a single instruction instead of the code above. No need for preempt etc.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists