From patchwork Sun Jan 10 09:44:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 12008953 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A09BC433E0 for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BAC622CAF for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725988AbhAJJqB (ORCPT ); Sun, 10 Jan 2021 04:46:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbhAJJqA (ORCPT ); Sun, 10 Jan 2021 04:46:00 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4487AC06179F for ; Sun, 10 Jan 2021 01:45:20 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id b9so20589276ejy.0 for ; Sun, 10 Jan 2021 01:45:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uRUpkim9GeyZSrMIp8Mj1SXPSgk6+Y1Eu1l7OFdPFxM=; b=YWwPQZ2bzvc1i/jQMu8cUfvnkrGsRiHw5J9apBbRrteiceU1G+IUaqUiZ28fCAWaNI qaS0jIlSCN9eUan3JwqsOq1AgNHoaqB7y7GNDbRnHghfS7JgH2dTywCUW7uyRxuHuv0s qwalIDmoK0ytSj0DISJ2jv78gdy39Dt1K5+DZpNNo1WsP0le7oUHsj0Jk2nXWh7Qibh5 nv5FLPgVeY/UyPRIjBR5OnD8sHfh79urUodF5+k7QHF93jkiaeOnZdOVVYWj9LeKwcU7 YvC7cAfjhN47ycfKbd5FA1NpMSj/Ic7Pv45RexuUkHfxL6x1itfcUa88rxumd0mrxT4c U9Rg== 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=uRUpkim9GeyZSrMIp8Mj1SXPSgk6+Y1Eu1l7OFdPFxM=; b=iU/TJRIWeER2Tm8glhyiYeDJAa6r7AMQRe/41Apiq4emI0KfstaD70zq1koeULUy3q BISwP7JqwmXUO1KMXADAD20GplBINVXyXhCVDW4qV3Mpfw9Uh5XF3UxO1mJOViGSdgIP L7TIguZPYBE8rGY3gPScucWzArhqjuYwEfGxm5paqYsY5YG+bop8o+v1gV8MSc/ggB2d btAEkhnhvpBGETxHwaiR2f6R4Cf9/Lb5/im9h3hXLijTEdzZB9JW3NKHqySM4XTutSls rRNZFCQJcqYH9yuyR9lrXN/3vzypsJuK6aPY4OnNUaKawQ1D+gXCtcLqJDVW2S9Axh5O cqlQ== X-Gm-Message-State: AOAM532nrCabVYErXDoaa9PT0kdQIv1e08wD1ckvTZPhFIedh2vN0pyV +t5GmPh00u+IMcw7/0X/zycmoP8foO1TjUZE X-Google-Smtp-Source: ABdhPJwkrZLIWdrO8+rFOHXaBZm9QIKujJJwm27e9nvMEGevvC1A6aERfsE+9XqGExdm1ll+RgSX/w== X-Received: by 2002:a17:906:98d4:: with SMTP id zd20mr7584814ejb.532.1610271918950; Sun, 10 Jan 2021 01:45:18 -0800 (PST) Received: from ls00508.pb.local ([2001:1438:4010:2540:f4fd:e8ab:2d54:e8c]) by smtp.gmail.com with ESMTPSA id k15sm5549675ejc.79.2021.01.10.01.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 01:45:18 -0800 (PST) From: Guoqing Jiang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com, Guoqing Jiang Subject: [PATCH RFC V4 1/4] block: add a statistic table for io latency Date: Sun, 10 Jan 2021 10:44:54 +0100 Message-Id: <20210110094457.6624-2-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> References: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Usually, we get the status of block device by cat stat file, but we can only know the total time with that file. And we would like to know more accurate statistic, such as each latency range, which helps people to diagnose if there is issue about the hardware. Also a new config option is introduced to control if people want to know the additional statistics or not, and we use the option for io sector in next patch. This change is based on our internal patch from Florian-Ewald Mueller (florian-ewald.mueller@cloud.ionos.com). Signed-off-by: Guoqing Jiang --- Documentation/ABI/testing/sysfs-block | 8 ++++++ block/Kconfig | 8 ++++++ block/blk-core.c | 29 +++++++++++++++++++ block/genhd.c | 41 +++++++++++++++++++++++++++ include/linux/part_stat.h | 7 +++++ 5 files changed, 93 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block index e34cdeeeb9d4..4371a0f2cb5e 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -27,6 +27,14 @@ Description: For more details refer Documentation/admin-guide/iostats.rst +What: /sys/block//io_latency +Date: January 2021 +Contact: Guoqing Jiang +Description: + The /sys/block//io_latency files displays the I/O + latency of disk . With it, it is convenient to know + the statistics of I/O latency for each type (read, write, + discard and flush) which have happened to the disk. What: /sys/block///stat Date: February 2008 diff --git a/block/Kconfig b/block/Kconfig index a2297edfdde8..ca3854a7e3db 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -174,6 +174,14 @@ config BLK_DEBUG_FS Unless you are building a kernel for a tiny system, you should say Y here. +config BLK_ADDITIONAL_DISKSTAT + bool "Block layer additional diskstat" + default n + help + Enabling this option adds io latency statistics for each block device. + + If unsure, say N. + config BLK_DEBUG_FS_ZONED bool default BLK_DEBUG_FS && BLK_DEV_ZONED diff --git a/block/blk-core.c b/block/blk-core.c index 96e5fcd7f071..18cf881d8194 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1277,6 +1277,33 @@ static void update_io_ticks(struct block_device *part, unsigned long now, } } +/* + * Either account additional stat for request if req is not NULL or account for bio. + */ +static void blk_additional_latency(struct block_device *part, const int sgrp, + struct request *req, unsigned long start_jiffies) +{ +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT + unsigned int idx; + unsigned long duration, now = READ_ONCE(jiffies); + + if (req) + duration = jiffies_to_nsecs(now) - req->start_time_ns; + else + duration = jiffies_to_nsecs(now - start_jiffies); + + duration /= NSEC_PER_MSEC; + duration /= HZ_TO_MSEC_NUM; + if (likely(duration > 0)) { + idx = ilog2(duration); + if (idx > ADD_STAT_NUM - 1) + idx = ADD_STAT_NUM - 1; + } else + idx = 0; + part_stat_inc(part, latency_table[idx][sgrp]); +#endif +} + static void blk_account_io_completion(struct request *req, unsigned int bytes) { if (req->part && blk_do_io_stat(req)) { @@ -1301,6 +1328,7 @@ void blk_account_io_done(struct request *req, u64 now) part_stat_lock(); update_io_ticks(req->part, jiffies, true); + blk_additional_latency(req->part, sgrp, req, 0); part_stat_inc(req->part, ios[sgrp]); part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns); part_stat_unlock(); @@ -1360,6 +1388,7 @@ static void __part_end_io_acct(struct block_device *part, unsigned int op, part_stat_lock(); update_io_ticks(part, now, true); + blk_additional_latency(part, sgrp, NULL, start_time); part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration)); part_stat_local_dec(part, in_flight[op_is_write(op)]); part_stat_unlock(); diff --git a/block/genhd.c b/block/genhd.c index 419548e92d82..643b679883e1 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1276,6 +1276,44 @@ static struct device_attribute dev_attr_fail_timeout = __ATTR(io-timeout-fail, 0644, part_timeout_show, part_timeout_store); #endif +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT +static ssize_t io_latency_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct block_device *bdev = dev_to_bdev(dev); + size_t count = 0; + int i, sgrp; + + for (i = 0; i < ADD_STAT_NUM; i++) { + unsigned int from, to; + + if (i == ADD_STAT_NUM - 1) { + count += scnprintf(buf + count, PAGE_SIZE - count, " >= %5d ms: ", + (2 << (i - 2)) * HZ_TO_MSEC_NUM); + } else { + if (i < 2) { + from = i; + to = i + 1; + } else { + from = 2 << (i - 2); + to = 2 << (i - 1); + } + count += scnprintf(buf + count, PAGE_SIZE - count, "[%5d - %-5d) ms: ", + from * HZ_TO_MSEC_NUM, to * HZ_TO_MSEC_NUM); + } + + for (sgrp = 0; sgrp < NR_STAT_GROUPS; sgrp++) + count += scnprintf(buf + count, PAGE_SIZE - count, "%lu ", + part_stat_read(bdev, latency_table[i][sgrp])); + count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); + } + + return count; +} + +static struct device_attribute dev_attr_io_latency = + __ATTR(io_latency, 0444, io_latency_show, NULL); +#endif + static struct attribute *disk_attrs[] = { &dev_attr_range.attr, &dev_attr_ext_range.attr, @@ -1294,6 +1332,9 @@ static struct attribute *disk_attrs[] = { #endif #ifdef CONFIG_FAIL_IO_TIMEOUT &dev_attr_fail_timeout.attr, +#endif +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT + &dev_attr_io_latency.attr, #endif NULL }; diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h index d2558121d48c..763953238227 100644 --- a/include/linux/part_stat.h +++ b/include/linux/part_stat.h @@ -9,6 +9,13 @@ struct disk_stats { unsigned long sectors[NR_STAT_GROUPS]; unsigned long ios[NR_STAT_GROUPS]; unsigned long merges[NR_STAT_GROUPS]; +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT + /* + * We measure latency (ms) for 1, 2, ..., 1024 and >=1024. + */ +#define ADD_STAT_NUM 12 + unsigned long latency_table[ADD_STAT_NUM][NR_STAT_GROUPS]; +#endif unsigned long io_ticks; local_t in_flight[2]; }; From patchwork Sun Jan 10 09:44:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 12008959 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BFD2C433E6 for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B3EB23B06 for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726022AbhAJJqC (ORCPT ); Sun, 10 Jan 2021 04:46:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbhAJJqC (ORCPT ); Sun, 10 Jan 2021 04:46:02 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E784C0617A2 for ; Sun, 10 Jan 2021 01:45:21 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id w1so20377855ejf.11 for ; Sun, 10 Jan 2021 01:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ynHjJZnXcTj+bY9/RDRCYwdL51Yr1C6TsS7Tr2/rNzo=; b=gEWGV1KdKtgbnv3xFFJYzbawrAPzveV89G/ctL1RPtKHY8Ismh8x1u3nZvQVmg05qs AoWT8VWXFPLxN09+q8vs89ofYldfjGDA3h+mZqAGprEtUXZDK0cUMzVk8JxMfxRTd6db 7gl1JJNN8P3o/70L3BUUcpQAto8cBsDXlQ8l/FIqXTfxaPP6lAndjkZ+zBbHXfbKm8VM rNdP6VuEphz4eQ3rCorKcRke5XZ4TX2LXVZX68qUBDtf6bbNiIQsehJUKwDJt72tgem8 rKLnnpkDZ9Sc4KQVRPdFxXKaPZaVCwdAklhd3zRShVyvs5HonOD9wI/Znh/jqTgN9xWy L5ew== 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=ynHjJZnXcTj+bY9/RDRCYwdL51Yr1C6TsS7Tr2/rNzo=; b=GVP6y1q+LFc3M0MMgK0X0IYD2nc9qWExhkuFUpbAYD9aqFUA4Vg0H1YpTT4FmXxOvI CBD59lL2DyJ5Pl9xkAvMIykgnJyf7HK+SPd8SXJ4LU+WNymYnjvhVTVrqaZV9bQzWpK/ UqbK0zL067U1JTV8/89UTuiPRfel2ZZSxDmRgeoEnVLZbjUrskFi8gVlYQTabilhrNPo SAdIoY89NdVD4MR5DxaCHU0NVthummBcVGRqVExisNa6xqugerjkuoaEqXXHQPJRpcQE K5Soy/4Fd+CvsWVsmTCxkQ6I+2lTpkpybUoAtTyO4aPC/kX3h/oXezg7NWRzVuHE+9VB bHRw== X-Gm-Message-State: AOAM531dAMwWtoyifuoE8RTEXOxZSHk7xYCRzlFnqoKeYpx1uYAVtVa+ LQRBklC6jD9uIWmBJuT8D2Mjng== X-Google-Smtp-Source: ABdhPJw4AYtLjene+x5O2Q74CmALI1SH8ALR4l+RRX6tVIlS1LQAfWiFSiSyllUqZillAsXryZ5iAQ== X-Received: by 2002:a17:906:d8dc:: with SMTP id re28mr7667264ejb.168.1610271919889; Sun, 10 Jan 2021 01:45:19 -0800 (PST) Received: from ls00508.pb.local ([2001:1438:4010:2540:f4fd:e8ab:2d54:e8c]) by smtp.gmail.com with ESMTPSA id k15sm5549675ejc.79.2021.01.10.01.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 01:45:19 -0800 (PST) From: Guoqing Jiang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com, Guoqing Jiang Subject: [PATCH RFC V4 2/4] block: add a statistic table for io sector Date: Sun, 10 Jan 2021 10:44:55 +0100 Message-Id: <20210110094457.6624-3-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> References: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With the sector table, so we can know the distribution of different IO size from upper layer, which means we could have the opportunity to tune the performance based on the mostly issued IOs. This change is based on our internal patch from Florian-Ewald Mueller (florian-ewald.mueller@cloud.ionos.com). Signed-off-by: Guoqing Jiang --- Documentation/ABI/testing/sysfs-block | 9 +++++++ block/Kconfig | 3 ++- block/blk-core.c | 18 +++++++++++++ block/genhd.c | 37 +++++++++++++++++++++++++++ include/linux/part_stat.h | 3 ++- 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block index 4371a0f2cb5e..0ffb63469772 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -36,6 +36,15 @@ Description: the statistics of I/O latency for each type (read, write, discard and flush) which have happened to the disk. +What: /sys/block//io_size +Date: January 2021 +Contact: Guoqing Jiang +Description: + The /sys/block//io_size files displays the I/O + size of disk . With it, it is convenient to know + the statistics of I/O size for each type (read, write, + discard and flush) which have happened to the disk. + What: /sys/block///stat Date: February 2008 Contact: Jerome Marchand diff --git a/block/Kconfig b/block/Kconfig index ca3854a7e3db..ad04ec253b09 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -178,7 +178,8 @@ config BLK_ADDITIONAL_DISKSTAT bool "Block layer additional diskstat" default n help - Enabling this option adds io latency statistics for each block device. + Enabling this option adds io latency and io size statistics for each + block device. If unsure, say N. diff --git a/block/blk-core.c b/block/blk-core.c index 18cf881d8194..719595578bc8 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1304,12 +1304,29 @@ static void blk_additional_latency(struct block_device *part, const int sgrp, #endif } +static void blk_additional_sector(struct block_device *part, const int sgrp, + unsigned int sectors) +{ +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT + unsigned int idx; + + if (sectors == 1) + idx = 0; + else + idx = ilog2(sectors); + + idx = (idx > (ADD_STAT_NUM - 1)) ? (ADD_STAT_NUM - 1) : idx; + part_stat_inc(part, size_table[idx][sgrp]); +#endif +} + static void blk_account_io_completion(struct request *req, unsigned int bytes) { if (req->part && blk_do_io_stat(req)) { const int sgrp = op_stat_group(req_op(req)); part_stat_lock(); + blk_additional_sector(req->part, sgrp, bytes >> SECTOR_SHIFT); part_stat_add(req->part, sectors[sgrp], bytes >> 9); part_stat_unlock(); } @@ -1357,6 +1374,7 @@ static unsigned long __part_start_io_acct(struct block_device *part, update_io_ticks(part, now, false); part_stat_inc(part, ios[sgrp]); part_stat_add(part, sectors[sgrp], sectors); + blk_additional_sector(part, sgrp, sectors); part_stat_local_inc(part, in_flight[op_is_write(op)]); part_stat_unlock(); diff --git a/block/genhd.c b/block/genhd.c index 643b679883e1..059c82088cc4 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1312,6 +1312,42 @@ static ssize_t io_latency_show(struct device *dev, struct device_attribute *attr static struct device_attribute dev_attr_io_latency = __ATTR(io_latency, 0444, io_latency_show, NULL); + +static ssize_t io_size_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct block_device *bdev = dev_to_bdev(dev); + size_t count = 0; + int i, sgrp; + + for (i = 0; i < ADD_STAT_NUM; i++) { + unsigned int from, to; + + if (i == ADD_STAT_NUM - 1) { + from = 2 << (i - 2); + count += scnprintf(buf + count, PAGE_SIZE - count, + " >=%5d KB: ", from); + } else { + if (i < 2) { + from = i; + to = i + 1; + } else { + from = 2 << (i - 2); + to = 2 << (i - 1); + } + count += scnprintf(buf + count, PAGE_SIZE - count, + "[%5d - %-5d) KB: ", from, to); + } + for (sgrp = 0; sgrp < NR_STAT_GROUPS; sgrp++) + count += scnprintf(buf + count, PAGE_SIZE - count, "%lu ", + part_stat_read(bdev, size_table[i][sgrp])); + count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); + } + + return count; +} + +static struct device_attribute dev_attr_io_size = + __ATTR(io_size, 0444, io_size_show, NULL); #endif static struct attribute *disk_attrs[] = { @@ -1335,6 +1371,7 @@ static struct attribute *disk_attrs[] = { #endif #ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT &dev_attr_io_latency.attr, + &dev_attr_io_size.attr, #endif NULL }; diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h index 763953238227..8a6440ec9134 100644 --- a/include/linux/part_stat.h +++ b/include/linux/part_stat.h @@ -11,10 +11,11 @@ struct disk_stats { unsigned long merges[NR_STAT_GROUPS]; #ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT /* - * We measure latency (ms) for 1, 2, ..., 1024 and >=1024. + * We measure latency (ms) and size (KB) for 1, 2, ..., 1024 and >=1024. */ #define ADD_STAT_NUM 12 unsigned long latency_table[ADD_STAT_NUM][NR_STAT_GROUPS]; + unsigned long size_table[ADD_STAT_NUM][NR_STAT_GROUPS]; #endif unsigned long io_ticks; local_t in_flight[2]; From patchwork Sun Jan 10 09:44:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 12008957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8A92C433E9 for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DE8023976 for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbhAJJqJ (ORCPT ); Sun, 10 Jan 2021 04:46:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbhAJJqI (ORCPT ); Sun, 10 Jan 2021 04:46:08 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C42C0617A3 for ; Sun, 10 Jan 2021 01:45:22 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id lt17so20522355ejb.3 for ; Sun, 10 Jan 2021 01:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P3uXkH3R+VG/EIFJCdwP8rkqb3Bg5khoXbVqxj05Xxo=; b=Y0iydH3yVwTAnHT3ns1WgPrjtsbc9lxr/ECy0UxaFBMqfViGExb8mcXn1KxeKPV7gV qvMF38ZWxzfxARGUM0BQkLIiOidJnohKcDzozHJZ08HL/CcX8pwsww4Hh0Al+BwKiZp6 mXpFifdTlSOV+tzFkqZKRI9yCTofLuPhwnFmDbvj4iDydIXj+zEoetQbiwCHuTwjyc04 ss/sKfoV61gGv6iGR41epVtO0MaMlB1MHmUevkvoSo++kv621F1hT5t7sndPT2D/NEZj MrwVcvTxrvcwxwFOb2kwbKNs+/jBATmg3b4vFED7snWvSsV+ZDCf5UTN+npS8qdDtMHu eA5A== 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=P3uXkH3R+VG/EIFJCdwP8rkqb3Bg5khoXbVqxj05Xxo=; b=tXZjR3L21yB7Pz4owTWIcMXtDnkXwLXFGr8Rs3WCpKm4CUN1D9CQv3myP/dytjwV+L 89Sz8SXdjHYsxWImPsdcEIfJ9QZby2WegR8gRoQ98XvmZRyNjzsC7bElwkyJukbyRftJ DNGoC8OHDZydRuMqePqAze7ep6mWqgQtX9AlbOaSu8JeFfor4Y6tmIawQZhvRliLiSbc Vk1eohij1//sMhKCPsf/X7YEc4YX95es5TR9s/1SQaS2NOI9XzsP+TCNbOTZg0UG4yFq UcXehcWltD9JeEfLgF66BwOeOipOsKEyGHhw9Tp376adw9y6+dZWT9CeAnttHtefcHWi L12g== X-Gm-Message-State: AOAM532folScESyPJpUbTN9mPaMlqOpl8k2hAyTelZD5j/aPSBQtLjwC /ELJ9fjydCbP7WCGrRaTeqHFQw== X-Google-Smtp-Source: ABdhPJwlznfXLHWDC1DHFtEy44NJiy8T+cdiqWm7Rprf07fn/XqAgRAuTwB5ultqMZMlx+/eGizfyw== X-Received: by 2002:a17:906:edb2:: with SMTP id sa18mr7247347ejb.264.1610271920671; Sun, 10 Jan 2021 01:45:20 -0800 (PST) Received: from ls00508.pb.local ([2001:1438:4010:2540:f4fd:e8ab:2d54:e8c]) by smtp.gmail.com with ESMTPSA id k15sm5549675ejc.79.2021.01.10.01.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 01:45:20 -0800 (PST) From: Guoqing Jiang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com, Guoqing Jiang Subject: [PATCH RFC V4 3/4] block: add io_extra_stats node Date: Sun, 10 Jan 2021 10:44:56 +0100 Message-Id: <20210110094457.6624-4-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> References: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Even we have introduced a Kconfig option (default N) to control the accounting of additional data, but the option still could be enabled occasionally while user doesn't care about the size and latency of io, and they could suffer from the additional overhead. So introduce a specific sysfs node to avoid such mistake. Signed-off-by: Guoqing Jiang --- Documentation/ABI/testing/sysfs-block | 9 +++++++++ Documentation/block/queue-sysfs.rst | 6 ++++++ block/blk-sysfs.c | 10 ++++++++++ include/linux/blkdev.h | 6 ++++++ 4 files changed, 31 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block index 0ffb63469772..e1611c62a3e1 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -333,3 +333,12 @@ Description: does not complete in this time then the block driver timeout handler is invoked. That timeout handler can decide to retry the request, to fail it or to start a device recovery strategy. + +What: /sys/block//queue/io_extra_stats +Date: January 2021 +Contact: Guoqing Jiang +Description: + Indicates if people want to know the extra statistics (I/O + size and I/O latency) from /sys/block//io_latency + and /sys/block//io_size. The value is 0 by default, + set if the extra statistics are needed. diff --git a/Documentation/block/queue-sysfs.rst b/Documentation/block/queue-sysfs.rst index 2638d3446b79..14c4a4c7b9a9 100644 --- a/Documentation/block/queue-sysfs.rst +++ b/Documentation/block/queue-sysfs.rst @@ -99,6 +99,12 @@ iostats (RW) This file is used to control (on/off) the iostats accounting of the disk. +io_extra_stats (RW) +------------------- +This file is used to control (on/off) the additional accounting of the +io size and io latency of disk, and BLK_ADDITIONAL_DISKSTAT should be +enabled if you want the additional accounting. + logical_block_size (RO) ----------------------- This is the logical block size of the device, in bytes. diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index b513f1683af0..87f174f32e9a 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -288,6 +288,9 @@ QUEUE_SYSFS_BIT_FNS(nonrot, NONROT, 1); QUEUE_SYSFS_BIT_FNS(random, ADD_RANDOM, 0); QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0); QUEUE_SYSFS_BIT_FNS(stable_writes, STABLE_WRITES, 0); +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT +QUEUE_SYSFS_BIT_FNS(io_extra_stats, IO_EXTRA_STAT, 0); +#endif #undef QUEUE_SYSFS_BIT_FNS static ssize_t queue_zoned_show(struct request_queue *q, char *page) @@ -616,6 +619,10 @@ QUEUE_RW_ENTRY(queue_iostats, "iostats"); QUEUE_RW_ENTRY(queue_random, "add_random"); QUEUE_RW_ENTRY(queue_stable_writes, "stable_writes"); +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT +QUEUE_RW_ENTRY(queue_io_extra_stats, "io_extra_stats"); +#endif + static struct attribute *queue_attrs[] = { &queue_requests_entry.attr, &queue_ra_entry.attr, @@ -658,6 +665,9 @@ static struct attribute *queue_attrs[] = { &queue_io_timeout_entry.attr, #ifdef CONFIG_BLK_DEV_THROTTLING_LOW &blk_throtl_sample_time_entry.attr, +#endif +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT + &queue_io_extra_stats_entry.attr, #endif NULL, }; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 070de09425ad..a86ecd062340 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -625,6 +625,7 @@ struct request_queue { #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */ #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */ #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */ +#define QUEUE_FLAG_IO_EXTRA_STAT 30 /* extra IO accounting for size and latency */ #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_SAME_COMP) | \ @@ -662,6 +663,11 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); #else #define blk_queue_rq_alloc_time(q) false #endif +#ifdef CONFIG_BLK_ADDITIONAL_DISKSTAT +#define blk_queue_io_extra_stat(q) test_bit(QUEUE_FLAG_IO_EXTRA_STAT, &(q)->queue_flags) +#else +#define blk_queue_io_extra_stat(q) false +#endif #define blk_noretry_request(rq) \ ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ From patchwork Sun Jan 10 09:44:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoqing Jiang X-Patchwork-Id: 12008955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8DCBC43381 for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85DF722CAF for ; Sun, 10 Jan 2021 09:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726036AbhAJJqE (ORCPT ); Sun, 10 Jan 2021 04:46:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbhAJJqD (ORCPT ); Sun, 10 Jan 2021 04:46:03 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48834C0617A4 for ; Sun, 10 Jan 2021 01:45:23 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id ce23so20452396ejb.8 for ; Sun, 10 Jan 2021 01:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Hf/mF6iwnrVFlIuClv3PcBYTzfxrz6M0GNkOg7s98nM=; b=EprqDYrmfym7cJ0YEoYR0CbcvJG3noO3YzCGn/zI6MF6UIJ4PtythWtgbo/iQZXjNg opAJ+MMXsBVhFM7uXGmeSO9G/7+cNS2XVwZ1hsSwcSkjwrhnUb/6Ae286op4uFGghwtm h6dgQ1tlEuZpELzp7wDHZ4mYkeXdyYMID+1z1mlyjAye/eiUXgQePcSbChMig9V10/9b yr55KOqcJhN4mc+VP811+wdNnITI6GFfko8vM98yYw0ZZeZ5Y8lS8hnIp1glSuMIh4I2 SsKtAVidcMaprol8dbYBuWO4DkavoZQmvU8zUrXcbZ5Y3K4Fy05UfRiPF0TDk8hVzt7a +htw== 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=Hf/mF6iwnrVFlIuClv3PcBYTzfxrz6M0GNkOg7s98nM=; b=i4GAs583DW/VKSizgO9i7/GcMykeIQxplhw9VIndapYvi02Rn1+rJrHBa6fFyhBDh6 aUUF97JOpxs8ilb7BMGuXHoPaSo37upgzLNE6BZZ7KHPUIJV/U9lYoJlS/4k76xlnPM6 9yEguUZ0xInquUDklrRt9q7Vkoy2nB+hpJW6Zx5+MAVyfjfKScwHqmhYVRt8RZBqfYxJ GmVbPyspzietvqyx8YjKhyrsdvEl6U30SLJAw1sTdaABr+cIScNg9yR/HkS7ln+sCxZu PReV8APMVOyKgdgOjmjHzGg7OdS7GELWhYY8mmqSQP2LhPF+BVJVCFt0CI54ItDWgJf9 GoPg== X-Gm-Message-State: AOAM530NRsAooim8klwja6Qv302gtfFzlib+pL8910pJk+nBOvbUhFLZ PqS53rS1YXCwEMlR3sPHcGx8gA== X-Google-Smtp-Source: ABdhPJyhJBECWKPtxe6RSyS9IDwuyMuIprm5wt2YT0YLKP60qNy6LhkWVbF8SZaaDngCVbSQDN/F/g== X-Received: by 2002:a17:906:7d09:: with SMTP id u9mr7223201ejo.380.1610271921876; Sun, 10 Jan 2021 01:45:21 -0800 (PST) Received: from ls00508.pb.local ([2001:1438:4010:2540:f4fd:e8ab:2d54:e8c]) by smtp.gmail.com with ESMTPSA id k15sm5549675ejc.79.2021.01.10.01.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 01:45:21 -0800 (PST) From: Guoqing Jiang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com, Guoqing Jiang Subject: [PATCH RFC V4 4/4] block: call blk_additional_{latency,sector} only when io_extra_stats is true Date: Sun, 10 Jan 2021 10:44:57 +0100 Message-Id: <20210110094457.6624-5-guoqing.jiang@cloud.ionos.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> References: <20210110094457.6624-1-guoqing.jiang@cloud.ionos.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org If ADDITIONAL_DISKSTAT is enabled carelessly, then it is bad to people who don't want the additional overhead. Now add check before call blk_additional_{latency,sector}, which guarntee only those who really know about the attribute can account the additional data. Signed-off-by: Guoqing Jiang --- block/blk-core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 719595578bc8..c38287d34825 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1326,7 +1326,8 @@ static void blk_account_io_completion(struct request *req, unsigned int bytes) const int sgrp = op_stat_group(req_op(req)); part_stat_lock(); - blk_additional_sector(req->part, sgrp, bytes >> SECTOR_SHIFT); + if (blk_queue_io_extra_stat(req->q)) + blk_additional_sector(req->part, sgrp, bytes >> SECTOR_SHIFT); part_stat_add(req->part, sectors[sgrp], bytes >> 9); part_stat_unlock(); } @@ -1345,7 +1346,8 @@ void blk_account_io_done(struct request *req, u64 now) part_stat_lock(); update_io_ticks(req->part, jiffies, true); - blk_additional_latency(req->part, sgrp, req, 0); + if (blk_queue_io_extra_stat(req->q)) + blk_additional_latency(req->part, sgrp, req, 0); part_stat_inc(req->part, ios[sgrp]); part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns); part_stat_unlock(); @@ -1374,7 +1376,8 @@ static unsigned long __part_start_io_acct(struct block_device *part, update_io_ticks(part, now, false); part_stat_inc(part, ios[sgrp]); part_stat_add(part, sectors[sgrp], sectors); - blk_additional_sector(part, sgrp, sectors); + if (blk_queue_io_extra_stat(part->bd_disk->queue)) + blk_additional_sector(part, sgrp, sectors); part_stat_local_inc(part, in_flight[op_is_write(op)]); part_stat_unlock(); @@ -1406,7 +1409,8 @@ static void __part_end_io_acct(struct block_device *part, unsigned int op, part_stat_lock(); update_io_ticks(part, now, true); - blk_additional_latency(part, sgrp, NULL, start_time); + if (blk_queue_io_extra_stat(part->bd_disk->queue)) + blk_additional_latency(part, sgrp, NULL, start_time); part_stat_add(part, nsecs[sgrp], jiffies_to_nsecs(duration)); part_stat_local_dec(part, in_flight[op_is_write(op)]); part_stat_unlock();