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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91709C433FE for ; Sun, 2 Oct 2022 05:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229529AbiJBFid (ORCPT ); Sun, 2 Oct 2022 01:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiJBFic (ORCPT ); Sun, 2 Oct 2022 01:38:32 -0400 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 16A57326C1 for ; Sat, 1 Oct 2022 22:38:29 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 2925cCTs019070; Sun, 2 Oct 2022 07:38:12 +0200 Date: Sun, 2 Oct 2022 07:38:12 +0200 From: Willy Tarreau To: "Jason A. Donenfeld" Cc: Eric Dumazet , "David S . Miller" , Jakub Kicinski , Paolo Abeni , netdev , Eric Dumazet , Christophe Leroy Subject: Re: [PATCH net-next] once: add DO_ONCE_SLOW() for sleepable contexts Message-ID: <20221002053812.GA18978@1wt.eu> References: <20221001205102.2319658-1-eric.dumazet@gmail.com> <20221001211529.GC15441@1wt.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sun, Oct 02, 2022 at 12:50:38AM +0200, Jason A. Donenfeld wrote: > > > This patch adds DO_ONCE_SLOW() which uses a mutex instead of a spinlock > > > for operations where we prefer to stay in process context. > > > > That's a nice improvement I think. I was wondering if, for this special > > case, we *really* need an exclusive DO_ONCE(). I mean, we're getting > > random bytes, we really do not care if two CPUs change them in parallel > > provided that none uses them before the table is entirely filled. Thus > > that could probably end up as something like: > > > > if (!atomic_read(&done)) { > > get_random_bytes(array); > > atomic_set(&done, 1); > > } > > If you don't care about the tables being consistent between CPUs, then > yea, sure, that seems like a reasonable approach, and I like not > polluting once.{c,h} with some _SLOW() special cases. I don't see this as pollution, it possibly is a nice addition for certain use cases or early fast paths where the risk of contention is high. > If you don't want > the atomic read in there you could also do the same pattern with a > static branch, like what DO_ONCE() does: > > if (static_branch_unlikely(&need_bytes)) { > get_random_bytes(array); > static_branch_disable(&need_bytes); > } > > Anyway, same thing as your suggestion more or less. What I don't know in fact is if the code patching itself can be responsible for a measurable part of the extra time Christophe noticed. Anyway at least Christophe now has a few approaches to try, let's first see if any of them fixes the regression. Willy