public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] further lockref cleanups
@ 2025-01-29 14:33 Andreas Gruenbacher
  2025-01-29 14:33 ` [PATCH 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Andreas Gruenbacher @ 2025-01-29 14:33 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

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/20250115094702.504610-1-hch@lst.de/

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(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] gfs2: use lockref_init for gl_lockref
  2025-01-29 14:33 [PATCH 0/3] further lockref cleanups Andreas Gruenbacher
@ 2025-01-29 14:33 ` Andreas Gruenbacher
  2025-01-29 15:43   ` Christoph Hellwig
  2025-01-29 14:33 ` [PATCH 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
  2025-01-29 14:33 ` [PATCH 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
  2 siblings, 1 reply; 9+ messages in thread
From: Andreas Gruenbacher @ 2025-01-29 14:33 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

Move the initialization of gl_lockref from gfs2_init_glock_once() to
gfs2_glock_get().  This allows to use lockref_init() there.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/gfs2/glock.c | 2 +-
 fs/gfs2/main.c  | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 8c4c1f871a88..b29eb71e3e29 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -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;
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 04cadc02e5a6..0727f60ad028 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -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);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] gfs2: switch to lockref_init(..., 1)
  2025-01-29 14:33 [PATCH 0/3] further lockref cleanups Andreas Gruenbacher
  2025-01-29 14:33 ` [PATCH 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
@ 2025-01-29 14:33 ` Andreas Gruenbacher
  2025-01-29 16:50   ` Christoph Hellwig
  2025-01-29 14:33 ` [PATCH 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
  2 siblings, 1 reply; 9+ messages in thread
From: Andreas Gruenbacher @ 2025-01-29 14:33 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

In 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.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/gfs2/quota.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 58bc5013ca49..6ae529a5388b 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -236,7 +236,7 @@ static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, str
 		return 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;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] lockref: remove count argument of lockref_init
  2025-01-29 14:33 [PATCH 0/3] further lockref cleanups Andreas Gruenbacher
  2025-01-29 14:33 ` [PATCH 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
  2025-01-29 14:33 ` [PATCH 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
@ 2025-01-29 14:33 ` Andreas Gruenbacher
  2025-01-29 15:44   ` Christoph Hellwig
  2 siblings, 1 reply; 9+ messages in thread
From: Andreas Gruenbacher @ 2025-01-29 14:33 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Andreas Gruenbacher, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

All users of lockref_init() now initialize the count to 1, so hardcode
that and remove the count argument.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 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(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 1a01d7a6a7a9..973a66dd3adf 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -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;
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 254f6ad2c336..85a08230d7c2 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -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;
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index b29eb71e3e29..65c07aa95718 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -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;
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 6ae529a5388b..2298e06797ac 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -236,7 +236,7 @@ static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, str
 		return 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);
diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index c39f119659ba..30c68ad1859a 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -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);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] gfs2: use lockref_init for gl_lockref
  2025-01-29 14:33 ` [PATCH 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
@ 2025-01-29 15:43   ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2025-01-29 15:43 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: Christian Brauner, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] lockref: remove count argument of lockref_init
  2025-01-29 14:33 ` [PATCH 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
@ 2025-01-29 15:44   ` Christoph Hellwig
  2025-01-29 17:19     ` Andreas Gruenbacher
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2025-01-29 15:44 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: Christian Brauner, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

Maybe the lockref_init kerneldoc now needs to say that it's initialized
to a hold count of 1?

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] gfs2: switch to lockref_init(..., 1)
  2025-01-29 14:33 ` [PATCH 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
@ 2025-01-29 16:50   ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2025-01-29 16:50 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: Christian Brauner, Christoph Hellwig, gfs2, linux-fsdevel,
	linux-kernel

On Wed, Jan 29, 2025 at 03:33:51PM +0100, Andreas Gruenbacher wrote:
> In 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.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] lockref: remove count argument of lockref_init
  2025-01-29 15:44   ` Christoph Hellwig
@ 2025-01-29 17:19     ` Andreas Gruenbacher
  2025-01-31  7:30       ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Gruenbacher @ 2025-01-29 17:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Christian Brauner, gfs2, linux-fsdevel, linux-kernel

On Wed, Jan 29, 2025 at 4:44 PM Christoph Hellwig <hch@lst.de> wrote:
> Maybe the lockref_init kerneldoc 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.

> Otherwise looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>

Thanks,
Andreas


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] lockref: remove count argument of lockref_init
  2025-01-29 17:19     ` Andreas Gruenbacher
@ 2025-01-31  7:30       ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2025-01-31  7:30 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: Christoph Hellwig, Christian Brauner, gfs2, linux-fsdevel,
	linux-kernel

On Wed, Jan 29, 2025 at 06:19:39PM +0100, Andreas Gruenbacher wrote:
> On Wed, Jan 29, 2025 at 4:44 PM Christoph Hellwig <hch@lst.de> wrote:
> > Maybe the lockref_init kerneldoc 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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-01-31  7:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-29 14:33 [PATCH 0/3] further lockref cleanups Andreas Gruenbacher
2025-01-29 14:33 ` [PATCH 1/3] gfs2: use lockref_init for gl_lockref Andreas Gruenbacher
2025-01-29 15:43   ` Christoph Hellwig
2025-01-29 14:33 ` [PATCH 2/3] gfs2: switch to lockref_init(..., 1) Andreas Gruenbacher
2025-01-29 16:50   ` Christoph Hellwig
2025-01-29 14:33 ` [PATCH 3/3] lockref: remove count argument of lockref_init Andreas Gruenbacher
2025-01-29 15:44   ` Christoph Hellwig
2025-01-29 17:19     ` Andreas Gruenbacher
2025-01-31  7:30       ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox