From patchwork Thu Jan 20 03:31:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 12718236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47DEEC433F5 for ; Thu, 20 Jan 2022 03:32:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 455276B00C0; Wed, 19 Jan 2022 22:32:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DCF06B00C2; Wed, 19 Jan 2022 22:32:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 257136B00C4; Wed, 19 Jan 2022 22:32:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 0F3CB6B00C0 for ; Wed, 19 Jan 2022 22:32:15 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B8A1680EBF87 for ; Thu, 20 Jan 2022 03:32:14 +0000 (UTC) X-FDA: 79049242188.14.D675CD1 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf12.hostedemail.com (Postfix) with ESMTP id 6580740024 for ; Thu, 20 Jan 2022 03:32:14 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id v74so917573pfc.1 for ; Wed, 19 Jan 2022 19:32:14 -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=avfcsolUwTB3gUFqIQFVla7Ofu7zVG13ZXv9BDPZrYZlxMec99riYLN33DEh4YxWGV t8eXNb/ARjpJ9Bcc+YH2MuIE17YtKUyEGvgiqKEk+HsGvv0nB9GUdxXlWP7ih8E8yaUD 6DZ7O+4eJ44i9uu4338Mt+v48o6SbgRQgmveJreUCMBetgyDVLp+9q+s2E/vZJlqpv+R uxRtbRwElSE68wJFo+doiPcIbyr+WLTptL2qrwc6Ce+rveB4CpDF10mwQw+IqglH6hPe leJeaFANviwFEbHskppQBpKLN8gxC1QSxQXbwGEiK4jgYVRPT0fTr5o8bWqmbVu8nH4F rHow== X-Gm-Message-State: AOAM530sBINKfSziNzbkPIu50YraXihTIwtG5DHmeDDAK/J9yJTrenxJ +u+QdmdC0eseYRh2CFc1NZo= X-Google-Smtp-Source: ABdhPJyU2wvXBwrRe/LnxztvOS2PjL2olL8B7hpWapZ/PFjhalgfpmkk/8PC41fbNLGwhYQatAoi+g== 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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6580740024 X-Stat-Signature: 3nf5id55opg9edetpuqfzsjqfkhzx5ig Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ULO3DXzf; spf=pass (imf12.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1642649534-826693 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);