From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 2/8] GFS2: Fix race in glock lru glock disposal
Date: Fri, 18 Jul 2014 11:37:39 +0100 [thread overview]
Message-ID: <1405679865-15728-3-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <1405679865-15728-1-git-send-email-swhiteho@redhat.com>
We must not leave items on the LRU list with GLF_LOCK set, since
they can be removed if the glock is brought back into use, which
may then potentially result in a hang, waiting for GLF_LOCK to
clear.
It doesn't happen very often, since it requires a glock that has
not been used for a long time to be brought back into use at the
same moment that the shrinker is part way through disposing of
glocks.
The fix is to set GLF_LOCK at a later time, when we already know
that the other locks can be obtained. Also, we now only release
the lru_lock in case a resched is needed, rather than on every
iteration.
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 278fae5..c1e5b12 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1406,12 +1406,16 @@ __acquires(&lru_lock)
gl = list_entry(list->next, struct gfs2_glock, gl_lru);
list_del_init(&gl->gl_lru);
if (!spin_trylock(&gl->gl_spin)) {
+add_back_to_lru:
list_add(&gl->gl_lru, &lru_list);
atomic_inc(&lru_count);
continue;
}
+ if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
+ spin_unlock(&gl->gl_spin);
+ goto add_back_to_lru;
+ }
clear_bit(GLF_LRU, &gl->gl_flags);
- spin_unlock(&lru_lock);
gl->gl_lockref.count++;
if (demote_ok(gl))
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
@@ -1419,7 +1423,7 @@ __acquires(&lru_lock)
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
gl->gl_lockref.count--;
spin_unlock(&gl->gl_spin);
- spin_lock(&lru_lock);
+ cond_resched_lock(&lru_lock);
}
}
@@ -1444,7 +1448,7 @@ static long gfs2_scan_glock_lru(int nr)
gl = list_entry(lru_list.next, struct gfs2_glock, gl_lru);
/* Test for being demotable */
- if (!test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
+ if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
list_move(&gl->gl_lru, &dispose);
atomic_dec(&lru_count);
freed++;
--
1.8.3.1
next prev parent reply other threads:[~2014-07-18 10:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 10:37 [Cluster-devel] GFS2: Pre-pull patch posting (fixes) Steven Whitehouse
2014-07-18 10:37 ` [Cluster-devel] [PATCH 1/8] GFS2: Only wait for demote when last holder is dequeued Steven Whitehouse
2014-07-18 10:37 ` Steven Whitehouse [this message]
2014-07-18 10:37 ` [Cluster-devel] [PATCH 3/8] GFS2: Use GFP_NOFS when allocating glocks Steven Whitehouse
2014-07-18 10:37 ` [Cluster-devel] [PATCH 4/8] GFS2: replace count*size kzalloc by kcalloc Steven Whitehouse
2014-07-18 10:37 ` [Cluster-devel] [PATCH 5/8] GFS2: Allow flocks to use normal glock dq rather than dq_wait Steven Whitehouse
2014-07-18 10:37 ` [Cluster-devel] [PATCH 6/8] GFS2: Allow caching of glocks for flock Steven Whitehouse
2014-07-18 10:37 ` [Cluster-devel] [PATCH 7/8] GFS2: memcontrol: Spelling s/invlidate/invalidate/ Steven Whitehouse
2014-07-18 10:37 ` [Cluster-devel] [PATCH 8/8] GFS2: fs/gfs2/rgrp.c: kernel-doc warning fixes Steven Whitehouse
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=1405679865-15728-3-git-send-email-swhiteho@redhat.com \
--to=swhiteho@redhat.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;
as well as URLs for NNTP newsgroup(s).