From patchwork Mon Apr 9 06:15:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jianchao.wang" X-Patchwork-Id: 10330643 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 22DFC6020F for ; Mon, 9 Apr 2018 06:16:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 183DB288FD for ; Mon, 9 Apr 2018 06:16:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CEE328A64; Mon, 9 Apr 2018 06:16:16 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 84713288FD for ; Mon, 9 Apr 2018 06:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751815AbeDIGPS (ORCPT ); Mon, 9 Apr 2018 02:15:18 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:53266 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751669AbeDIGPP (ORCPT ); Mon, 9 Apr 2018 02:15:15 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w39649Vl037747; Mon, 9 Apr 2018 06:15:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=Y3N8lR4yttn4BswDyh1EFdyMFxjYWK5gLDPQViHeIiI=; b=gqKCDGsk1GwHYMYihl102y+7YLZjD/NZ8kck7sNxP1icPdzHEfbkBP0qN8LolAqbqrOS m/mGTOm39h205HH/4IdDv8O356q+AHEfU569YCNkG8czv872kKOglwrn5xFG9KLOaVnq nK+ZxOuNDTU98HCewOUVfCBxlAQg+qfQjjolnJ1HzMSvlBVPYK+IQionjoUyDxDg2utF cCMXLQ1QjjfCq4YBWihHM5gKua1rTlV1+Yul+FLlA0MwobXNvGnZb84eentPlNX40M9+ G/t2zAit3AW+YdLwXGNK+SaQVSjQB/xG3GwyAEiHzrBaZKqwHJ7uQwPhMKyjFeNKwI6x HQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2h6ne73scb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 09 Apr 2018 06:15:11 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w396FACh002850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Apr 2018 06:15:10 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w396FAGj019520; Mon, 9 Apr 2018 06:15:10 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.69.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 08 Apr 2018 23:15:09 -0700 From: Jianchao Wang To: axboe@kernel.dk, shli@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] blk-throttle: discard stale last_low_overflow_time Date: Mon, 9 Apr 2018 14:15:46 +0800 Message-Id: <1523254546-1951-1-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8857 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804090068 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When there is only one type of traffic, the associated last_low_overflow_time will not be updated, so the value is stale and invalid and we should discard it. Otherwise, __tg_last_low_overflow_time always return the stale value because it is smaller, and then we always get bps/iops has been below low limit for 1 throtl_slice, and limit_index will jump down and up between LOW and MAX, the actual bps/iops stays on low_limit. Add last_submit_time[2] into tg to track the time when bio enters into blk_throtl_bio. If there is no bio entering during past 5 throtl_slices, and the actual dispatching bps/iops are indeed lower than low limit, return 0 as the last_low_overflow_time which indicates it is stale. We will discard the stale last_low_overflow_time, but if both types are stale, return 0, Otherwise, the cgroups which don't have any traffic will prevent upgrade. Signed-off-by: Jianchao Wang --- block/blk-throttle.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index c5a1316..851aa16 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -158,6 +158,7 @@ struct throtl_grp { unsigned int io_disp[2]; unsigned long last_low_overflow_time[2]; + unsigned long last_submit_time[2]; uint64_t last_bytes_disp[2]; unsigned int last_io_disp[2]; @@ -1752,15 +1753,42 @@ static struct blkcg_policy blkcg_policy_throtl = { .pd_free_fn = throtl_pd_free, }; +/* + * If there is no any traffic of type 'rw' into blk_throtl_bio during + * past 5 throtl_slice, AND the actual dispatching bps/iops of type 'rw' + * is indeed lower than low limit, we return 0 as the last_low_overflow_time + * which indicates it is stale. + */ +static inline unsigned long tg_return_lloft(struct throtl_grp *tg, + unsigned int rw) +{ + unsigned long time = tg->last_low_overflow_time[rw]; + unsigned long now = jiffies; + + if (!time_after(now, + tg->last_submit_time[rw] + 5 * tg->td->throtl_slice)) + return time; + + if (!time_after(now, time + 5 * tg->td->throtl_slice)) + return time; + + return 0; +} + static unsigned long __tg_last_low_overflow_time(struct throtl_grp *tg) { unsigned long rtime = jiffies, wtime = jiffies; if (tg->bps[READ][LIMIT_LOW] || tg->iops[READ][LIMIT_LOW]) - rtime = tg->last_low_overflow_time[READ]; + rtime = tg_return_lloft(tg, READ); if (tg->bps[WRITE][LIMIT_LOW] || tg->iops[WRITE][LIMIT_LOW]) - wtime = tg->last_low_overflow_time[WRITE]; - return min(rtime, wtime); + wtime = tg_return_lloft(tg, WRITE); + + /* + * A cgroup w/o any traffic could have two stale value, return 0 instead + * of 'now', otherwise, it will prevent upgrade. + */ + return (rtime && wtime) ? min(rtime, wtime) : (rtime + wtime); } /* tg should not be an intermediate node */ @@ -2175,8 +2203,11 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg, while (true) { if (tg->last_low_overflow_time[rw] == 0) tg->last_low_overflow_time[rw] = jiffies; + if (unlikely(tg->last_submit_time[rw] == 0)) + tg->last_submit_time[rw] = jiffies; throtl_downgrade_check(tg); throtl_upgrade_check(tg); + tg->last_submit_time[rw] = jiffies; /* throtl is FIFO - if bios are already queued, should queue */ if (sq->nr_queued[rw]) break;