Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp460325imu; Mon, 26 Nov 2018 13:22:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VOgp4fpJeCOUcVqjzD/guk7razqXPRmvwLGpjzdAuLnTXUfWCLSv2i5u6COlZ/mykzTggX X-Received: by 2002:a65:6392:: with SMTP id h18mr27009960pgv.107.1543267349426; Mon, 26 Nov 2018 13:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543267349; cv=none; d=google.com; s=arc-20160816; b=sO5oLwJYh+cPwb0wQXFHvxTokAbdm8LknLDMIA6ItAn9I0tjddOIhh4naUlHPnfpkF XF/FD3xft/aLdpkqRK9lTSGDt0Dxnzq0GiQT02lZuqtDutcDG/wAuDUGuBiSmZrMLQob ymSJ0fllH1sMRJegoT1tB0uDvkekwIc12VmEnSSlZydeFZ3fUgGqWLfWHNobe7fy+obL 11lCpR1l4bMVDsuNpX+3yuoX6boDHZPaDLpwE4bvpUMCKarJ0XUydD7lLe2RQ1sDhXyd rf8Iz9y0+mpjOxL6bCvbNLj70PMtBQ4TmVutAlv2t5Rmiq/109jAsTJNjQXso2zDLEwG ZjUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BZvs5OryDI6sX+Ah4z4QS3SeAhV6AtbGXkw3bMhIx54=; b=PDaJYl7lTZIiszSz6ves19/mjxEW7FxYCQrduJj+LM1v2vm+1/mhXEJ8Ut4/qWUWuy wL91+tNGVX/3HYqqH5RARORN9/L8xHCeuLto65Zv1bvKgbDqAD9/0E4u+llgB0MppbZ3 g7kDT22i0za/iFs3PMHoU2/rJ34XNwrI3kQ/OooKTWMPja4kAEtaiOK6gnyKIiBWtBuA qzQ5HWLoKIBFCsffLM4pk6++9OSkCVUbITbCTG8qYDesLn+KP1KSnQvFF9AjqvpwV7GN xCi/2iC9gSQTcGj6/28R7nCtkHBYx32j1pzmfz9JYWat0Be1AQnDHS5ctbOy2puDmM8h OsFQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15si1376818pgf.321.2018.11.26.13.22.13; Mon, 26 Nov 2018 13:22:29 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727348AbeK0IPW (ORCPT + 99 others); Tue, 27 Nov 2018 03:15:22 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:38595 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726296AbeK0IPV (ORCPT ); Tue, 27 Nov 2018 03:15:21 -0500 Received: by mail-yb1-f195.google.com with SMTP id u103-v6so8141658ybi.5; Mon, 26 Nov 2018 13:19:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BZvs5OryDI6sX+Ah4z4QS3SeAhV6AtbGXkw3bMhIx54=; b=JNaUGzOsoZ6rO39laoaQ1Di0LIqYc6ErY4Uu8nRLvBeIx0CWmicfhVdKRAsvxXFS43 D6cfOD+xFVFXqklcFw9wlqtAAzZkIT1NiOAQWVAZk3JcslsfcJXt3pzY0a9M65R3Kg/B /6dzhJUrC0pxhpFMhP6pov73qZmmf99WY3V5mFLmQa7kbcyYsG8JklXOtPpcuA2hOWaN cWtHhzJZw6THGy4nTkCcpjn3Gm7NVxx1KPFvbEMmHiLzwEJxYLedPVQ4wFLw/uMClf7n 8ZPYo/op5t8P03JjVaZSsDlWd83OD3U6Hgk32akjVb2J6owgz3lsZnTOjgMjjCg+iXaW mBEw== X-Gm-Message-State: AA+aEWZ/FqQNqElHyI4m4EP2MkdU56UC+T+fMsO9Rkr3N2L6wxVOBDGP m7VPDlmWVmNgu/t4rHus1WE= X-Received: by 2002:a5b:1c3:: with SMTP id f3-v6mr25575767ybp.267.1543267194545; Mon, 26 Nov 2018 13:19:54 -0800 (PST) Received: from dennisz-mbp.thefacebook.com ([199.201.65.135]) by smtp.gmail.com with ESMTPSA id d135-v6sm495462ywh.43.2018.11.26.13.19.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Nov 2018 13:19:53 -0800 (PST) From: Dennis Zhou To: Jens Axboe , Tejun Heo , Johannes Weiner , Josef Bacik Cc: kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 02/13] blkcg: update blkg_lookup_create() to do locking Date: Mon, 26 Nov 2018 16:19:35 -0500 Message-Id: <20181126211946.77067-3-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20181126211946.77067-1-dennis@kernel.org> References: <20181126211946.77067-1-dennis@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To know when to create a blkg, the general pattern is to do a blkg_lookup() and if that fails, lock and do the lookup again, and if that fails finally create. It doesn't make much sense for everyone who wants to do creation to write this themselves. This changes blkg_lookup_create() to do locking and implement this pattern. The old blkg_lookup_create() is renamed to __blkg_lookup_create(). If a call site wants to do its own error handling or already owns the queue lock, they can use __blkg_lookup_create(). This will be used in upcoming patches. Signed-off-by: Dennis Zhou Reviewed-by: Josef Bacik Acked-by: Tejun Heo Reviewed-by: Liu Bo --- block/blk-cgroup.c | 30 +++++++++++++++++++++++++++--- block/blk-iolatency.c | 2 +- include/linux/blk-cgroup.h | 4 +++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 63d226a084cd..b1ec98eeeae0 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -249,7 +249,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 - lookup blkg, try to create one if not there * @blkcg: blkcg of interest * @q: request_queue of interest * @@ -262,8 +262,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(struct blkcg *blkcg, + struct request_queue *q) { struct blkcg_gq *blkg; @@ -293,6 +293,30 @@ struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, } } +/** + * 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. + */ +struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, + struct request_queue *q) +{ + struct blkcg_gq *blkg = blkg_lookup(blkcg, q); + + if (unlikely(!blkg)) { + spin_lock_irq(&q->queue_lock); + + blkg = __blkg_lookup_create(blkcg, q); + + spin_unlock_irq(&q->queue_lock); + } + + return blkg; +} + static void blkg_destroy(struct blkcg_gq *blkg) { struct blkcg *blkcg = blkg->blkcg; diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c index fe0c4ca312ff..e6f68f15dee9 100644 --- a/block/blk-iolatency.c +++ b/block/blk-iolatency.c @@ -486,7 +486,7 @@ static void blkcg_iolatency_throttle(struct rq_qos *rqos, struct bio *bio) blkg = blkg_lookup(blkcg, q); if (unlikely(!blkg)) { spin_lock_irq(&q->queue_lock); - blkg = blkg_lookup_create(blkcg, q); + blkg = __blkg_lookup_create(blkcg, q); if (IS_ERR(blkg)) blkg = NULL; spin_unlock_irq(&q->queue_lock); diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index db8214047486..49f399cfb0b6 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -181,6 +181,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(struct blkcg *blkcg, struct request_queue *q); int blkcg_init_queue(struct request_queue *q); @@ -799,7 +801,7 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q, blkg = blkg_lookup(blkcg, q); if (unlikely(!blkg)) { spin_lock_irq(&q->queue_lock); - blkg = blkg_lookup_create(blkcg, q); + blkg = __blkg_lookup_create(blkcg, q); if (IS_ERR(blkg)) blkg = NULL; spin_unlock_irq(&q->queue_lock); -- 2.17.1