Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp125690ima; Tue, 5 Feb 2019 19:31:58 -0800 (PST) X-Google-Smtp-Source: AHgI3IZiJfyVYE8lCUn82w1dacM8k18X7CPatPrj5bxlp6O9d+DH0h4F/QqfXQGFMnWk+fapnjJ1 X-Received: by 2002:a62:4549:: with SMTP id s70mr8291688pfa.233.1549423918826; Tue, 05 Feb 2019 19:31:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549423918; cv=none; d=google.com; s=arc-20160816; b=lgldxYVbIP9/FHHKu6G3CYG5wNO9EqA0NfbVIBDsD9HLjOvsKcO7VxXhooVb6XoPbY QfHIvmpPze5HFQdzTQNpxqfenv4wLuUdMXf8IPDuvVvUgbVGdNzWeXJhrMrgbv/4GqqJ g7TZJNPmXoqK4RmqzcY3xIG9CoNEKba0WSOm4mSVdmYPCl1nYQ7gt7moLLgYwfouweE0 TNhxsUTGs4FhzsHaARAqegUgoKa6YckYAqmbvaR+h+2hhJ39KI/bVNdeoCvJ0ICMiBVY Ekgb2VY3988zxgs/l8BA5a2FsXxDZ8Ru/WX+JKtlof9L3EgO1UsAfHa9hrTr7c+bozd/ KyHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2KpckL251BnDQ49dTdykZYRulEXUqhwHnii8N+nrLDg=; b=dsXMFJNDbASD75Mv/V8tz+zVAgQPbqUnhBlynyu7rJo03XKyxQcNjWt7/VzVbfEqB7 9Ao83Mptxp7FyYl0S9Btsc72AgTg5b9NqiT0S+KB7qEk6zvgwYIlZJgU8Us5ASHEL3tq FpqHkm13+oJaFACzDOWg/MYklyhhnoVTJt5PNt/KW00OzSFveuhSVtD0oheVqt65YWr7 HixIUfTIwscGSbrpMj6H2kXvI3+US0M237vW1xWHaNnJ8kNOm/DMfYMxNajr6Bfhu4Uw 1IT5Wv+FDVNbFGhy+0i2ontiQLSDMw91ZZa4httFECFVcdl+jWhJkM6z3WmqtdAdlYcy I2cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Yomxc3ni; 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 i13si3439641pgg.100.2019.02.05.19.31.43; Tue, 05 Feb 2019 19:31:58 -0800 (PST) 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=Yomxc3ni; 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 S1727140AbfBFCvO (ORCPT + 99 others); Tue, 5 Feb 2019 21:51:14 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34039 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbfBFCvO (ORCPT ); Tue, 5 Feb 2019 21:51:14 -0500 Received: by mail-wm1-f67.google.com with SMTP id y185so714507wmd.1 for ; Tue, 05 Feb 2019 18:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2KpckL251BnDQ49dTdykZYRulEXUqhwHnii8N+nrLDg=; b=Yomxc3nimH1mOtkYijpjOJCMQSYXAYvp0kMusntYfM7tGBabX7kuF6UXnjRzjvWWOa 80/3plFrHSRKZ6ghgyR2Pw0hh7rUnPIbuT9sd2MNAR7h6RsyWqGWPlbo5sUR4jp7bALQ t/U9NJTOvUHoqa8ycY+DlXy2gYpLXRuRqVfTVkGULOBrOB8FhgQydl1IrsCE6qpCV+ZM SPRUtTStO6EFv947MQIbrdrNjJv8AmH62026R7QWOQouH2TMOGUL5kJTcpykocye+Qka u7V55VonPFGFQFpTmSaLeCIq0V6iv90ukUf+E00wpl3UdYToXtG6mfyVxC3waByOS3GV 4s1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2KpckL251BnDQ49dTdykZYRulEXUqhwHnii8N+nrLDg=; b=cMJScFaPC6GgrpWhrdO2FwtIL7IffJ8r8N2UY8oCPde0J4kLaA4JqqKcgxFklGeJ7D VohKnBwGVCn3cG8+1TXk0THNPe81WR/FQ+oJXZZQ+yepX9UlyYZqa1VQnWL4Yson36F2 ymjtyeWTVmBeFX1C4dPFN8PDcrHJM3SANW/SDReJo8X/KzJlPwtjDWd6IiXXZGKDOUfu Qiz/b13d73oUIKdipm/Z1hyCewLnfF1m9GCozTXBl/AGqxo1zIPozp0149UgsGS3/8BE cWLhivqTPbgUu/KD382dIBPRNn9IwC1H9bVaq5ZBR4bQbrGa5PnmNyslv2cNBXQJHaDP EAdw== X-Gm-Message-State: AHQUAua3/mciNTVAW9Ex0BHdFwYjjs4TqAVK6LS7Wbdryb5czVHgIagb 5OtCjzoED1AqfZqs+LshkU6sp9SwfFiT12+CQQhqMA== X-Received: by 2002:a1c:c7:: with SMTP id 190mr1239785wma.74.1549421471121; Tue, 05 Feb 2019 18:51:11 -0800 (PST) MIME-Version: 1.0 References: <20190116193501.1910-1-hannes@cmpxchg.org> <20190128150635.c22842034ab7e271c6416d2f@linux-foundation.org> In-Reply-To: <20190128150635.c22842034ab7e271c6416d2f@linux-foundation.org> From: Suren Baghdasaryan Date: Tue, 5 Feb 2019 18:50:59 -0800 Message-ID: Subject: Re: [PATCH] psi: fix aggregation idle shut-off To: Andrew Morton Cc: Johannes Weiner , Peter Zijlstra , Tejun Heo , Lai Jiangshan , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, On Mon, Jan 28, 2019 at 3:06 PM Andrew Morton wrote: > > On Wed, 16 Jan 2019 14:35:01 -0500 Johannes Weiner wrote: > > > psi has provisions to shut off the periodic aggregation worker when > > there is a period of no task activity - and thus no data that needs > > aggregating. However, while developing psi monitoring, Suren noticed > > that the aggregation clock currently won't stay shut off for good. > > > > Debugging this revealed a flaw in the idle design: an aggregation run > > will see no task activity and decide to go to sleep; shortly > > thereafter, the kworker thread that executed the aggregation will go > > idle and cause a scheduling change, during which the psi callback will > > kick the !pending worker again. This will ping-pong forever, and is > > equivalent to having no shut-off logic at all (but with more code!) > > > > Fix this by exempting aggregation workers from psi's clock waking > > logic when the state change is them going to sleep. To do this, tag > > workers with the last work function they executed, and if in psi we > > see a worker going to sleep after aggregating psi data, we will not > > reschedule the aggregation work item. > > > > What if the worker is also executing other items before or after? > > > > Any psi state times that were incurred by work items preceding the > > aggregation work will have been collected from the per-cpu buckets > > during the aggregation itself. If there are work items following the > > aggregation work, the worker's last_func tag will be overwritten and > > the aggregator will be kept alive to process this genuine new activity. > > > > If the aggregation work is the last thing the worker does, and we > > decide to go idle, the brief period of non-idle time incurred between > > the aggregation run and the kworker's dequeue will be stranded in the > > per-cpu buckets until the clock is woken by later activity. But that > > should not be a problem. The buckets can hold 4s worth of time, and > > future activity will wake the clock with a 2s delay, giving us 2s > > worth of data we can leave behind when disabling aggregation. If it > > takes a worker more than two seconds to go idle after it finishes its > > last work item, we likely have bigger problems in the system, and > > won't notice one sample that was averaged with a bogus per-CPU weight. > > > > --- a/kernel/sched/psi.c > > +++ b/kernel/sched/psi.c > > @@ -480,9 +481,6 @@ static void psi_group_change(struct psi_group *group, int cpu, > > groupc->tasks[t]++; > > > > write_seqcount_end(&groupc->seq); > > - > > - if (!delayed_work_pending(&group->clock_work)) > > - schedule_delayed_work(&group->clock_work, PSI_FREQ); > > } > > > > static struct psi_group *iterate_groups(struct task_struct *task, void **iter) > > This breaks Suren's "psi: introduce psi monitor": > > --- kernel/sched/psi.c~psi-introduce-psi-monitor > +++ kernel/sched/psi.c > @@ -752,8 +1012,25 @@ static void psi_group_change(struct psi_ > > write_seqcount_end(&groupc->seq); > > - if (!delayed_work_pending(&group->clock_work)) > - schedule_delayed_work(&group->clock_work, PSI_FREQ); > + /* > + * Polling flag resets to 0 at the max rate of once per update window > + * (at least 500ms interval). smp_wmb is required after group->polling > + * 0-to-1 transition to order groupc->times and group->polling writes > + * because stall detection logic in the slowpath relies on groupc->times > + * changing before group->polling. Explicit smp_wmb is missing because > + * cmpxchg() implies smp_mb. > + */ > + if ((state_mask & group->trigger_mask) && > + atomic_cmpxchg(&group->polling, 0, 1) == 0) { > + /* > + * Start polling immediately even if the work is already > + * scheduled > + */ > + mod_delayed_work(system_wq, &group->clock_work, 1); > + } else { > + if (!delayed_work_pending(&group->clock_work)) > + schedule_delayed_work(&group->clock_work, PSI_FREQ); > + } > } > > and I'm too lazy to go in and figure out how to fix it. > > If we're sure about "psi: fix aggregation idle shut-off" (and I am not) > then can I ask for a redo of "psi: introduce psi monitor"? I resolved the conflict with "psi: introduce psi monitor" patch and posted v4 at https://lore.kernel.org/lkml/20190206023446.177362-1-surenb@google.com, however please be advised that it also includes additional cleanup changes yet to be reviewed. The first 4 patches in this series are already in linux-next, so this one should apply cleanly there. Please let me know if it creates any other issues. Thanks, Suren.