Improve throughput through rgrp sharing (v2)
cover Improve throughput through rgrp sharing (v2)
Hi,
On 18 April, I posted v1 of this patch set. The idea is to allow multiple processes on a node to share a glock that's held exclusively in order to improve performance. Sharing rgrps allows for better throughput by reducing contention.
Version 1 implemented this by introducing a new glock mode for sharing glocks. Steve Whitehouse suggested we didn't need a new mode: we can accomplish the same thing just by having a new glock flag, which also makes the patch more simple.
This version 2 patch set implements Steve's suggestion.
The first patch introduces the new glock flag. The second patch puts it into use for rgrp sharing. Exclusive access to the rgrp is implemented through an rwsem.
Performance testing using iozone looks even better than version 1.
---
Bob Peterson (2):
GFS2: Introduce GLF_EX_SHARING bit: local EX sharing
GFS2: Take advantage of new EXSH glock mode for rgrps
fs/gfs2/bmap.c | 2 +- fs/gfs2/dir.c | 2 +- fs/gfs2/glock.c | 23 ++++++++++--- fs/gfs2/glock.h | 4 +++ fs/gfs2/incore.h | 2 ++ fs/gfs2/inode.c | 7 ++-- fs/gfs2/rgrp.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++--------- fs/gfs2/rgrp.h | 2 +- fs/gfs2/super.c | 8 +++-- fs/gfs2/xattr.c | 8 +++-- 10 files changed, 129 insertions(+), 32 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/2 GFS2: Introduce GLF_EX_SHARING bit: local EX sharing
This patch is a first step in rgrp sharing. It allows for glocks locked in EX mode to be shared amongst processes on that node. Like a Shared glock, multiple processes may hold the lock in EX mode at the same time, provided they're all on the same node. All other nodes will see this as an EX lock.
For now, there are no users of the new flag. A future patch will use it to improve performance with rgrp sharing.
--- fs/gfs2/glock.c | 23 +++++++++++++++++++---- fs/gfs2/glock.h | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-)
fs/gfs2/glock.c +19 -4
@@ -279,10 +279,20 @@ void gfs2_glock_put(struct gfs2_glock *gl)static inline int may_grant (const struct gfs2_glock *gl,const struct gfs2_holder *gh) { - const struct gfs2_holder *gh_head = list_entry(gl->gl_holders.next, const struct gfs2_holder, gh_list); -if ((gh->gh_state ==LM_ST_EXCLUSIVE || - gh_head->gh_state ==LM_ST_EXCLUSIVE ) && gh != gh_head) -return 0 ; +const struct gfs2_holder *gh_head =list_entry (gl->gl_holders.next, + const struct gfs2_holder, + gh_list); + +if (gh != gh_head) { +if (gh_head->gh_state ==LM_ST_EXCLUSIVE && + (gh_head->gh_flags &LM_FLAG_SHAREDEX ) && + gh->gh_state ==LM_ST_EXCLUSIVE && + (gh->gh_flags &LM_FLAG_SHAREDEX )) +return 1 ; +if ((gh->gh_state ==LM_ST_EXCLUSIVE || + gh_head->gh_state ==LM_ST_EXCLUSIVE )) +return 0 ; + }if (gl->gl_state == gh->gh_state)return 1 ;if (gh->gh_flags &GL_EXACT )
@@ -292,6 +302,9 @@ static inline int may_grant(const struct gfs2_glock *gl, const struct gfs2_holdereturn 1 ;if (gh->gh_state ==LM_ST_DEFERRED && gh_head->gh_state ==LM_ST_DEFERRED )return 1 ; +if (gh_head->gh_flags &LM_FLAG_SHAREDEX && + gh->gh_flags &LM_FLAG_SHAREDEX ) +return 1 ; }if (gl->gl_state !=LM_ST_UNLOCKED && (gh->gh_flags &LM_FLAG_ANY ))return 1 ;
@@ -1680,6 +1693,8 @@ static const char *hflags2str(char *buf, u16 flags, unsigned long iflags) *p++ ='A' ;if (flags &LM_FLAG_PRIORITY ) *p++ ='p' ; +if (flags &LM_FLAG_SHAREDEX ) + *p++ ='s' ;if (flags &GL_ASYNC ) *p++ ='a' ;if (flags &GL_EXACT )
fs/gfs2/glock.h +4 -0
@@ -78,6 +78,9 @@ enum {* request and directly join the other shared lock. A shared lock request * without the priority flag might be forced to wait until the deferred * requested had acquired and released the lock. +* +* LM_FLAG_SHAREDEX +* The glock may be held in EXCLUSIVE mode, but it's still shared */ #define LM_FLAG_TRY 0x0001
@@ -85,6 +88,7 @@ enum {#define LM_FLAG_NOEXP 0x0004#define LM_FLAG_ANY 0x0008#define LM_FLAG_PRIORITY 0x0010 +#define LM_FLAG_SHAREDEX 0x0020#define GL_ASYNC 0x0040#define GL_EXACT 0x0080#define GL_SKIP 0x0100
Signature · 1 line
2.14.3
PATCH 2/2 GFS2: Take advantage of new EXSH glock mode for rgrps
In reply to Bob PetersonThis patch switches rgrp locking to EXSH mode so that it's only taken when the rgrp is added to an active transaction, or when blocks are being reserved. As soon as the transaction is ended, the rgrp exclusivity is released. This allows for rgrp sharing.
--- fs/gfs2/bmap.c | 2 +- fs/gfs2/dir.c | 2 +- fs/gfs2/glock.h | 2 +- fs/gfs2/incore.h | 2 ++ fs/gfs2/inode.c | 7 ++-- fs/gfs2/rgrp.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++--------- fs/gfs2/rgrp.h | 2 +- fs/gfs2/super.c | 8 +++-- fs/gfs2/xattr.c | 8 +++-- 9 files changed, 107 insertions(+), 29 deletions(-)
fs/gfs2/bmap.c +1 -1
@@ -1108,7 +1108,7 @@ static int sweep_bh_for_rgrps(struct gfs2_inode *ip, struct gfs2_holder *rd_gh, goto out; } ret =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE , -0 , rd_gh); +LM_FLAG_SHAREDEX , rd_gh);if (ret) goto out;
fs/gfs2/dir.c +1 -1
@@ -2020,7 +2020,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len, l_blocks++; } -gfs2_rlist_alloc (&rlist,LM_ST_EXCLUSIVE ); +gfs2_rlist_alloc (&rlist);for (x =0 ; x < rlist.rl_rgrps; x++) {struct gfs2_rgrpd *rgd =gfs2_glock2rgrp (rlist.rl_ghs[x].gh_gl);
fs/gfs2/glock.h +1 -1
@@ -80,7 +80,7 @@ enum {* requested had acquired and released the lock. * * LM_FLAG_SHAREDEX -* The glock may be held in EXCLUSIVE mode, but it's still shared +* The glock may be held in EXCLUSIVE mode, but it's still shared. */ #define LM_FLAG_TRY 0x0001
fs/gfs2/incore.h +2 -0
@@ -100,6 +100,8 @@ struct gfs2_rgrpd {#define GFS2_RDF_PREFERRED 0x80000000/* This rgrp is preferred */ #define GFS2_RDF_MASK 0xf0000000/* mask for internal flags */ spinlock_t rd_rsspin;/* protects reservation related vars */ +struct rw_semaphore rd_sem;/* ensures local rgrp exclusivity */ +pid_t rd_expid;/* rgrp locked EX by this pid */ struct rb_root rd_rstree;/* multi-block reservation tree */ };
fs/gfs2/inode.c +4 -3
@@ -1121,8 +1121,8 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)if (!rgd) goto out_inodes; -gfs2_holder_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , ghs +2 ); - +gfs2_holder_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,LM_FLAG_SHAREDEX , + ghs +2 ); error =gfs2_glock_nq (ghs);/* parent */ if (error)
@@ -1409,7 +1409,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,*/ nrgd =gfs2_blk2rgrpd (sdp, nip->i_no_addr,1 );if (nrgd) -gfs2_holder_init (nrgd->rd_gl,LM_ST_EXCLUSIVE ,0 , ghs + num_gh++); +gfs2_holder_init (nrgd->rd_gl,LM_ST_EXCLUSIVE , +LM_FLAG_SHAREDEX , ghs + num_gh++); }for (x =0 ; x < num_gh; x++) {
fs/gfs2/rgrp.c +87 -16
290 lines not on this page · raw message
fs/gfs2/rgrp.h +1 -1
@@ -68,7 +68,7 @@ struct gfs2_rgrp_list {extern void gfs2_rlist_add (struct gfs2_inode *ip,struct gfs2_rgrp_list *rlist,u64 block); -extern void gfs2_rlist_alloc (struct gfs2_rgrp_list *rlist,unsigned int state); +extern void gfs2_rlist_alloc (struct gfs2_rgrp_list *rlist);extern void gfs2_rlist_free (struct gfs2_rgrp_list *rlist);extern u64 gfs2_ri_total (struct gfs2_sbd *sdp);extern void gfs2_rgrp_dump (struct seq_file *seq,const struct gfs2_glock *gl);
fs/gfs2/super.c +5 -3
@@ -1131,8 +1131,9 @@ static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host done =0 ; else if (rgd_next && !error) { error =gfs2_glock_nq_init (rgd_next->rd_gl, -LM_ST_SHARED , -GL_ASYNC , +LM_ST_EXCLUSIVE , +GL_ASYNC | +LM_FLAG_SHAREDEX , gh); rgd_next =gfs2_rgrpd_get_next (rgd_next); done =0 ;
@@ -1507,7 +1508,8 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip) goto out_qs; } - error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , &gh); + error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE , +LM_FLAG_SHAREDEX , &gh);if (error) goto out_qs;
fs/gfs2/xattr.c +5 -3
@@ -262,7 +262,8 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,return -EIO ; } - error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , &rg_gh); + error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE , +LM_FLAG_SHAREDEX , &rg_gh);if (error)return error;
@@ -1314,7 +1315,7 @@ static int ea_dealloc_indirect(struct gfs2_inode *ip)else goto out; -gfs2_rlist_alloc (&rlist,LM_ST_EXCLUSIVE ); +gfs2_rlist_alloc (&rlist);for (x =0 ; x < rlist.rl_rgrps; x++) {struct gfs2_rgrpd *rgd =gfs2_glock2rgrp (rlist.rl_ghs[x].gh_gl);
@@ -1397,7 +1398,8 @@ static int ea_dealloc_block(struct gfs2_inode *ip)return -EIO ; } - error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE ,0 , &gh); + error =gfs2_glock_nq_init (rgd->rd_gl,LM_ST_EXCLUSIVE , +LM_FLAG_SHAREDEX , &gh);if (error)return error;
Signature · 1 line
2.14.3
cover Improve throughput through rgrp sharing (v2)
In reply to Bob PetersonHi,
Quoted 12 lines · Bob Peterson
Hi,
On 18 April, I posted v1 of this patch set. The idea is to allow multiple processes on a node to share a glock that's held exclusively in order to improve performance. Sharing rgrps allows for better throughput by reducing contention.
Version 1 implemented this by introducing a new glock mode for sharing glocks. Steve Whitehouse suggested we didn't need a new mode: we can accomplish the same thing just by having a new glock flag, which also makes the patch more simple.
Quoted 7 lines
This version 2 patch set implements Steve's suggestion.
The first patch introduces the new glock flag. The second patch puts it into use for rgrp sharing. Exclusive access to the rgrp is implemented through an rwsem.
Performance testing using iozone looks even better than version 1.
Sounds really good! We should make sure that we give this a really good round of testing and it would be nice to see some details of the performance improvements. Overall though, that's an excellent result :-)
Steve.
Quoted 17 lines
---
Bob Peterson (2):
GFS2: IntroduceGLF_EX_SHARINGbit: local EX sharing
GFS2: Take advantage of new EXSH glock mode for rgrpsfs/gfs2/bmap.c | 2 +- fs/gfs2/dir.c | 2 +- fs/gfs2/glock.c | 23 ++++++++++--- fs/gfs2/glock.h | 4 +++ fs/gfs2/incore.h | 2 ++ fs/gfs2/inode.c | 7 ++-- fs/gfs2/rgrp.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++--------- fs/gfs2/rgrp.h | 2 +- fs/gfs2/super.c | 8 +++-- fs/gfs2/xattr.c | 8 +++-- 10 files changed, 129 insertions(+), 32 deletions(-)