percpu-refcount: one bit is enough for REF_STATUS
authorTejun Heo <tj@kernel.org>
Sat, 28 Jun 2014 12:10:12 +0000 (08:10 -0400)
committerTejun Heo <tj@kernel.org>
Sat, 28 Jun 2014 12:10:12 +0000 (08:10 -0400)
percpu-refcount currently reserves two lowest bits of its percpu
pointer to indicate its state; however, only one bit is used for
PCPU_REF_DEAD.

Simplify it by removing PCPU_STATUS_BITS/MASK and testing
PCPU_REF_DEAD directly.  This also allows the compiler to choose a
more efficient instruction depending on the architecture.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Kent Overstreet <kmo@daterainc.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
include/linux/percpu-refcount.h
lib/percpu-refcount.c

index 5d8920e23073d8caff4ebe834eaab219e53dba0f..bfdeb0d48e210571aec7748a4cd2e1d824879a7f 100644 (file)
@@ -88,12 +88,10 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)
        return percpu_ref_kill_and_confirm(ref, NULL);
 }
 
-#define PCPU_STATUS_BITS       2
-#define PCPU_STATUS_MASK       ((1 << PCPU_STATUS_BITS) - 1)
 #define PCPU_REF_PTR           0
 #define PCPU_REF_DEAD          1
 
-#define REF_STATUS(count)      (((unsigned long) count) & PCPU_STATUS_MASK)
+#define REF_STATUS(count)      (((unsigned long) count) & PCPU_REF_DEAD)
 
 /**
  * percpu_ref_get - increment a percpu refcount
index 963b7034a51b6e43d058ca3b940b2d8cf491ec9f..17bce2bccc14766e7e736068a2a18bd8f413c4d0 100644 (file)
@@ -96,7 +96,7 @@ static void percpu_ref_kill_rcu(struct rcu_head *rcu)
 
        /* Mask out PCPU_REF_DEAD */
        pcpu_count = (unsigned __percpu *)
-               (((unsigned long) pcpu_count) & ~PCPU_STATUS_MASK);
+               (((unsigned long) pcpu_count) & ~PCPU_REF_DEAD);
 
        for_each_possible_cpu(cpu)
                count += *per_cpu_ptr(pcpu_count, cpu);