Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3086553rdb; Mon, 4 Dec 2023 17:01:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrpJHNPfazpFBwlZFImlsF4zcBavztSEvnIMtqM2PZ5Tz2PwZVsiVmDIdvaqAOTq+FB3E4 X-Received: by 2002:a05:6a00:130a:b0:6ce:6898:c426 with SMTP id j10-20020a056a00130a00b006ce6898c426mr454807pfu.31.1701738099092; Mon, 04 Dec 2023 17:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701738099; cv=none; d=google.com; s=arc-20160816; b=0HR24y4R3EUHvxQVfVQxp9Guia9VErs2IcIDxPynXMubRJrZi1klZnMiy2nUQtRfVk p/+RoNP3oLgPYs89eyPOrnQGSAKZs8gguAHWhZj5J98a4H6Jg2VAX06wjV88nckdjADB 8dDFFIOfbC7gyzjJdvP4mDx8uARavg0VeIWg2WbtH3v1N8Qf6endlKhXXt1OERTU4GCX yVjA2Jbxxrl6JZCDXpuVBA56iTsPbay2gWuOuSfK3un8hI/ceN19Mgx1E6N9KBLLWcL+ HiSCm+Oqt9JaGrFmrTsZdri7WMoW2wUDEWJ/YH/WY5+KMFWMewp7uoaa779aDBa+Cy5t 2UfA== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=3Lbk4HWmSAmiIgyNxsBgCTiloBrK6Na2ZkN+fM1shHA=; fh=99ZpYi0lREmTZ+Ei9+53xdBGF7Xgh+ZpbVl15HBE0HY=; b=yC4MuKPCgLlj02MxWTIEkF5yfTw1hf8CQ6XTtRdjaTs4aeJlNis96Fm+L04sc1S6bF HSz7AJ8Mw7SI3bBhrVHaHj4WQLhwFvECGx4falHrqEycPAKbT072IDMAvOXUerWkFxtH 2XXbY9LBopKTLMGSxJLyJh8U/d5JKB/MDMKIMrBB9Kql5n/Oh+biDCtyaxsXNtL4cK14 fQc2zHSv7X35ow4wnY1Ek3eXkiaJYNo5d+qUDZ7pWfJROnExzbSfegJShhAGaGKUP3LL Mg2qQpokzKvMnDrJBrOfyCLL8rB+w++6jUqcRTg/uy7LVatuyWpHuCkfe4jRRdfhXkOU iIjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eayp4XkN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id f13-20020a056a00228d00b006ce690155fcsi549962pfe.245.2023.12.04.17.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 17:01:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eayp4XkN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 13F4F8039DF9; Mon, 4 Dec 2023 17:01:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231567AbjLEBBT (ORCPT + 99 others); Mon, 4 Dec 2023 20:01:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjLEBBS (ORCPT ); Mon, 4 Dec 2023 20:01:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D224101 for ; Mon, 4 Dec 2023 17:01:24 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27B7FC433C7; Tue, 5 Dec 2023 01:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701738084; bh=87+opENFHVxb4r8vWzTfPZbzUsfLV0xi8qw1aguD08c=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=eayp4XkNfs4A+5kiHvcgyT8erJMahBuKlXkjRI+zG9MhS/KzQOEAR4XnJ6MXkOgoZ 5fOITSZSmSGMeDXUrsaWreX4882T8jzHitfh5M0S/B8YTyFtVxQjw8UFFYgYwCW5y7 SHsNo7cCman4adEx0/NH/V7+Lg3GKcNw9JDZ6CA/3x8bpViRjuvjCBjYhzCLPGjZOH n9fJYT7SUehfCMbcw44fXoOQ9EMn5EbRWzcSP4kGP+DAc4xMR1FAqQT19x5IjCsU7z kGSz8tPdAidqknvhfhpzm5etbx9dzc4pFnXeB9T3i3vcNQyP5sNevP6oy6blq1RWgb DQKIkMWmh2oJw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B1A76CE1147; Mon, 4 Dec 2023 17:01:21 -0800 (PST) Date: Mon, 4 Dec 2023 17:01:21 -0800 From: "Paul E. McKenney" To: Thomas Gleixner Cc: Steven Rostedt , Ankur Arora , linux-kernel@vger.kernel.org, peterz@infradead.org, torvalds@linux-foundation.org, linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, willy@infradead.org, mgorman@suse.de, jon.grimm@amd.com, bharata@amd.com, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, jgross@suse.com, andrew.cooper3@citrix.com, mingo@kernel.org, bristot@kernel.org, mathieu.desnoyers@efficios.com, geert@linux-m68k.org, glaubitz@physik.fu-berlin.de, anton.ivanov@cambridgegreys.com, mattst88@gmail.com, krypton@ulrich-teichert.org, David.Laight@aculab.com, richard@nod.at, mjguzik@gmail.com, Simon Horman , Julian Anastasov , Alexei Starovoitov , Daniel Borkmann Subject: Re: [RFC PATCH 47/86] rcu: select PREEMPT_RCU if PREEMPT Message-ID: Reply-To: paulmck@kernel.org References: <87wmu2ywrk.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wmu2ywrk.ffs@tglx> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 17:01:36 -0800 (PST) On Tue, Nov 28, 2023 at 11:53:19AM +0100, Thomas Gleixner wrote: > Paul! > > On Tue, Nov 21 2023 at 07:19, Paul E. McKenney wrote: > > On Tue, Nov 21, 2023 at 10:00:59AM -0500, Steven Rostedt wrote: > >> Right now, the use of cond_resched() is basically a whack-a-mole game where > >> we need to whack all the mole loops with the cond_resched() hammer. As > >> Thomas said, this is backwards. It makes more sense to just not preempt in > >> areas that can cause pain (like holding a mutex or in an RCU critical > >> section), but still have the general kernel be fully preemptable. > > > > Which is quite true, but that whack-a-mole game can be ended without > > getting rid of build-time selection of the preemption model. Also, > > that whack-a-mole game can be ended without eliminating all calls to > > cond_resched(). > > Which calls to cond_resched() should not be eliminated? The ones which, if eliminated, will result in excessive latencies. This question is going to take some time to answer. One type of potential issue is where the cond_resched() precedes something like mutex_lock(), where that mutex_lock() takes the fast path and preemption follows shortly thereafter. It would clearly have been better to have preempted before acquisition. Another is the aforementioned situations where removing the cond_resched() increases latency. Yes, capping the preemption latency is a wonderful thing, and the people I chatted with are all for that, but it is only natural that there would be a corresponding level of concern about the cases where removing the cond_resched() calls increases latency. There might be others as well. These are the possibilities that have come up thus far. > They all suck and keeping some of them is just counterproductive as > again people will sprinkle them all over the place for the very wrong > reasons. Yes, but do they suck enough and are they counterproductive enough to be useful and necessary? ;-) > > Additionally, if the end goal is to be fully preemptible as in eventually > > eliminating lazy preemption, you have a lot more convincing to do. > > That's absolutely not the case. Even RT uses the lazy mode to prevent > overeager preemption for non RT tasks. OK, that is very good to hear. > The whole point of the exercise is to keep the kernel always fully > preemptible, but only enforce the immediate preemption at the next > possible preemption point when necessary. > > The decision when it is necessary is made by the scheduler and not > delegated to the whim of cond/might_resched() placement. I am not arguing that the developer placing a given cond_resched() always knows best, but you have some work to do to convince me that the scheduler always knows best. > That is serving both worlds best IMO: > > 1) LAZY preemption prevents the negative side effects of overeager > preemption, aka. lock contention and pointless context switching. > > The whole thing behaves like a NONE kernel unless there are > real-time tasks or a task did not comply to the lazy request within > a given time. Almost, give or take the potential issues called out above for the possible downsides of removing all of the cond_resched() invocations. > 2) It does not prevent the scheduler from making decisions to preempt > at the next possible preemption point in order to get some > important computation on the CPU. > > A NONE kernel sucks vs. any sporadic [real-time] task. Just run > NONE and watch the latencies. The latencies are determined by the > interrupted context, the placement of the cond_resched() call and > the length of the loop which is running. > > People have complained about that and the only way out for them is > to switch to VOLUNTARY or FULL preemption and thereby paying the > price for overeager preemption. > > A price which you don't want to pay for good reasons but at the > same time you care about latencies in some aspects and the only > answer you have for that is cond_resched() or similar which is not > an answer at all. All good points, but none of them are in conflict with the possibility of leaving some cond_resched() calls behind if they ar needed. > 3) Looking at the initial problem Ankur was trying to solve there is > absolutely no acceptable solution to solve that unless you think > that the semantically invers 'allow_preempt()/disallow_preempt()' > is anywhere near acceptable. I am not arguing for allow_preempt()/disallow_preempt(), so for that argument, you need to find someone else to argue with. ;-) Thanx, Paul