Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp922099imm; Tue, 5 Jun 2018 06:36:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJLtuMdkCjoFMDPqc/rYA1g4nkUvYxQVjEyEdwF0S0xXekOIxkxAJGvl1qYTe+vxXqsaf9F X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr26517418plg.170.1528205791884; Tue, 05 Jun 2018 06:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528205791; cv=none; d=google.com; s=arc-20160816; b=y74VRYFuvaKm8ibJwRcJpHsgORbh+wpPF3o5Bs9WFoHLP6kdcFTvZbPiUWOe3TPtuA pX5WgRzmkE6pWttXmPtWZgWZso+gO9tWL745pHnUtPF3K2DO6mhR9Wv2YIYu1GNwF4OR 8wcZGQj3JIAOd7WzdKWskQeTpLdsKW04JudoFeLljKz9L+CbKOU/JrvDu4xRrh8eSKiy JPR5uUgEIvWse+mCpMCi3V5swr1W3ReUhBM9ExQ1uT0iyUDBEH2Jq7XV3z5L+BhETOK9 M9cKTjp2ojhDx8A+Ri/rDcaw7cyBk5uxR734NZTLp0dUhRYdzLd5fzC6DZmNUZN9+iTe S1cA== 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:dkim-signature:arc-authentication-results; bh=DYjnlTNA/693YUK2Gqhsje8xLxjoBdeV8D140ceewns=; b=ZjZG0343dC6AiDseHBPqAiFn7fmpR5z7R4ky3WddH2gYy2SXlsRFzHZogQFRjMGOMe 52KvgnqoZw21OdPuR05Yy0RoVr60wsw2ZUz83Ti7JWhFa+gVVQMvd8MKOxN9cwYoCbxP jVJkVMBgH0iLX56vlBnVPBp3KEruLw+cGdzcfjhall0P7g9rvXJwtCVIsL0UVwi6UNxr pjdDNmIaI96K1Pth+5g3YLiTil16SVRgOvH3E5jTYp7oUsz+U+tpVscCSnBAGt8J8fow Y3w8rbXqTOD+gD6E+mQGh0zwXFXkI95DWckcVjp5j0KIH6qEFW9tSOkxWSaQdssaiq43 O4Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=XAM1eudY; 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 t69-v6si22262791pgd.55.2018.06.05.06.36.17; Tue, 05 Jun 2018 06:36:31 -0700 (PDT) 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; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=XAM1eudY; 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 S1752276AbeFENeE (ORCPT + 99 others); Tue, 5 Jun 2018 09:34:04 -0400 Received: from mail-qk0-f177.google.com ([209.85.220.177]:43692 "EHLO mail-qk0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbeFEN3x (ORCPT ); Tue, 5 Jun 2018 09:29:53 -0400 Received: by mail-qk0-f177.google.com with SMTP id g126-v6so1460711qke.10 for ; Tue, 05 Jun 2018 06:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DYjnlTNA/693YUK2Gqhsje8xLxjoBdeV8D140ceewns=; b=XAM1eudYWk/rUpP/B+Oy/XFF2F0BoG7rgFb8n4cV1TV3gG4MR4u2bRXcJB/QcycRbb 4rerANnT9GNWpAaXCPLv/pA9RXIKyrjm71gaXRo/xkAuBwxm97ccsNe/ZFozUajGp0l6 bxPMKYwlLW9KSE7d/gix0KJCeYPT+qq+clwtQZiHwI+1OiGm8xkoQdrAiAT73cEmee9h NDGQoqi435ZMYgDWHZt3qxxTw94o4hWySZKjwrt31n+VVGroFhtUXXZVqmqcTbK07VjN 9tBGx04+pOFWvDGg9HhiySD+rgADdf+1v73ukWoVbTntFX07WJ2I5Sp/aXD1ljrAYGNH WgoQ== 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=DYjnlTNA/693YUK2Gqhsje8xLxjoBdeV8D140ceewns=; b=Tv1I3F6HH5Oc+q46DVgD0mMIwzIFs4PVD78n6R3NOOMSiIjLXEC3CaCOzi0DHAn70d +Bb4rjd/o31LmTgainKxeO1DvELptVSmDOrsD3ioWY01+xJuoeOojvRraxPE9S79NPjX gyc8X0HUhWckhYPMddlT2YjdFT3j/f9GnxXYBCVc5aabhkaC5+M1w43r8o1UDo/ahjZx /MoAX568dtaxdcAK52ImrsHn/Ri1B0v6//gfKALBJweQxhSxw9ZuEloHEzSY/T8FCLGp s5+AN1iyJrc+oMrWwK/Ez89ri0xtgNKDygwLi7U1ng/oExrYPxfkaf8Gvi7N1zupS1A1 g49w== X-Gm-Message-State: APt69E33aY5uwZeX3sup6JSDrzr3uPN0C1RCtTuQe8AjOgd4gWC6tKIy /JeA1FqhaCED4zGd8hInu3oMcg== X-Received: by 2002:a37:17ea:: with SMTP id 103-v6mr21704655qkx.373.1528205392264; Tue, 05 Jun 2018 06:29:52 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id g56-v6sm20043486qta.83.2018.06.05.06.29.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:29:51 -0700 (PDT) From: Josef Bacik To: axboe@kernel.dk, kernel-team@fb.com, linux-block@vger.kernel.org, akpm@linux-foundation.org, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, linux-fsdevel@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 01/13] block: add bi_blkg to the bio for cgroups Date: Tue, 5 Jun 2018 09:29:36 -0400 Message-Id: <20180605132948.1664-2-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605132948.1664-1-josef@toxicpanda.com> References: <20180605132948.1664-1-josef@toxicpanda.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik Currently io.low uses a bi_cg_private to stash its private data for the blkg, however other blkcg policies may want to use this as well. Since we can get the private data out of the blkg, move this to bi_blkg in the bio and make it generic, then we can use bio_associate_blkg() to attach the blkg to the bio. Theoretically we could simply replace the bi_css with this since we can get to all the same information from the blkg, however you have to lookup the blkg, so for example wbc_init_bio() would have to lookup and possibly allocate the blkg for the css it was trying to attach to the bio. This could be problematic and result in us either not attaching the css at all to the bio, or falling back to the root blkcg if we are unable to allocate the corresponding blkg. So for now do this, and in the future if possible we could just replace the bi_css with bi_blkg and update the helpers to do the correct translation. Signed-off-by: Josef Bacik Acked-by: Tejun Heo --- block/bio.c | 23 +++++++++++++++++++++++ block/blk-throttle.c | 21 +++++++-------------- include/linux/bio.h | 1 + include/linux/blk_types.h | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/block/bio.c b/block/bio.c index 0a4df92cd689..57c4b1986e76 100644 --- a/block/bio.c +++ b/block/bio.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "blk.h" @@ -2026,6 +2027,24 @@ int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css) } EXPORT_SYMBOL_GPL(bio_associate_blkcg); +/** + * bio_associate_blkg - associate a bio with the specified blkg + * @bio: target bio + * @blkg: the blkg to associate + * + * Associate @bio with the blkg specified by @blkg. This is the queue specific + * blkcg information associated with the @bio, a reference will be taken on the + * @blkg and will be freed when the bio is freed. + */ +int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg) +{ + if (unlikely(bio->bi_blkg)) + return -EBUSY; + blkg_get(blkg); + bio->bi_blkg = blkg; + return 0; +} + /** * bio_disassociate_task - undo bio_associate_current() * @bio: target bio @@ -2040,6 +2059,10 @@ void bio_disassociate_task(struct bio *bio) css_put(bio->bi_css); bio->bi_css = NULL; } + if (bio->bi_blkg) { + blkg_put(bio->bi_blkg); + bio->bi_blkg = NULL; + } } /** diff --git a/block/blk-throttle.c b/block/blk-throttle.c index f63d88c92c3a..5112cef3166b 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2131,12 +2131,8 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td) static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio) { #ifdef CONFIG_BLK_DEV_THROTTLING_LOW - if (bio->bi_css) { - if (bio->bi_cg_private) - blkg_put(tg_to_blkg(bio->bi_cg_private)); - bio->bi_cg_private = tg; - blkg_get(tg_to_blkg(tg)); - } + if (bio->bi_css) + bio_associate_blkg(bio, tg_to_blkg(tg)); bio_issue_init(&bio->bi_issue, bio_sectors(bio)); #endif } @@ -2284,6 +2280,7 @@ void blk_throtl_stat_add(struct request *rq, u64 time_ns) void blk_throtl_bio_endio(struct bio *bio) { + struct blkcg_gq *blkg; struct throtl_grp *tg; u64 finish_time_ns; unsigned long finish_time; @@ -2291,20 +2288,18 @@ void blk_throtl_bio_endio(struct bio *bio) unsigned long lat; int rw = bio_data_dir(bio); - tg = bio->bi_cg_private; - if (!tg) + blkg = bio->bi_blkg; + if (!blkg) return; - bio->bi_cg_private = NULL; + tg = blkg_to_tg(blkg); finish_time_ns = ktime_get_ns(); tg->last_finish_time = finish_time_ns >> 10; start_time = bio_issue_time(&bio->bi_issue) >> 10; finish_time = __bio_issue_time(finish_time_ns) >> 10; - if (!start_time || finish_time <= start_time) { - blkg_put(tg_to_blkg(tg)); + if (!start_time || finish_time <= start_time) return; - } lat = finish_time - start_time; /* this is only for bio based driver */ @@ -2333,8 +2328,6 @@ void blk_throtl_bio_endio(struct bio *bio) tg->bio_cnt /= 2; tg->bad_bio_cnt /= 2; } - - blkg_put(tg_to_blkg(tg)); } #endif diff --git a/include/linux/bio.h b/include/linux/bio.h index 98b175cc00d5..f2f3f1428e81 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -547,6 +547,7 @@ do { \ #ifdef CONFIG_BLK_CGROUP int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css); +int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg); void bio_disassociate_task(struct bio *bio); void bio_clone_blkcg_association(struct bio *dst, struct bio *src); #else /* CONFIG_BLK_CGROUP */ diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 4cb970cdcd11..ff181df8c195 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -179,8 +179,8 @@ struct bio { */ struct io_context *bi_ioc; struct cgroup_subsys_state *bi_css; + struct blkcg_gq *bi_blkg; #ifdef CONFIG_BLK_DEV_THROTTLING_LOW - void *bi_cg_private; struct bio_issue bi_issue; #endif #endif -- 2.14.3