Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3726993pxb; Tue, 17 Nov 2020 01:43:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwx4AluH+Yk5dzNLpfnEJUD9FWeKT+RGk8eVjzGBbtYU6uBf9gw7U0ir2hhU+NeyDb6f6cY X-Received: by 2002:a17:906:46d2:: with SMTP id k18mr17801965ejs.33.1605606187787; Tue, 17 Nov 2020 01:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605606187; cv=none; d=google.com; s=arc-20160816; b=FTbvjx/66+PFxRbyVeFSWRjgQyf0EsT9ZXMr6X1/KUwxDONIWqosDt9a2HSOTNdFRR waImFMyt38Ov8r8HsrmeE7/WyYhsX+P884ctMG1gFfAvJkb1XIQ4eiloQXOrMocOn4St 402qrpEZye9tcGejLoa7qFlZNEfgWt0OV/PpVLrVgIOLim7/FBmWa6HpsAkyvkwn3/Z1 ch2GCIzBhfB74q0PytlJXZ3Mvv7NL09VA1o7iGchRkWPj94hSd7dtNyZpu6H37ALhxnf r1ToUYkX2r4IQvR1MPRbohjCRO825EL/mMtOgop8pTg+x2B9f/elNQCPH+xoH+hMx8Ok SOjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ml+AWrO6PMqaRF0x0zELssnj5J1f5i17DJx7o/swHjw=; b=kLQK4/LuBQXvzOHhH7ba7rQeWg2Gw4rX5FPLLGPJUhWef4y25+y9UU2Bsro0U9vcyp di7BaO3RWS+jVhKCJXud02NfQldXh4/kf9y1j25WQHPcUUapPzQ+NmO8Q2qG8sBX+xoD 54vPfh8C5SHgDZaLiF7bWEPqjbno55ARPRyP+UP3VNT3be5ShwTCj5OAUQSSBbfD6bMS ozScfshG0B+G4JeUto9EPxRTu/lXzhEAyK+lna3KC5IZ42uoJHkpRaRyvylxlW4E7+pS OXrMoaYjAhV8ux9eFLKtFCh3LV6uSL+k2cw9w7+ncNj89eAioGtulIe+hzBmAY1hK38g GP3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ecD4yzUI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o18si13625653edr.500.2020.11.17.01.42.45; Tue, 17 Nov 2020 01:43:07 -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=@infradead.org header.s=casper.20170209 header.b=ecD4yzUI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727232AbgKQJig (ORCPT + 99 others); Tue, 17 Nov 2020 04:38:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726502AbgKQJig (ORCPT ); Tue, 17 Nov 2020 04:38:36 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE2CEC0613CF for ; Tue, 17 Nov 2020 01:38:35 -0800 (PST) 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=Ml+AWrO6PMqaRF0x0zELssnj5J1f5i17DJx7o/swHjw=; b=ecD4yzUIy4eHZvXRSm5fpFqGS1 IC1HOihF+b1EhuWTYh4ND4xzy0GC5e12hECr/FbJXKO1/UXCVRyAR2NRCH2DObzNJH+PMfi7cWdH6 1c5sy1x/jCrbL9VjcEt3yMdw8dAXWe5ipow4Y83SIcBwxmk+zW5IuYma241V9q9AumwfKNzII2W4L TlITcNH1W/uoJ6GS3XDYMlK39cS1TiTUsAjYWQ8T5sxZx0AExhmbQEH3KhFlLkYJ8giebFH+WNSBm Yo5HBq1+9JUBWlGF/bhc/5ejAQisl9GTcYDhZTE80F2RrYWJhSVQM5oQc9d69n2pWXVO1lsrae4EL qNSEOHVg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kexRW-00062f-Kt; Tue, 17 Nov 2020 09:38:30 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 9AD29301959; Tue, 17 Nov 2020 10:38:29 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8546C2012638E; Tue, 17 Nov 2020 10:38:29 +0100 (CET) Date: Tue, 17 Nov 2020 10:38:29 +0100 From: Peter Zijlstra To: Mel Gorman Cc: Will Deacon , Davidlohr Bueso , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Tejun Heo Subject: [PATCH] sched: Fix rq->nr_iowait ordering Message-ID: <20201117093829.GD3121429@hirez.programming.kicks-ass.net> References: <20201116091054.GL3371@techsingularity.net> <20201116131102.GA29992@willie-the-truck> <20201116133721.GQ3371@techsingularity.net> <20201116142005.GE3121392@hirez.programming.kicks-ass.net> <20201116193149.GW3371@techsingularity.net> <20201117083016.GK3121392@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201117083016.GK3121392@hirez.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org And poking at this reminded me of an order email from TJ that seems to have stagnated. --- Subject: sched: Fix rq->nr_iowait ordering From: Peter Zijlstra Date: Thu, 24 Sep 2020 13:50:42 +0200 schedule() ttwu() deactivate_task(); if (p->on_rq && ...) // false atomic_dec(&task_rq(p)->nr_iowait); if (prev->in_iowait) atomic_inc(&rq->nr_iowait); Allows nr_iowait to be decremented before it gets incremented, resulting in more dodgy IO-wait numbers than usual. Note that because we can now do ttwu_queue_wakelist() before p->on_cpu==0, we lose the natural ordering and have to further delay the decrement. Fixes: Fixes: c6e7bd7afaeb ("sched/core: Optimize ttwu() spinning on p->on_cpu") Reported-by: Tejun Heo Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2949,7 +2949,12 @@ ttwu_do_activate(struct rq *rq, struct t #ifdef CONFIG_SMP if (wake_flags & WF_MIGRATED) en_flags |= ENQUEUE_MIGRATED; + else #endif + if (p->in_iowait) { + delayacct_blkio_end(p); + atomic_dec(&task_rq(p)->nr_iowait); + } activate_task(rq, p, en_flags); ttwu_do_wakeup(rq, p, wake_flags, rf); @@ -3336,11 +3341,6 @@ try_to_wake_up(struct task_struct *p, un if (READ_ONCE(p->on_rq) && ttwu_runnable(p, wake_flags)) goto unlock; - if (p->in_iowait) { - delayacct_blkio_end(p); - atomic_dec(&task_rq(p)->nr_iowait); - } - #ifdef CONFIG_SMP /* * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be @@ -3411,6 +3411,11 @@ try_to_wake_up(struct task_struct *p, un cpu = select_task_rq(p, p->wake_cpu, wake_flags | WF_TTWU); if (task_cpu(p) != cpu) { + if (p->in_iowait) { + delayacct_blkio_end(p); + atomic_dec(&task_rq(p)->nr_iowait); + } + wake_flags |= WF_MIGRATED; psi_ttwu_dequeue(p); set_task_cpu(p, cpu);