Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4270430imm; Mon, 18 Jun 2018 12:00:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIxAdMi0nHNl5xC9y9nQvnTyIwD6HIhmg0da/wDWQHghCZiRhthVtOXWoA7knjFcGDMj9vb X-Received: by 2002:a63:ac11:: with SMTP id v17-v6mr12177242pge.274.1529348415055; Mon, 18 Jun 2018 12:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529348415; cv=none; d=google.com; s=arc-20160816; b=mfen1gQj79yiFTIwlb0ojMkZElS2NL9bzzkzwi1dU8wjQJM1etlLEqzAPKfG7KY1Uo a2Uxq8bIB7TRCOu4VTrrjuzhXQfPpA6Y41XrnYRMQzFYVAztLU/7YKCfcsugoUHugrwq 4Q5LQK/h/jY1GNG68ggIfzdseQVKh2UbpJm8F4DtvdQBs75auy/C+ET+1rc4/VwuyOpo eXMYbbvAVU1vTa1YfjFwiJ95VdsvfcyJ9eo4NiCbK5scm8xhKbv5BIhaf24Q2JVIesfH v8mMxiD6yrKkzFJW9k5GPQ6zRMvBi6ipTxpflOMQQRyz94nu+ypebLdl6cjbB1DIPZ7w iyTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=lnRTBJpovA7QwXK7hp8JqymvNFz/yn4lpYMVqSF/Npg=; b=Ehjl0SuX7gSrBJVepwcZDnVfHj65gnYEDvXa45+cWRdPx7rcmcKvTxf8DrLsI2tvp3 3R4xo8YMHTI3UIrV+zwXJapza5RyXF1otGd0Yc1GfVU4BlLRjNAPJSBpn8ZgJVBmv+uI /oyUkHoGxiYdYIWnYBydSw2CXI0n9BiwireUIj0tSKB5AqkKidXMuUxnIKkVQ4YSlzcP ZKKN5zkBLPHtCalY1wd2/ic1k8jr6S5fcGUu7+8l1xxQSoguqknqSAUM8h5ln2OyKCzx ODoBZvltccI3hWTrXtv45cPVLMa2ZQkxDV+400Z7CwFZhypR5fwsl9zxZLV+0z0V4lp5 1tZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AQbdpZtt; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67-v6si15167989pla.475.2018.06.18.12.00.01; Mon, 18 Jun 2018 12:00:15 -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=@google.com header.s=20161025 header.b=AQbdpZtt; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935953AbeFRS6f (ORCPT + 99 others); Mon, 18 Jun 2018 14:58:35 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:46161 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935828AbeFRS6e (ORCPT ); Mon, 18 Jun 2018 14:58:34 -0400 Received: by mail-pl0-f65.google.com with SMTP id 30-v6so9508788pld.13 for ; Mon, 18 Jun 2018 11:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=lnRTBJpovA7QwXK7hp8JqymvNFz/yn4lpYMVqSF/Npg=; b=AQbdpZttr6lVUelGCk+hG5txqJGgldtwHzgUKeahCMEUJoNRwQTvloRElY9EfvH0H/ IiBzlwNewfUtyAgYydj0nvzyE3YmRvAYMSGyxH3EojmDosbK7DhmpoDf5EL55jn0+aWD mPa5jsD5bImfLUc/f8f7E9rmN1oZ0v/09OtYP+7uOgbyKZG2v37gvpDgxN4bxTywxue2 x7R5aCZ9FV2Y2aBhkZF72IEoSjhzCxeitz2F1w809bGqaUiRKTizSvk9XurEvuxbFJZO lI0uTUi1FXutFXRMY/yHBlLAuT7n0c3eKpdGlo7qLXl1wufYPJdIhHe2AOl29Wnh46/8 8/ig== 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:references:date:in-reply-to :message-id:user-agent:mime-version; bh=lnRTBJpovA7QwXK7hp8JqymvNFz/yn4lpYMVqSF/Npg=; b=X7lCnLDq9EPit993SMGLpyAGAH1vITYE7Tx0KP1S5DUi0yGCkgsjeURIn1TvW9fb81 R/UC9z8NaIBfJFqQsRHzOkf504jZqZ935D7A3iMr1GfpUwIgu8wNc6K/5DXNuy1C8bQ/ pqQicQdzD4yIcevwwn4ZTSf7b1jOS8rwm0fNWgYoPw4Ch1iPfDv+2dTsp/rTdp5oePCz SLxNTyTWJdfTHSQGYXsC9cyf0hPvDJol0/PgJRjEihEPzV7x39x0Sg9GXBwR2RbHVIc4 uixYLsSYEc2kIGu1GT0jkoYzMzLtXGwZWqX5EfdvsB6q4YwWujGHFso6j91BHR7Bo8h2 TgSw== X-Gm-Message-State: APt69E0JeyfVroVspWVQSP6q8nN1Cdpvg/83uVuwpAK613vpVtHF5x+5 e6vGaahRwH3JifDzIMPhV9Bnkqn6qwg= X-Received: by 2002:a17:902:8306:: with SMTP id bd6-v6mr15466628plb.120.1529348313035; Mon, 18 Jun 2018 11:58:33 -0700 (PDT) Received: from bsegall-linux.svl.corp.google.com.localhost ([2620:15c:2cb:201:549c:c572:5008:d36f]) by smtp.gmail.com with ESMTPSA id w7-v6sm21644692pgr.82.2018.06.18.11.58.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 11:58:31 -0700 (PDT) From: bsegall@google.com To: Xunlei Pang Cc: Peter Zijlstra , Ingo Molnar , Ben Segall , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] sched/fair: Advance global expiration when period timer is restarted References: <20180618091657.21939-1-xlpang@linux.alibaba.com> Date: Mon, 18 Jun 2018 11:58:30 -0700 In-Reply-To: <20180618091657.21939-1-xlpang@linux.alibaba.com> (Xunlei Pang's message of "Mon, 18 Jun 2018 17:16:57 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Xunlei Pang writes: > I noticed the group frequently got throttled even it consumed > low cpu usage, this caused some jitters on the response time > to some of our business containers enabling cpu quota. > > It's very easy to reproduce: > mkdir /sys/fs/cgroup/cpu/test > cd /sys/fs/cgroup/cpu/test > echo 100000 > cpu.cfs_quota_us > echo $$ > tasks > then repeat: > cat cpu.stat |grep nr_throttled // nr_throttled will increase > > After some analysis, we found that cfs_rq::runtime_remaining will > be cleared by expire_cfs_rq_runtime() due to two equal but stale > "cfs_{b|q}->runtime_expires" after period timer is re-armed. If this is after the first patch, then this is no longer what should happen, and instead it would incorrectly /keep/ old local cfs_rq runtime, and not __refill global runtime until the period. > > The global expiration should be advanced accordingly when the > bandwidth period timer is restarted. > > Signed-off-by: Xunlei Pang > --- > kernel/sched/fair.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 9f384264e832..bb006e671609 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -5204,13 +5204,18 @@ static void init_cfs_rq_runtime(struct cfs_rq *cfs_rq) > > void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b) > { > + u64 overrun; > + > lockdep_assert_held(&cfs_b->lock); > > - if (!cfs_b->period_active) { > - cfs_b->period_active = 1; > - hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); > - hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); > - } > + if (cfs_b->period_active) > + return; > + > + cfs_b->period_active = 1; > + overrun = hrtimer_forward_now(&cfs_b->period_timer, cfs_b->period); > + cfs_b->runtime_expires += (overrun + 1) * ktime_to_ns(cfs_b->period); I think we actually want if (overrun) __refill_cfs_bandwidth_runtime(), much like tg_set_cfs_bandwidth > + cfs_b->expires_seq++; > + hrtimer_start_expires(&cfs_b->period_timer, HRTIMER_MODE_ABS_PINNED); > } > > static void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b)