From patchwork Mon Apr 13 16:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 11485911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6EEA13B2 for ; Mon, 13 Apr 2020 16:28:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8685620735 for ; Mon, 13 Apr 2020 16:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586795292; bh=cdZ/qDu6vXnhfAxmdwijvm6okHK4a0yV2zCSJpW32yg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CCvJ8Gxt6HwRmO/kwH/OgWo9+KU9F7dnBnBe8pRxulx0izlILdC9RX3mqlGyLjsxz PTW0ijIqSz3aS1ufK7dvpOFJP3p8O6ecT6QjebIepoawd8WYLn0hGdxvnQTRR4a+Hp Tm68vxJ50zR8hJyVSmajHcW4ihkkyqeQXh/Zx4nQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731544AbgDMQ2L (ORCPT ); Mon, 13 Apr 2020 12:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731412AbgDMQ2H (ORCPT ); Mon, 13 Apr 2020 12:28:07 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 934B8C0A3BDC; Mon, 13 Apr 2020 09:28:06 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id q17so7308537qtp.4; Mon, 13 Apr 2020 09:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EDuQGOMVvT7vJ9dx+HQYmA7qvlQ1fW/fXGsJhnifUIg=; b=d0Fx3xEv33RKqDBpKlCR5cOoN8m6zAtngj0EXmSQnL48T8TommdYl5LHiVMDDT3cyq 3GNhu/PrrbOby91Z63E8BYZnLXdh1YN+tmrlM2+t+eGCoRpiKdGEr9MxoQHNaXMVHUL5 +fJCWF33JkVr0eDDdcdIuiWtE8IVl7aMMh8ogvQvaF7EEK3PQAgtlSYa7aZ/O7K9H8dD eaySWM9ulYrXAP5jrHDEP7idY6dQvEFNlOoSs8RLlNyo0Wb5aQyEUFCP3rF4XpmR5qgT 0+V0rUzow43RTqsmdnPWB6Y8xfI5PiCLbX97VUjDMRahEU7pmNPPjKSuhjaCfVhHULV+ R08g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EDuQGOMVvT7vJ9dx+HQYmA7qvlQ1fW/fXGsJhnifUIg=; b=l4cqJ9jbD4rjHa3fqlpcv6jeE1ARApiK5Z78WBWqTcyrvD7lzVeBenezLzxOip3ByY dtDPWU2NmHxZE/m+uX7iYHNyLu+wkd65emroLTv2z28TQChSn5eVxtP/FA0pvXDMlUjb iwuLvjg1GUVe1X5tL9PIL6I7HyfOkqf+PKlDSCy6xL+lUNtQ0fxY2p54J5XumhBcFTRq 6tov/drwNjb/4RVMTyDBtEilTHBmsuKsWrB7iM2S2AqcaUZ3hYbA+GrcZhqBfhhbVcyE klSS0Dqtufh8EMDS4PorrC9YgCbsTTqDmRzeu7GhInLEW0Iqy/m9NHn/IZXME2PG03ID 6Vfw== X-Gm-Message-State: AGi0PuZw1vDa5WlTD4/lNScWRSEDgzm2yQE7vEYJ8mpxLHaf792KvUAv Pv+opwZ9Xh4pbPWk1Gnx8zw= X-Google-Smtp-Source: APiQypKCGG6qTQS/DXHKp331uf+LjnuULl0MdLiuu0cc89BKmHDBz3GyscZTkTTLACZtFFw1V0sSuw== X-Received: by 2002:ac8:3403:: with SMTP id u3mr12424057qtb.274.1586795285464; Mon, 13 Apr 2020 09:28:05 -0700 (PDT) Received: from localhost ([199.96.181.106]) by smtp.gmail.com with ESMTPSA id y126sm8667350qke.28.2020.04.13.09.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 09:28:04 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, cgroups@vger.kernel.org, newella@fb.com, josef@toxicpanda.com, asml.silence@gmail.com, ming.lei@redhat.com, bvanassche@acm.org, Tejun Heo Subject: [PATCH 1/4] blk-iocost: switch to fixed non-auto-decaying use_delay Date: Mon, 13 Apr 2020 12:27:55 -0400 Message-Id: <20200413162758.97252-2-tj@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200413162758.97252-1-tj@kernel.org> References: <20200413162758.97252-1-tj@kernel.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The use_delay mechanism was introduced by blk-iolatency to hold memory allocators accountable for the reclaim and other shared IOs they cause. The duration of the delay is dynamically balanced between iolatency increasing the value on each target miss and it auto-decaying as time passes and threads get delayed on it. While this works well for iolatency, iocost's control model isn't compatible with it. There is no repeated "violation" events which can be balanced against auto-decaying. iocost instead knows how much a given cgroup is over budget and wants to prevent that cgroup from issuing IOs while over budget. Until now, iocost has been adding the cost of force-issued IOs. However, this doesn't reflect the amount which is already over budget and is simply not enough to counter the auto-decaying allowing anon-memory leaking low priority cgroup to go over its alloted share of IOs. As auto-decaying doesn't make much sense for iocost, this patch introduces a different mode of operation for use_delay - when blkcg_set_delay() are used insted of blkcg_add/use_delay(), the delay duration is not auto-decayed until it is explicitly cleared with blkcg_clear_delay(). iocost is updated to keep the delay duration synchronized to the budget overage amount. With this change, iocost can effectively police cgroups which generate significant amount of force-issued IOs. Signed-off-by: Tejun Heo Cc: Josef Bacik --- block/blk-cgroup.c | 6 ++++++ block/blk-iocost.c | 23 ++++++++------------ include/linux/blk-cgroup.h | 43 +++++++++++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index c5dc833212e1..0a63c6cbbcb1 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1530,6 +1530,10 @@ static void blkcg_scale_delay(struct blkcg_gq *blkg, u64 now) { u64 old = atomic64_read(&blkg->delay_start); + /* negative use_delay means no scaling, see blkcg_set_delay() */ + if (atomic_read(&blkg->use_delay) < 0) + return; + /* * We only want to scale down every second. The idea here is that we * want to delay people for min(delay_nsec, NSEC_PER_SEC) in a certain @@ -1717,6 +1721,8 @@ void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay) */ void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta) { + if (WARN_ON_ONCE(atomic_read(&blkg->use_delay) < 0)) + return; blkcg_scale_delay(blkg, now); atomic64_add(delta, &blkg->delay_nsec); } diff --git a/block/blk-iocost.c b/block/blk-iocost.c index db35ee682294..a8e99ef76a08 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -1209,14 +1209,14 @@ static enum hrtimer_restart iocg_waitq_timer_fn(struct hrtimer *timer) return HRTIMER_NORESTART; } -static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now, u64 cost) +static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now) { struct ioc *ioc = iocg->ioc; struct blkcg_gq *blkg = iocg_to_blkg(iocg); u64 vtime = atomic64_read(&iocg->vtime); u64 vmargin = ioc->margin_us * now->vrate; u64 margin_ns = ioc->margin_us * NSEC_PER_USEC; - u64 expires, oexpires; + u64 delta_ns, expires, oexpires; u32 hw_inuse; /* debt-adjust vtime */ @@ -1233,15 +1233,10 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now, u64 cost) return false; /* use delay */ - if (cost) { - u64 cost_ns = DIV64_U64_ROUND_UP(cost * NSEC_PER_USEC, - now->vrate); - blkcg_add_delay(blkg, now->now_ns, cost_ns); - } - blkcg_use_delay(blkg); - - expires = now->now_ns + DIV64_U64_ROUND_UP(vtime - now->vnow, - now->vrate) * NSEC_PER_USEC; + delta_ns = DIV64_U64_ROUND_UP(vtime - now->vnow, + now->vrate) * NSEC_PER_USEC; + blkcg_set_delay(blkg, delta_ns); + expires = now->now_ns + delta_ns; /* if already active and close enough, don't bother */ oexpires = ktime_to_ns(hrtimer_get_softexpires(&iocg->delay_timer)); @@ -1260,7 +1255,7 @@ static enum hrtimer_restart iocg_delay_timer_fn(struct hrtimer *timer) struct ioc_now now; ioc_now(iocg->ioc, &now); - iocg_kick_delay(iocg, &now, 0); + iocg_kick_delay(iocg, &now); return HRTIMER_NORESTART; } @@ -1378,7 +1373,7 @@ static void ioc_timer_fn(struct timer_list *timer) atomic64_read(&iocg->abs_vdebt)) { /* might be oversleeping vtime / hweight changes, kick */ iocg_kick_waitq(iocg, &now); - iocg_kick_delay(iocg, &now, 0); + iocg_kick_delay(iocg, &now); } else if (iocg_is_idle(iocg)) { /* no waiter and idle, deactivate */ iocg->last_inuse = iocg->inuse; @@ -1737,7 +1732,7 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio) */ if (bio_issue_as_root_blkg(bio) || fatal_signal_pending(current)) { atomic64_add(abs_cost, &iocg->abs_vdebt); - if (iocg_kick_delay(iocg, &now, cost)) + if (iocg_kick_delay(iocg, &now)) blkcg_schedule_throttle(rqos->q, (bio->bi_opf & REQ_SWAP) == REQ_SWAP); return; diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h index 35f8ffe92b70..3f0f51c4a571 100644 --- a/include/linux/blk-cgroup.h +++ b/include/linux/blk-cgroup.h @@ -629,6 +629,8 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q, static inline void blkcg_use_delay(struct blkcg_gq *blkg) { + if (WARN_ON_ONCE(atomic_read(&blkg->use_delay) < 0)) + return; if (atomic_add_return(1, &blkg->use_delay) == 1) atomic_inc(&blkg->blkcg->css.cgroup->congestion_count); } @@ -637,6 +639,8 @@ static inline int blkcg_unuse_delay(struct blkcg_gq *blkg) { int old = atomic_read(&blkg->use_delay); + if (WARN_ON_ONCE(old < 0)) + return 0; if (old == 0) return 0; @@ -661,20 +665,39 @@ static inline int blkcg_unuse_delay(struct blkcg_gq *blkg) return 1; } +/** + * blkcg_set_delay - Enable allocator delay mechanism with the specified delay amount + * @blkg: target blkg + * @delay: delay duration in nsecs + * + * When enabled with this function, the delay is not decayed and must be + * explicitly cleared with blkcg_clear_delay(). Must not be mixed with + * blkcg_[un]use_delay() and blkcg_add_delay() usages. + */ +static inline void blkcg_set_delay(struct blkcg_gq *blkg, u64 delay) +{ + int old = atomic_read(&blkg->use_delay); + + /* We only want 1 person setting the congestion count for this blkg. */ + if (!old && atomic_cmpxchg(&blkg->use_delay, old, -1) == old) + atomic_inc(&blkg->blkcg->css.cgroup->congestion_count); + + atomic64_set(&blkg->delay_nsec, delay); +} + +/** + * blkcg_clear_delay - Disable allocator delay mechanism + * @blkg: target blkg + * + * Disable use_delay mechanism. See blkcg_set_delay(). + */ static inline void blkcg_clear_delay(struct blkcg_gq *blkg) { int old = atomic_read(&blkg->use_delay); - if (!old) - return; + /* We only want 1 person clearing the congestion count for this blkg. */ - while (old) { - int cur = atomic_cmpxchg(&blkg->use_delay, old, 0); - if (cur == old) { - atomic_dec(&blkg->blkcg->css.cgroup->congestion_count); - break; - } - old = cur; - } + if (old && atomic_cmpxchg(&blkg->use_delay, old, 0) == old) + atomic_dec(&blkg->blkcg->css.cgroup->congestion_count); } void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta); From patchwork Mon Apr 13 16:27:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 11485913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A16014B4 for ; Mon, 13 Apr 2020 16:28:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C03320692 for ; Mon, 13 Apr 2020 16:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586795296; bh=l7EHXXuK+JZDgnGcmIcgycO07cKTa/x3n3ZOYfkXeDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=YysqCLnOvId55JY0F+8r4tBzrZUzs6CL9PQ/u02ENhxE374j1dBZZSvoVovFcFcw4 Ps2qEGL+RiuoSzDLsxIilX63eU46SGSP2f28aoKM+ckHsRZtaGcORctSDTuzBy/Dp3 CwIEmCRkgaOx0gTom/50zzl0n4uvqDZbUHZ9sCR4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731555AbgDMQ2P (ORCPT ); Mon, 13 Apr 2020 12:28:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731549AbgDMQ2N (ORCPT ); Mon, 13 Apr 2020 12:28:13 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC12CC0A3BDC; Mon, 13 Apr 2020 09:28:12 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id q73so4661432qvq.2; Mon, 13 Apr 2020 09:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Bb68KuCtf8ropkgUO+IBtBH+v6R3qhUQPcdqIOx+rM=; b=Idl9GkA9HQvbQPkneNaD4EDbW0bbJidNvjTkeHuZJlearodmyrz5gMnAaz9cbsn1+m JJKck5eqtqcbU8gqlEca7iGKJciIDnwAfeAGlakOewAWipjb3jmIzgSfB4cdRANrawlR AFAHwo4g06P0mR1tXN8woUHz0Nl59+rctt0x1vqF2dQyjeErhwo893sWLcsvsOAnUf5T 1SnYPx0wckshu0C3LKxJbUnkVabws9/qG/EXnDQa5GJHREc27A20KSQ3CSB7nFMlnijM thsAARnQIQXzS0KnRWd3YixU1fP5+jDhzEu7X5vUIFZXPUuP12elzWok7mVt6petTW37 amOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=6Bb68KuCtf8ropkgUO+IBtBH+v6R3qhUQPcdqIOx+rM=; b=pFLM8uDb443heOmHntvEtqKhOy8HwDPwsnZ1G1qH4Ute3fRH+D6n+ML5bARpzWrNdu H4iu17QG2v0/GqwU1ZJWzYs8Q+sz25ZvJffW5hRxyl7GYCYv/eN7vELcgvJrrSITEu9S uHoFtyWI1gYcjrvl4DgbNp1fsawSxvWGRh6sAb8kJGpHq8uxfnQ71uH4bs7y2IQZWjXE vEr1c4jVIfNfkVdf1imDblZpu7/Cf+a1+ix++g9GPTSwmEOFQ3iNhIcCwGVkEGZeBbnP qP3wyTi4w8Ov9FLFOy8KdYcoSki6pm+OMwZ59l0ligfTEfEy5392p2Jdjntd1/HtMMdQ osXA== X-Gm-Message-State: AGi0PuY5pAFKQ24cNk2xs/x86dm2iMzz0zsCLOKRcO1hPmZLnyrpFYEG DyKLIk8soOx8uOsBsRLrKsk= X-Google-Smtp-Source: APiQypIqvHOIbF8qJrplLBlIquVlJaDJ5Qa54tzuYPVVsfGx4+1Y0Jb0vancrL/OpLiKaR1ct97oOQ== X-Received: by 2002:a0c:e848:: with SMTP id l8mr18138070qvo.82.1586795290230; Mon, 13 Apr 2020 09:28:10 -0700 (PDT) Received: from localhost ([199.96.181.106]) by smtp.gmail.com with ESMTPSA id j2sm4872937qtp.5.2020.04.13.09.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 09:28:06 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, cgroups@vger.kernel.org, newella@fb.com, josef@toxicpanda.com, asml.silence@gmail.com, ming.lei@redhat.com, bvanassche@acm.org, Tejun Heo Subject: [PATCH 2/4] blk-iocost: account for IO size when testing latencies Date: Mon, 13 Apr 2020 12:27:56 -0400 Message-Id: <20200413162758.97252-3-tj@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200413162758.97252-1-tj@kernel.org> References: <20200413162758.97252-1-tj@kernel.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On each IO completion, iocost decides whether the IO met or missed its latency target. Currently, the targets are fixed numbers per IO type. While this can be good enough for loose latency targets way higher than typical completion latencies, the effect of IO size makes it difficult to tighten the latency target - a target adequate for 4k IOs might be too tight for 512k IOs and vice-versa. iocost already has all the necessary information to account for different IO sizes when testing whether the latency target is met as iocost can calculate the size vtime cost of a given IO. This patch updates the completion path to calculate the size vtime cost of the IO, deduct the nsec equivalent from the observed latency and use the adjusted value to decide whether the target is met. This makes latency targets independent from IO size and enables determining adequate latency targets with fixed size fio runs. Signed-off-by: Tejun Heo Cc: Andy Newell --- block/Kconfig | 1 + block/blk-iocost.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/block/Kconfig b/block/Kconfig index 3bc76bb113a0..41cb34b0fcd1 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -146,6 +146,7 @@ config BLK_CGROUP_IOLATENCY config BLK_CGROUP_IOCOST bool "Enable support for cost model based cgroup IO controller" depends on BLK_CGROUP=y + select BLK_RQ_IO_DATA_LEN select BLK_RQ_ALLOC_TIME ---help--- Enabling this option enables the .weight interface for cost diff --git a/block/blk-iocost.c b/block/blk-iocost.c index a8e99ef76a08..9a667dd75eef 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -260,6 +260,7 @@ enum { VTIME_PER_SEC_SHIFT = 37, VTIME_PER_SEC = 1LLU << VTIME_PER_SEC_SHIFT, VTIME_PER_USEC = VTIME_PER_SEC / USEC_PER_SEC, + VTIME_PER_NSEC = VTIME_PER_SEC / NSEC_PER_SEC, /* bound vrate adjustments within two orders of magnitude */ VRATE_MIN_PPM = 10000, /* 1% */ @@ -1668,6 +1669,31 @@ static u64 calc_vtime_cost(struct bio *bio, struct ioc_gq *iocg, bool is_merge) return cost; } +static void calc_size_vtime_cost_builtin(struct request *rq, struct ioc *ioc, + u64 *costp) +{ + unsigned int pages = blk_rq_stats_sectors(rq) >> IOC_SECT_TO_PAGE_SHIFT; + + switch (req_op(rq)) { + case REQ_OP_READ: + *costp = pages * ioc->params.lcoefs[LCOEF_RPAGE]; + break; + case REQ_OP_WRITE: + *costp = pages * ioc->params.lcoefs[LCOEF_WPAGE]; + break; + default: + *costp = 0; + } +} + +static u64 calc_size_vtime_cost(struct request *rq, struct ioc *ioc) +{ + u64 cost; + + calc_size_vtime_cost_builtin(rq, ioc, &cost); + return cost; +} + static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio) { struct blkcg_gq *blkg = bio->bi_blkg; @@ -1837,7 +1863,7 @@ static void ioc_rqos_done_bio(struct rq_qos *rqos, struct bio *bio) static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) { struct ioc *ioc = rqos_to_ioc(rqos); - u64 on_q_ns, rq_wait_ns; + u64 on_q_ns, rq_wait_ns, size_nsec; int pidx, rw; if (!ioc->enabled || !rq->alloc_time_ns || !rq->start_time_ns) @@ -1858,8 +1884,10 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) on_q_ns = ktime_get_ns() - rq->alloc_time_ns; rq_wait_ns = rq->start_time_ns - rq->alloc_time_ns; + size_nsec = div64_u64(calc_size_vtime_cost(rq, ioc), VTIME_PER_NSEC); - if (on_q_ns <= ioc->params.qos[pidx] * NSEC_PER_USEC) + if (on_q_ns <= size_nsec || + on_q_ns - size_nsec <= ioc->params.qos[pidx] * NSEC_PER_USEC) this_cpu_inc(ioc->pcpu_stat->missed[rw].nr_met); else this_cpu_inc(ioc->pcpu_stat->missed[rw].nr_missed); @@ -2267,6 +2295,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, spin_lock_irq(&ioc->lock); if (enable) { + blk_stat_enable_accounting(ioc->rqos.q); blk_queue_flag_set(QUEUE_FLAG_RQ_ALLOC_TIME, ioc->rqos.q); ioc->enabled = true; } else { From patchwork Mon Apr 13 16:27:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 11485915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90BB614B4 for ; Mon, 13 Apr 2020 16:28:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78DFE20732 for ; Mon, 13 Apr 2020 16:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586795298; bh=agr1+itNsIKiJBbUpIsQxY/CacCCfWlxdtPqYys19oE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=SKY1VBaye69pCLOS43MduzuzJylp/ec5Q22B21OUQyMGX8jUKQjUKiqypoMZ3CcoN d7r4i0E0HOtjVIwm4frV04C5iD40TmgO+xpv4HQyU8azELZqZ+Qgy2Z9Bhc+md69Dc lpRDgYsMggxC7fGZ6qLRiEV6jwKkdWdP/opuuuSg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731559AbgDMQ2P (ORCPT ); Mon, 13 Apr 2020 12:28:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731551AbgDMQ2N (ORCPT ); Mon, 13 Apr 2020 12:28:13 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A575C0A3BE2; Mon, 13 Apr 2020 09:28:13 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id m67so9974507qke.12; Mon, 13 Apr 2020 09:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IVee5LEPnYY6zF34ZuR4jFCQhJmfapbvjjnOL4aQYjw=; b=Hot53CJtn2fBB2y8DyRmzWibMmNk9ZIIP9y86sAKCSgqmJRIirb7rq/rg9vVFHnIyo sGfhoI7DFFRLH49s/i6ZBGxgN9cU8CP3sIam6U57heTNuHtE6eu57i83Q/cMpPPgMUH3 t4W7ZyclBAcEs7wR7DokFFMkT/QQZ0R82M0sgxt0X04FRNhUQVgAVsrfUeM7//RUt1WK vlCFv+UR/M4mB8KVZ6MRvJfNaKEnuqr/496K+TXk/zeglyn27a3M38gm74aKp51oPdOx WQYfkSoqQ91xCveNYnKuabqx7uksKGngDPt6EYC3tj1VTLrYCuwID+nggxy2DUlBqQTl +MSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IVee5LEPnYY6zF34ZuR4jFCQhJmfapbvjjnOL4aQYjw=; b=PAn81Euw1aBi3YsajVkElnbPMz65FB9+v0E1NT4UJ1hHx3lN48lk5q9/btWjD+4uyV Oqd1/T+9CeQujZR8uQZCFC8e0cj697s+MsH/HQG2v+QSPo+Lz/ViS/Y/HEoSnYpHKDMH g8XsuRDhnZGjanikmqVtQu8InUz31iOmp25wo543LtRwGKIPmJtAEkGaFr898A6wxPvp 1XSH+bfxR0ltgXLzeBMd5NmW9cnZupBlos81fZPT9pIdm9duozHqGhjsvXBoZ1mzf28A +3hP+w7EnclRy/5mmc5aGsXkQfMM/5P7lZHIjCsDTpXsC92SAE7JogtaoxSg9zW2SZxf b6AQ== X-Gm-Message-State: AGi0PuaB6mNrLw9Y3T7aGAUqh6zZf4vv7H3cEUzIbBkLTd+HxUELGpYN L6OX15Hduu2ZMLEOuavx7vE= X-Google-Smtp-Source: APiQypIA6+LanoMTgQgStyIDckI4dzIeJrzHna7Cz2nic3/Xj6lgKMjyy8a9jBX4T+nZqTM7b+uqAg== X-Received: by 2002:a37:54e:: with SMTP id 75mr17288729qkf.257.1586795292462; Mon, 13 Apr 2020 09:28:12 -0700 (PDT) Received: from localhost ([199.96.181.106]) by smtp.gmail.com with ESMTPSA id n190sm8497416qkb.93.2020.04.13.09.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 09:28:11 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, cgroups@vger.kernel.org, newella@fb.com, josef@toxicpanda.com, asml.silence@gmail.com, ming.lei@redhat.com, bvanassche@acm.org, Tejun Heo Subject: [PATCH 3/4] iocost_monitor: exit successfully if interval is zero Date: Mon, 13 Apr 2020 12:27:57 -0400 Message-Id: <20200413162758.97252-4-tj@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200413162758.97252-1-tj@kernel.org> References: <20200413162758.97252-1-tj@kernel.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This is to help external tools to decide whether iocost_monitor has all its requirements met or not based on the exit status of an -i0 run. Signed-off-by: Tejun Heo --- tools/cgroup/iocost_monitor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/cgroup/iocost_monitor.py b/tools/cgroup/iocost_monitor.py index 7427a5ee761b..eb2363b868c5 100644 --- a/tools/cgroup/iocost_monitor.py +++ b/tools/cgroup/iocost_monitor.py @@ -28,7 +28,8 @@ parser.add_argument('devname', metavar='DEV', parser.add_argument('--cgroup', action='append', metavar='REGEX', help='Regex for target cgroups, ') parser.add_argument('--interval', '-i', metavar='SECONDS', type=float, default=1, - help='Monitoring interval in seconds') + help='Monitoring interval in seconds (0 exits immediately ' + 'after checking requirements)') parser.add_argument('--json', action='store_true', help='Output in json') args = parser.parse_args() @@ -243,6 +244,9 @@ ioc = None if ioc is None: err(f'Could not find ioc for {devname}'); +if interval == 0: + sys.exit(0) + # Keep printing while True: now = time.time() From patchwork Mon Apr 13 16:27:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 11485917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0B0D13B2 for ; Mon, 13 Apr 2020 16:28:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8195820692 for ; Mon, 13 Apr 2020 16:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586795301; bh=bBEB/aPitXY5YRdbhgEhohfbura7iEH04Bc+z/1PaAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j9/780ktX5pfXUDBjeioAjS0iyNMBtoydw+3MP8arGI06hqtdezxIGYg49CvK0GUU MqWusWvRR89oMQW8VFlb+4Dg9E98yqjh16beJTz4UPDIXUeYDUrpk02YwamxBrYR6m G3r+/SkoeCkSDeXghV3rdwptqTgYFapSKZFOrdjI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731565AbgDMQ2T (ORCPT ); Mon, 13 Apr 2020 12:28:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731558AbgDMQ2P (ORCPT ); Mon, 13 Apr 2020 12:28:15 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C65EC0A3BDC; Mon, 13 Apr 2020 09:28:15 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id da9so625979qvb.3; Mon, 13 Apr 2020 09:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oUkkM58FQ7/zwRHxuQQD1SOxcIY68c2GOGKvgkHNmUk=; b=iHM4peE0B7c2LWhuK1L8wKWz3xluirMtuEeZzNSpfKtK4vFwAm6fuMwuF7a1rsGGnG jXA7Re6osRnNCm00LHi73qpuNxvU2Mc3VWIWT5RQYzUIvTW70xBFsPcB4kV2g7N412U7 ArFLNIKn/Rd4dIBMgxzoyGZX9Y3v9Cldr9f+6dBGK9UEj13nwKkam0J9+GHfBVCn78kb U5YHVVZ4A3QF31vS32j2cDO65OlDuRGhDnRAoh86GlBGLiTa2oUxgAStyEmU0qxm/WGw tW9XemwnS8zpHKq039mvCTgkPNHACTb9mGmyqsM9gUdxCgJG51su4SvZEnu0HJvHTyQU lvPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oUkkM58FQ7/zwRHxuQQD1SOxcIY68c2GOGKvgkHNmUk=; b=IuEh1lrTwUEmPZyLBiwXeC8bndouoE0sAiC/VJnzs/Kz1rDtW6XrlN9s+ZoQ6hVlgW bHJmFHWGZW5KDSOUcSK2jdj11UzaNGYctRn8T/1S7QxFQJ/WSj77GEj5+pCA5F/neXRl rUM2whUFY+H90V0GVf1ISOFppHsd3ARqUnR7/9oQ7t6/OntxqxnTI+EwQnCjxFeiLpDc eIZXsXv6b24WXGi1RaHZVLBrO2OdKQJIJwG/aNWeEUzAGVr//woNiBJ75rPFCO7PQySZ L07jdL3KFDKroB717aqnB7lPvzuowlaGZ1ps+WYVPqc8gwfjEGhQtGG3lW3n/ILns1H8 aAEw== X-Gm-Message-State: AGi0Pua3F+iOt8QARWiKG5eFPkwqz9AM+jiyRA30AqfWA58stRYaHgoM QbAVFsdnYr02UfJRDJLTHz0isdZRACI= X-Google-Smtp-Source: APiQypJwvhy7iuOaZ7hP+9n1TUG0oLkMcKs4ryUx9kDY3wfgkyszstXm/7PJfP++9VweLFQL4JMpXg== X-Received: by 2002:a0c:a122:: with SMTP id d31mr17862921qva.109.1586795294460; Mon, 13 Apr 2020 09:28:14 -0700 (PDT) Received: from localhost ([199.96.181.106]) by smtp.gmail.com with ESMTPSA id m14sm8698505qkm.82.2020.04.13.09.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 09:28:13 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, cgroups@vger.kernel.org, newella@fb.com, josef@toxicpanda.com, asml.silence@gmail.com, ming.lei@redhat.com, bvanassche@acm.org, Tejun Heo Subject: [PATCH 4/4] iocost_monitor: drop string wrap around numbers when outputting json Date: Mon, 13 Apr 2020 12:27:58 -0400 Message-Id: <20200413162758.97252-5-tj@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200413162758.97252-1-tj@kernel.org> References: <20200413162758.97252-1-tj@kernel.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Wrapping numbers in strings is used by some to work around bit-width issues in some enviroments. The problem isn't innate to json and the workaround seems to cause more integration problems than help. Let's drop the string wrapping. Signed-off-by: Tejun Heo --- tools/cgroup/iocost_monitor.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/cgroup/iocost_monitor.py b/tools/cgroup/iocost_monitor.py index eb2363b868c5..188b3379b9a1 100644 --- a/tools/cgroup/iocost_monitor.py +++ b/tools/cgroup/iocost_monitor.py @@ -113,14 +113,14 @@ autop_names = { def dict(self, now): return { 'device' : devname, - 'timestamp' : str(now), - 'enabled' : str(int(self.enabled)), - 'running' : str(int(self.running)), - 'period_ms' : str(self.period_ms), - 'period_at' : str(self.period_at), - 'period_vtime_at' : str(self.vperiod_at), - 'busy_level' : str(self.busy_level), - 'vrate_pct' : str(self.vrate_pct), } + 'timestamp' : now, + 'enabled' : self.enabled, + 'running' : self.running, + 'period_ms' : self.period_ms, + 'period_at' : self.period_at, + 'period_vtime_at' : self.vperiod_at, + 'busy_level' : self.busy_level, + 'vrate_pct' : self.vrate_pct, } def table_preamble_str(self): state = ('RUN' if self.running else 'IDLE') if self.enabled else 'OFF' @@ -175,19 +175,19 @@ autop_names = { def dict(self, now, path): out = { 'cgroup' : path, - 'timestamp' : str(now), - 'is_active' : str(int(self.is_active)), - 'weight' : str(self.weight), - 'weight_active' : str(self.active), - 'weight_inuse' : str(self.inuse), - 'hweight_active_pct' : str(self.hwa_pct), - 'hweight_inuse_pct' : str(self.hwi_pct), - 'inflight_pct' : str(self.inflight_pct), - 'debt_ms' : str(self.debt_ms), - 'use_delay' : str(self.use_delay), - 'delay_ms' : str(self.delay_ms), - 'usage_pct' : str(self.usage), - 'address' : str(hex(self.address)) } + 'timestamp' : now, + 'is_active' : self.is_active, + 'weight' : self.weight, + 'weight_active' : self.active, + 'weight_inuse' : self.inuse, + 'hweight_active_pct' : self.hwa_pct, + 'hweight_inuse_pct' : self.hwi_pct, + 'inflight_pct' : self.inflight_pct, + 'debt_ms' : self.debt_ms, + 'use_delay' : self.use_delay, + 'delay_ms' : self.delay_ms, + 'usage_pct' : self.usage, + 'address' : self.address } for i in range(len(self.usages)): out[f'usage_pct_{i}'] = str(self.usages[i]) return out