public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Herrmann <aherrmann@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Tejun Heo <tj@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org
Subject: Re: [PATCH 17/17] blk-cgroup: pass a gendisk to the blkg allocation helpers
Date: Fri, 23 Sep 2022 09:03:44 +0200	[thread overview]
Message-ID: <Yy1aUP/EFXhL1zHR@suselix> (raw)
In-Reply-To: <20220921180501.1539876-18-hch@lst.de>

On Wed, Sep 21, 2022 at 08:05:01PM +0200, Christoph Hellwig wrote:
> Prepare for storing the blkcg information in the gendisk instead of
> the request_queue.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  block/blk-cgroup.c | 56 +++++++++++++++++++++++-----------------------
>  1 file changed, 28 insertions(+), 28 deletions(-)

Reviewed-by: Andreas Herrmann <aherrmann@suse.de>

> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index fc82057db9629..94af5f3f3620b 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -202,19 +202,19 @@ static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
>  /**
>   * blkg_alloc - allocate a blkg
>   * @blkcg: block cgroup the new blkg is associated with
> - * @q: request_queue the new blkg is associated with
> + * @disk: gendisk the new blkg is associated with
>   * @gfp_mask: allocation mask to use
>   *
>   * Allocate a new blkg assocating @blkcg and @q.
>   */
> -static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
> +static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
>  				   gfp_t gfp_mask)
>  {
>  	struct blkcg_gq *blkg;
>  	int i, cpu;
>  
>  	/* alloc and init base part */
> -	blkg = kzalloc_node(sizeof(*blkg), gfp_mask, q->node);
> +	blkg = kzalloc_node(sizeof(*blkg), gfp_mask, disk->queue->node);
>  	if (!blkg)
>  		return NULL;
>  
> @@ -225,10 +225,10 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
>  	if (!blkg->iostat_cpu)
>  		goto err_free;
>  
> -	if (!blk_get_queue(q))
> +	if (!blk_get_queue(disk->queue))
>  		goto err_free;
>  
> -	blkg->q = q;
> +	blkg->q = disk->queue;
>  	INIT_LIST_HEAD(&blkg->q_node);
>  	spin_lock_init(&blkg->async_bio_lock);
>  	bio_list_init(&blkg->async_bios);
> @@ -243,11 +243,11 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
>  		struct blkcg_policy *pol = blkcg_policy[i];
>  		struct blkg_policy_data *pd;
>  
> -		if (!blkcg_policy_enabled(q, pol))
> +		if (!blkcg_policy_enabled(disk->queue, pol))
>  			continue;
>  
>  		/* alloc per-policy data and attach it to blkg */
> -		pd = pol->pd_alloc_fn(gfp_mask, q, blkcg);
> +		pd = pol->pd_alloc_fn(gfp_mask, disk->queue, blkcg);
>  		if (!pd)
>  			goto err_free;
>  
> @@ -275,17 +275,16 @@ static void blkg_update_hint(struct blkcg *blkcg, struct blkcg_gq *blkg)
>   * If @new_blkg is %NULL, this function tries to allocate a new one as
>   * necessary using %GFP_NOWAIT.  @new_blkg is always consumed on return.
>   */
> -static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
> -				    struct request_queue *q,
> +static struct blkcg_gq *blkg_create(struct blkcg *blkcg, struct gendisk *disk,
>  				    struct blkcg_gq *new_blkg)
>  {
>  	struct blkcg_gq *blkg;
>  	int i, ret;
>  
> -	lockdep_assert_held(&q->queue_lock);
> +	lockdep_assert_held(&disk->queue->queue_lock);
>  
>  	/* request_queue is dying, do not create/recreate a blkg */
> -	if (blk_queue_dying(q)) {
> +	if (blk_queue_dying(disk->queue)) {
>  		ret = -ENODEV;
>  		goto err_free_blkg;
>  	}
> @@ -298,7 +297,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
>  
>  	/* allocate */
>  	if (!new_blkg) {
> -		new_blkg = blkg_alloc(blkcg, q, GFP_NOWAIT | __GFP_NOWARN);
> +		new_blkg = blkg_alloc(blkcg, disk, GFP_NOWAIT | __GFP_NOWARN);
>  		if (unlikely(!new_blkg)) {
>  			ret = -ENOMEM;
>  			goto err_put_css;
> @@ -308,7 +307,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
>  
>  	/* link parent */
>  	if (blkcg_parent(blkcg)) {
> -		blkg->parent = blkg_lookup(blkcg_parent(blkcg), q);
> +		blkg->parent = blkg_lookup(blkcg_parent(blkcg), disk->queue);
>  		if (WARN_ON_ONCE(!blkg->parent)) {
>  			ret = -ENODEV;
>  			goto err_put_css;
> @@ -326,10 +325,10 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
>  
>  	/* insert */
>  	spin_lock(&blkcg->lock);
> -	ret = radix_tree_insert(&blkcg->blkg_tree, q->id, blkg);
> +	ret = radix_tree_insert(&blkcg->blkg_tree, disk->queue->id, blkg);
>  	if (likely(!ret)) {
>  		hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
> -		list_add(&blkg->q_node, &q->blkg_list);
> +		list_add(&blkg->q_node, &disk->queue->blkg_list);
>  
>  		for (i = 0; i < BLKCG_MAX_POLS; i++) {
>  			struct blkcg_policy *pol = blkcg_policy[i];
> @@ -358,19 +357,20 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
>  /**
>   * blkg_lookup_create - lookup blkg, try to create one if not there
>   * @blkcg: blkcg of interest
> - * @q: request_queue of interest
> + * @disk: gendisk of interest
>   *
> - * Lookup blkg for the @blkcg - @q pair.  If it doesn't exist, try to
> + * Lookup blkg for the @blkcg - @disk pair.  If it doesn't exist, try to
>   * create one.  blkg creation is performed recursively from blkcg_root such
>   * that all non-root blkg's have access to the parent blkg.  This function
> - * should be called under RCU read lock and takes @q->queue_lock.
> + * should be called under RCU read lock and takes @disk->queue->queue_lock.
>   *
>   * Returns the blkg or the closest blkg if blkg_create() fails as it walks
>   * down from root.
>   */
>  static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
> -		struct request_queue *q)
> +		struct gendisk *disk)
>  {
> +	struct request_queue *q = disk->queue;
>  	struct blkcg_gq *blkg;
>  	unsigned long flags;
>  
> @@ -408,7 +408,7 @@ static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
>  			parent = blkcg_parent(parent);
>  		}
>  
> -		blkg = blkg_create(pos, q, NULL);
> +		blkg = blkg_create(pos, disk, NULL);
>  		if (IS_ERR(blkg)) {
>  			blkg = ret_blkg;
>  			break;
> @@ -652,6 +652,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
>  	__acquires(rcu) __acquires(&bdev->bd_queue->queue_lock)
>  {
>  	struct block_device *bdev;
> +	struct gendisk *disk;
>  	struct request_queue *q;
>  	struct blkcg_gq *blkg;
>  	int ret;
> @@ -659,8 +660,8 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
>  	bdev = blkcg_conf_open_bdev(&input);
>  	if (IS_ERR(bdev))
>  		return PTR_ERR(bdev);
> -
> -	q = bdev_get_queue(bdev);
> +	disk = bdev->bd_disk;
> +	q = disk->queue;
>  
>  	/*
>  	 * blkcg_deactivate_policy() requires queue to be frozen, we can grab
> @@ -703,7 +704,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
>  		spin_unlock_irq(&q->queue_lock);
>  		rcu_read_unlock();
>  
> -		new_blkg = blkg_alloc(pos, q, GFP_KERNEL);
> +		new_blkg = blkg_alloc(pos, disk, GFP_KERNEL);
>  		if (unlikely(!new_blkg)) {
>  			ret = -ENOMEM;
>  			goto fail_exit_queue;
> @@ -729,7 +730,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
>  			blkg_update_hint(pos, blkg);
>  			blkg_free(new_blkg);
>  		} else {
> -			blkg = blkg_create(pos, q, new_blkg);
> +			blkg = blkg_create(pos, disk, new_blkg);
>  			if (IS_ERR(blkg)) {
>  				ret = PTR_ERR(blkg);
>  				goto fail_preloaded;
> @@ -1234,7 +1235,7 @@ int blkcg_init_disk(struct gendisk *disk)
>  
>  	INIT_LIST_HEAD(&q->blkg_list);
>  
> -	new_blkg = blkg_alloc(&blkcg_root, q, GFP_KERNEL);
> +	new_blkg = blkg_alloc(&blkcg_root, disk, GFP_KERNEL);
>  	if (!new_blkg)
>  		return -ENOMEM;
>  
> @@ -1243,7 +1244,7 @@ int blkcg_init_disk(struct gendisk *disk)
>  	/* Make sure the root blkg exists. */
>  	/* spin_lock_irq can serve as RCU read-side critical section. */
>  	spin_lock_irq(&q->queue_lock);
> -	blkg = blkg_create(&blkcg_root, q, new_blkg);
> +	blkg = blkg_create(&blkcg_root, disk, new_blkg);
>  	if (IS_ERR(blkg))
>  		goto err_unlock;
>  	q->root_blkg = blkg;
> @@ -1860,8 +1861,7 @@ static inline struct blkcg_gq *blkg_tryget_closest(struct bio *bio,
>  	struct blkcg_gq *blkg, *ret_blkg = NULL;
>  
>  	rcu_read_lock();
> -	blkg = blkg_lookup_create(css_to_blkcg(css),
> -				  bdev_get_queue(bio->bi_bdev));
> +	blkg = blkg_lookup_create(css_to_blkcg(css), bio->bi_bdev->bd_disk);
>  	while (blkg) {
>  		if (blkg_tryget(blkg)) {
>  			ret_blkg = blkg;
> -- 
> 2.30.2
> 

-- 
Regards,
Andreas

SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nürnberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman
(HRB 36809, AG Nürnberg)

  reply	other threads:[~2022-09-23  7:03 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21 18:04 blk-cgroup cleanups Christoph Hellwig
2022-09-21 18:04 ` [PATCH 01/17] blk-cgroup: fix error unwinding in blkcg_init_queue Christoph Hellwig
2022-09-22 13:00   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 02/17] blk-cgroup: remove blk_queue_root_blkg Christoph Hellwig
2022-09-22 13:03   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 03/17] blk-cgroup: remove open coded blkg_lookup instances Christoph Hellwig
2022-09-22 13:17   ` Andreas Herrmann
2022-09-26 20:56   ` Tejun Heo
2022-09-21 18:04 ` [PATCH 04/17] blk-cgroup: cleanup the blkg_lookup family of functions Christoph Hellwig
2022-09-22 14:15   ` Andreas Herrmann
2022-09-26 20:58   ` Tejun Heo
2022-09-21 18:04 ` [PATCH 05/17] blk-cgroup: remove blkg_lookup_check Christoph Hellwig
2022-09-22 14:16   ` Andreas Herrmann
2022-09-26 21:18   ` Tejun Heo
2022-09-21 18:04 ` [PATCH 06/17] blk-cgroup: pass a gendisk to blkcg_init_queue and blkcg_exit_queue Christoph Hellwig
2022-09-22 13:34   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 07/17] blk-ioprio: pass a gendisk to blk_ioprio_init and blk_ioprio_exit Christoph Hellwig
2022-09-22 13:38   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 08/17] blk-iolatency: pass a gendisk to blk_iolatency_init Christoph Hellwig
2022-09-22 13:40   ` Andreas Herrmann
2022-09-27  1:19   ` Jens Axboe
2022-09-21 18:04 ` [PATCH 09/17] blk-iocost: simplify ioc_name Christoph Hellwig
2022-09-22 12:10   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 10/17] blk-iocost: pass a gendisk to blk_iocost_init Christoph Hellwig
2022-09-22 12:11   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 11/17] blk-iocost: cleanup ioc_qos_write Christoph Hellwig
2022-09-22 12:11   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 12/17] blk-throttle: pass a gendisk to blk_throtl_init and blk_throtl_exit Christoph Hellwig
2022-09-23  6:38   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 13/17] blk-throttle: pass a gendisk to blk_throtl_register_queue Christoph Hellwig
2022-09-23  6:39   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 14/17] blk-throttle: pass a gendisk to blk_throtl_cancel_bios Christoph Hellwig
2022-09-23  6:42   ` Andreas Herrmann
2022-09-21 18:04 ` [PATCH 15/17] blk-cgroup: pass a gendisk to blkg_destroy_all Christoph Hellwig
2022-09-22 13:42   ` Andreas Herrmann
2022-09-21 18:05 ` [PATCH 16/17] blk-cgroup: pass a gendisk to blkcg_schedule_throttle Christoph Hellwig
2022-09-22 14:21   ` Andreas Herrmann
2022-09-21 18:05 ` [PATCH 17/17] blk-cgroup: pass a gendisk to the blkg allocation helpers Christoph Hellwig
2022-09-23  7:03   ` Andreas Herrmann [this message]
2022-09-26 21:26 ` blk-cgroup cleanups Tejun Heo
2022-09-27  1:19 ` Jens Axboe

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=Yy1aUP/EFXhL1zHR@suselix \
    --to=aherrmann@suse.de \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=tj@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox