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 X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C10DCC43381 for ; Wed, 20 Feb 2019 23:00:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 79A0D20859 for ; Wed, 20 Feb 2019 23:00:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pLNcaYc1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726172AbfBTXAr (ORCPT ); Wed, 20 Feb 2019 18:00:47 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40578 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbfBTXAr (ORCPT ); Wed, 20 Feb 2019 18:00:47 -0500 Received: by mail-pg1-f195.google.com with SMTP id u9so9153556pgo.7 for ; Wed, 20 Feb 2019 15:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pQdxcR9TbhLVhtLOO3+NKOe3vWeabRR3UtJpsWl/S3w=; b=pLNcaYc1JgcNGI7MdWBq72jNvxxd76ivEzC3vlLI+J9oPdpfeRGW5bi3ZkQNR4qK5b S4DupHwCrLf4zdxr9X/0j8QSk5ulWVYHVcyGBMaPRyXoLZH8AyXsqiy8/8gEPuwJcJbf nFfmGUSfGha7qlmoP4JFD2nfN3nmDri35G3JvUHipqcqV92zA+Wma+nULvUoy8B1aLGD ye5nc0W1OKMFuMuGZypS1B9FIABeeKWV06eONudnyo8/4mOhNfSGudWvXRaYBCMyZANl bwHnwAtpjo+YWis4nuLjX//CriX0bytCOlxNW7EXG/PHpE2/FfojUrljTtQZfujUqSQs 1ZnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pQdxcR9TbhLVhtLOO3+NKOe3vWeabRR3UtJpsWl/S3w=; b=QPhBamPPu2NXiZFO2rT6zjArKUcnjQCxQxRTFskFZ1myD4DUSwYsDtTJXs0RqTIDKD W6Fw6nzY3faSBWiAMUMYjg2OMiDqhoAkl62GURECcpep5OcOzzc0b29ALGHwoM8kXVbk 3ae0f5oz6HES+ye2tc99Bj3vcQlBz0vcGl1FdjBlFYEGoPx7dkmHSEflLBixtSiPzrLA rK+/G018TyTxYtv2C4SJ1yTvl72++cd7xrfC6z7XKnz/LQFLGUWpoy8SNevPt9exkO77 XY0PrrXGTHe3il4rmpFdIIfE38682ak3TPk8Bpxg6OrDmBnEtfzZZ0eYbJ/7aUMYBy4/ mc7A== X-Gm-Message-State: AHQUAuYg1Td0dDbdUdCrnvAvfcqiLcqHAM8n3dacUZvMIhyhIE5/LnWT zCt2/iznjZKphb/DqvQ8LDb8q0tfA/k1cAMVVqs= X-Google-Smtp-Source: AHgI3IaFIYZO9i9Mn9vfQNJ2iIDStxLIpkeEoMVvT8KOhJpBLBVgeGnifD1n22oZMJuh3TX0n6u9+UJ0qejhzpk3dAM= X-Received: by 2002:a63:2586:: with SMTP id l128mr31737130pgl.104.1550703646245; Wed, 20 Feb 2019 15:00:46 -0800 (PST) MIME-Version: 1.0 References: <20190211085548.7190-1-vladbu@mellanox.com> <20190211085548.7190-8-vladbu@mellanox.com> <20190214182442.GA19269@splinter> In-Reply-To: From: Cong Wang Date: Wed, 20 Feb 2019 15:00:34 -0800 Message-ID: Subject: Re: [PATCH net-next v4 07/17] net: sched: protect filter_chain list with filter_chain_lock mutex To: Vlad Buslov Cc: Ido Schimmel , "netdev@vger.kernel.org" , "jhs@mojatatu.com" , "jiri@resnulli.us" , "davem@davemloft.net" , "ast@kernel.org" , "daniel@iogearbox.net" Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Feb 19, 2019 at 7:20 AM Vlad Buslov wrote: > > > On Tue 19 Feb 2019 at 05:08, Cong Wang wrote: > > On Fri, Feb 15, 2019 at 2:02 AM Vlad Buslov wrote: > >> > >> I looked at the code and problem seems to be matchall classifier > >> specific. My implementation of unlocked cls API assumes that concurrent > >> insertions are possible and checks for it when deleting "empty" tp. > >> Since classifiers don't expose number of elements, the only way to test > >> this is to do tp->walk() on them and assume that walk callback is called > >> once per filter on every classifier. In your example new tp is created > >> for second filter, filter insertion fails, number of elements on newly > >> created tp is checked with tp->walk() before deleting it. However, > >> matchall classifier always calls the tp->walk() callback once, even when > >> it doesn't have a valid filter (in this case with NULL filter pointer). > > > > Again, this can be eliminated by just switching to normal > > non-retry logic. This is yet another headache to review this > > kind of unlock-and-retry logic, I have no idea why you are such > > a big fan of it. > > The retry approach was suggested to me multiple times by Jiri on > previous code reviews so I assumed it is preferred approach in such > cases. I don't have a strong preference in this regard, but locking > whole tp on filter update will remove any parallelism when updating same > classifier instance concurrently. The goal of these changes is to allow > parallel rule update and to achieve that I had to introduce some > complexity into the code. Yeah, but with unlock-and-retry it would waste more time when retry occurs. So it can't be better in the worst scenario. The question is essentially that do we want to waste CPU cycles when conflicts occurs or just block there until it is safe to enter the critical section? And, is the retry bound? Is it possible that we would retry infinitely as long as we time it correctly? > > Now let me explain why these two approaches result completely different > performance in this case. Lets start with a list of most CPU-consuming > parts in new filter creation process in descending order (raw data at > the end of this mail): > > 1) Hardware offload - if available and no skip_hw. > 2) Exts (actions) initalization - most expensive part even with single > action, CPU usage increases with number of actions per filter. > 3) cls API. > 4) Flower classifier data structure initialization. > > Note that 1)+2) is ~80% of cost of creating a flower filter. So if we > just lock the whole flower classifier instance during rule update we > serialize 1, 2 and 4, and only cls API (~13% of CPU cost) can be > executed concurrently. However, in proposed flower implementation hw > offloading and action initialization code is called without any locks > and tp->lock is only obtained when modifying flower data structures, > which means that only 3) is serialized and everything else (87% of CPU > cost) can be executed in parallel. What about when conflicts detected and retry the whole change? And, of course, how often do conflicts happen? Thanks.