Skip to content

Commit 73118ca

Browse files
AstralBobAndreas Gruenbacher
authored andcommitted
gfs2: Replace gl_revokes with a GLF flag
The gl_revokes value determines how many outstanding revokes a glock has on the superblock revokes list; this is used to avoid unnecessary log flushes. However, gl_revokes is only ever tested for being zero, and it's only decremented in revoke_lo_after_commit, which removes all revokes from the list, so we know that the gl_revoke values of all the glocks on the list will reach zero. Therefore, we can replace gl_revokes with a bit flag. This saves an atomic counter in struct gfs2_glock. Signed-off-by: Bob Peterson <[email protected]> Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 9287c64 commit 73118ca

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

fs/gfs2/glock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void gfs2_glock_free(struct gfs2_glock *gl)
140140
{
141141
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
142142

143-
BUG_ON(atomic_read(&gl->gl_revokes));
143+
BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags));
144144
rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
145145
smp_mb();
146146
wake_up_glock(gl);
@@ -1801,7 +1801,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
18011801
state2str(gl->gl_target),
18021802
state2str(gl->gl_demote_state), dtime,
18031803
atomic_read(&gl->gl_ail_count),
1804-
atomic_read(&gl->gl_revokes),
1804+
test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0,
18051805
(int)gl->gl_lockref.count, gl->gl_hold_time);
18061806

18071807
list_for_each_entry(gh, &gl->gl_holders, gh_list)

fs/gfs2/incore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ enum {
345345
GLF_OBJECT = 14, /* Used only for tracing */
346346
GLF_BLOCKING = 15,
347347
GLF_INODE_CREATING = 16, /* Inode creation occurring */
348+
GLF_REVOKES = 17, /* Glock has revokes in queue */
348349
};
349350

350351
struct gfs2_glock {
@@ -374,7 +375,6 @@ struct gfs2_glock {
374375
struct list_head gl_lru;
375376
struct list_head gl_ail_list;
376377
atomic_t gl_ail_count;
377-
atomic_t gl_revokes;
378378
struct delayed_work gl_work;
379379
union {
380380
/* For inode and iopen glocks only */

fs/gfs2/log.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,10 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
606606
gfs2_remove_from_ail(bd); /* drops ref on bh */
607607
bd->bd_bh = NULL;
608608
sdp->sd_log_num_revoke++;
609-
if (atomic_inc_return(&gl->gl_revokes) == 1)
609+
if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
610+
set_bit(GLF_REVOKES, &gl->gl_flags);
610611
gfs2_glock_hold(gl);
612+
}
611613
set_bit(GLF_LFLUSH, &gl->gl_flags);
612614
list_add(&bd->bd_list, &sdp->sd_log_le_revoke);
613615
}

fs/gfs2/lops.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -662,19 +662,34 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
662662
static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
663663
{
664664
struct list_head *head = &sdp->sd_log_le_revoke;
665-
struct gfs2_bufdata *bd;
666-
struct gfs2_glock *gl;
665+
struct gfs2_bufdata *bd, *tmp;
667666

668-
while (!list_empty(head)) {
669-
bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
670-
list_del_init(&bd->bd_list);
671-
gl = bd->bd_gl;
672-
if (atomic_dec_return(&gl->gl_revokes) == 0) {
673-
clear_bit(GLF_LFLUSH, &gl->gl_flags);
674-
gfs2_glock_queue_put(gl);
667+
/*
668+
* Glocks can be referenced repeatedly on the revoke list, but the list
669+
* only holds one reference. All glocks on the list will have the
670+
* GLF_REVOKES flag set initially.
671+
*/
672+
673+
list_for_each_entry_safe(bd, tmp, head, bd_list) {
674+
struct gfs2_glock *gl = bd->bd_gl;
675+
676+
if (test_bit(GLF_REVOKES, &gl->gl_flags)) {
677+
/* Keep each glock on the list exactly once. */
678+
clear_bit(GLF_REVOKES, &gl->gl_flags);
679+
continue;
675680
}
681+
list_del(&bd->bd_list);
682+
kmem_cache_free(gfs2_bufdata_cachep, bd);
683+
}
684+
list_for_each_entry_safe(bd, tmp, head, bd_list) {
685+
struct gfs2_glock *gl = bd->bd_gl;
686+
687+
list_del(&bd->bd_list);
676688
kmem_cache_free(gfs2_bufdata_cachep, bd);
689+
clear_bit(GLF_LFLUSH, &gl->gl_flags);
690+
gfs2_glock_queue_put(gl);
677691
}
692+
/* the list is empty now */
678693
}
679694

680695
static void revoke_lo_before_scan(struct gfs2_jdesc *jd,

fs/gfs2/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static void gfs2_init_glock_once(void *foo)
5959
INIT_LIST_HEAD(&gl->gl_lru);
6060
INIT_LIST_HEAD(&gl->gl_ail_list);
6161
atomic_set(&gl->gl_ail_count, 0);
62-
atomic_set(&gl->gl_revokes, 0);
6362
}
6463

6564
static void gfs2_init_gl_aspace_once(void *foo)

fs/gfs2/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip)
14741474
truncate_inode_pages(gfs2_glock2aspace(ip->i_gl), 0);
14751475
truncate_inode_pages(&inode->i_data, 0);
14761476

1477-
if (atomic_read(&gl->gl_revokes) == 0) {
1477+
if (!test_bit(GLF_REVOKES, &gl->gl_flags)) {
14781478
clear_bit(GLF_LFLUSH, &gl->gl_flags);
14791479
clear_bit(GLF_DIRTY, &gl->gl_flags);
14801480
}

0 commit comments

Comments
 (0)