further lockref cleanups
Subsystems (3)
Andreas Gruenbacher
maintainercover further lockref cleanups
As discussed in Christoph's "lockref cleanups" thread [*], here are some further cleanups in gfs2 that then allow lockref_init's count argument to be dropped. Please review.
Christian, can this go into the vfs tree as Christioph's previous cleanups did?
Thanks,
Andreas
[*] https://lore.kernel.org/lkml/[email protected]/
Andreas Gruenbacher (3):
gfs2: use lockref_init for gl_lockref
gfs2: switch to lockref_init(..., 1)
lockref: remove count argument of lockref_init
fs/dcache.c | 2 +- fs/erofs/zdata.c | 2 +- fs/gfs2/glock.c | 2 +- fs/gfs2/main.c | 1 - fs/gfs2/quota.c | 4 ++-- include/linux/lockref.h | 5 ++--- 6 files changed, 7 insertions(+), 9 deletions(-)
Signature · 1 line
2.48.1
Andreas Gruenbacher
maintainerPATCH 1/3 gfs2: use lockref_init for gl_lockref
Move the initialization of gl_lockref from gfs2_init_glock_once() to gfs2_glock_get(). This allows to use lockref_init() there.
--- fs/gfs2/glock.c | 2 +- fs/gfs2/main.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
fs/gfs2/glock.c +1 -1
@@ -1201,8 +1201,8 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,if (glops->go_instantiate) gl->gl_flags |=BIT (GLF_INSTANTIATE_NEEDED ); gl->gl_name = name; +lockref_init (&gl->gl_lockref,1 );lockdep_set_subclass (&gl->gl_lockref.lock, glops->go_subclass); - gl->gl_lockref.count =1 ; gl->gl_state =LM_ST_UNLOCKED ; gl->gl_target =LM_ST_UNLOCKED ; gl->gl_demote_state =LM_ST_EXCLUSIVE ;
fs/gfs2/main.c +0 -1
@@ -51,7 +51,6 @@ static void gfs2_init_glock_once(void *foo) {struct gfs2_glock *gl = foo; -spin_lock_init (&gl->gl_lockref.lock);INIT_LIST_HEAD (&gl->gl_holders);INIT_LIST_HEAD (&gl->gl_lru);INIT_LIST_HEAD (&gl->gl_ail_list);
Signature · 1 line
2.48.1
Re: [PATCH 1/3] gfs2: use lockref_init for gl_lockref
Looks good:
Andreas Gruenbacher
maintainerPATCH 2/3 gfs2: switch to lockref_init(..., 1)
In reply to Andreas GruenbacherIn qd_alloc(), initialize the lockref count to 1 to cover the common case. Compensate for that in gfs2_quota_init() by adjusting the count back down to 0; this only occurs when mounting the filesystem rw.
--- fs/gfs2/quota.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/gfs2/quota.c +2 -2
@@ -236,7 +236,7 @@ static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, strreturn NULL ; qd->qd_sbd = sdp; -lockref_init (&qd->qd_lockref,0 ); +lockref_init (&qd->qd_lockref,1 ); qd->qd_id = qid; qd->qd_slot =-1 ;INIT_LIST_HEAD (&qd->qd_lru);
@@ -297,7 +297,6 @@ static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,spin_lock_bucket (hash); *qdp = qd =gfs2_qd_search_bucket (hash, sdp, qid);if (qd ==NULL ) { - new_qd->qd_lockref.count++; *qdp = new_qd;list_add (&new_qd->qd_list, &sdp->sd_quota_list);hlist_bl_add_head_rcu (&new_qd->qd_hlist, &qd_hash_table[hash]);
@@ -1450,6 +1449,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)if (qd ==NULL ) goto fail_brelse; + qd->qd_lockref.count =0 ;set_bit (QDF_CHANGE , &qd->qd_flags); qd->qd_change = qc_change; qd->qd_slot = slot;
Signature · 1 line
2.48.1
Re: [PATCH 2/3] gfs2: switch to lockref_init(..., 1)
Quoted 3 lines · Andreas Gruenbacher
In
qd_alloc(), initialize the lockref count to 1 to cover the common case. Compensate for that ingfs2_quota_init()by adjusting the count back down to 0; this only occurs when mounting the filesystem rw.
Looks good:
Andreas Gruenbacher
maintainerPATCH 3/3 lockref: remove count argument of lockref_init
In reply to Andreas GruenbacherAll users of lockref_init() now initialize the count to 1, so hardcode that and remove the count argument.
--- fs/dcache.c | 2 +- fs/erofs/zdata.c | 2 +- fs/gfs2/glock.c | 2 +- fs/gfs2/quota.c | 2 +- include/linux/lockref.h | 5 ++--- 5 files changed, 6 insertions(+), 7 deletions(-)
fs/dcache.c +1 -1
@@ -1682,7 +1682,7 @@ static struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)smp_store_release (&dentry->d_name.name, dname);/* ^^^ */ dentry->d_flags =0 ; -lockref_init (&dentry->d_lockref,1 ); +lockref_init (&dentry->d_lockref);seqcount_spinlock_init (&dentry->d_seq, &dentry->d_lock); dentry->d_inode =NULL ; dentry->d_parent = dentry;
fs/erofs/zdata.c +1 -1
@@ -747,7 +747,7 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)if (IS_ERR (pcl))return PTR_ERR (pcl); -lockref_init (&pcl->lockref,1 );/* one ref for this request */ +lockref_init (&pcl->lockref);/* one ref for this request */ pcl->algorithmformat = map->m_algorithmformat; pcl->length =0 ; pcl->partial = true;
fs/gfs2/glock.c +1 -1
@@ -1201,7 +1201,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,if (glops->go_instantiate) gl->gl_flags |=BIT (GLF_INSTANTIATE_NEEDED ); gl->gl_name = name; -lockref_init (&gl->gl_lockref,1 ); +lockref_init (&gl->gl_lockref);lockdep_set_subclass (&gl->gl_lockref.lock, glops->go_subclass); gl->gl_state =LM_ST_UNLOCKED ; gl->gl_target =LM_ST_UNLOCKED ;
fs/gfs2/quota.c +1 -1
@@ -236,7 +236,7 @@ static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, strreturn NULL ; qd->qd_sbd = sdp; -lockref_init (&qd->qd_lockref,1 ); +lockref_init (&qd->qd_lockref); qd->qd_id = qid; qd->qd_slot =-1 ;INIT_LIST_HEAD (&qd->qd_lru);
include/linux/lockref.h +2 -3
@@ -37,12 +37,11 @@ struct lockref {/** * lockref_init - Initialize a lockref * @lockref: pointer to lockref structure -* @count: initial count */ -static inline void lockref_init (struct lockref *lockref,unsigned int count) +static inline void lockref_init (struct lockref *lockref) {spin_lock_init (&lockref->lock); - lockref->count = count; + lockref->count =1 ; }void lockref_get (struct lockref *lockref);
Signature · 1 line
2.48.1
Re: [PATCH 3/3] lockref: remove count argument of lockref_init
Maybe the lockref_init kerneldoc now needs to say that it's initialized to a hold count of 1?
Otherwise looks good:
Andreas Gruenbacher
maintainerRe: [PATCH 3/3] lockref: remove count argument of lockref_init
Quoted 2 lines · Christoph Hellwig
Maybe the
lockref_initkerneldoc now needs to say that it's initialized to a hold count of 1?
I always feel a bit guilty when adding a comment like "Initializes @lockref->count to 1" and five lines further down in the code, it says 'lockref->count = 1'. But okay.
Quoted 4 lines
Otherwise looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Thanks,
Andreas
Re: [PATCH 3/3] lockref: remove count argument of lockref_init
Quoted 7 lines · Andreas Gruenbacher
Quoted 2 lines · Christoph Hellwig
Maybe the
lockref_initkerneldoc now needs to say that it's initialized to a hold count of 1?I always feel a bit guilty when adding a comment like "Initializes @lockref->count to 1" and five lines further down in the code, it says '
lockref->count= 1'. But okay.
It reads a bit odd, but kerneldoc comments aren't just for the reader of the code - they also get extraced into rendered documentation.