Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3073555pxf; Sun, 21 Mar 2021 18:04:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytD888D5VQG/qeU7x4kojUBrLbNuYoqOVnfgEVzSZ2T3vpA/368TGNn8PU8tNaLH4zny+p X-Received: by 2002:a50:fa92:: with SMTP id w18mr22738664edr.172.1616375054594; Sun, 21 Mar 2021 18:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616375054; cv=none; d=google.com; s=arc-20160816; b=pgn7wS6hYu9MtHHyj5DnL3gzl5wUMFpGkf3WCUszvVyMu9Pmc9oCQxb44Rcaa0dte4 gQSJPITDtyiyqR0WGe8If//ikzxoSL2O4ntgCu/GexGAtiHgEebO5h5RpKxch18i8Tmu mWitKAOUNU4RwERa0/8bxRUwmOaRW9rgXBh2EHD2hDr+ZQnrjdbuNH9SV/jXv6mr3LQJ YNAXSCXrk0ZVNplljdhR8eI5PQAlWDqIdZ4zShZiwh9DvdHjhAHfLFoktZYeaJrS8pU4 jj6lAiiLy/TxLVkJUiuOgfZJ4sKCiejm6aYfj6fB0F4sR/DHi6CmBZGFewdQk4XiJsyG LjqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=hXu1P78W8C1HtWChqvjv/8DCj6sQHA9gTp8d5+2pwbc=; b=S2gBE19PCjxqdwEiUwISAJcZIP2b31jF6C5LvgiH7enAwNFpQES4+iMY11+qaiLklA JWi1EbbBFb1Jr/xTmC69SjXWw63pEgSZji2sofh2tW3k8Lz4ASxoUMcff0dA6SjWgVh3 XCB46Zdj9MmfsC1iIe3xqXUFBKT1UdEv1NrIKX2XFGrcdD6VFcLyDR7j2j6NqO40S3po ABaC+aL21QjhCK98w+WWQU8cakY6GFk5nfZ6SrcuF1hATwOZtNfczMn8VQfdV1mT8WTr 9wQ8VYiksE8PD19w6MVYXmVHFIrDfh9qG0CNL5ULA4o/x5G2raY7QX6zCTU9VySGb1mN 31Mg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l27si9364480edc.394.2021.03.21.18.03.52; Sun, 21 Mar 2021 18:04:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbhCVAzj (ORCPT + 99 others); Sun, 21 Mar 2021 20:55:39 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:5099 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbhCVAzM (ORCPT ); Sun, 21 Mar 2021 20:55:12 -0400 Received: from dggeml406-hub.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4F3bb62HRPzYMlt; Mon, 22 Mar 2021 08:53:22 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggeml406-hub.china.huawei.com (10.3.17.50) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 22 Mar 2021 08:55:09 +0800 Received: from [127.0.0.1] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2106.2; Mon, 22 Mar 2021 08:55:09 +0800 Subject: Re: [Linuxarm] Re: [RFC v2] net: sched: implement TCQ_F_CAN_BYPASS for lockless qdisc To: Cong Wang CC: "Jason A. Donenfeld" , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , "Jakub Kicinski" , David Miller , "Vladimir Oltean" , Alexei Starovoitov , "Daniel Borkmann" , Andrii Nakryiko , "Eric Dumazet" , Wei Wang , "Cong Wang ." , Taehee Yoo , "Linux Kernel Network Developers" , LKML , , Marc Kleine-Budde , References: <1615603667-22568-1-git-send-email-linyunsheng@huawei.com> <1615777818-13969-1-git-send-email-linyunsheng@huawei.com> <20210315115332.1647e92b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> <87eegddhsj.fsf@toke.dk> <3bae7b26-9d7f-15b8-d466-ff5c26d08b35@huawei.com> From: Yunsheng Lin Message-ID: <9d045462-051e-0cde-24d0-349dd397e2b7@huawei.com> Date: Mon, 22 Mar 2021 08:55:09 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggeme701-chm.china.huawei.com (10.1.199.97) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/20 2:15, Cong Wang wrote: > On Thu, Mar 18, 2021 at 12:33 AM Yunsheng Lin wrote: >> >> On 2021/3/17 21:45, Jason A. Donenfeld wrote: >>> On 3/17/21, Toke Høiland-Jørgensen wrote: >>>> Cong Wang writes: >>>> >>>>> On Mon, Mar 15, 2021 at 2:07 PM Jakub Kicinski wrote: >>>>>> >>>>>> I thought pfifo was supposed to be "lockless" and this change >>>>>> re-introduces a lock between producer and consumer, no? >>>>> >>>>> It has never been truly lockless, it uses two spinlocks in the ring >>>>> buffer >>>>> implementation, and it introduced a q->seqlock recently, with this patch >>>>> now we have priv->lock, 4 locks in total. So our "lockless" qdisc ends >>>>> up having more locks than others. ;) I don't think we are going to a >>>>> right direction... >>>> >>>> Just a thought, have you guys considered adopting the lockless MSPC ring >>>> buffer recently introduced into Wireguard in commit: >>>> >>>> 8b5553ace83c ("wireguard: queueing: get rid of per-peer ring buffers") >>>> >>>> Jason indicated he was willing to work on generalising it into a >>>> reusable library if there was a use case for it. I haven't quite though >>>> through the details of whether this would be such a use case, but >>>> figured I'd at least mention it :) >>> >>> That offer definitely still stands. Generalization sounds like a lot of fun. >>> >>> Keep in mind though that it's an eventually consistent queue, not an >>> immediately consistent one, so that might not match all use cases. It >>> works with wg because we always trigger the reader thread anew when it >>> finishes, but that doesn't apply to everyone's queueing setup. >> >> Thanks for mentioning this. >> >> "multi-producer, single-consumer" seems to match the lockless qdisc's >> paradigm too, for now concurrent enqueuing/dequeuing to the pfifo_fast's >> queues() is not allowed, it is protected by producer_lock or consumer_lock. >> >> So it would be good to has lockless concurrent enqueuing, while dequeuing >> can be protected by qdisc_lock() or q->seqlock, which meets the "multi-producer, >> single-consumer" paradigm. > > I don't think so. Usually we have one queue for each CPU so we can expect > each CPU has a lockless qdisc assigned, but we can not assume this in > the code, so we still have to deal with multiple CPU's sharing a lockless qdisc, > and we usually enqueue and dequeue in process context, so it means we could > have multiple producers and multiple consumers. For lockless qdisc, dequeuing is always within the qdisc_run_begin() and qdisc_run_end(), so multiple consumers is protected with each other by q->seqlock . For enqueuing, multiple consumers is protected by producer_lock, see pfifo_fast_enqueue() -> skb_array_produce() -> ptr_ring_produce(). I am not sure if lockless MSPC can work with the process context, but even if not, the enqueuing is also protected by rcu_read_lock_bh(), which provides some kind of atomicity, so that producer_lock can be reomved when lockless MSPC is used. > > On the other hand, I don't think the problems we have been fixing are the ring > buffer implementation itself, they are about the high-level qdisc > state transitions. > > Thanks. > > . >