From: Juergen Gross <jgross@suse.com>
To: Yunsheng Lin <linyunsheng@huawei.com>,
davem@davemloft.net, kuba@kernel.org
Cc: olteanv@gmail.com, ast@kernel.org, daniel@iogearbox.net,
andriin@fb.com, edumazet@google.com, weiwan@google.com,
cong.wang@bytedance.com, ap420073@gmail.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linuxarm@openeuler.org, mkl@pengutronix.de,
linux-can@vger.kernel.org, jhs@mojatatu.com,
xiyou.wangcong@gmail.com, jiri@resnulli.us, andrii@kernel.org,
kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org,
bpf@vger.kernel.org, jonas.bonn@netrounds.com, pabeni@redhat.com,
mzhivich@akamai.com, johunt@akamai.com, albcamus@gmail.com,
kehuan.feng@gmail.com, a.fatoum@pengutronix.de,
atenart@kernel.org, alexander.duyck@gmail.com,
Jiri Kosina <JKosina@suse.com>
Subject: Re: [PATCH net v3] net: sched: fix packet stuck problem for lockless qdisc
Date: Mon, 12 Apr 2021 10:21:23 +0200 [thread overview]
Message-ID: <fb02ea12-7e37-4fdb-775e-824ba5d42ffd@suse.com> (raw)
In-Reply-To: <c0e6bb67-1f60-b784-0baa-4a942b0f1f1e@huawei.com>
[-- Attachment #1.1.1: Type: text/plain, Size: 4683 bytes --]
On 12.04.21 03:04, Yunsheng Lin wrote:
> 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 <linyunsheng@huawei.com>
>>
>> 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 <jgross@suse.com>
>
> 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:)
This should be possible, yes.
I'm using the setup to catch another bug which is showing up every few
days. I don't see a reason why I shouldn't be able to add your patch
and verify it in parallel.
Juergen
[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
next prev parent reply other threads:[~2021-04-12 8:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 3:13 [PATCH net v3] net: sched: fix packet stuck problem for lockless qdisc Yunsheng Lin
2021-04-09 5:31 ` Juergen Gross
2021-04-12 1:04 ` Yunsheng Lin
2021-04-12 8:21 ` Juergen Gross [this message]
[not found] ` <20210409090909.1767-1-hdanton@sina.com>
2021-04-12 1:24 ` Yunsheng Lin
[not found] ` <20210412032111.1887-1-hdanton@sina.com>
2021-04-12 3:37 ` Yunsheng Lin
[not found] ` <20210412072856.2046-1-hdanton@sina.com>
2021-04-12 12:00 ` Yunsheng Lin
[not found] ` <20210413022129.2203-1-hdanton@sina.com>
2021-04-13 2:56 ` Yunsheng Lin
[not found] ` <20210413032620.2259-1-hdanton@sina.com>
2021-04-13 3:34 ` Yunsheng Lin
[not found] ` <20210413071241.2325-1-hdanton@sina.com>
2021-04-13 7:57 ` Yunsheng Lin
[not found] ` <20210413083352.2424-1-hdanton@sina.com>
2021-04-13 9:03 ` Yunsheng Lin
2021-04-13 9:15 ` Juergen Gross
2021-04-16 11:46 ` Jiri Kosina
2021-04-18 22:59 ` Michal Kubecek
2021-04-19 2:04 ` Yunsheng Lin
2021-04-19 12:21 ` [Linuxarm] " Yunsheng Lin
2021-04-19 15:25 ` Michal Kubecek
2021-04-19 14:57 ` Michal Kubecek
2021-04-20 1:45 ` Yunsheng Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fb02ea12-7e37-4fdb-775e-824ba5d42ffd@suse.com \
--to=jgross@suse.com \
--cc=JKosina@suse.com \
--cc=a.fatoum@pengutronix.de \
--cc=albcamus@gmail.com \
--cc=alexander.duyck@gmail.com \
--cc=andrii@kernel.org \
--cc=andriin@fb.com \
--cc=ap420073@gmail.com \
--cc=ast@kernel.org \
--cc=atenart@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=john.fastabend@gmail.com \
--cc=johunt@akamai.com \
--cc=jonas.bonn@netrounds.com \
--cc=kafai@fb.com \
--cc=kehuan.feng@gmail.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@openeuler.org \
--cc=linyunsheng@huawei.com \
--cc=mkl@pengutronix.de \
--cc=mzhivich@akamai.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=songliubraving@fb.com \
--cc=weiwan@google.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).