From: Andrew Morton <akpm@zip.com.au>
To: Robert Love <rml@tech9.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] only irq-safe atomic ops
Date: Fri, 22 Feb 2002 22:51:46 -0800 [thread overview]
Message-ID: <3C773C02.93C7753E@zip.com.au> (raw)
In-Reply-To: <1014444810.1003.53.camel@phantasy>
Robert Love wrote:
>
> The following patch implements i386 versions of atomic_inc and
> atomic_dec that are LOCK-less but provide IRQ-atomicity and act as a
> memory-barrier.
>
> An applicable use would be data that needs to be IRQ-safe but not
> SMP-safe (or, more likely, is already SMP-safe for some other reason).
>
> Additionally, these variants could prevent having to use
> preempt_disable/enable or "full" atomic ops around per-CPU data with a
> preemptible kernel.
>
Thanks, Robert.
Some background here - for the delayed allocation code which I'm
cooking up I need to globally count the number of dirty pages in the
machine. Currently that's done with atomic_inc(&nr_dirty_pages)
in SetPageDirty().
But this counter (which is used for when-to-start-writeback decisions)
is unavoidably approximate. It would be nice to make it a per-CPU
array. So on the rare occasions when the dirty-page count is needed,
I can just whizz across the per-cpu counters adding them all up.
But how to increment or decrement a per-cpu counter? The options
are:
- per_cpu_integer++;
This is *probably* OK on all architectures. But there are no
guarantees that the compiler won't play games, and that this
operation is preempt-safe.
- preempt_disable(); per_cpu_counter++; preempt_enable();
A bit heavyweight for add-one-to-i.
- atomic_inc
A buslocked operation where it is not needed - we only need
a preempt-locked operation here. But it's per-cpu data, and
the buslocked rmw won't be too costly.
I can't believe how piddling this issue is :)
But if there's a general need for such a micro-optimisation
then we need to:
1: Create <linux/atomic.h> (for heavens sake!)
2: In <linux/atomic.h>,
#ifndef ARCH_HAS_ATOMIC_INQ_THINGIES
#define atomic_inc_irq atomic_inc
...
#endif
But for now, I suggest we not bother. I'll just use atomic_inc().
-
next prev parent reply other threads:[~2002-02-23 6:53 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-23 6:13 [PATCH] only irq-safe atomic ops Robert Love
2002-02-23 6:51 ` Andrew Morton [this message]
2002-02-23 7:29 ` Robert Love
2002-02-23 7:54 ` Andrew Morton
2002-02-23 11:38 ` yodaiken
2002-02-23 18:20 ` Robert Love
2002-02-23 19:06 ` yodaiken
2002-02-23 21:57 ` Roman Zippel
2002-02-23 22:10 ` Andrew Morton
2002-02-23 22:23 ` yodaiken
2002-02-23 22:40 ` Andrew Morton
2002-02-23 22:48 ` yodaiken
2002-02-23 23:13 ` Robert Love
2002-02-23 23:45 ` Robert Love
2002-02-23 23:56 ` Andrew Morton
2002-02-24 1:05 ` yodaiken
2002-02-24 1:08 ` Robert Love
2002-02-23 22:00 ` John Levon
2002-02-23 22:43 ` yodaiken
2002-02-23 20:01 ` Stephen Lord
2002-02-23 20:27 ` Andrew Morton
2002-02-23 9:38 ` Russell King
[not found] <1014444810.1003.53.camel@phantasy.suse.lists.linux.kernel>
[not found] ` <3C773C02.93C7753E@zip.com.au.suse.lists.linux.kernel>
[not found] ` <1014449389.1003.149.camel@phantasy.suse.lists.linux.kernel>
[not found] ` <3C774AC8.5E0848A2@zip.com.au.suse.lists.linux.kernel>
[not found] ` <3C77F503.1060005@sgi.com.suse.lists.linux.kernel>
[not found] ` <3C77FB35.16844FE7@zip.com.au.suse.lists.linux.kernel>
2002-02-23 20:56 ` Andi Kleen
2002-02-23 21:06 ` Andrew Morton
2002-02-23 21:17 ` Stephen Lord
2002-02-23 21:42 ` Andrew Morton
2002-02-23 22:10 ` Stephen Lord
2002-02-23 22:34 ` Andrew Morton
2002-02-23 23:07 ` Mike Fedyk
2002-02-23 23:47 ` Andrew Morton
2002-02-25 13:02 ` Stephen Lord
2002-02-25 13:12 ` Jens Axboe
2002-02-25 13:18 ` Stephen Lord
2002-02-25 19:42 ` Andrew Morton
2002-02-25 19:45 ` Steve Lord
2002-02-25 20:05 ` Andrew Morton
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=3C773C02.93C7753E@zip.com.au \
--to=akpm@zip.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=rml@tech9.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.