Received: by 10.223.164.202 with SMTP id h10csp311112wrb; Tue, 14 Nov 2017 16:01:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMaPeeQkh0Xr7SvoxulVc+we1GaO3LCoWec1DnCSNgW760XtLvoQrsZoLUQg95DiCopMOWwz X-Received: by 10.99.127.67 with SMTP id p3mr13794629pgn.321.1510704079093; Tue, 14 Nov 2017 16:01:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510704079; cv=none; d=google.com; s=arc-20160816; b=oFYw0cto0tkLyuT0NQZ4bUYk8FJ91EiKUPGWnqH+sJIjgNXYcIz8rl57gz0CaSCWpq TOp2mKeO+Cpi6eVPx1IHC27xkk4BRuDV2RqHOI7HNQ+en5InYtid9X64602LfvM8/PnC 7lNeD5vqbAeVTi30UxJsvSS4eHv1CkLPuk8Nd2RlforsTR0tMgRbPePmQBdxEkK25ejQ 9pRhk0MGYPkxEyDnOcuoAafmKtjcmKiC09zAX5iLJJAYcGNsDW71tirpcWGSrkPncz5g E/GKHIw41Nn2d9ZPNWFO5fYGdLYUy73emFly5K/PYm2Sgv87aG6+kyeFdrpgAtdutQln 2+iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:arc-authentication-results; bh=vuBDfwltCF2PZQsxnqbbJT4xNBqOJhnsANCR1B0+u34=; b=U7VT8VAzTGKrtjIFkvBPYbaweus//so3SmlvRdi55exOSxvHJVXnSb/MvYFS/NYUU2 Xr9js3hzJZMZPbbPYLGdgW5DSSoKmcLqbaDvvRtdUFG65DVNHNrN8zWP0P39YqYM/UKI zmWEA5thjHGbNNY0LNzR3ivco/RJ4Lrja8AcBEww2ULg8UHkA7MpfzlKs0zkX3Vs5sOE GN4hmQhANjZVpaXhiGpF7lD4yf3kj0d3mHMJHU9+ABFj/628LrsnSzfwwpFsh+++Tgrd pZ8K6cOUOOWkYuf+XXDy6NYsT9H4djXn6OR5OE3kvtFoNSs7fCYvJDDYTMI5+QD1Qsb7 yN3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f30si16808283plf.535.2017.11.14.16.01.06; Tue, 14 Nov 2017 16:01:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756818AbdKNXSc (ORCPT + 87 others); Tue, 14 Nov 2017 18:18:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:50500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753823AbdKNXS1 (ORCPT ); Tue, 14 Nov 2017 18:18:27 -0500 Received: from kernel.org (unknown [199.201.64.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 86D2721872; Tue, 14 Nov 2017 23:18:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86D2721872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=shli@kernel.org Date: Tue, 14 Nov 2017 15:18:25 -0800 From: Shaohua Li To: Tejun Heo Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org, kernel-team@fb.com, lizefan@huawei.com, hannes@cmpxchg.org, cgroups@vger.kernel.org, guro@fb.com Subject: Re: [PATCH 4/7] blkcg: refactor blkcg_gq lookup and creation in blkcg_bio_issue_check() Message-ID: <20171114231825.3iq7sz4wbmphww5i@kernel.org> References: <20171112222613.3613362-1-tj@kernel.org> <20171112222613.3613362-5-tj@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171112222613.3613362-5-tj@kernel.org> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 12, 2017 at 02:26:10PM -0800, Tejun Heo wrote: > blkcg_bio_issue_check() open codes blkcg_gq lookup and creation using > blkg_lookup() and blkg_lookup_create(). Refactor the code so that > > * blkg_lookup_create() is renamed to blkcg_lookup_create_locked(). > > * blkg_lookup_create() is now a new function which encapsulates the > RCU protected lookup and queue_locked protected creation. > > * blkg_lookup_create() is guaranteed to return a non-NULL blkcg_gq. > The NULL checks are removed from the users. > > This is pure refactoring and doesn't introduce any functional changes. > > Signed-off-by: Tejun Heo Reviewed-by: Shaohua Li > --- > block/blk-cgroup.c | 6 +++--- > block/blk-throttle.c | 2 +- > include/linux/blk-cgroup.h | 32 +++++++++++++++++++++----------- > 3 files changed, 25 insertions(+), 15 deletions(-) > > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c > index 60a4486..490b0a6 100644 > --- a/block/blk-cgroup.c > +++ b/block/blk-cgroup.c > @@ -290,7 +290,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, > } > > /** > - * blkg_lookup_create - lookup blkg, try to create one if not there > + * blkg_lookup_create_locked - lookup blkg, try to create one if not there > * @blkcg: blkcg of interest > * @q: request_queue of interest > * > @@ -303,8 +303,8 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg, > * value on error. If @q is dead, returns ERR_PTR(-EINVAL). If @q is not > * dead and bypassing, returns ERR_PTR(-EBUSY). > */ > -struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, > - struct request_queue *q) > +struct blkcg_gq *blkg_lookup_create_locked(struct blkcg *blkcg, > + struct request_queue *q) > { > struct blkcg_gq *blkg; > > diff --git a/block/blk-throttle.c b/block/blk-throttle.c > index 8631763..1e6916b 100644 > --- a/block/blk-throttle.c > +++ b/block/blk-throttle.c > @@ -2123,7 +2123,7 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, > struct bio *bio) > { > struct throtl_qnode *qn = NULL; > - struct throtl_grp *tg = blkg_to_tg(blkg ?: q->root_blkg); > + struct throtl_grp *tg = blkg_to_tg(blkg); > struct throtl_service_queue *sq; > bool rw = bio_data_dir(bio); > bool throttled = false; > diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h > index b5721d32..1de5158 100644 > --- a/include/linux/blk-cgroup.h > +++ b/include/linux/blk-cgroup.h > @@ -172,8 +172,8 @@ extern struct cgroup_subsys_state * const blkcg_root_css; > > struct blkcg_gq *blkg_lookup_slowpath(struct blkcg *blkcg, > struct request_queue *q, bool update_hint); > -struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, > - struct request_queue *q); > +struct blkcg_gq *blkg_lookup_create_locked(struct blkcg *blkcg, > + struct request_queue *q); > int blkcg_init_queue(struct request_queue *q); > void blkcg_drain_queue(struct request_queue *q); > void blkcg_exit_queue(struct request_queue *q); > @@ -680,6 +680,24 @@ static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg > struct bio *bio) { return false; } > #endif > > +static inline struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, > + struct request_queue *q) > +{ > + struct blkcg_gq *blkg; > + > + blkg = blkg_lookup(blkcg, q); > + if (likely(blkg)) > + return blkg; > + > + spin_lock_irq(q->queue_lock); > + blkg = blkg_lookup_create_locked(blkcg, q); > + spin_unlock_irq(q->queue_lock); > + if (likely(!IS_ERR(blkg))) > + return blkg; > + else > + return q->root_blkg; > +} > + > static inline bool blkcg_bio_issue_check(struct request_queue *q, > struct bio *bio) > { > @@ -693,19 +711,11 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q, > /* associate blkcg if bio hasn't attached one */ > bio_associate_blkcg(bio, &blkcg->css); > > - blkg = blkg_lookup(blkcg, q); > - if (unlikely(!blkg)) { > - spin_lock_irq(q->queue_lock); > - blkg = blkg_lookup_create(blkcg, q); > - if (IS_ERR(blkg)) > - blkg = NULL; > - spin_unlock_irq(q->queue_lock); > - } > + blkg = blkg_lookup_create(blkcg, q); > > throtl = blk_throtl_bio(q, blkg, bio); > > if (!throtl) { > - blkg = blkg ?: q->root_blkg; > blkg_rwstat_add(&blkg->stat_bytes, bio->bi_opf, > bio->bi_iter.bi_size); > blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1); > -- > 2.9.5 > From 1583901091567037028@xxx Sun Nov 12 22:29:50 +0000 2017 X-GM-THRID: 1583901091567037028 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread