From: Alex Elder <aelder@sgi.com>
To: XFS Mailing List <xfs@oss.sgi.com>
Subject: [PATCH 1/5] percpu_counter: fix test in __percpu_counter_add_unless_lt()
Date: Wed, 22 Dec 2010 21:56:15 -0600 [thread overview]
Message-ID: <1293076575.2408.425.camel@doink> (raw)
In __percpu_counter_add_unless_lt(), there is a test to see if
a call to __percpu_counter_add() can be made, knowing the result
will not be less than the given threshhold and the called function
will do the addition without taking a lock.
Unfortunately, it is using the wrong value in its comparison--the
amount to add is not properly being taken into account. As a
result, __percpu_counter_add() could end up adding a value when it
should not. And even if the result will be non-negative, the called
function may take the lock anyway because it does so if the *sum* of
the (percpu) delta count and the given amount (and not just the amount
alone) is greater than the batch size (or less than its negative).
Fix the comparison, and since it __percpu_counter_add() will do
the right thing (and might lock anyway), just call it regardless
of what amount is getting added.
Signed-off-by: Alex Elder <aelder@sgi.com>
---
lib/percpu_counter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: b/lib/percpu_counter.c
===================================================================
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -239,10 +239,10 @@ int __percpu_counter_add_unless_lt(struc
goto out;
/*
- * If the counter is over the threshold and the change is less than the
- * batch size, we might be able to avoid locking.
+ * If the updated counter will be over the threshold we know
+ * we can safely add, and might be able to avoid locking.
*/
- if (count > threshold + error && abs(amount) < batch) {
+ if (count + amount > threshold + error) {
__percpu_counter_add(fbc, amount, batch);
ret = 1;
goto out;
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next reply other threads:[~2010-12-23 3:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-23 3:56 Alex Elder [this message]
2010-12-23 6:06 ` [PATCH 1/5] percpu_counter: fix test in __percpu_counter_add_unless_lt() Dave Chinner
2010-12-29 20:56 ` Alex Elder
2010-12-29 21:49 ` Alex Elder
2010-12-30 22:35 ` Dave Chinner
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=1293076575.2408.425.camel@doink \
--to=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