From: Dave Chinner <david@fromorbit.com>
To: Alex Elder <aelder@sgi.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 5/5] percpu_counter: only disable preemption if needed in add_unless_lt()
Date: Thu, 23 Dec 2010 17:31:38 +1100 [thread overview]
Message-ID: <20101223063138.GF18264@dastard> (raw)
In-Reply-To: <1293076602.2408.434.camel@doink>
On Wed, Dec 22, 2010 at 09:56:42PM -0600, Alex Elder wrote:
> In __percpu_counter_add_unless_lt() we don't need to disable
> preemption unless we're manipulating a per-cpu variable. That only
> happens in a limited case, so narrow the scope of that preemption to
> surround that case. This makes the "out" label rather unnecessary,
> so replace a couple "goto out" calls to just return.
>
> Signed-off-by: Alex Elder <aelder@sgi.com>
>
> ---
> lib/percpu_counter.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> Index: b/lib/percpu_counter.c
> ===================================================================
> --- a/lib/percpu_counter.c
> +++ b/lib/percpu_counter.c
> @@ -232,8 +232,6 @@ int __percpu_counter_add_unless_lt(struc
> int cpu;
> int ret = -1;
>
> - preempt_disable();
> -
> /*
> * Check to see if rough count will be sufficient for
> * comparison. First, if the upper bound is too low,
> @@ -241,7 +239,7 @@ int __percpu_counter_add_unless_lt(struc
> */
> count = percpu_counter_read(fbc);
> if (count + error + amount < threshold)
> - goto out;
> + return -1;
>
> /*
> * Next, if the lower bound is above the threshold, we can
> @@ -251,12 +249,15 @@ int __percpu_counter_add_unless_lt(struc
> if (count - error + amount > threshold) {
> s32 *pcount = this_cpu_ptr(fbc->counters);
>
> + preempt_disable();
> + pcount = this_cpu_ptr(fbc->counters);
> count = *pcount + amount;
> if (abs(count) < batch) {
> *pcount = count;
> - ret = 1;
> - goto out;
> + preempt_enable();
> + return 1;
> }
> + preempt_enable();
> }
Regardless of the other changes, this is not valid. That is:
amount = -1;
count = fbc->count;
.....
<get preempted>
<other operations may significantly change fbc->count (i.e
lots more than error will catch), so the current value of
count in this context is wrong and cannot be trusted>
<start running again>
if (count - error + amount > threshold) {
<not valid to run this lockless optimisation based
on a stale count value>
....
}
Effectively, if we want to be able to use lockless optimisations, we
need to ensure that the value of the global counter that we read
remains within the given error bounds until we have finished making
the lockless modification. That is done via disabling preemption
across the entire function...
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2010-12-23 6:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-23 3:56 [PATCH 5/5] percpu_counter: only disable preemption if needed in add_unless_lt() Alex Elder
2010-12-23 6:31 ` Dave Chinner [this message]
2010-12-29 16:29 ` Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101223063138.GF18264@dastard \
--to=david@fromorbit.com \
--cc=aelder@sgi.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox