From: Eric Sandeen <sandeen@sandeen.net>
To: Dave Chinner <david@fromorbit.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH] Fix reference counting race on log buffers
Date: Fri, 11 Jul 2008 01:28:14 -0500 [thread overview]
Message-ID: <4876FD7E.3080207@sandeen.net> (raw)
In-Reply-To: <1215752481-6862-1-git-send-email-david@fromorbit.com>
Dave Chinner wrote:
> When we release the iclog, we do an atomic_dec_and_lock to determine
> if we are the last reference to enable update of log headers and
> writeout. however, in xlog_state_get_iclog_space() we need to check
> if we have the last reference count there. if we do, we release the
> log buffer, otherwise we decrement the reference count.
>
> The issue is that the compare and decrement in
> xlog_state_get_iclog_space() is not atomic, so both places can see a
> reference count of 2 and neither will release the iclog. That leads
> to a filesystem hang.
>
> Close the hole replacing the compare and decrement with
> atomic_add_unless() to ensure that they are executed atomically.
>
> Signed-off-by: Dave Chinner <david@fromorbit.com>
Tested-by: Eric Sandeen <sandeen@sandeen.net>
Passes the fs_mark testcase I hit this on, 18 million inodes & counting.
Thanks,
-Eric
> ---
> fs/xfs/xfs_log.c | 15 +++++++++++----
> 1 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
> index 760d543..0816c5d 100644
> --- a/fs/xfs/xfs_log.c
> +++ b/fs/xfs/xfs_log.c
> @@ -2425,13 +2425,20 @@ restart:
> if (iclog->ic_size - iclog->ic_offset < 2*sizeof(xlog_op_header_t)) {
> xlog_state_switch_iclogs(log, iclog, iclog->ic_size);
>
> - /* If I'm the only one writing to this iclog, sync it to disk */
> - if (atomic_read(&iclog->ic_refcnt) == 1) {
> + /*
> + * If I'm the only one writing to this iclog, sync it to disk.
> + * We need to do an atomic compare and decrement here to avoid
> + * racing with concurrent atomic_dec_and_lock() calls in
> + * xlog_state_release_iclog() when there is more than one
> + * reference to the iclog.
> + */
> + if (!atomic_add_unless(&iclog->ic_refcnt, -1, 1)) {
> + /* we are the only one */
> spin_unlock(&log->l_icloglock);
> - if ((error = xlog_state_release_iclog(log, iclog)))
> + error = xlog_state_release_iclog(log, iclog);
> + if (error)
> return error;
> } else {
> - atomic_dec(&iclog->ic_refcnt);
> spin_unlock(&log->l_icloglock);
> }
> goto restart;
next prev parent reply other threads:[~2008-07-11 6:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-11 5:01 [PATCH] Fix reference counting race on log buffers Dave Chinner
2008-07-11 5:25 ` Timothy Shimmin
2008-07-11 5:30 ` Timothy Shimmin
2008-07-11 7:19 ` Dave Chinner
2008-07-11 6:28 ` Eric Sandeen [this message]
2008-07-11 6:53 ` Mark Goodwin
[not found] ` <20080814180603.GA3087@infradead.org>
[not found] ` <48A4DB09.7020702@sgi.com>
[not found] ` <20080815012807.GA547@infradead.org>
[not found] ` <48A4F61E.3050106@sgi.com>
2008-08-15 22:07 ` Christoph Hellwig
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=4876FD7E.3080207@sandeen.net \
--to=sandeen@sandeen.net \
--cc=david@fromorbit.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