From patchwork Tue Dec 21 08:33:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 12689261 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 990BAC433F5 for ; Tue, 21 Dec 2021 08:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDBA56B0071; Tue, 21 Dec 2021 03:34:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8BBC6B0073; Tue, 21 Dec 2021 03:34:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C53EB6B0074; Tue, 21 Dec 2021 03:34:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0071.hostedemail.com [216.40.44.71]) by kanga.kvack.org (Postfix) with ESMTP id B16A36B0071 for ; Tue, 21 Dec 2021 03:34:17 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 74081894A3 for ; Tue, 21 Dec 2021 08:34:17 +0000 (UTC) X-FDA: 78941139354.17.3D48CF5 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf24.hostedemail.com (Postfix) with ESMTP id 0BE8818002E for ; Tue, 21 Dec 2021 08:34:12 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id 205so6889384pfu.0 for ; Tue, 21 Dec 2021 00:34:16 -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=8bEuaCXKu7mmH+AFbJUwOkYk9y4UKVGL2CArXivgAI8=; b=lgn0Ry4DKRKlifOlEa5IZRu6RN/QPMmmkpsk4gmZ1XxFzZ+yb7wa9vEalOS3srUEKS fXgF9BdEz8kY/fegfMfPhsYfakIWM6aRC3ba2p175OYedLnotYt7nIxOVWnIil7IAMT4 VTEwOJSOQCtHD2g4Nu7IVKcOqwKBsRoq43TKJaUoOjGYBB9L2eGUE5lJZeXilt9RezMT Qu6Y/32Vp89cCzQT3hZ3uNrsFSf8QwGPBF7NWkxKmg7kAWyerT2dt19HUY6L9hVLpOga m/O8XVJS9aZrDYR3YgufWkiT68edFKwLeObXWbxC4fegBRS56h1U8CmliJyUzdlZSgM6 tWzw== 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=8bEuaCXKu7mmH+AFbJUwOkYk9y4UKVGL2CArXivgAI8=; b=owmERH5M3Pmd9EHqdD5aKdWZof1mYLgd7W1k25OjEmgGymuA66rKy3h9Bq5DCJEDpE YSB36nEtk/zRZ/EAMhGFbSowGPQcNTY/nDJ949CDFfyC0m5BRu6H6hPJZc+A//6pHlAU 0HzTKpvWZwWZfB+dEcBmXsa1Vi0wWMMM0A48PMFHeGo4indrb/qUTKmJm5PZuIGK58Gh AL1HmlFpSTH5ChbeBZt1oa0luqp6gKmrlfwS3QGeaQfzc4Q2JbJfOwgNBabHTcsMoCeY baLEKbBcCSL95O8hB50hq/YcM+xkrpM6wzl8kU8i1CS6HGFPj6VQN1a16wHkmlvGAkdX xI0g== X-Gm-Message-State: AOAM531vhHz+e/Re0V44x9XqzkyLdhNooywUcwLEB7ndDaABF/S/KNWN TeANikdlojuaKHZvaY5eFNU= X-Google-Smtp-Source: ABdhPJxwt4vGC82RUYlckmCavwTE42kN6ucOJ/JiNA/74vROdIg/ilCXcSdJjbYshE9DunHBLXfbZw== X-Received: by 2002:a05:6a00:b89:b0:4bb:15c:908c with SMTP id g9-20020a056a000b8900b004bb015c908cmr2209268pfj.34.1640075656070; Tue, 21 Dec 2021 00:34:16 -0800 (PST) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id g12sm1448585pfv.136.2021.12.21.00.34.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Dec 2021 00:34:15 -0800 (PST) From: Huangzhaoyang To: Johannes Weiner , Suren Baghdasaryan , Zhaoyang Huang , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] psi: fix possible trigger missing in the window Date: Tue, 21 Dec 2021 16:33:57 +0800 Message-Id: <1640075637-14520-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0BE8818002E X-Stat-Signature: buc945izrtz31zci1ybhja3xpkoic7g4 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lgn0Ry4D; spf=pass (imf24.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1640075652-966198 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 There could be missing wake up if the rest of the window remain the same stall states as the polling_total updates for every polling_min_period. Introducing threshold_breach flag to record the trigger's status and update the logic. Suggested-by: Suren Baghdasaryan Signed-off-by: Zhaoyang Huang --- v2: modify the logic according to Suren's suggestion --- --- 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);