Skip to content

Commit 7cf8dcd

Browse files
AstralBobswhiteho
authored andcommitted
GFS2: Automatically adjust glock min hold time
This patch is a performance improvement for GFS2 in a clustered environment. It makes the glock hold time self-adjusting. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 17d539f commit 7cf8dcd

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

‎fs/gfs2/glock.c‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
409409
if (held1 && held2 && list_empty(&gl->gl_holders))
410410
clear_bit(GLF_QUEUED, &gl->gl_flags);
411411

412+
if (new_state != gl->gl_target)
413+
/* shorten our minimum hold time */
414+
gl->gl_hold_time = max(gl->gl_hold_time - GL_GLOCK_HOLD_DECR,
415+
GL_GLOCK_MIN_HOLD);
412416
gl->gl_state = new_state;
413417
gl->gl_tchange = jiffies;
414418
}
@@ -668,7 +672,7 @@ static void glock_work_func(struct work_struct *work)
668672
gl->gl_demote_state != LM_ST_EXCLUSIVE) {
669673
unsigned long holdtime, now = jiffies;
670674

671-
holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time;
675+
holdtime = gl->gl_tchange + gl->gl_hold_time;
672676
if (time_before(now, holdtime))
673677
delay = holdtime - now;
674678

@@ -679,9 +683,14 @@ static void glock_work_func(struct work_struct *work)
679683
}
680684
run_queue(gl, 0);
681685
spin_unlock(&gl->gl_spin);
682-
if (!delay ||
683-
queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
686+
if (!delay)
684687
gfs2_glock_put(gl);
688+
else {
689+
if (gl->gl_name.ln_type != LM_TYPE_INODE)
690+
delay = 0;
691+
if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
692+
gfs2_glock_put(gl);
693+
}
685694
if (drop_ref)
686695
gfs2_glock_put(gl);
687696
}
@@ -743,6 +752,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
743752
gl->gl_tchange = jiffies;
744753
gl->gl_object = NULL;
745754
gl->gl_sbd = sdp;
755+
gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
746756
INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
747757
INIT_WORK(&gl->gl_delete, delete_work_func);
748758

@@ -855,8 +865,15 @@ static int gfs2_glock_demote_wait(void *word)
855865

856866
static void wait_on_holder(struct gfs2_holder *gh)
857867
{
868+
unsigned long time1 = jiffies;
869+
858870
might_sleep();
859871
wait_on_bit(&gh->gh_iflags, HIF_WAIT, gfs2_glock_holder_wait, TASK_UNINTERRUPTIBLE);
872+
if (time_after(jiffies, time1 + HZ)) /* have we waited > a second? */
873+
/* Lengthen the minimum hold time. */
874+
gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time +
875+
GL_GLOCK_HOLD_INCR,
876+
GL_GLOCK_MAX_HOLD);
860877
}
861878

862879
static void wait_on_demote(struct gfs2_glock *gl)
@@ -1093,8 +1110,9 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
10931110

10941111
gfs2_glock_hold(gl);
10951112
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1096-
!test_bit(GLF_DEMOTE, &gl->gl_flags))
1097-
delay = gl->gl_ops->go_min_hold_time;
1113+
!test_bit(GLF_DEMOTE, &gl->gl_flags) &&
1114+
gl->gl_name.ln_type == LM_TYPE_INODE)
1115+
delay = gl->gl_hold_time;
10981116
if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
10991117
gfs2_glock_put(gl);
11001118
}
@@ -1273,12 +1291,13 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
12731291
unsigned long now = jiffies;
12741292

12751293
gfs2_glock_hold(gl);
1276-
holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time;
1277-
if (test_bit(GLF_QUEUED, &gl->gl_flags)) {
1294+
holdtime = gl->gl_tchange + gl->gl_hold_time;
1295+
if (test_bit(GLF_QUEUED, &gl->gl_flags) &&
1296+
gl->gl_name.ln_type == LM_TYPE_INODE) {
12781297
if (time_before(now, holdtime))
12791298
delay = holdtime - now;
12801299
if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags))
1281-
delay = gl->gl_ops->go_min_hold_time;
1300+
delay = gl->gl_hold_time;
12821301
}
12831302

12841303
spin_lock(&gl->gl_spin);
@@ -1667,7 +1686,7 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
16671686
dtime *= 1000000/HZ; /* demote time in uSec */
16681687
if (!test_bit(GLF_DEMOTE, &gl->gl_flags))
16691688
dtime = 0;
1670-
gfs2_print_dbg(seq, "G: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d v:%d r:%d\n",
1689+
gfs2_print_dbg(seq, "G: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d v:%d r:%d m:%ld\n",
16711690
state2str(gl->gl_state),
16721691
gl->gl_name.ln_type,
16731692
(unsigned long long)gl->gl_name.ln_number,
@@ -1676,7 +1695,7 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
16761695
state2str(gl->gl_demote_state), dtime,
16771696
atomic_read(&gl->gl_ail_count),
16781697
atomic_read(&gl->gl_revokes),
1679-
atomic_read(&gl->gl_ref));
1698+
atomic_read(&gl->gl_ref), gl->gl_hold_time);
16801699

16811700
list_for_each_entry(gh, &gl->gl_holders, gh_list) {
16821701
error = dump_holder(seq, gh);

‎fs/gfs2/glock.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ enum {
113113

114114
#define GLR_TRYFAILED 13
115115

116+
#define GL_GLOCK_MAX_HOLD (long)(HZ / 5)
117+
#define GL_GLOCK_DFT_HOLD (long)(HZ / 5)
118+
#define GL_GLOCK_MIN_HOLD (long)(10)
119+
#define GL_GLOCK_HOLD_INCR (long)(HZ / 20)
120+
#define GL_GLOCK_HOLD_DECR (long)(HZ / 40)
121+
116122
struct lm_lockops {
117123
const char *lm_proto_name;
118124
int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname);

‎fs/gfs2/glops.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ const struct gfs2_glock_operations gfs2_inode_glops = {
551551
.go_lock = inode_go_lock,
552552
.go_dump = inode_go_dump,
553553
.go_type = LM_TYPE_INODE,
554-
.go_min_hold_time = HZ / 5,
555554
.go_flags = GLOF_ASPACE,
556555
};
557556

@@ -562,7 +561,6 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = {
562561
.go_unlock = rgrp_go_unlock,
563562
.go_dump = gfs2_rgrp_dump,
564563
.go_type = LM_TYPE_RGRP,
565-
.go_min_hold_time = HZ / 5,
566564
.go_flags = GLOF_ASPACE,
567565
};
568566

‎fs/gfs2/incore.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ struct gfs2_glock_operations {
163163
int (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl);
164164
void (*go_callback) (struct gfs2_glock *gl);
165165
const int go_type;
166-
const unsigned long go_min_hold_time;
167166
const unsigned long go_flags;
168167
#define GLOF_ASPACE 1
169168
};
@@ -221,6 +220,7 @@ struct gfs2_glock {
221220

222221
unsigned int gl_hash;
223222
unsigned long gl_demote_time; /* time of first demote request */
223+
long gl_hold_time;
224224
struct list_head gl_holders;
225225

226226
const struct gfs2_glock_operations *gl_ops;

0 commit comments

Comments
 (0)