Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4348636ybi; Mon, 3 Jun 2019 09:24:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFfxIIDNPFiT81OKQAlte5qRTWHkNUs6P30RpgFs3A0SLNfITRZ8zV4IE/eRpPQc2HRvar X-Received: by 2002:a17:902:2862:: with SMTP id e89mr31323864plb.258.1559579093456; Mon, 03 Jun 2019 09:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559579093; cv=none; d=google.com; s=arc-20160816; b=MqN0XtR7bDvih6O9dJl9vEfRtV8z9FlhnnUQa2SiWu7ejmzW/PMfqe/rbH7qh1fkyR 8dlnE47P9IbpKQsyUn2YFj/s6Babjy6ymG2AdaCditnTFCDNyxPVGXIqAowUN6/43kw8 eTdjrCOpbvj8UJz6IMucHa2GpsAriVa+YkckS8RC9uaKtyiQXdBBLz1poYeDxNPcRf8P H0MzkL9FCZuSelw/0vLj4P+9ub/1uC+KfIU35NdhrPqBqROdYF/or/ExzVf8WS2Bb5/w jhTR12nzZM8RdxAUxt6CD0QkthsJPSz5LPhX6z9zt/H3CLckGZEQijP/fxlgchYh8j9c n74A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=JANRXtNq/OlXEVUckmhj0Gl/WVjY8ue45Pv7dcHW6sM=; b=IV/2HvvHlKqDx6mYJWZkRTkSbeYHbYuP1KT+NLoBmizBMjjrvMpreY2ofNm3j8UD4F YtPNkhnm6GiQ27L3YsFLLxZX5BOoSODQLQ6VbxEdqVH6ToeH2YAhiac7wK98NIOttznw cq6p/3dqi2O5IX7lj0yrHBmJk/do4v+I1hE+9Kcl7enR3TV1aDzP/ZzBb067/dt+eI8J AFgkt5q5XWYVpj5wvIG7mjEwKTzKetj4dKRHAFREb8WatpHtNR/bRwUpajiHeyieqjB6 IVMpOnBQoFRdffe3V4E31U+p86rmrw+HkQNampioZ0itcuTTFVDEBMsYk4+UrVj6e7Gv 23+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=QGgQrPwV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si20165681pfr.13.2019.06.03.09.24.35; Mon, 03 Jun 2019 09:24:53 -0700 (PDT) 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=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=QGgQrPwV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728853AbfFCQXO (ORCPT + 99 others); Mon, 3 Jun 2019 12:23:14 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:46507 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbfFCQXN (ORCPT ); Mon, 3 Jun 2019 12:23:13 -0400 Received: by mail-pf1-f195.google.com with SMTP id y11so10880210pfm.13 for ; Mon, 03 Jun 2019 09:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=JANRXtNq/OlXEVUckmhj0Gl/WVjY8ue45Pv7dcHW6sM=; b=QGgQrPwVRdf1FporyJuiYg8dww4nmTS56JSFMbwI0B2HL2g870kOaQE9Ywt0x006N6 PjQFzmPuMSqVgpLiHGQiHxKi+RNegLkeQbj9M/kqEAraRxIHkA9uTMK+9MY40yM1oNUU 5RSFX82A4bupgDJL3ID6O1kJCNBQ58xyApRr93QMRGu7ilTUQKe3S+1NMJg8dP1ccaFA H9LgGRGjK46Hz1/8qSOzwXc4iBACaNU/zFlTIHtoP7vs7a5etSrbMcZ3Xa4KVMiZdd7M 27X98Iw/B26uLHcsFuTvb75LvBV0snxsJTFjnQkkPdtn8eciopq44UTkUBjqPGHN3ZFh JbLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JANRXtNq/OlXEVUckmhj0Gl/WVjY8ue45Pv7dcHW6sM=; b=doyUWv0izmqgBU2ekISB12cDkGh1ea8NR9KoR/qCevuEZ2VL/cUeP2dX0oXNFWm652 whMRClDoWAPrvR1c8HxkX92FtnsasWvaCGf8dL2m5f6wqdhq7nP4iQKjx9OXGxDl8tXq 2q5FjhmAyWUQbOSA2eOmsh8z+Pj/it95slDLGz6Up/N9N8wXiAuM2frWSjrsk+4g6r3F QApPt49I1VjOzEeNQyAk4oPJxyaQ7NzROvQs4FTcTNcCXG4Zlu/aw3n/bl6ESgtom7kA JoKlBRiOrSZPlATSQXHuMVkYoz94IGq8IsIEAHHLtszDgMl2bAFnqwxZ9jZog8hz+bfW U/iw== X-Gm-Message-State: APjAAAXqsxBxuHgmByqvLyVI+HTi9g9q318sDpmED7J+9qQizamPkWGs QpomVQzAsYfyNyDWzMNzPiY8GTghTkIaEA== X-Received: by 2002:a17:90a:195e:: with SMTP id 30mr31687487pjh.116.1559578991519; Mon, 03 Jun 2019 09:23:11 -0700 (PDT) Received: from [192.168.1.158] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id d10sm16947450pgh.43.2019.06.03.09.23.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 09:23:10 -0700 (PDT) Subject: Re: [PATCH] block: fix a crash in do_task_dead() To: Peter Zijlstra Cc: Qian Cai , akpm@linux-foundation.org, hch@lst.de, oleg@redhat.com, gkohli@codeaurora.org, mingo@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1559161526-618-1-git-send-email-cai@lca.pw> <20190530080358.GG2623@hirez.programming.kicks-ass.net> <82e88482-1b53-9423-baad-484312957e48@kernel.dk> <20190603123705.GB3419@hirez.programming.kicks-ass.net> From: Jens Axboe Message-ID: <9a75cc4f-bd14-1d98-6653-b49a2842dd16@kernel.dk> Date: Mon, 3 Jun 2019 10:23:09 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190603123705.GB3419@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/3/19 6:37 AM, Peter Zijlstra wrote: > On Fri, May 31, 2019 at 03:12:13PM -0600, Jens Axboe wrote: >> On 5/30/19 2:03 AM, Peter Zijlstra wrote: > >>> What is the purpose of that patch ?! The Changelog doesn't mention any >>> benefit or performance gain. So why not revert that? >> >> Yeah that is actually pretty weak. There are substantial performance >> gains for small IOs using this trick, the changelog should have >> included those. I guess that was left on the list... > > OK. I've looked at the try_to_wake_up() path for these exact > conditions and we're certainly sub-optimal there, and I think we can put > much of this special case in there. Please see below. > >> I know it's not super kosher, your patch, but I don't think it's that >> bad hidden in a generic helper. > > How about the thing that Oleg proposed? That is, not set a waiter when > we know the loop is polling? That would avoid the need for this > alltogether, it would also avoid any set_current_state() on the wait > side of things. > > Anyway, Oleg, do you see anything blatantly buggered with this patch? > > (the stats were already dodgy for rq-stats, this patch makes them dodgy > for task-stats too) > > --- > kernel/sched/core.c | 38 ++++++++++++++++++++++++++++++++------ > 1 file changed, 32 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 102dfcf0a29a..474aa4c8e9d2 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1990,6 +1990,28 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) > unsigned long flags; > int cpu, success = 0; > > + if (p == current) { > + /* > + * We're waking current, this means 'p->on_rq' and 'task_cpu(p) > + * == smp_processor_id()'. Together this means we can special > + * case the whole 'p->on_rq && ttwu_remote()' case below > + * without taking any locks. > + * > + * In particular: > + * - we rely on Program-Order guarantees for all the ordering, > + * - we're serialized against set_special_state() by virtue of > + * it disabling IRQs (this allows not taking ->pi_lock). > + */ > + if (!(p->state & state)) > + goto out; > + > + success = 1; > + trace_sched_waking(p); > + p->state = TASK_RUNNING; > + trace_sched_woken(p); > + goto out; > + } > + > /* > * If we are going to wake up a thread waiting for CONDITION we > * need to ensure that CONDITION=1 done by the caller can not be > @@ -1999,7 +2021,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) > raw_spin_lock_irqsave(&p->pi_lock, flags); > smp_mb__after_spinlock(); > if (!(p->state & state)) > - goto out; > + goto unlock; > > trace_sched_waking(p); > > @@ -2029,7 +2051,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) > */ > smp_rmb(); > if (p->on_rq && ttwu_remote(p, wake_flags)) > - goto stat; > + goto unlock; > > #ifdef CONFIG_SMP > /* > @@ -2089,12 +2111,16 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) > #endif /* CONFIG_SMP */ > > ttwu_queue(p, cpu, wake_flags); > -stat: > - ttwu_stat(p, cpu, wake_flags); > -out: > +unlock: > raw_spin_unlock_irqrestore(&p->pi_lock, flags); > > - return success; > +out: > + if (success) { > + ttwu_stat(p, cpu, wake_flags); > + return true; > + } > + > + return false; > } > > /** Let me run some tests with this vs mainline vs blk wakeup hack removed. -- Jens Axboe