* [PATCH] percpu_counter: change inaccurate comment
@ 2010-10-07 16:37 Eric Dumazet
2010-10-07 19:42 ` Christoph Lameter
0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2010-10-07 16:37 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
percpu_counter used to be huge objects, they are not anymore,
thanks to fine alloc_percpu() granularity.
We now consume 4 bytes per possible cpu.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
include/linux/percpu_counter.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/linux/percpu_counter.h b/include/linux/percpu_counter.h
index 8a7d510..5e2cb5c 100644
--- a/include/linux/percpu_counter.h
+++ b/include/linux/percpu_counter.h
@@ -3,7 +3,8 @@
/*
* A simple "approximate counter" for use in ext2 and ext3 superblocks.
*
- * WARNING: these things are HUGE. 4 kbytes per counter on 32-way P4.
+ * WARNING: these things are big : 4 bytes per possible cpu per counter.
+ * For a 64 cpus machine: 256 bytes + sizeof(struct percpu_counter)
*/
#include <linux/spinlock.h>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] percpu_counter: change inaccurate comment
2010-10-07 16:37 [PATCH] percpu_counter: change inaccurate comment Eric Dumazet
@ 2010-10-07 19:42 ` Christoph Lameter
2010-10-07 20:04 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Lameter @ 2010-10-07 19:42 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Andrew Morton, linux-kernel
On Thu, 7 Oct 2010, Eric Dumazet wrote:
> percpu_counter used to be huge objects, they are not anymore,
> thanks to fine alloc_percpu() granularity.
>
> We now consume 4 bytes per possible cpu.
Ahh I did not notice that they switched.... Then we may also want the
following patch to improve performance. It would even be better if we
could do a this_cpu_add(fbc->counters, amount) there but the 64 bit size
fo count looks suspiciously like you are expecting overflows beyond ints
max size.
Subject: percpu_counter: Use this_cpu_ptr instead of per_cpu_ptr
this_cpu_ptr avoids an array lookup and can use the percpu
offset of the local cpu directly.
Signed-off-by: Christoph Lameter <cl@linux.com>
---
lib/percpu_counter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: linux-2.6/lib/percpu_counter.c
===================================================================
--- linux-2.6.orig/lib/percpu_counter.c 2010-10-07 14:36:39.000000000 -0500
+++ linux-2.6/lib/percpu_counter.c 2010-10-07 14:38:43.000000000 -0500
@@ -30,9 +30,9 @@ void __percpu_counter_add(struct percpu_
{
s64 count;
s32 *pcount;
- int cpu = get_cpu();
- pcount = per_cpu_ptr(fbc->counters, cpu);
+ preempt_disable();
+ pcount = this_cpu_ptr(fbc->counters);
count = *pcount + amount;
if (count >= batch || count <= -batch) {
spin_lock(&fbc->lock);
@@ -42,7 +42,7 @@ void __percpu_counter_add(struct percpu_
} else {
*pcount = count;
}
- put_cpu();
+ preempt_enable();
}
EXPORT_SYMBOL(__percpu_counter_add);
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] percpu_counter: change inaccurate comment
2010-10-07 19:42 ` Christoph Lameter
@ 2010-10-07 20:04 ` Eric Dumazet
2010-10-07 20:13 ` Christoph Lameter
0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2010-10-07 20:04 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Andrew Morton, linux-kernel
Le jeudi 07 octobre 2010 à 14:42 -0500, Christoph Lameter a écrit :
> On Thu, 7 Oct 2010, Eric Dumazet wrote:
>
> > percpu_counter used to be huge objects, they are not anymore,
> > thanks to fine alloc_percpu() granularity.
> >
> > We now consume 4 bytes per possible cpu.
>
> Ahh I did not notice that they switched.... Then we may also want the
> following patch to improve performance. It would even be better if we
> could do a this_cpu_add(fbc->counters, amount) there but the 64 bit size
> fo count looks suspiciously like you are expecting overflows beyond ints
> max size.
>
Yes, this 64bit interface is very strange.
>
> Subject: percpu_counter: Use this_cpu_ptr instead of per_cpu_ptr
>
> this_cpu_ptr avoids an array lookup and can use the percpu
> offset of the local cpu directly.
>
> Signed-off-by: Christoph Lameter <cl@linux.com>
>
> ---
> lib/percpu_counter.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> Index: linux-2.6/lib/percpu_counter.c
> ===================================================================
> --- linux-2.6.orig/lib/percpu_counter.c 2010-10-07 14:36:39.000000000 -0500
> +++ linux-2.6/lib/percpu_counter.c 2010-10-07 14:38:43.000000000 -0500
> @@ -30,9 +30,9 @@ void __percpu_counter_add(struct percpu_
> {
> s64 count;
> s32 *pcount;
> - int cpu = get_cpu();
>
> - pcount = per_cpu_ptr(fbc->counters, cpu);
> + preempt_disable();
> + pcount = this_cpu_ptr(fbc->counters);
> count = *pcount + amount;
> if (count >= batch || count <= -batch) {
> spin_lock(&fbc->lock);
> @@ -42,7 +42,7 @@ void __percpu_counter_add(struct percpu_
> } else {
> *pcount = count;
> }
> - put_cpu();
> + preempt_enable();
> }
> EXPORT_SYMBOL(__percpu_counter_add);
>
If enclosed by preempt_disable()/preempt_enable(), maybe we could use
__this_cpu_ptr() ?
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] percpu_counter: change inaccurate comment
2010-10-07 20:04 ` Eric Dumazet
@ 2010-10-07 20:13 ` Christoph Lameter
2010-10-07 20:42 ` Eric Dumazet
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Lameter @ 2010-10-07 20:13 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Andrew Morton, linux-kernel
On Thu, 7 Oct 2010, Eric Dumazet wrote:
> If enclosed by preempt_disable()/preempt_enable(), maybe we could use
> __this_cpu_ptr() ?
The only difference between __this_cpu_ptr and this_cpu_ptr is that
this_cpu_ptr checks that preempt was disabled. __this_cpu_ptr allows use
even without preempt. Preempt must be disabled here so the use of
this_cpu_ptr is appropriate.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] percpu_counter: change inaccurate comment
2010-10-07 20:13 ` Christoph Lameter
@ 2010-10-07 20:42 ` Eric Dumazet
2010-10-07 21:06 ` Christoph Lameter
0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2010-10-07 20:42 UTC (permalink / raw)
To: Christoph Lameter; +Cc: Andrew Morton, linux-kernel
Le jeudi 07 octobre 2010 à 15:13 -0500, Christoph Lameter a écrit :
> On Thu, 7 Oct 2010, Eric Dumazet wrote:
>
> > If enclosed by preempt_disable()/preempt_enable(), maybe we could use
> > __this_cpu_ptr() ?
>
> The only difference between __this_cpu_ptr and this_cpu_ptr is that
> this_cpu_ptr checks that preempt was disabled. __this_cpu_ptr allows use
> even without preempt. Preempt must be disabled here so the use of
> this_cpu_ptr is appropriate.
>
>
Thats not how I read the thing.
In both variants, preemption _must_ be disabled, its only the context
that can tell how sure we are...
<quote>
commit 7340a0b15280c
__this_cpu_ptr -> Do not check for preemption context
this_cpu_ptr -> Check preemption context
</quote>
If preemption was enabled, both pointers would not be very useful...
We use __this_cpu_ptr() in contexts where cpu _cannot_ change under us,
(we just disabled preemption one line above), so its not necessary to
perform the check.
vi +316 include/linux/percpu.h
#define _this_cpu_generic_to_op(pcp, val, op) \
do { \
preempt_disable(); \
*__this_cpu_ptr(&(pcp)) op val; \
preempt_enable(); \
} while (0)
...
#define __this_cpu_generic_to_op(pcp, val, op) \
do { \
*__this_cpu_ptr(&(pcp)) op val; \
} while (0)
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] percpu_counter: change inaccurate comment
2010-10-07 20:42 ` Eric Dumazet
@ 2010-10-07 21:06 ` Christoph Lameter
0 siblings, 0 replies; 6+ messages in thread
From: Christoph Lameter @ 2010-10-07 21:06 UTC (permalink / raw)
To: Eric Dumazet; +Cc: Andrew Morton, linux-kernel
On Thu, 7 Oct 2010, Eric Dumazet wrote:
> >
> > The only difference between __this_cpu_ptr and this_cpu_ptr is that
> > this_cpu_ptr checks that preempt was disabled. __this_cpu_ptr allows use
> > even without preempt. Preempt must be disabled here so the use of
> > this_cpu_ptr is appropriate.
> >
> >
>
> Thats not how I read the thing.
>
> In both variants, preemption _must_ be disabled, its only the context
> that can tell how sure we are...
Correct. One checks the other one does not check.
> <quote>
>
> commit 7340a0b15280c
>
> __this_cpu_ptr -> Do not check for preemption context
> this_cpu_ptr -> Check preemption context
>
> </quote>
>
> If preemption was enabled, both pointers would not be very useful...
>
> We use __this_cpu_ptr() in contexts where cpu _cannot_ change under us,
> (we just disabled preemption one line above), so its not necessary to
> perform the check.
Someone could screw up the code in the future. Thats what its there for.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-10-07 21:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-07 16:37 [PATCH] percpu_counter: change inaccurate comment Eric Dumazet
2010-10-07 19:42 ` Christoph Lameter
2010-10-07 20:04 ` Eric Dumazet
2010-10-07 20:13 ` Christoph Lameter
2010-10-07 20:42 ` Eric Dumazet
2010-10-07 21:06 ` Christoph Lameter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®