From: David Teigland <teigland@redhat.com>
To: Arjan van de Ven <arjan@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, akpm@osdl.org,
linux-cluster@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: GFS, what's remaining
Date: Thu, 8 Sep 2005 13:41:28 +0800 [thread overview]
Message-ID: <20050908054128.GD12220@redhat.com> (raw)
In-Reply-To: <1125574523.5025.10.camel@laptopd505.fenrus.org>
On Thu, Sep 01, 2005 at 01:35:23PM +0200, Arjan van de Ven wrote:
> +static inline void glock_put(struct gfs2_glock *gl)
> +{
> + if (atomic_read(&gl->gl_count) == 1)
> + gfs2_glock_schedule_for_reclaim(gl);
> + gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_count) > 0,);
> + atomic_dec(&gl->gl_count);
> +}
>
> this code has a race
The first two lines of the function with the race are non-essential and
could be removed. In the common case where there's no race, they just add
efficiency by moving the glock to the reclaim list immediately.
Otherwise, the scand thread would do it later when actively trying to
reclaim glocks.
> +static inline int queue_empty(struct gfs2_glock *gl, struct list_head *head)
> +{
> + int empty;
> + spin_lock(&gl->gl_spin);
> + empty = list_empty(head);
> + spin_unlock(&gl->gl_spin);
> + return empty;
> +}
>
> that looks like a racey interface to me... if so.. why bother locking at
> all?
The spinlock protects the list but is not the primary method of
synchronizing processes that are working with a glock.
When the list is in fact empty, there will be no race, and the locking
wouldn't be necessary. In this case, the "glmutex" in the code fragment
below is preventing any change in the list, so we can safely release the
spinlock immediately.
When the list is not empty, then a process could be adding another entry
to the list without "glmutex" locked [1], making the spinlock necessary.
In this case we quit after queue_empty() returns and don't do anything
else, so releasing the spinlock immediately was still safe.
[1] A process that already holds a glock (i.e. has a "holder" struct on
the gl_holders list) is allowed to hold it again by adding another holder
struct to the same list. It adds the second hold without locking glmutex.
if (gfs2_glmutex_trylock(gl)) {
if (gl->gl_ops == &gfs2_inode_glops) {
struct gfs2_inode *ip = get_gl2ip(gl);
if (ip && !atomic_read(&ip->i_count))
gfs2_inode_destroy(ip);
}
if (queue_empty(gl, &gl->gl_holders) &&
gl->gl_state != LM_ST_UNLOCKED)
handle_callback(gl, LM_ST_UNLOCKED);
gfs2_glmutex_unlock(gl);
}
There is a second way that queue_empty() is used, and that's within
assertions that the list is empty. If the assertion is correct, locking
isn't necessary; locking is only needed if there's already another bug
causing the list to not be empty and the assertion to fail.
> static int gi_skeleton(struct gfs2_inode *ip, struct gfs2_ioctl *gi,
> + gi_filler_t filler)
> +{
> + unsigned int size = gfs2_tune_get(ip->i_sbd, gt_lockdump_size);
> + char *buf;
> + unsigned int count = 0;
> + int error;
> +
> + if (size > gi->gi_size)
> + size = gi->gi_size;
> +
> + buf = kmalloc(size, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + error = filler(ip, gi, buf, size, &count);
> + if (error)
> + goto out;
> +
> + if (copy_to_user(gi->gi_data, buf, count + 1))
> + error = -EFAULT;
>
> where does count get a sensible value?
from filler()
We'll add comments in the code to document the things above.
Thanks,
Dave
next prev parent reply other threads:[~2005-09-08 5:41 UTC|newest]
Thread overview: 105+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-01 10:46 GFS, what's remaining David Teigland
2005-09-01 10:42 ` Arjan van de Ven
2005-09-01 10:59 ` Andrew Morton
2005-09-01 14:49 ` Alan Cox
2005-09-01 14:27 ` Christoph Hellwig
2005-09-01 15:28 ` Alan Cox
2005-09-01 15:11 ` Lars Marowsky-Bree
2005-09-01 17:56 ` Christoph Hellwig
2005-09-02 7:04 ` David Teigland
2005-09-01 17:23 ` Daniel Phillips
2005-09-01 20:21 ` Andrew Morton
2005-09-02 21:17 ` Andi Kleen
2005-09-02 23:03 ` Bryan Henderson
2005-09-03 0:16 ` Mark Fasheh
2005-09-03 6:42 ` Daniel Phillips
2005-09-03 6:46 ` Wim Coekaerts
2005-09-03 22:21 ` Daniel Phillips
2005-09-04 1:09 ` [Linux-cluster] " Joel Becker
2005-09-04 1:32 ` Andrew Morton
2005-09-04 3:06 ` Joel Becker
2005-09-04 4:22 ` [Linux-cluster] " Daniel Phillips
2005-09-04 4:30 ` Joel Becker
2005-09-04 4:51 ` Daniel Phillips
2005-09-04 5:00 ` Joel Becker
2005-09-04 5:52 ` [Linux-cluster] " Daniel Phillips
2005-09-04 5:56 ` Joel Becker
2005-09-04 4:46 ` Andrew Morton
2005-09-04 4:58 ` Joel Becker
2005-09-04 5:41 ` Andrew Morton
2005-09-04 5:49 ` Joel Becker
2005-09-05 4:30 ` David Teigland
2005-09-05 8:54 ` [Linux-cluster] " Andrew Morton
2005-09-05 9:24 ` David Teigland
2005-09-05 9:19 ` [Linux-cluster] " Andrew Morton
2005-09-05 9:30 ` Daniel Phillips
2005-09-05 9:48 ` David Teigland
2005-09-05 12:21 ` Alan Cox
2005-09-05 19:53 ` [Linux-cluster] " Andrew Morton
2005-09-05 23:20 ` Alan Cox
2005-09-05 23:06 ` Andrew Morton
2005-09-14 9:01 ` [Linux-cluster] " Patrick Caulfield
2005-09-05 19:11 ` kurt.hackel
2005-09-04 6:10 ` Mark Fasheh
2005-09-04 7:23 ` Andrew Morton
2005-09-04 8:17 ` Mark Fasheh
2005-09-04 8:37 ` Andrew Morton
2005-09-04 6:40 ` [Linux-cluster] " Daniel Phillips
2005-09-04 7:28 ` Andrew Morton
2005-09-04 8:01 ` [Linux-cluster] " Joel Becker
2005-09-04 8:18 ` Andrew Morton
2005-09-04 9:11 ` Joel Becker
2005-09-04 9:18 ` [Linux-cluster] " Andrew Morton
2005-09-04 9:39 ` Joel Becker
2005-09-04 18:03 ` [Linux-cluster] " Hua Zhong
2005-09-04 19:51 ` Daniel Phillips
2005-09-04 7:12 ` Hua Zhong
2005-09-04 8:37 ` Alan Cox
2005-09-05 23:32 ` Joel Becker
2005-09-03 5:57 ` Daniel Phillips
2005-09-05 14:14 ` Lars Marowsky-Bree
2005-09-05 15:49 ` Daniel Phillips
2005-09-05 16:18 ` Dmitry Torokhov
2005-09-06 0:57 ` Daniel Phillips
2005-09-06 2:03 ` Dmitry Torokhov
2005-09-06 4:02 ` Daniel Phillips
2005-09-06 4:07 ` GFS, what's remainingh Dmitry Torokhov
2005-09-06 4:58 ` Daniel Phillips
2005-09-06 5:05 ` Dmitry Torokhov
2005-09-06 6:48 ` Daniel Phillips
2005-09-06 6:55 ` Dmitry Torokhov
2005-09-06 7:18 ` Daniel Phillips
2005-09-06 14:31 ` Dmitry Torokhov
2005-09-06 13:42 ` Alan Cox
2005-09-03 7:06 ` GFS, what's remaining Wim Coekaerts
2005-09-06 12:55 ` Suparna Bhattacharya
2005-09-03 5:18 ` David Teigland
2005-09-03 6:14 ` Arjan van de Ven
2005-09-03 6:42 ` D. Hazelton
2005-09-03 10:35 ` David Teigland
2005-09-03 20:56 ` Daniel Phillips
2005-09-04 20:33 ` Pavel Machek
2005-09-04 22:18 ` Joel Becker
2005-09-05 5:54 ` Theodore Ts'o
2005-09-05 7:09 ` Mark Fasheh
2005-09-05 14:07 ` Theodore Ts'o
2005-09-05 8:27 ` real read-only [was Re: GFS, what's remaining] Pavel Machek
2005-09-05 14:03 ` Theodore Ts'o
2005-09-05 10:44 ` Re: GFS, what's remaining Stephen C. Tweedie
2005-09-05 16:41 ` Greg Freemyer
2005-09-01 11:35 ` Arjan van de Ven
2005-09-02 9:44 ` David Teigland
2005-09-02 11:46 ` Jörn Engel
2005-09-03 5:28 ` Greg KH
2005-09-05 3:47 ` David Teigland
2005-09-05 8:58 ` Jörn Engel
2005-09-05 9:18 ` David Teigland
2005-09-05 5:43 ` David Teigland
2005-09-05 6:32 ` Pekka Enberg
2005-09-05 7:55 ` David Teigland
2005-09-05 8:00 ` Pekka Enberg
2005-09-10 10:11 ` Arjan van de Ven
2005-09-05 6:29 ` David Teigland
2005-09-08 5:41 ` David Teigland [this message]
2005-09-01 12:33 ` Pekka Enberg
2005-09-01 17:27 ` Daniel Phillips
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=20050908054128.GD12220@redhat.com \
--to=teigland@redhat.com \
--cc=akpm@osdl.org \
--cc=arjan@infradead.org \
--cc=linux-cluster@redhat.com \
--cc=linux-fsdevel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).