[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140513110951.GB30445@twins.programming.kicks-ass.net>
Date: Tue, 13 May 2014 13:09:51 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Mel Gorman <mgorman@...e.de>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Johannes Weiner <hannes@...xchg.org>,
Vlastimil Babka <vbabka@...e.cz>, Jan Kara <jack@...e.cz>,
Michal Hocko <mhocko@...e.cz>, Hugh Dickins <hughd@...gle.com>,
Dave Hansen <dave.hansen@...el.com>,
Linux Kernel <linux-kernel@...r.kernel.org>,
Linux-MM <linux-mm@...ck.org>,
Linux-FSDevel <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH 17/19] fs: buffer: Do not use unnecessary atomic
operations when discarding buffers
On Tue, May 13, 2014 at 10:45:48AM +0100, Mel Gorman wrote:
> Discarding buffers uses a bunch of atomic operations when discarding buffers
> because ...... I can't think of a reason. Use a cmpxchg loop to clear all the
> necessary flags. In most (all?) cases this will be a single atomic operations.
>
> Signed-off-by: Mel Gorman <mgorman@...e.de>
> ---
> fs/buffer.c | 14 +++++++++-----
> include/linux/buffer_head.h | 5 +++++
> 2 files changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/fs/buffer.c b/fs/buffer.c
> index 9ddb9fc..e80012d 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -1485,14 +1485,18 @@ EXPORT_SYMBOL(set_bh_page);
> */
> static void discard_buffer(struct buffer_head * bh)
> {
> + unsigned long b_state, b_state_old;
> +
> lock_buffer(bh);
> clear_buffer_dirty(bh);
> bh->b_bdev = NULL;
> - clear_buffer_mapped(bh);
> - clear_buffer_req(bh);
> - clear_buffer_new(bh);
> - clear_buffer_delay(bh);
> - clear_buffer_unwritten(bh);
> + b_state = bh->b_state;
> + for (;;) {
> + b_state_old = cmpxchg(&bh->b_state, b_state, (b_state & ~BUFFER_FLAGS_DISCARD));
> + if (b_state_old == b_state)
> + break;
> + b_state = b_state_old;
> + }
> unlock_buffer(bh);
> }
So.. I'm soon going to introduce atomic_{or,and}() and
atomic64_{or,and}() across the board, but of course this isn't an
atomic_long_t but a regular unsigned long.
Its a bit unfortunate we have this discrepancy with types vs atomic ops,
there's:
cmpxchg, xchg -- mostly available for all 1,2,3,4 (and 8 where
appropriate) byte values.
bitops -- operate on unsigned long *
atomic* -- operate on atomic_*t
So while ideally we'd be able to use the unconditional atomic and
operation which is available on a lot of architectures, we'll be stuck
with a cmpxchg loop instead :/
*sigh*
Anyway, nothing wrong with this patch, however, you could, if you really
wanted to push things, also include BH_Lock in that clear :-)
Content of type "application/pgp-signature" skipped
Powered by blists - more mailing lists