From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D38EC2D0E4 for ; Tue, 17 Nov 2020 09:38:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A48732467A for ; Tue, 17 Nov 2020 09:38:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ecD4yzUI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbgKQJig (ORCPT ); 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); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DA2DC2D0E4 for ; Tue, 17 Nov 2020 09:39:11 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C830924671 for ; Tue, 17 Nov 2020 09:39:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Pul5tudM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ecD4yzUI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C830924671 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Qwna1wMvjDMTWUDraNezni5FQ+T5IyjEl4p5GJvfhDE=; b=Pul5tudM8iUwAQbTODHEHJO1K /GL89zcP9t1NwNEmi9NIaJHmyOHbUUqn0JPRPijGY1lFrOzngKpp1sB9GmpWlw5fJxQDovoqN+Q/0 AKG2yPk/EsexLpbeGfOL/WPG6ucAP2GoxIXmrTstp+EaN85QXrtgJ/3j/qY8owH6OiondtAZoQxTE baf95MVK7Mf30NdQD1LPEse2yWBks0ngEHq0IpoxRTnJPxNxirUn5kAz4ayVeenBKOB+qz7IEkulv VrUqHobZkV94ExuGVzm+TMf9pNtkJR8xEsjizwmXSsc/LmHeMB3xdhZf+4xGMy5csOOpcADsOfVdZ jMfyjVNhQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kexRZ-0000vH-HB; Tue, 17 Nov 2020 09:38:33 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kexRY-0000v9-99 for linux-arm-kernel@merlin.infradead.org; Tue, 17 Nov 2020 09:38:32 +0000 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 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-Disposition: inline In-Reply-To: <20201117083016.GK3121392@hirez.programming.kicks-ass.net> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tejun Heo , Davidlohr Bueso , Will Deacon , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel