One use for reference-count biases...
One use for reference-count biases...
Posted Jun 9, 2009 5:39 UTC (Tue) by neilbrown (subscriber, #359)In reply to: One use for reference-count biases... by PaulMcKenney
Parent article: Linux kernel design patterns - part 1
Yes, I wouldn't be surprised if reference counts that are spread across multiple per-cpu variables would have very different trade-offs and hence different Patterns to the more traditional kinds!
I'm having trouble picturing exactly how the counters you describe would work (and particularly exactly what happens when the per-cpu counter hits zero) but it seems possible that the "one bit of information" that I claim a bias stores would, in this case, be the bit "Someone cares about a precise total value" and that one bit could conceivably be stored in a read-mostly cache line that could be easily shared among multiple processors.
So the code might look like:
if (dec_and_test(per_cpu_counter)) if (__test_bit(flag_name, &flag_variable)) do some costly cross-cpu thing;
Is there any chance that would achieve the same result?
It may well be a case where you don't want to pay the price of an extra bit though.
Posted Jun 9, 2009 13:50 UTC (Tue)
by PaulMcKenney (✭ supporter ✭, #9624)
[Link] (1 responses)
But it has been a good ten years since I messed with this, so I should take another look at it.
In any case, I very much agree with your overall premise that higher-level primitives are a very great improvement over continually re-inventing the wheel, most especially for those wheels with a strong history of being re-invented badly!!!
Posted Dec 23, 2011 5:30 UTC (Fri)
by atiqure (guest, #81951)
[Link]
Hmmmm... I was thinking more in terms of something like the following:One use for reference-count biases...
preempt_disable();
if (per_cpu_counter > 0)
per_cpu_counter++;
else
do some costly global-lock-and-variable thing
preempt_enable();
One use for reference-count biases...