From patchwork Tue Jun 5 13:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10448301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C982160467 for ; Tue, 5 Jun 2018 13:33:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC010292E9 for ; Tue, 5 Jun 2018 13:33:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B05F42937E; Tue, 5 Jun 2018 13:33:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B06F292E9 for ; Tue, 5 Jun 2018 13:33:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752025AbeFENdg (ORCPT ); Tue, 5 Jun 2018 09:33:36 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:44395 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751842AbeFEN3z (ORCPT ); Tue, 5 Jun 2018 09:29:55 -0400 Received: by mail-qt0-f193.google.com with SMTP id l33-v6so2328678qta.11 for ; Tue, 05 Jun 2018 06:29:55 -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=Kp8LQTKmX3YVv+T71mlHfYgoh8Y4/YET2LM7+5wZcWg=; b=uTpzeTKXNincpajs1dhzrxo+XBqdx6RWkAwxIsDcBRFaAivsc8jWhGSEoq9HObPZSR zyh+91dTf1K3ZhyKlBb9CB+JeldiPrQWPppve90pXg5d9cR4LcvGWLC25R7d8stg5MjU +lnlNr8pZ1kJYnrW40Bw5uXozGdOzVPY/Qgu3s8q0WahSHqfrrvh1tSyNQY+RxzEHwGD 6YDGSWyqNEf9VMfkUXY95PvuYERuSz5wSOr0/UQPUIJtGSHgMZ7qiLr/+aMiYDuCyGpB JYzK6boXKhAgBSgr3lUtJ46kEMdVJ2eOP9OH5GcYMGwNDQfVQYFtTfMHihbV2MTBm9Fl udVg== 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=Kp8LQTKmX3YVv+T71mlHfYgoh8Y4/YET2LM7+5wZcWg=; b=tq7IDEgiDnmbcjCT+ycvnS40znWI0Bnxo0ZbWi2FMxm0EdEYjY4IhNs/aNd+P6mXPn DFAo1IhIFzCKLDEWpNie6IqdwEJNndTQfpbjEFfVXFUJu0F1c8mwIXPdKy01mXpq62oO 2f06LqAHVWFu3fs4zEtcb7u2ffhiapeJtIgdYr7Zp4iPRZgcwgQRFWdHxfqGkM5UBwpN yvVn+Jxsq1f+rIrgfMKPMWYW3oTCtAequskOfRT9CjIUCtnTfhlVi2Ket0mgh8QZ0cKO RZVHu3vzHJs+hZkAVCJv7MzWt1Ny2eeoJd4I7O9EwDLHnImJc2mFx3040AykvHGXtJu8 MSeg== X-Gm-Message-State: APt69E1aJjAPY0xC+vdDQL+GIv6b4HFTMU7em/PIIvBpxDi82Nsxw6jG 1Xy6tngsRqCQPtd6FNftVarmeA== X-Google-Smtp-Source: ADUXVKKNApFYE74XOj946Haq9J01CxIL2etcpf86fnq5N9f/CkPuakypz0bsOIoyq3HH7SkcqJcUNA== X-Received: by 2002:a0c:d6c7:: with SMTP id l7-v6mr4369894qvi.36.1528205394925; Tue, 05 Jun 2018 06:29:54 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id s186-v6sm34257822qkb.53.2018.06.05.06.29.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 06:29:54 -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 03/13] blk-cgroup: allow controllers to output their own stats Date: Tue, 5 Jun 2018 09:29:38 -0400 Message-Id: <20180605132948.1664-4-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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik blk-iolatency has a few stats that it would like to print out, and instead of adding a bunch of crap to the generic code just provide a helper so that controllers can add stuff to the stat line if they want to. Hide it behind a boot option since it changes the output of io.stat from normal, and these stats are only interesting to developers. Signed-off-by: Josef Bacik --- block/blk-cgroup.c | 61 +++++++++++++++++++++++++++++++++++++++++++--- include/linux/blk-cgroup.h | 3 +++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index eb85cb87c40f..b2ac6a7f851f 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -50,6 +50,8 @@ static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS]; static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */ +static bool blkcg_debug_stats = false; + static bool blkcg_policy_enabled(struct request_queue *q, const struct blkcg_policy *pol) { @@ -954,13 +956,28 @@ static int blkcg_print_stat(struct seq_file *sf, void *v) hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) { const char *dname; + char *buf; struct blkg_rwstat rwstat; u64 rbytes, wbytes, rios, wios; + size_t size = seq_get_buf(sf, &buf), count = 0, total = 0; + int i; dname = blkg_dev_name(blkg); if (!dname) continue; + /* + * Hooray string manipulation, count is the size written NOT + * INCLUDING THE \0, so size is now count+1 less than what we + * had before, but we want to start writing the next bit from + * the \0 so we only add count to buf. + */ + count = snprintf(buf, size, "%s ", dname); + if (count >= size) + continue; + buf += count; + size -= count + 1; + spin_lock_irq(blkg->q->queue_lock); rwstat = blkg_rwstat_recursive_sum(blkg, NULL, @@ -975,9 +992,44 @@ static int blkcg_print_stat(struct seq_file *sf, void *v) spin_unlock_irq(blkg->q->queue_lock); - if (rbytes || wbytes || rios || wios) - seq_printf(sf, "%s rbytes=%llu wbytes=%llu rios=%llu wios=%llu\n", - dname, rbytes, wbytes, rios, wios); + if (rbytes || wbytes || rios || wios) { + total += count; + count = snprintf(buf, size, + "rbytes=%llu wbytes=%llu rios=%llu wios=%llu", + rbytes, wbytes, rios, wios); + if (count >= size) + continue; + buf += count; + total += count; + size -= count + 1; + } + + if (!blkcg_debug_stats) + goto next; + + mutex_lock(&blkcg_pol_mutex); + for (i = 0; i < BLKCG_MAX_POLS; i++) { + struct blkcg_policy *pol = blkcg_policy[i]; + + if (!blkg->pd[i] || !pol->pd_stat_fn) + continue; + + count = pol->pd_stat_fn(blkg->pd[i], buf, size); + if (count >= size) + continue; + buf += count; + total += count; + size -= count + 1; + } + mutex_unlock(&blkcg_pol_mutex); +next: + if (total) { + count = snprintf(buf, size, "\n"); + if (count >= size) + continue; + total += count; + seq_commit(sf, total); + } } rcu_read_unlock(); @@ -1547,3 +1599,6 @@ void blkcg_policy_unregister(struct blkcg_policy *pol) mutex_unlock(&blkcg_pol_register_mutex); } EXPORT_SYMBOL_GPL(blkcg_policy_unregister); + +module_param(blkcg_debug_stats, bool, 0444); +MODULE_PARM_DESC(blkcg_debug_stats, "True if you want debug stats, false if not"); diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index 69aa71dc0c04..b41292726c0f 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -148,6 +148,8 @@ typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd); typedef void (blkcg_pol_offline_pd_fn)(struct blkg_policy_data *pd); typedef void (blkcg_pol_free_pd_fn)(struct blkg_policy_data *pd); typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkg_policy_data *pd); +typedef size_t (blkcg_pol_stat_pd_fn)(struct blkg_policy_data *pd, char *buf, + size_t size); struct blkcg_policy { int plid; @@ -167,6 +169,7 @@ struct blkcg_policy { blkcg_pol_offline_pd_fn *pd_offline_fn; blkcg_pol_free_pd_fn *pd_free_fn; blkcg_pol_reset_pd_stats_fn *pd_reset_stats_fn; + blkcg_pol_stat_pd_fn *pd_stat_fn; }; extern struct blkcg blkcg_root;