From: Eric Dumazet <dada1@cosmosbay.com>
To: Ravikiran G Thirumalai <kiran@scalex86.org>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>
Subject: Re: [patch] Avoid use of spinlock for percpu_counter
Date: Thu, 26 Jan 2006 15:17:35 +0100 [thread overview]
Message-ID: <43D8D9FF.1050409@cosmosbay.com> (raw)
In-Reply-To: <20060125231654.GB3658@localhost.localdomain>
Ravikiran G Thirumalai a écrit :
> The spinlock in struct percpu_counter protects just one counter. It's
> not obvious why it was done this way (I am guessing it was because earlier,
> atomic_t was guaranteed 24 bits only on some arches). Since we have
> atomic_long_t now, I don't see why this cannot be replaced with an atomic_t.
>
> Comments?
Yes this makes sense.
Furthermore, we could try to fix 'struct percpu_counter' management (if SMP)
if alloc_percpu(long) call done in percpu_counter_init() fails. This is
currently ignored and can crash.
Something like (hybrid patch, to get the idea) :
--- a/mm/swap.c 2006-01-26 15:58:42.000000000 +0100
+++ b/mm/swap.c 2006-01-26 16:00:54.000000000 +0100
@@ -472,9 +472,12 @@
{
long count;
long *pcount;
- int cpu = get_cpu();
- pcount = per_cpu_ptr(fbc->counters, cpu);
+ if (unlikely(fbc->counters == NULL)) {
+ atomic_long_add(amount, &fbc->count);
+ return;
+ }
+ pcount = per_cpu_ptr(fbc->counters, get_cpu());
count = *pcount + amount;
if (count >= FBC_BATCH || count <= -FBC_BATCH) {
atomic_long_add(count, &fbc->count);
--- a/include/linux/percpu_counter.h 2006-01-26 16:02:31.000000000 +0100
+++ b/include/linux/percpu_counter.h 2006-01-26 16:02:53.000000000 +0100
@@ -35,7 +35,8 @@
static inline void percpu_counter_destroy(struct percpu_counter *fbc)
{
- free_percpu(fbc->counters);
+ if (fbc->counters)
+ free_percpu(fbc->counters);
}
void percpu_counter_mod(struct percpu_counter *fbc, long amount);
Eric
next prev parent reply other threads:[~2006-01-26 14:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-25 23:16 [patch] Avoid use of spinlock for percpu_counter Ravikiran G Thirumalai
2006-01-26 14:17 ` Eric Dumazet [this message]
2006-01-26 18:04 ` Ravikiran G Thirumalai
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=43D8D9FF.1050409@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=akpm@osdl.org \
--cc=kiran@scalex86.org \
--cc=linux-kernel@vger.kernel.org \
/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