Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1238257pxb; Fri, 21 Jan 2022 13:04:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPhXJV0hv4jNyYQ09O4SXppRHY3Zs84PQV61QL0+3e815cubyL1sH/IdzEuFBBfjGKU1cX X-Received: by 2002:a17:902:74c1:b0:14a:d9fa:d8a3 with SMTP id f1-20020a17090274c100b0014ad9fad8a3mr5511351plt.119.1642799096835; Fri, 21 Jan 2022 13:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799096; cv=none; d=google.com; s=arc-20160816; b=CkC/ZtLX86o7KnijOsxwXpBZ3aovzIr2GRgCOinl6NKjFsyYGvMDySN/15rzNx80Ic ogv1+0BpF1pU4/yfpf7O1Tmh2s4JI8TXy1BNEBUWQS0cv9fbaTtcBe23VObIVrpNTyCJ prWWORmXhj0twF5ACbJwWoO9uoHl7ldant770IBTgI4lfCO8PlVb8ogR3CWMrPWw/GMd NGYS5C8G8vayFHaxL2VfaCwe3kkdAW2wLwaRDcGGQFjhVYS0QIhz9/tjcuSpGriBQC0Q 1cbfcqov3dekmPb0EMXE1rDCk/GfmVL1Mk6gV4sgH9qeNb2CkJmsg7Ygco367HkeIYX1 zK6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:to:from:dkim-signature; bh=6VcCCa/uNyu5klYi1x3xHgmWoLaBIpIlwVyG80i3crM=; b=bomn25VUluHJKO7gUIwIdQzbEF+3dSzbYKHg/N9bwLA/IoRspJCJqZLpaO21Gr453h FP2A3JVui55NRLQo7uQ592IIwAD3/6+LmDsfmb+poaHs7HerHvMsaREJrUYQBn7F1JzH 1gQktc5Xaj0IXNq5sh33KYc67jg5qOnu/pUxDpLpeN7FGRJDqxIHtfQur/Ye1ZmpmlIL at2UtzGv832Nsm87yON+EUMznuNWijSPElBdx/0/V42aFngwPBoVVDCLcOv6/wk015ch PEJA+1unEQaxF0uvfJOrRw0wI5W7gMwfWdGyMYHTje+jFVEXYSSnTIosUlArbAKmUspB aNBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ULO3DXzf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si6426541pjg.95.2022.01.21.13.04.44; Fri, 21 Jan 2022 13:04:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ULO3DXzf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358362AbiATDcP (ORCPT + 99 others); Wed, 19 Jan 2022 22:32:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234287AbiATDcO (ORCPT ); Wed, 19 Jan 2022 22:32:14 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D35F7C061574 for ; Wed, 19 Jan 2022 19:32:13 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id y27so26561pfa.0 for ; Wed, 19 Jan 2022 19:32:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id; bh=6VcCCa/uNyu5klYi1x3xHgmWoLaBIpIlwVyG80i3crM=; b=ULO3DXzfltvoF1pPRTDLBeRyPli2sY9LcwnVN7wBK9Jt7yVlWDQNnb7gYkJNYAxTIu x4NHVSMFt6GAv4NTEBv4gUcyDxZj+iJcP5rp8S69Zp8ABkhsZl/OSJ7pF+5fDappiqZX XBHaDFEQ+tr1diJixNZFQuuELVy0MbHIwpHA+QpA+QVRUHHDcBXeSm7s1NnXD6gdGYju WXQvmIuah5g6h30xHnSUFk7okFOgXJcjjgq9jwvHjXuIpA8pezl0Z0Mg1kuOa7zM+VlJ 3UPLXl7bYtU6BlWj2mqWMityaizZgsvCG8jETXUTQgGU/zM2B0gfaTjicKDjj2tVkxrm g6pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id; bh=6VcCCa/uNyu5klYi1x3xHgmWoLaBIpIlwVyG80i3crM=; b=YurO39wVaeNfDvPuRtyEsB0SESkWdrlTF0QCa0xv5SQthh3ey8c6/Xr28MZwOhIyCl lqHPmfC7U0yHQ6bgROLp54q+DVogwQaNdQEmCKiwXtCwJ4zdhkPjJ9d2sXhSsGgMRaD5 4etHbsuqmwOMp+9jb3gDV8mU3WtzNkIHiiUA0bDMJnXja851vOae0EBeRGrg8Lbs3HJi uytiYefLjOqg1jobdKXlF7uRfD+0MP53sqBh5nZaZc6SX0C9EOVnpI6YUP/48g36m2xs 2wlh6BH8eGO9j8gCqvN7QIp8RAe/eUpBaW9PmeA0SSxaBJno9lA8ySmVneKTRIenop8d YIow== X-Gm-Message-State: AOAM532LMHamm4M4N15IaAYaMKYTkaBDOCCcXPp/fX+Z9D8oXw6DZzCH 6YMGSU++I1o0Ru+w5HTInlKYnXVijLvKDw== X-Received: by 2002:a05:6a00:803:b0:4c3:37b9:74d8 with SMTP id m3-20020a056a00080300b004c337b974d8mr23024575pfk.60.1642649533338; Wed, 19 Jan 2022 19:32:13 -0800 (PST) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id h10sm1035996pfh.49.2022.01.19.19.32.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jan 2022 19:32:12 -0800 (PST) From: Huangzhaoyang To: Johannes Weiner , Suren Baghdasaryan , Peter Zijlstra , Zhaoyang Huang , Ingo Molnar , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [Resend PATCH v3] psi: fix possible trigger missing in the window Date: Thu, 20 Jan 2022 11:31:56 +0800 Message-Id: <1642649516-15076-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhaoyang Huang When a new threshold breaching stall happens after a psi event was generated and within the window duration, the new event is not generated because the events are rate-limited to one per window. If after that no new stall is recorded then the event will not be generated even after rate-limiting duration has passed. This is happening because with no new stall, window_update will not be called even though threshold was previously breached. To fix this, record threshold breaching occurrence and generate the event once window duration is passed. Suggested-by: Suren Baghdasaryan Signed-off-by: Zhaoyang Huang --- v2: modify the logic according to Suren's suggestion v3: update commit message --- --- include/linux/psi_types.h | 2 ++ kernel/sched/psi.c | 38 +++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index 0a23300..87b694a 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -132,6 +132,8 @@ struct psi_trigger { /* Refcounting to prevent premature destruction */ struct kref refcount; + + bool threshold_breach; }; struct psi_group { diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 1652f2b..5c67ab9 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -524,24 +524,29 @@ static u64 update_triggers(struct psi_group *group, u64 now) */ list_for_each_entry(t, &group->triggers, node) { u64 growth; + bool trigger_stalled = + group->polling_total[t->state] != total[t->state]; - /* Check for stall activity */ - if (group->polling_total[t->state] == total[t->state]) - continue; - - /* - * Multiple triggers might be looking at the same state, - * remember to update group->polling_total[] once we've - * been through all of them. Also remember to extend the - * polling time if we see new stall activity. - */ - new_stall = true; - - /* Calculate growth since last update */ - growth = window_update(&t->win, now, total[t->state]); - if (growth < t->threshold) + /* Check for stall activity or a previous threshold breach */ + if (!trigger_stalled && !t->threshold_breach) continue; + if (trigger_stalled) { + /* + * Multiple triggers might be looking at the same state, + * remember to update group->polling_total[] once we've + * been through all of them. Also remember to extend the + * polling time if we see new stall activity. + */ + new_stall = true; + + /* Calculate growth since last update */ + growth = window_update(&t->win, now, total[t->state]); + if (growth < t->threshold) + continue; + + t->threshold_breach = true; + } /* Limit event signaling to once per window */ if (now < t->last_event_time + t->win.size) continue; @@ -550,6 +555,8 @@ static u64 update_triggers(struct psi_group *group, u64 now) if (cmpxchg(&t->event, 0, 1) == 0) wake_up_interruptible(&t->event_wait); t->last_event_time = now; + /* Reset threshold breach flag once event got generated */ + t->threshold_breach = false; } if (new_stall) @@ -1152,6 +1159,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, t->last_event_time = 0; init_waitqueue_head(&t->event_wait); kref_init(&t->refcount); + t->threshold_breach = false; mutex_lock(&group->trigger_lock); -- 1.9.1