Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3260053lqo; Wed, 15 May 2024 04:48:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyyLhFrmdCJlyuBdYZYO8OyAKlhzNh4isJV3H/jOJ/jnQEh1OjqneL4YXZ3ZCR6preImucwKxvtATr/12NNq20x87ydyeFsIO6mZ0Tng== X-Google-Smtp-Source: AGHT+IGhubTJNmlsvDjAb+9PKq3KTjOKcPdwYkCFGcaIw2HvT5674B+fS8FX+eNuQcY5HFtez8gw X-Received: by 2002:a05:620a:2993:b0:792:9527:c162 with SMTP id af79cd13be357-792c75f1f79mr1982303185a.50.1715773732595; Wed, 15 May 2024 04:48:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715773732; cv=pass; d=google.com; s=arc-20160816; b=pZ6lCXRuCrDpHLwIvUhX4hInM1DXUwaR8BJTAkpRRAt63Jg0rALOmWAZYWdu+Asq2Y XVE4X1fTsKhMzJjDgNPlMS/2vCp+QO1kiRsFY1xmnc3iokd/n/bE/YPvMB171R1wiEdX w/uCXMZ6jGTrnMIpYmPLRIuAbfp0/z0T1oV5KZJRfY1GhFu/P0lC7Py/AXpOHpq6wuzv 9jlb5Ni+u6zHV/G/z9RX0eKGpSjQgUEzAl1nSBSawYA0swn1Ql0tVAnwOuHvHlmllQkP 23MGx3R624N8xDwiT/gBWkkmBtySqYVUzH0ugX41qYxym431bD/u9ppUOhsHXPi0cNHo eWBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FFsrr8x9TFZA3GNSLmifIzCZ7TQAIkuSwKQBBQMGbKY=; fh=EvERlYCpu0LE1ei6EJAydx/jEk6dXzqx+59wyqqeea0=; b=YXLIvO1XpQXXMh7XExQo1XcuRKhf27C8lOSVPD0S4MI1W71IVd49HjbKHxC4bihEIg oJ0Q4JkCnd/TQF9+LSKNY+oTAOqVNHcKbXoTWMTXWF80wWcZus5mtH0eIo+eXb9orFzs qFGOrNgEsSNtMV4K9KiucU8wEtHlgdDSZukQ9BXBk6l9SAP0CeVT0lbOdmifbFV2bLM0 G/I+5wTTHqTkYCn9hhke+Uml0FIxMWll4Nk480XF6M/KvnnpIXroPyhQp7ggnGz0SCAA p+xRg76vGZYlFSysV5dd1+GoSG/UMlkzegzXB7RSe8GT97tf7X0yOasGbF2Pmwi1GXy3 GzIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VzQmBzBq; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-179819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179819-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf30a447si1519055785a.290.2024.05.15.04.48.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 04:48:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=VzQmBzBq; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-179819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179819-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 461AB1C20E7A for ; Wed, 15 May 2024 11:48:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05FC46F077; Wed, 15 May 2024 11:48:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VzQmBzBq" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65B992CCD0 for ; Wed, 15 May 2024 11:48:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715773726; cv=none; b=DD68aQx3RGKK8YkxnbXbZExF8Oqe5cO/b06JLZeN49S6EpUK9Gy+1XBTIOwoLRYLxYWhETteGsVu3RE754iYa1WyeNVM7kihR6iwSXaXvaCQXfNEpQUiNpjkb4OeOmGGC2bjEdTZwU3Sj6L2W2iDIAzb2AHOMItJRNaTmHJv1j8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715773726; c=relaxed/simple; bh=nRdoqcnIgajr9m4SQFCPnF8s6F1in0LeJsdZrDbz8Kw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h4cDPALAw6+VeK6pYVQd3DJOF1oqSP9GCNPYK1dU6WNbYLSI/8H8oFMaY2R/VE03hml6lbqk4CaxACw4U0uujKrQkKOMZ/E7Fqv328t3xS+jmz6LbXKq2geE2jGeEdVRdVUkhvTef7Sa1zaKt6saFOHFmvYLvnZzJDNkQXsCl0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=VzQmBzBq; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FFsrr8x9TFZA3GNSLmifIzCZ7TQAIkuSwKQBBQMGbKY=; b=VzQmBzBqyQDehI94nbb/4CxlJV RN2zwY6Up8luzn4Sh1x0kibz5XUMs9ztoSE6S2smGY4tbiYX7pscIEg4gG9xLmYVs7yvr1T6SeGU1 L2m6dIRuSnGcC/ERiyY/2Rk1Hm0fRcdkCWY8ZdVJnwZp6NAYMGUUBNL89n7D2a9bTSNVHVxbL1vE0 AmCXMgAIbT7YkwG5lRtjDQMu+5G+UugbjwOPAvGjLUxEI+QXAophEpPhA/OiHYysfXuU4hQBLx1BM CId9ULtzIfr/awT+D/YWgootBuw02fSxz6hprqJNW2g4BnAC4xKyOCtxFm1Gb4VgTUW/2/14kh+RC q7cgTE+A==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7D7X-0000000ALfd-3sHZ; Wed, 15 May 2024 11:48:32 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id ED9C83005E3; Wed, 15 May 2024 13:48:28 +0200 (CEST) Date: Wed, 15 May 2024 13:48:28 +0200 From: Peter Zijlstra To: Luis Machado Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, kprateek.nayak@amd.com, wuyun.abel@bytedance.com, tglx@linutronix.de, efault@gmx.de, nd , John Stultz , Hongyan.Xia2@arm.com Subject: Re: [RFC][PATCH 08/10] sched/fair: Implement delayed dequeue Message-ID: <20240515114828.GO12673@noisy.programming.kicks-ass.net> References: <20240405110010.631664251@infradead.org> <3888d7c8-660e-479c-8c10-8295204e5f36@arm.com> <1461277e-af68-41e7-947c-9178b55810b1@arm.com> <20240425104220.GE21980@noisy.programming.kicks-ass.net> <20240425114949.GH12673@noisy.programming.kicks-ass.net> <20240426093241.GI12673@noisy.programming.kicks-ass.net> <2fba04b0-e55e-41f4-8b7a-723734fe1ad2@arm.com> <219b8b49-3767-4010-aa68-9e1cf66c2ccb@arm.com> <20240515093649.GF40213@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240515093649.GF40213@noisy.programming.kicks-ass.net> On Wed, May 15, 2024 at 11:36:49AM +0200, Peter Zijlstra wrote: > On Fri, May 10, 2024 at 03:49:46PM +0100, Luis Machado wrote: > > Just a quick update on this. While investigating this behavior, I > > spotted very high loadavg values on an idle system. For instance: > > > > load average: 4733.84, 4721.24, 4680.33 > > > > I wonder if someone else also spotted this. > > Hadn't spotted it, but now that you mention it, I can definitely see it. > > Let me go prod with something sharp. Thanks! What's the point of making notes if you then don't read them... *sigh*. Does this help? --- kernel/sched/core.c | 23 ++++++++++++----------- kernel/sched/fair.c | 4 ++-- kernel/sched/sched.h | 8 ++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5ffd7e047393..43f061bcfe54 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2154,14 +2154,18 @@ void activate_task(struct rq *rq, struct task_struct *p, int flags) void deactivate_task(struct rq *rq, struct task_struct *p, int flags) { - bool sleep = flags & DEQUEUE_SLEEP; + SCHED_WARN_ON(flags & DEQUEUE_SLEEP); - if (dequeue_task(rq, p, flags)) { - WRITE_ONCE(p->on_rq, sleep ? 0 : TASK_ON_RQ_MIGRATING); - ASSERT_EXCLUSIVE_WRITER(p->on_rq); - } else { - SCHED_WARN_ON(!sleep); /* only sleep can fail */ - } + dequeue_task(rq, p, flags); + + WRITE_ONCE(p->on_rq, TASK_ON_RQ_MIGRATING); + ASSERT_EXCLUSIVE_WRITER(p->on_rq); +} + +static void block_task(struct rq *rq, struct task_struct *p, int flags) +{ + if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags)) + __block_task(rq, p); } static inline int __normal_prio(int policy, int rt_prio, int nice) @@ -6693,9 +6697,6 @@ static void __sched notrace __schedule(unsigned int sched_mode) !(prev_state & TASK_NOLOAD) && !(prev_state & TASK_FROZEN); - if (prev->sched_contributes_to_load) - rq->nr_uninterruptible++; - /* * __schedule() ttwu() * prev_state = prev->state; if (p->on_rq && ...) @@ -6707,7 +6708,7 @@ static void __sched notrace __schedule(unsigned int sched_mode) * * After this, schedule() must not care about p->state any more. */ - deactivate_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); + block_task(rq, prev, DEQUEUE_SLEEP | DEQUEUE_NOCLOCK); if (prev->in_iowait) { atomic_inc(&rq->nr_iowait); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 536eabcb1a71..596a5fabe490 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7032,8 +7032,8 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags) util_est_update(&rq->cfs, p, task_sleep); hrtick_update(rq); - /* Fix-up what deactivate_task() skipped. */ - WRITE_ONCE(p->on_rq, 0); + /* Fix-up what block_task() skipped. */ + __block_task(rq, p); } } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 12841d8195c5..48e5f49d9bc2 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2560,6 +2560,14 @@ static inline void sub_nr_running(struct rq *rq, unsigned count) sched_update_tick_dependency(rq); } +static inline void __block_task(struct rq *rq, struct task_struct *p) +{ + WRITE_ONCE(p->on_rq, 0); + ASSERT_EXCLUSIVE_WRITER(p->on_rq); + if (p->sched_contributes_to_load) + rq->nr_uninterruptible++; +} + extern void activate_task(struct rq *rq, struct task_struct *p, int flags); extern void deactivate_task(struct rq *rq, struct task_struct *p, int flags);