[ltt-dev] [PATCH] Fix dirty page accounting in redirty_page_for_writepage()

Ingo Molnar mingo at elte.hu
Thu Apr 30 10:10:50 EDT 2009


* Christoph Lameter <cl at linux.com> wrote:

> On Thu, 30 Apr 2009, Ingo Molnar wrote:
> 
> > > I see however that it's only guaranteed to be atomic wrt preemption.
> >
> > That's really only true for the non-x86 fallback defines. If we so
> > decide, we could make the fallbacks in asm-generic/percpu.h irq-safe
> 
> The fallbacks have different semantics and therefore we cannot 
> rely on irq safeness in the core code when using the x86 cpu ops.

Well it's irq and preempt safe on x86.

It's preempt-safe on other architectures - but the fallback is not 
irq-safe on other architectures. That is remedied easily via the 
patch below. (Note: totally untested)

	Ingo

diff --git a/include/linux/percpu.h b/include/linux/percpu.h
index 1581ff2..6b3984a 100644
--- a/include/linux/percpu.h
+++ b/include/linux/percpu.h
@@ -139,17 +139,23 @@ static inline void free_percpu(void *p)
 #ifndef percpu_read
 # define percpu_read(var)						\
   ({									\
+	unsigned long flags;						\
 	typeof(per_cpu_var(var)) __tmp_var__;				\
-	__tmp_var__ = get_cpu_var(var);					\
-	put_cpu_var(var);						\
+									\
+	local_irq_save(flags);						\
+	__tmp_var__ = __get_cpu_var(var);				\
+	local_irq_restore(flags);					\
 	__tmp_var__;							\
   })
 #endif
 
 #define __percpu_generic_to_op(var, val, op)				\
 do {									\
-	get_cpu_var(var) op val;					\
-	put_cpu_var(var);						\
+	unsigned long flags;						\
+									\
+	local_irq_save(flags);						\
+	op val;								\
+	local_irq_restore(flags);					\
 } while (0)
 
 #ifndef percpu_write




More information about the lttng-dev mailing list