Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp213637pxj; Wed, 16 Jun 2021 00:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDL6W5hoG7B/UbKmNhhFaxQWNX/zwRPt+L7xunZgzCEWnHVMTToSD8biKAOPsrCFtAiITb X-Received: by 2002:a92:2a0a:: with SMTP id r10mr2666246ile.274.1623827812674; Wed, 16 Jun 2021 00:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623827812; cv=none; d=google.com; s=arc-20160816; b=X6BHg9jgv2hrwMYTOOmmyBH5FhPeXL0LHD1bUdOfntp3RtEfGY6PQyKhz4GpnDB4kz WCeROIdt3LE8jmMiSf5P1BSaDIz6zZxOjpu7iLM81z5Ub5285gXnI48vYlE3GnXUXHXG sfuYewkTOcx5BYRiWyYCgOqts+cbdV5aN8XU4ZvT6DoXNDiSaZXoN1Gz7GM3NhRupca8 1du8hmFy+mnit+J6J0+AjW5Sn1oZu3rZN8mdcOBSIY9BkbLrH3XD0K4xgJnHsMNc+JTE vAv2xfgz0hvoCQiKLXN6O0RidTy0ULwsbq0s3UavSjCelCMvD2AXz27/juSA7O6QphiW zZqA== 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=Nm/O/6WGf8Wxwk4bIaTq5mHG8cnBuV454KMheuOsnFI=; b=xmaK94d3eD00aX3wSLAPxFEN4KFKHI/1wTDx47LzJMSGxkWxLLb8FQPm3rek5AtMOR V6Uivxi/55bbg5P3OhyFry6OziFz1moohcIKNOsq5aXJQC5++52DQsq6Z0KdV+wCcVR5 VK0Nd7NLYnfzgrdWv70l9r4zRPiBGXjcHaK8dnnho8WP5+4W9fgi8XHLWePHqZ8vkK2W 3hdp7rXqlCOO4vP2fqA7k4UMJ4r6lmvILdtevPOcDzruV+YqsbVD/YZIbBbqFw+dgFj1 QS4L+9/mbAtXfSMT7HGa9PdYOeqPrHEt3RVd3Pf7BPK7aXDDfkmQu+89vADZUwEd+NwY y+Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Sd7qT4LE; 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 g15si1504966ilk.84.2021.06.16.00.16.38; Wed, 16 Jun 2021 00:16:52 -0700 (PDT) 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=Sd7qT4LE; 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 S231256AbhFPHSN (ORCPT + 99 others); Wed, 16 Jun 2021 03:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbhFPHSM (ORCPT ); Wed, 16 Jun 2021 03:18:12 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E02C061574 for ; Wed, 16 Jun 2021 00:16:07 -0700 (PDT) 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=Nm/O/6WGf8Wxwk4bIaTq5mHG8cnBuV454KMheuOsnFI=; b=Sd7qT4LEl4QVGTXSruESA+QmZQ 3OS5zEOCVfuZFQnvMhW/9S8sMD0xN0yVxL6A87ZjhJHHOENHLSxY8tMfTEGlW6WVQ64dcklx+dQFN b8+ujIJSzOIsKFOGgb1/9OiKcZa0gUBImpoGN7/whQsLYOem+x1pN7QqdgbCD1ik0fE0E756PlEro PQR8njayoRXir53PnU+NyYZQuA3KzBgK21if5QIhrgKN6s+RVeSQYbAewS+t8IeQSbLTAZxagHoe0 geh//y/cs2f0lXXDNPadR0fgACEOReiSwojIn6aXvK1KOs7RqwKQgYDOHT+TuEqYxbzhfaZG2EoZM eqxr+Tpg==; 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.94.2 #2 (Red Hat Linux)) id 1ltPlZ-007jiE-Up; Wed, 16 Jun 2021 07:15:17 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8C57F3001E3; Wed, 16 Jun 2021 09:15:12 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 39FEE20C169F5; Wed, 16 Jun 2021 09:15:12 +0200 (CEST) Date: Wed, 16 Jun 2021 09:15:12 +0200 From: Peter Zijlstra To: Yafang Shao Cc: Vincent Guittot , Ingo Molnar , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Mel Gorman , Daniel Bristot de Oliveira , LKML , Valentin Schneider , Thomas Gleixner Subject: Re: [PATCH] sched, fair: try to prevent migration thread from preempting non-cfs task Message-ID: References: <20210615121551.31138-1-laoar.shao@gmail.com> <20210615203534.GA4272@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 16, 2021 at 09:44:46AM +0800, Yafang Shao wrote: > On Wed, Jun 16, 2021 at 4:35 AM Peter Zijlstra wrote: > > > > On Tue, Jun 15, 2021 at 08:15:51PM +0800, Yafang Shao wrote: > > > --- > > > kernel/sched/fair.c | 14 ++++++++++++++ > > > 1 file changed, 14 insertions(+) > > > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > > index 3248e24a90b0..597c7a940746 100644 > > > --- a/kernel/sched/fair.c > > > +++ b/kernel/sched/fair.c > > > @@ -9797,6 +9797,20 @@ static int load_balance(int this_cpu, struct rq *this_rq, > > > /* Record that we found at least one task that could run on this_cpu */ > > > env.flags &= ~LBF_ALL_PINNED; > > > > > > + /* > > > + * There may be a race between load balance starting migration > > > + * thread to pull the cfs running thread and the RT thread > > > + * waking up and preempting cfs task before migration threads > > > + * which then preempt the RT thread. > > > + * We'd better do the last minute check before starting > > > + * migration thread to avoid preempting latency-sensitive thread. > > > + */ > > > + if (busiest->curr->sched_class != &fair_sched_class) { > > > + raw_spin_unlock_irqrestore(&busiest->lock, > > > + flags); > > > > This won't apply. > > > > Also, there's still a race window, you've just shrunk it, not fixed it. > > Busiest can reschedule between the mandatory rq unlock and doing the > > stopper wakeup. > > > > An actual fix might be to have the active migration done by a FIFO-1 > > task, instead of stopper. The obvious down-side is that that would mean > > spawning yet another per-cpu kthread. > > > > The stopper and the migration thread are different threads in the earlier days. > commit 969c79215a35 ("sched: replace migration_thread with cpu_stop") > merged them into one thread. Yes, I know, I was there. But that's not what I'm saying, we need the migration thread to be super high perio for other cases. That change still makes sense. > Regarding the priority of stopper (with highest priority) and > migration (higher than CFS, but lower than RT) , keeping them in one > single thread seems not a good way. I never suggested as such. Only the active migration of CFS can be done by a FIFO-1 task (the lowest prio that is higher than CFS) and possible the numa balancing thing. Other migrations will still need to use stopper, and as such you'll keep having interference from stopper. The suggestion was adding a cfs_migration thread, specifically for active balance (and maybe numa). Just not sure the cost of carrying yet another per-cpu kernel thread is worth the benefit.