Skip to content

Commit ee2be7d

Browse files
author
Andreas Gruenbacher
committed
gfs2: Replace gfs2_glock_queue_put with gfs2_glock_put_async
Function gfs2_glock_queue_put() puts a glock reference by enqueuing glock work instead of putting the reference directly. This ensures that the operation won't sleep, but it is costly and really only necessary when putting the final glock reference. Replace it with a new gfs2_glock_put_async() function that only queues glock work when putting the last glock reference. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent f80d882 commit ee2be7d

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

fs/gfs2/glock.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,6 @@ static void __gfs2_glock_put(struct gfs2_glock *gl)
285285
sdp->sd_lockstruct.ls_ops->lm_put_lock(gl);
286286
}
287287

288-
/*
289-
* Cause the glock to be put in work queue context.
290-
*/
291-
void gfs2_glock_queue_put(struct gfs2_glock *gl)
292-
{
293-
gfs2_glock_queue_work(gl, 0);
294-
}
295-
296288
/**
297289
* gfs2_glock_put() - Decrement reference count on glock
298290
* @gl: The glock to put
@@ -307,6 +299,22 @@ void gfs2_glock_put(struct gfs2_glock *gl)
307299
__gfs2_glock_put(gl);
308300
}
309301

302+
/*
303+
* gfs2_glock_put_async - Decrement reference count without sleeping
304+
* @gl: The glock to put
305+
*
306+
* Decrement the reference count on glock immediately unless it is the last
307+
* reference. Defer putting the last reference to work queue context.
308+
*/
309+
void gfs2_glock_put_async(struct gfs2_glock *gl)
310+
{
311+
if (lockref_put_or_lock(&gl->gl_lockref))
312+
return;
313+
314+
__gfs2_glock_queue_work(gl, 0);
315+
spin_unlock(&gl->gl_lockref.lock);
316+
}
317+
310318
/**
311319
* may_grant - check if it's ok to grant a new lock
312320
* @gl: The glock
@@ -2529,8 +2537,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n)
25292537
if (gl) {
25302538
if (n == 0)
25312539
return;
2532-
if (!lockref_put_not_zero(&gl->gl_lockref))
2533-
gfs2_glock_queue_put(gl);
2540+
gfs2_glock_put_async(gl);
25342541
}
25352542
for (;;) {
25362543
gl = rhashtable_walk_next(&gi->hti);

fs/gfs2/glock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
172172
int create, struct gfs2_glock **glp);
173173
struct gfs2_glock *gfs2_glock_hold(struct gfs2_glock *gl);
174174
void gfs2_glock_put(struct gfs2_glock *gl);
175-
void gfs2_glock_queue_put(struct gfs2_glock *gl);
175+
void gfs2_glock_put_async(struct gfs2_glock *gl);
176176

177177
void __gfs2_holder_init(struct gfs2_glock *gl, unsigned int state,
178178
u16 flags, struct gfs2_holder *gh,

fs/gfs2/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ void gfs2_glock_remove_revoke(struct gfs2_glock *gl)
786786
{
787787
if (atomic_dec_return(&gl->gl_revokes) == 0) {
788788
clear_bit(GLF_LFLUSH, &gl->gl_flags);
789-
gfs2_glock_queue_put(gl);
789+
gfs2_glock_put_async(gl);
790790
}
791791
}
792792

fs/gfs2/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ static int gfs2_drop_inode(struct inode *inode)
10491049

10501050
gfs2_glock_hold(gl);
10511051
if (!gfs2_queue_try_to_evict(gl))
1052-
gfs2_glock_queue_put(gl);
1052+
gfs2_glock_put_async(gl);
10531053
return 0;
10541054
}
10551055

@@ -1255,7 +1255,7 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
12551255
static void gfs2_glock_put_eventually(struct gfs2_glock *gl)
12561256
{
12571257
if (current->flags & PF_MEMALLOC)
1258-
gfs2_glock_queue_put(gl);
1258+
gfs2_glock_put_async(gl);
12591259
else
12601260
gfs2_glock_put(gl);
12611261
}

0 commit comments

Comments
 (0)