Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1388335pxb; Sun, 11 Apr 2021 18:12:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6oHMICif3Q7UsIRsjTcaiYqALN6dh1ppy6ZXSpQHYh6gTPxJtPlfHZ+RYps3YEw+zbifO X-Received: by 2002:a17:906:9bf9:: with SMTP id de57mr8771077ejc.209.1618189954789; Sun, 11 Apr 2021 18:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618189954; cv=none; d=google.com; s=arc-20160816; b=mFmnEtB50Kjim++9FBUkb7uESfKstF0goqpv62IWoi/uZiC9a4ZVEzJTR3bH2sjYOn ct7l+qieghzpEgCCFGlYdI/AjvpS6rjajzNLOkAoqeownLYGZM3emKqO5CqNxocsUQlq 6/xiqbk0x33y8AqyC8Ck5y98ezAfr5SnEsX49EiAjY3JaC7tSWYBkiWO4OTNtyIDepeq FsE9TGD/hq9/7y3+6GM9+cFn+CeSI2MOs551Oy+/Uuun3gMf90iImgeUKHLjaKDBX5HG /TG6WhLs61PiuRja1b15DxL0P41BMF9hSJkm0JgVGPTPSbyHQHK3axpbaXHbtDe8PBUJ RLZg== 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=4ZvwdRvP7naFsMQ4KPSBf/iZAEpVdqhmhhWYtMiNxnM=; b=Hz3J+zIB672FDEfQCWi5CggPb8Rz0SbUsSe4+e7izlccx9cxNxElkc7eTa7sMi4u43 0YRWjWmcjIX/aE1LlJZGu2y+nNQ4lBcbLt7H3uobbpeK2AHyjRXgFcJGvt+8l3LaAgGA cGR2EhcteVtZjZkWVdypdMxcZhBG/4D5hlOwmXCPOf+ptplpRBdrQLs9ti5sJpuGb/AO l+EGLQKQXDZQZorKVsfE8dfIYerbSUlqa58c8YgLJb98MvAwmOJ+KrRLoZI4bg7+2zwg USybnZwgZ7tuHSZ6cJaTbRI3hFxQjR1QXyCobVyOQen5s/wZ6f6RB72DZfIAYDlPMeRA kEaA== 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 i11si6562567edy.97.2021.04.11.18.12.12; Sun, 11 Apr 2021 18:12:34 -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 S235927AbhDLBFB (ORCPT + 99 others); Sun, 11 Apr 2021 21:05:01 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:5126 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235323AbhDLBFA (ORCPT ); Sun, 11 Apr 2021 21:05:00 -0400 Received: from dggeml405-hub.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FJVp16GyHzYVpt; Mon, 12 Apr 2021 09:02:33 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggeml405-hub.china.huawei.com (10.3.17.49) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 12 Apr 2021 09:04:37 +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, 12 Apr 2021 09:04:37 +0800 Subject: Re: [PATCH net v3] net: sched: fix packet stuck problem for lockless qdisc To: Juergen Gross , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Jiri Kosina References: <1616641991-14847-1-git-send-email-linyunsheng@huawei.com> From: Yunsheng Lin Message-ID: Date: Mon, 12 Apr 2021 09:04:37 +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: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggeme708-chm.china.huawei.com (10.1.199.104) 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/4/9 13:31, Juergen Gross wrote: > On 25.03.21 04:13, Yunsheng Lin wrote: >> Lockless qdisc has below concurrent problem: >> cpu0 cpu1 >> . . >> q->enqueue . >> . . >> qdisc_run_begin() . >> . . >> dequeue_skb() . >> . . >> sch_direct_xmit() . >> . . >> . q->enqueue >> . qdisc_run_begin() >> . return and do nothing >> . . >> qdisc_run_end() . >> >> cpu1 enqueue a skb without calling __qdisc_run() because cpu0 >> has not released the lock yet and spin_trylock() return false >> for cpu1 in qdisc_run_begin(), and cpu0 do not see the skb >> enqueued by cpu1 when calling dequeue_skb() because cpu1 may >> enqueue the skb after cpu0 calling dequeue_skb() and before >> cpu0 calling qdisc_run_end(). >> >> Lockless qdisc has below another concurrent problem when >> tx_action is involved: >> >> cpu0(serving tx_action) cpu1 cpu2 >> . . . >> . q->enqueue . >> . qdisc_run_begin() . >> . dequeue_skb() . >> . . q->enqueue >> . . . >> . sch_direct_xmit() . >> . . qdisc_run_begin() >> . . return and do nothing >> . . . >> clear __QDISC_STATE_SCHED . . >> qdisc_run_begin() . . >> return and do nothing . . >> . . . >> . qdisc_run_end() . >> >> This patch fixes the above data race by: >> 1. Get the flag before doing spin_trylock(). >> 2. If the first spin_trylock() return false and the flag is not >> set before the first spin_trylock(), Set the flag and retry >> another spin_trylock() in case other CPU may not see the new >> flag after it releases the lock. >> 3. reschedule if the flags is set after the lock is released >> at the end of qdisc_run_end(). >> >> For tx_action case, the flags is also set when cpu1 is at the >> end if qdisc_run_end(), so tx_action will be rescheduled >> again to dequeue the skb enqueued by cpu2. >> >> Only clear the flag before retrying a dequeuing when dequeuing >> returns NULL in order to reduce the overhead of the above double >> spin_trylock() and __netif_schedule() calling. >> >> The performance impact of this patch, tested using pktgen and >> dummy netdev with pfifo_fast qdisc attached: >> >> threads without+this_patch with+this_patch delta >> 1 2.61Mpps 2.60Mpps -0.3% >> 2 3.97Mpps 3.82Mpps -3.7% >> 4 5.62Mpps 5.59Mpps -0.5% >> 8 2.78Mpps 2.77Mpps -0.3% >> 16 2.22Mpps 2.22Mpps -0.0% >> >> Fixes: 6b3ba9146fe6 ("net: sched: allow qdiscs to handle locking") >> Signed-off-by: Yunsheng Lin > > I have a setup which is able to reproduce the issue quite reliably: > > In a Xen guest I'm mounting 8 NFS shares and run sysbench fileio on > each of them. The average latency reported by sysbench is well below > 1 msec, but at least once per hour I get latencies in the minute > range. > > With this patch I don't see these high latencies any longer (test > is running for more than 20 hours now). > > So you can add my: > > Tested-by: Juergen Gross Hi, Juergen Thanks for the testing. With the simulated test case suggested by Michal, I still has some potential issue to debug, hopefully will send out new version in this week. Also, is it possible to run your testcase any longer? I think "72 hours" would be enough to testify that it fixes the problem completely:) > > > Juergen