Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1328612pxb; Wed, 4 Nov 2020 06:13:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQGW0WwS+gjEGrqBZq2hU72DlBxkdnZpZDE8bl0oK1RTKlhs7lZm7/3beAV8lExVvYd36u X-Received: by 2002:aa7:dbcf:: with SMTP id v15mr18211355edt.70.1604499225863; Wed, 04 Nov 2020 06:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604499225; cv=none; d=google.com; s=arc-20160816; b=q2AW0LRNGS2rCXFJ8ZQXNF3b+VFQMJhQPDdT+fJDk2ZWC/vkEQBnaLEp7L8De2YSsv KVpQtC0TND9s+Texy/Qc0Cwfrq2oxcZXMj8UR3vRRZQwPCqU5zmHm7CPqvWSgtY4QJjY M/pA1YMnuizfSbQ63jWg8o+YO/bkI6wzB5ucuNQcUPq7LYiU3d/D4vAfVriYvyQaW5+T 6UhAm05sf2Kt4JdNQbY5Mb/zfb4vU0RxNtJAuSjC3nfCkMb8TTAuUXmmDIFSERMnHB1E DYp/1L3Lb5tOEkI4x2+y+llYON9DtP/PLvpBkU86KbSzcdrwpsLRg4omfJAodkXzgP6Y XhIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=/4dB5y/P39W/TZ7PNmaK0fou3k354W/C3gNtIDkoBc8=; b=tpruAX9NNNJmXA8ibIK1oxqcssZNppewBPG0zQsHBZngOY/FxphGKf0Pbw/qwwyEE9 qYtSGK2y9SwjAezJyHfCYLbQldIZYnbhPwzJJwRpUokai9OLOWO7zhvuI6IQfj6DhFTW v8FLUcrXtGKDPZ2C75rP0dEF2t7vB1Rv2ms2UwrtEsiSxaxrHKjvQCF1vBbXjSwJpHZa X3SqluAfll/gJe3WnmlcpgSCmGl9dq+keyI0aYc2WKNBxBmsj27986HT8p/05/ku3lhy E9M0r/uyIfD/WngMElXfHpTJZspmErIc0ulQrxoXJytM1/8/RSadXd7CirWg0UQZgBM6 IZ6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Duct3QTl; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si1513083ejg.9.2020.11.04.06.13.20; Wed, 04 Nov 2020 06:13:45 -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=@kernel.org header.s=default header.b=Duct3QTl; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730322AbgKDOMH (ORCPT + 99 others); Wed, 4 Nov 2020 09:12:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:38942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729630AbgKDOMB (ORCPT ); Wed, 4 Nov 2020 09:12:01 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-104-11.bvtn.or.frontiernet.net [50.39.104.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 811872236F; Wed, 4 Nov 2020 14:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604499120; bh=QdSmr2H/GgIpCFk9ITs9nleAHoo5vpqgzq/nhlD5j5o=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Duct3QTlVzj9YCibH1nesMfdKdKDezUDsGB1ooKWnQvtzb4N8BLefok0d14rDbL5L 9m0ELaVzExIPZznNhgFfetzco6BFybdu+phgtK8L4MBZg6Q4ryplDIjLofwygUxeY1 D+mo6NtTbmCUWNig4HraDZrkvEZBcAhvGyzFBqNI= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 1BBBF3520294; Wed, 4 Nov 2020 06:12:00 -0800 (PST) Date: Wed, 4 Nov 2020 06:12:00 -0800 From: "Paul E. McKenney" To: Uladzislau Rezki Cc: Joel Fernandes , LKML , RCU , Andrew Morton , Peter Zijlstra , Michal Hocko , Thomas Gleixner , "Theodore Y . Ts'o" , Sebastian Andrzej Siewior , Oleksiy Avramchenko , willy@infradead.org Subject: Re: [PATCH 01/16] rcu/tree: Add a work to allocate pages from regular context Message-ID: <20201104141200.GH3249@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20201029165019.14218-1-urezki@gmail.com> <20201103154723.GA1310511@google.com> <20201103163350.GA10665@pc636> <20201103191822.GC3249@paulmck-ThinkPad-P72> <20201104123553.GC17782@pc636> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201104123553.GC17782@pc636> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 04, 2020 at 01:35:53PM +0100, Uladzislau Rezki wrote: > On Tue, Nov 03, 2020 at 11:18:22AM -0800, Paul E. McKenney wrote: > > On Tue, Nov 03, 2020 at 05:33:50PM +0100, Uladzislau Rezki wrote: > > > On Tue, Nov 03, 2020 at 10:47:23AM -0500, Joel Fernandes wrote: > > > > On Thu, Oct 29, 2020 at 05:50:04PM +0100, Uladzislau Rezki (Sony) wrote: > > > > > The current memmory-allocation interface presents to following > > > > > difficulties that this patch is designed to overcome: > > > > > > > > > > a) If built with CONFIG_PROVE_RAW_LOCK_NESTING, the lockdep will > > > > > complain about violation("BUG: Invalid wait context") of the > > > > > nesting rules. It does the raw_spinlock vs. spinlock nesting > > > > > checks, i.e. it is not legal to acquire a spinlock_t while > > > > > holding a raw_spinlock_t. > > > > > > > > > > Internally the kfree_rcu() uses raw_spinlock_t whereas the > > > > > "page allocator" internally deals with spinlock_t to access > > > > > to its zones. The code also can be broken from higher level > > > > > of view: > > > > > > > > > > raw_spin_lock(&some_lock); > > > > > kfree_rcu(some_pointer, some_field_offset); > > > > > > > > > > > > > > > b) If built with CONFIG_PREEMPT_RT. Please note, in that case spinlock_t > > > > > is converted into sleepable variant. Invoking the page allocator from > > > > > atomic contexts leads to "BUG: scheduling while atomic". > > > > > > > > > > c) call_rcu() is invoked from raw atomic context and kfree_rcu() > > > > > and kvfree_rcu() are expected to be called from atomic raw context > > > > > as well. > > > > > > > > > > Move out a page allocation from contexts which trigger kvfree_rcu() > > > > > function to the separate worker. When a k[v]free_rcu() per-cpu page > > > > > cache is empty a fallback mechanism is used and a special job is > > > > > scheduled to refill the per-cpu cache. > > > > > > > > Looks good, still reviewing here. BTW just for my education, I was wondering > > > > about Thomas's email: > > > > https://lkml.org/lkml/2020/8/11/939 > > > > > > > > If slab allocations in pure raw-atomic context on RT is not allowed or > > > > recommended, should kfree_rcu() be allowed? > > > > > > > Thanks for reviewing, Joel :) > > > > > > The decision was made that we need to support kfree_rcu() from "real atomic contexts", > > > to align with how it used to be before. We can go and just convert our local locks > > > to the spinlock_t variant but that was not Paul goal, it can be that some users need > > > kfree_rcu() for raw atomics. > > > > People invoke call_rcu() from raw atomics, and so we should provide > > the same for kfree_rcu(). Yes, people could work around a raw-atomic > > prohibition, but such prohibitions incur constant costs over time in > > terms of development effort, increased bug rate, and increased complexity. > > Yes, this does increase all of those for RCU, but the relative increase > > is negligible, RCU being what it is. > > > I see your point. > > > > > slab can have same issue right? If per-cpu cache is drained, it has to > > > > allocate page from buddy allocator and there's no GFP flag to tell it about > > > > context where alloc is happening from. > > > > > > > Sounds like that. Apart of that, it might turn out soon that we or somebody > > > else will rise a question one more time about something GFP_RAW or GFP_NOLOCKS. > > > So who knows.. > > > > I would prefer that slab provide some way of dealing with raw atomic > > context, but the maintainers are thus far unconvinced. > > > I think, when preempt_rt is fully integrated to the kernel, we might get > new users with such demand. So, it is not a closed topic so far, IMHO. Agreed! ;-) > > > > Or are we saying that we want to support kfree on RT from raw atomic atomic > > > > context, even though kmalloc is not supported? I hate to bring up this > > > > elephant in the room, but since I am a part of the people maintaining this > > > > code, I believe I would rather set some rules than supporting unsupported > > > > usages. :-\ (Once I know what is supported and what isn't that is). If indeed > > > > raw atomic kfree_rcu() is a bogus use case because of -RT, then we ought to > > > > put a giant warning than supporting it :-(. > > > > > > > We discussed it several times, the conclusion was that we need to support > > > kfree_rcu() from raw contexts. At least that was a clear signal from Paul > > > to me. I think, if we obtain the preemtable(), so it becomes versatile, we > > > can drop the patch that is in question later on in the future. > > > > Given a universally meaningful preemptible(), we could directly call > > the allocator in some cases. It might (or might not) still make sense > > to defer the allocation when preemptible() indicated that a direct call > > to the allocator was unsafe. > > > I do not have a strong opinion here. Giving the fact that maintaining of > such "deferring" is not considered as a big effort, i think, we can live > with it. And agreed here as well. If this were instead a large body of complex code, I might feel otherwise. But as it is, why worry? Thanx, Paul