linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>, Tejun Heo <tj@kernel.org>
Cc: Dennis Zhou <dennis@kernel.org>, Li Zefan <lizefan@huawei.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	dm-devel@redhat.com, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	linux-mm@kvack.org
Subject: [PATCH 07/14] block: merge blkg_lookup_create and __blkg_lookup_create
Date: Sat, 27 Jun 2020 09:31:52 +0200	[thread overview]
Message-ID: <20200627073159.2447325-8-hch@lst.de> (raw)
In-Reply-To: <20200627073159.2447325-1-hch@lst.de>

No good reason to keep these two functions split.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-cgroup.c | 49 +++++++++++++++++-----------------------------
 1 file changed, 18 insertions(+), 31 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index bb0607bfd771cd..6aedb73ffbf473 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -316,30 +316,35 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
 }
 
 /**
- * __blkg_lookup_create - lookup blkg, try to create one if not there
+ * blkg_lookup_create - lookup blkg, try to create one if not there
  * @blkcg: blkcg of interest
  * @q: request_queue of interest
  *
  * Lookup blkg for the @blkcg - @q 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 @q->queue_lock.
+ * should be called under RCU read lock and takes @q->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)
+static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
+		struct request_queue *q)
 {
 	struct blkcg_gq *blkg;
+	unsigned long flags;
 
 	WARN_ON_ONCE(!rcu_read_lock_held());
-	lockdep_assert_held(&q->queue_lock);
 
-	blkg = __blkg_lookup(blkcg, q, true);
+	blkg = blkg_lookup(blkcg, q);
 	if (blkg)
 		return blkg;
 
+	spin_lock_irqsave(&q->queue_lock, flags);
+	blkg = __blkg_lookup(blkcg, q, true);
+	if (blkg)
+		goto found;
+
 	/*
 	 * Create blkgs walking down from blkcg_root to @blkcg, so that all
 	 * non-root blkgs have access to their parents.  Returns the closest
@@ -362,34 +367,16 @@ static struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg,
 		}
 
 		blkg = blkg_create(pos, q, NULL);
-		if (IS_ERR(blkg))
-			return ret_blkg;
+		if (IS_ERR(blkg)) {
+			blkg = ret_blkg;
+			break;
+		}
 		if (pos == blkcg)
-			return blkg;
-	}
-}
-
-/**
- * blkg_lookup_create - find or create a blkg
- * @blkcg: target block cgroup
- * @q: target request_queue
- *
- * This looks up or creates the blkg representing the unique pair
- * of the blkcg and the request_queue.
- */
-static struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
-				    struct request_queue *q)
-{
-	struct blkcg_gq *blkg = blkg_lookup(blkcg, q);
-
-	if (unlikely(!blkg)) {
-		unsigned long flags;
-
-		spin_lock_irqsave(&q->queue_lock, flags);
-		blkg = __blkg_lookup_create(blkcg, q);
-		spin_unlock_irqrestore(&q->queue_lock, flags);
+			break;
 	}
 
+found:
+	spin_unlock_irqrestore(&q->queue_lock, flags);
 	return blkg;
 }
 
-- 
2.26.2


  parent reply	other threads:[~2020-06-27  7:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-27  7:31 drive-by blk-cgroup cleanups Christoph Hellwig
2020-06-27  7:31 ` [PATCH 01/14] dm: use bio_uninit instead of bio_disassociate_blkg Christoph Hellwig
2020-06-29  9:31   ` Johannes Thumshirn
2020-07-08 14:02   ` Mike Snitzer
2020-06-27  7:31 ` [PATCH 02/14] block: remove bio_disassociate_blkg Christoph Hellwig
2020-06-29  9:33   ` Johannes Thumshirn
2020-06-27  7:31 ` [PATCH 03/14] block: really clone the block cgroup in bio_clone_blkg_association Christoph Hellwig
2020-06-29  9:37   ` Johannes Thumshirn
2020-06-27  7:31 ` [PATCH 04/14] block: merge __bio_associate_blkg into bio_associate_blkg_from_css Christoph Hellwig
2020-06-29  9:55   ` Johannes Thumshirn
2020-06-27  7:31 ` [PATCH 05/14] block: move bio_associate_blkg_from_page to mm/page_io.c Christoph Hellwig
2020-06-29  9:59   ` Johannes Thumshirn
2020-06-29 10:08   ` Johannes Thumshirn
2020-06-27  7:31 ` [PATCH 06/14] block: move the bio cgroup associatation helpers to blk-cgroup.c Christoph Hellwig
2020-06-29 11:51   ` Johannes Thumshirn
2020-06-27  7:31 ` Christoph Hellwig [this message]
2020-06-29 12:21   ` [PATCH 07/14] block: merge blkg_lookup_create and __blkg_lookup_create Johannes Thumshirn
2020-06-27  7:31 ` [PATCH 08/14] block: bypass blkg_tryget_closest for the root_blkg Christoph Hellwig
2020-06-27  7:31 ` [PATCH 09/14] block: move the initial blkg lookup into blkg_tryget_closest Christoph Hellwig
2020-06-27  7:31 ` [PATCH 10/14] blk-cgroup: remove the !bio->bi_blkg check in blkcg_bio_issue_check Christoph Hellwig
2020-06-27  7:31 ` [PATCH 11/14] cgroup: unexport cgroup_rstat_updated Christoph Hellwig
2020-06-27  7:31 ` [PATCH 12/14] blk-cgroup: move rcu locking from blkcg_bio_issue_check to blk_throtl_bio Christoph Hellwig
2020-06-27  7:31 ` [PATCH 13/14] blk-cgroup: remove blkcg_bio_issue_check Christoph Hellwig
2020-06-27  7:31 ` [PATCH 14/14] blk-cgroup: remove a dead check in blk_throtl_bio Christoph Hellwig
2020-06-29  8:05 ` drive-by blk-cgroup cleanups Johannes Thumshirn
2020-06-29  8:08   ` Christoph Hellwig
2020-06-29  8:12     ` Johannes Thumshirn
2020-06-29 13:56 ` Tejun Heo
2020-06-29 15:09 ` 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=20200627073159.2447325-8-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=dennis@kernel.org \
    --cc=dm-devel@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizefan@huawei.com \
    --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;
as well as URLs for NNTP newsgroup(s).