Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4018630pxb; Tue, 25 Jan 2022 01:31:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKs8G+47Tpr9h6QN1bONEg8LOf90qMAkRVHuvZ/JzE4txoeDZ5sC44VFgV0+o+A//AHybw X-Received: by 2002:a63:5007:: with SMTP id e7mr14555331pgb.295.1643103084553; Tue, 25 Jan 2022 01:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643103084; cv=none; d=google.com; s=arc-20160816; b=Untk3TlHS/DK90z6cA2QqQ6uM3siX6q8kxqWDtNMy4DA5OP6movk4m6V8EyaJuWRLR QfkVpQERZYGEbJOLAqvzlpUAy39D0TNcRYe8bbDKLPN8X0xtlv7/oRqRoR+EfS34Xgn2 uIDBxG8j2o3KK12Fim3GzGeP/qWjJwhCtgeTe1TZd8vleMXK0bNu6UrXtTt7eiGHmbki kyhR/YWOtsIedA9yq7f+Hg8IW49V4tmACeZQAWQubt3W15Th175k5GG0537ZLBK3j0O0 FAtj64kw2GJ0h8v6nUsX3y3R8UP/HtqJ1nDLHbKLMPGCiuZ2ArwvMGitLWtx2RY4p2HN 7zAg== 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=BCtqKKKae1nbJrnhJrOTwrukfpxsmoJefws7zuhcAHw=; b=TNk+U0s041G9MsfB1OkgkmGbJPzRmKtxD2jJJ/rd3vn0BnjrPY6lpwPIKyxzwXvvVW AwAO2574+LipZaqRhk92BOQqkQbwKHFx/u2XLjVGeOfqZn0fP9bb9t31fZmmrYm37b8u 9csxtUGJTPWRbW/uxCgMFUJW8RjlZCczD3a1s733buaMIbICO5lC7HMcUf21UjcHeC49 77bp139G+p0rIAO1km6QWqi1f2IZFdsQqiLYXHuA6gsfAZo2EVR0bKXwSMcbNxj+CYqO UCujcL36YCE2apngt20yFGxw8Tc/QTbNQDZUelhl+x8q8diGc196GSsdgGrGyHBF8gZ7 Bd7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="SSF72/Qj"; 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 p13si7608017plf.137.2022.01.25.01.31.12; Tue, 25 Jan 2022 01:31:24 -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="SSF72/Qj"; 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 S1451409AbiAYIh6 (ORCPT + 99 others); Tue, 25 Jan 2022 03:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1450719AbiAYIdN (ORCPT ); Tue, 25 Jan 2022 03:33:13 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B4EEC0612AF for ; Mon, 24 Jan 2022 22:57:18 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id d1so18303976plh.10 for ; Mon, 24 Jan 2022 22:57:18 -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=BCtqKKKae1nbJrnhJrOTwrukfpxsmoJefws7zuhcAHw=; b=SSF72/QjjYdyWJdBXKYhYAc8iQHn5Y8zWNSlDi9SMHxnF4VLhtwGVXfqxwNBdantFd L0VliNgqgt1dRmPK7YvWx2eZf4W3iYHMDRgfxa5qYShBhSRJEj7ZcFuv/vp2MUXyygYB qwrvhfSB9pD/rxwAydIzj3jIymkNMMhB2vseOArds+jRlk9CahLSkA0MYJlWExOPH1+u px385Af+ZE3Fq4JQGkeWCpIF+1KCFSZoBYnSbugtS5WG7khPHl19/XQohFJ4oz6Xiq5Z j7n7sZW4x4oj/3PXfSH/EGrCWNcgg0rpnNBG9TcVlDprFqSmJFbvoUZRpY/cRSG/ebyd byDA== 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=BCtqKKKae1nbJrnhJrOTwrukfpxsmoJefws7zuhcAHw=; b=dgjeyu7+1cJ5tMiK4rIHg7GUIAD/3LTUeR/ZskJkbakDU8DYxtKwdqjRsP36cgKN0B JKotLhs2I33I5qyiFkEWZGAkEk5ZNuhZh6akJm7MnmKmEPHyHMh16vbLorQOKonqKBkl CIQhBEmOcBt5oNE/FkrQ88v981RoWCxokW9hAidXCrh9QvBTkMT48YANgYXyB/M7JUVe i8fDys0gfS8lgSfFjD2FukZ3hHqolTJHE1DFaoGcsWYI2nFzE5r2e+BSN4bW71pmIuxK PTkoJ//IPQ3+Rv77H87VhuwuZiT8xFJuCMNAYzZr0wNdMX7sH4a7fwYLV7EsaqnN2oZE k38A== X-Gm-Message-State: AOAM532Li5hLOto9WTvvsuOzxwO/Y9p3bPrx5l6D8O435457zkGZKAm5 eUwbu+oLYOu9d6VjdEU/Y8g= X-Received: by 2002:a17:902:e5c5:b0:14b:1bbb:9f5 with SMTP id u5-20020a170902e5c500b0014b1bbb09f5mr16983715plf.62.1643093837548; Mon, 24 Jan 2022 22:57:17 -0800 (PST) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id o18sm18941565pfu.45.2022.01.24.22.57.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jan 2022 22:57:16 -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: [PATCHv4] psi: fix possible trigger missing in the window Date: Tue, 25 Jan 2022 14:56:58 +0800 Message-Id: <1643093818-19835-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 v4: update variable name and comments --- --- include/linux/psi_types.h | 3 +++ kernel/sched/psi.c | 46 ++++++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index 0a23300..e0ec129 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -132,6 +132,9 @@ struct psi_trigger { /* Refcounting to prevent premature destruction */ struct kref refcount; + + /* Deferred event(s) from previous ratelimit window */ + bool pending_event; }; struct psi_group { diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 1652f2b..dd80bd2 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -515,7 +515,7 @@ static void init_triggers(struct psi_group *group, u64 now) static u64 update_triggers(struct psi_group *group, u64 now) { struct psi_trigger *t; - bool new_stall = false; + bool update_total = false; u64 *total = group->total[PSI_POLL]; /* @@ -524,24 +524,35 @@ static u64 update_triggers(struct psi_group *group, u64 now) */ list_for_each_entry(t, &group->triggers, node) { u64 growth; + bool new_stall; - /* Check for stall activity */ - if (group->polling_total[t->state] == total[t->state]) - continue; + new_stall = group->polling_total[t->state] != total[t->state]; + /* Check for stall activity or a previous threshold breach */ + if (!new_stall && !t->pending_event) + 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. + * Check for new stall activity, as well as deferred + * events that occurred in the last window after the + * trigger had already fired (we want to ratelimit + * events without dropping any). */ - new_stall = true; - - /* Calculate growth since last update */ - growth = window_update(&t->win, now, total[t->state]); - if (growth < t->threshold) - continue; - + if (new_stall) { + /* + * 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. + */ + update_total = true; + + /* Calculate growth since last update */ + growth = window_update(&t->win, now, total[t->state]); + if (growth < t->threshold) + continue; + + t->pending_event = true; + } /* Limit event signaling to once per window */ if (now < t->last_event_time + t->win.size) continue; @@ -550,9 +561,11 @@ 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->pending_event = false; } - if (new_stall) + if (update_total) memcpy(group->polling_total, total, sizeof(group->polling_total)); @@ -1152,6 +1165,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->pending_event = false; mutex_lock(&group->trigger_lock); -- 1.9.1