Skip to content

Commit ee51baa

Browse files
author
Andreas Gruenbacher
committed
gfs2: Faster gfs2_upgrade_iopen_glock wakeups
Move function needs_demote() to glock.h and rename it to glock_needs_demote(). In handle_callback(), wake up the glock when setting the GLF_PENDING_DEMOTE flag as well. (Setting the GLF_DEMOTE flag already triggered a wake-up.) With that, check for glock_needs_demote() in gfs2_upgrade_iopen_glock() to wake up when either of those flags is set for the inode glock: the faster we can react to contention, the better. The GLF_PENDING_DEMOTE flag is only used for inode glocks (see gfs2_glock_cb()) so it's okay to only check for the GLF_DEMOTE flag in gfs2_drop_inode(). Still, using glock_needs_demote() there as well makes the code a little easier to read. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent f9417fc commit ee51baa

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

fs/gfs2/glock.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,11 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
563563
gl->gl_tchange = jiffies;
564564
}
565565

566-
static void gfs2_set_demote(struct gfs2_glock *gl)
566+
static void gfs2_set_demote(int nr, struct gfs2_glock *gl)
567567
{
568568
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
569569

570-
set_bit(GLF_DEMOTE, &gl->gl_flags);
570+
set_bit(nr, &gl->gl_flags);
571571
smp_mb();
572572
wake_up(&sdp->sd_async_glock_wait);
573573
}
@@ -1101,7 +1101,7 @@ static void glock_work_func(struct work_struct *work)
11011101

11021102
if (!delay) {
11031103
clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
1104-
gfs2_set_demote(gl);
1104+
gfs2_set_demote(GLF_DEMOTE, gl);
11051105
}
11061106
}
11071107
run_queue(gl, 0);
@@ -1443,10 +1443,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
14431443
static void request_demote(struct gfs2_glock *gl, unsigned int state,
14441444
unsigned long delay, bool remote)
14451445
{
1446-
if (delay)
1447-
set_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
1448-
else
1449-
gfs2_set_demote(gl);
1446+
gfs2_set_demote(delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE, gl);
14501447
if (gl->gl_demote_state == LM_ST_EXCLUSIVE) {
14511448
gl->gl_demote_state = state;
14521449
gl->gl_demote_time = jiffies;
@@ -1636,12 +1633,6 @@ int gfs2_glock_poll(struct gfs2_holder *gh)
16361633
return test_bit(HIF_WAIT, &gh->gh_iflags) ? 0 : 1;
16371634
}
16381635

1639-
static inline bool needs_demote(struct gfs2_glock *gl)
1640-
{
1641-
return (test_bit(GLF_DEMOTE, &gl->gl_flags) ||
1642-
test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags));
1643-
}
1644-
16451636
static void __gfs2_glock_dq(struct gfs2_holder *gh)
16461637
{
16471638
struct gfs2_glock *gl = gh->gh_gl;
@@ -1650,8 +1641,8 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16501641

16511642
/*
16521643
* This holder should not be cached, so mark it for demote.
1653-
* Note: this should be done before the check for needs_demote
1654-
* below.
1644+
* Note: this should be done before the glock_needs_demote
1645+
* check below.
16551646
*/
16561647
if (gh->gh_flags & GL_NOCACHE)
16571648
request_demote(gl, LM_ST_UNLOCKED, 0, false);
@@ -1664,7 +1655,7 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16641655
* If there hasn't been a demote request we are done.
16651656
* (Let the remaining holders, if any, keep holding it.)
16661657
*/
1667-
if (!needs_demote(gl)) {
1658+
if (!glock_needs_demote(gl)) {
16681659
if (list_empty(&gl->gl_holders))
16691660
fast_path = 1;
16701661
}

fs/gfs2/glock.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,10 @@ static inline bool gfs2_holder_queued(struct gfs2_holder *gh)
285285
void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation);
286286
bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation);
287287

288+
static inline bool glock_needs_demote(struct gfs2_glock *gl)
289+
{
290+
return (test_bit(GLF_DEMOTE, &gl->gl_flags) ||
291+
test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags));
292+
}
293+
288294
#endif /* __GLOCK_DOT_H__ */

fs/gfs2/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ static int gfs2_drop_inode(struct inode *inode)
10301030
if (inode->i_nlink &&
10311031
gfs2_holder_initialized(&ip->i_iopen_gh)) {
10321032
struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
1033-
if (test_bit(GLF_DEMOTE, &gl->gl_flags))
1033+
if (glock_needs_demote(gl))
10341034
clear_nlink(inode);
10351035
}
10361036

@@ -1294,7 +1294,7 @@ static bool gfs2_upgrade_iopen_glock(struct inode *inode)
12941294

12951295
wait_event_interruptible_timeout(sdp->sd_async_glock_wait,
12961296
!test_bit(HIF_WAIT, &gh->gh_iflags) ||
1297-
test_bit(GLF_DEMOTE, &ip->i_gl->gl_flags),
1297+
glock_needs_demote(ip->i_gl),
12981298
5 * HZ);
12991299
if (!test_bit(HIF_HOLDER, &gh->gh_iflags)) {
13001300
gfs2_glock_dq(gh);

0 commit comments

Comments
 (0)