All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Christoph Hellwig <hch@lst.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>, Jan Kara <jack@suse.cz>,
	linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH 5/5] mm: simplify bdi refcounting
Date: Fri, 22 Oct 2021 11:02:03 +0200	[thread overview]
Message-ID: <20211022090203.GF1026@quack2.suse.cz> (raw)
In-Reply-To: <20211021124441.668816-6-hch@lst.de>

On Thu 21-10-21 14:44:41, Christoph Hellwig wrote:
> Move grabbing and releasing the bdi refcount out of the common
> wb_init/wb_exit helpers into code that is only used for the non-default
> memcg driven bdi_writeback structures.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Can we perhaps add a comment to struct bdi_writeback definition (or maybe
wb_init()?) mentioning that it holds a reference to 'bdi' if it is
bdi_writeback struct for a cgroup? I don't see it mentioned anywhere and
now that you've changed the code, it isn't that obvious from the code
either... Otherwise the patch looks good so feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza


> ---
>  mm/backing-dev.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/backing-dev.c b/mm/backing-dev.c
> index 768e9ae489f66..5ccb250898083 100644
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -291,8 +291,6 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
>  
>  	memset(wb, 0, sizeof(*wb));
>  
> -	if (wb != &bdi->wb)
> -		bdi_get(bdi);
>  	wb->bdi = bdi;
>  	wb->last_old_flush = jiffies;
>  	INIT_LIST_HEAD(&wb->b_dirty);
> @@ -316,7 +314,7 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
>  
>  	err = fprop_local_init_percpu(&wb->completions, gfp);
>  	if (err)
> -		goto out_put_bdi;
> +		return err;
>  
>  	for (i = 0; i < NR_WB_STAT_ITEMS; i++) {
>  		err = percpu_counter_init(&wb->stat[i], 0, gfp);
> @@ -330,9 +328,6 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
>  	while (i--)
>  		percpu_counter_destroy(&wb->stat[i]);
>  	fprop_local_destroy_percpu(&wb->completions);
> -out_put_bdi:
> -	if (wb != &bdi->wb)
> -		bdi_put(bdi);
>  	return err;
>  }
>  
> @@ -373,8 +368,6 @@ static void wb_exit(struct bdi_writeback *wb)
>  		percpu_counter_destroy(&wb->stat[i]);
>  
>  	fprop_local_destroy_percpu(&wb->completions);
> -	if (wb != &wb->bdi->wb)
> -		bdi_put(wb->bdi);
>  }
>  
>  #ifdef CONFIG_CGROUP_WRITEBACK
> @@ -397,6 +390,7 @@ static void cgwb_release_workfn(struct work_struct *work)
>  	struct bdi_writeback *wb = container_of(work, struct bdi_writeback,
>  						release_work);
>  	struct blkcg *blkcg = css_to_blkcg(wb->blkcg_css);
> +	struct backing_dev_info *bdi = wb->bdi;
>  
>  	mutex_lock(&wb->bdi->cgwb_release_mutex);
>  	wb_shutdown(wb);
> @@ -416,6 +410,7 @@ static void cgwb_release_workfn(struct work_struct *work)
>  
>  	percpu_ref_exit(&wb->refcnt);
>  	wb_exit(wb);
> +	bdi_put(bdi);
>  	WARN_ON_ONCE(!list_empty(&wb->b_attached));
>  	kfree_rcu(wb, rcu);
>  }
> @@ -497,6 +492,7 @@ static int cgwb_create(struct backing_dev_info *bdi,
>  	INIT_LIST_HEAD(&wb->b_attached);
>  	INIT_WORK(&wb->release_work, cgwb_release_workfn);
>  	set_bit(WB_registered, &wb->state);
> +	bdi_get(bdi);
>  
>  	/*
>  	 * The root wb determines the registered state of the whole bdi and
> @@ -528,6 +524,7 @@ static int cgwb_create(struct backing_dev_info *bdi,
>  	goto out_put;
>  
>  err_fprop_exit:
> +	bdi_put(bdi);
>  	fprop_local_destroy_percpu(&wb->memcg_completions);
>  err_ref_exit:
>  	percpu_ref_exit(&wb->refcnt);
> -- 
> 2.30.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

WARNING: multiple messages have this Message-ID (diff)
From: Jan Kara <jack@suse.cz>
To: Christoph Hellwig <hch@lst.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>, Jan Kara <jack@suse.cz>,
	linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH 5/5] mm: simplify bdi refcounting
Date: Fri, 22 Oct 2021 11:02:03 +0200	[thread overview]
Message-ID: <20211022090203.GF1026@quack2.suse.cz> (raw)
In-Reply-To: <20211021124441.668816-6-hch@lst.de>

On Thu 21-10-21 14:44:41, Christoph Hellwig wrote:
> Move grabbing and releasing the bdi refcount out of the common
> wb_init/wb_exit helpers into code that is only used for the non-default
> memcg driven bdi_writeback structures.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Can we perhaps add a comment to struct bdi_writeback definition (or maybe
wb_init()?) mentioning that it holds a reference to 'bdi' if it is
bdi_writeback struct for a cgroup? I don't see it mentioned anywhere and
now that you've changed the code, it isn't that obvious from the code
either... Otherwise the patch looks good so feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza


> ---
>  mm/backing-dev.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/backing-dev.c b/mm/backing-dev.c
> index 768e9ae489f66..5ccb250898083 100644
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -291,8 +291,6 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
>  
>  	memset(wb, 0, sizeof(*wb));
>  
> -	if (wb != &bdi->wb)
> -		bdi_get(bdi);
>  	wb->bdi = bdi;
>  	wb->last_old_flush = jiffies;
>  	INIT_LIST_HEAD(&wb->b_dirty);
> @@ -316,7 +314,7 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
>  
>  	err = fprop_local_init_percpu(&wb->completions, gfp);
>  	if (err)
> -		goto out_put_bdi;
> +		return err;
>  
>  	for (i = 0; i < NR_WB_STAT_ITEMS; i++) {
>  		err = percpu_counter_init(&wb->stat[i], 0, gfp);
> @@ -330,9 +328,6 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
>  	while (i--)
>  		percpu_counter_destroy(&wb->stat[i]);
>  	fprop_local_destroy_percpu(&wb->completions);
> -out_put_bdi:
> -	if (wb != &bdi->wb)
> -		bdi_put(bdi);
>  	return err;
>  }
>  
> @@ -373,8 +368,6 @@ static void wb_exit(struct bdi_writeback *wb)
>  		percpu_counter_destroy(&wb->stat[i]);
>  
>  	fprop_local_destroy_percpu(&wb->completions);
> -	if (wb != &wb->bdi->wb)
> -		bdi_put(wb->bdi);
>  }
>  
>  #ifdef CONFIG_CGROUP_WRITEBACK
> @@ -397,6 +390,7 @@ static void cgwb_release_workfn(struct work_struct *work)
>  	struct bdi_writeback *wb = container_of(work, struct bdi_writeback,
>  						release_work);
>  	struct blkcg *blkcg = css_to_blkcg(wb->blkcg_css);
> +	struct backing_dev_info *bdi = wb->bdi;
>  
>  	mutex_lock(&wb->bdi->cgwb_release_mutex);
>  	wb_shutdown(wb);
> @@ -416,6 +410,7 @@ static void cgwb_release_workfn(struct work_struct *work)
>  
>  	percpu_ref_exit(&wb->refcnt);
>  	wb_exit(wb);
> +	bdi_put(bdi);
>  	WARN_ON_ONCE(!list_empty(&wb->b_attached));
>  	kfree_rcu(wb, rcu);
>  }
> @@ -497,6 +492,7 @@ static int cgwb_create(struct backing_dev_info *bdi,
>  	INIT_LIST_HEAD(&wb->b_attached);
>  	INIT_WORK(&wb->release_work, cgwb_release_workfn);
>  	set_bit(WB_registered, &wb->state);
> +	bdi_get(bdi);
>  
>  	/*
>  	 * The root wb determines the registered state of the whole bdi and
> @@ -528,6 +524,7 @@ static int cgwb_create(struct backing_dev_info *bdi,
>  	goto out_put;
>  
>  err_fprop_exit:
> +	bdi_put(bdi);
>  	fprop_local_destroy_percpu(&wb->memcg_completions);
>  err_ref_exit:
>  	percpu_ref_exit(&wb->refcnt);
> -- 
> 2.30.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2021-10-22  9:02 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 12:44 simplify bdi unregistation Christoph Hellwig
2021-10-21 12:44 ` Christoph Hellwig
2021-10-21 12:44 ` [PATCH 1/5] mm: export bdi_unregister Christoph Hellwig
2021-10-21 12:44   ` Christoph Hellwig
2021-10-22  8:41   ` Jan Kara
2021-10-22  8:41     ` Jan Kara
2021-10-21 12:44 ` [PATCH 2/5] mtd: call bdi_unregister explicitly Christoph Hellwig
2021-10-21 12:44   ` Christoph Hellwig
2021-10-22  8:43   ` Jan Kara
2021-10-22  8:43     ` Jan Kara
2021-10-21 12:44 ` [PATCH 3/5] fs: explicitly unregister per-superblock BDIs Christoph Hellwig
2021-10-21 12:44   ` Christoph Hellwig
2021-10-22  8:48   ` Jan Kara
2021-10-22  8:48     ` Jan Kara
2021-10-21 12:44 ` [PATCH 4/5] mm: don't automatically unregister bdis Christoph Hellwig
2021-10-21 12:44   ` Christoph Hellwig
2021-10-22  8:51   ` Jan Kara
2021-10-22  8:51     ` Jan Kara
2021-10-21 12:44 ` [PATCH 5/5] mm: simplify bdi refcounting Christoph Hellwig
2021-10-21 12:44   ` Christoph Hellwig
2021-10-22  9:02   ` Jan Kara [this message]
2021-10-22  9:02     ` Jan Kara
2021-10-27  7:42     ` Christoph Hellwig
2021-10-27  7:42       ` Christoph Hellwig
2021-10-27  9:47       ` Jan Kara
2021-10-27  9:47         ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211022090203.GF1026@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.