From nobody Sat Feb 7 22:07:08 2026 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76DF846425 for ; Fri, 1 Mar 2024 03:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709264854; cv=none; b=U207Wod5FQEliATEoLACwrRx9YJSVkW81OM9pwqd3zxSkDhfnQoy99ckwWIuYq7O7TP8zP5o70PjbA6txiQcTzBdPFurV69jdOGOXjm2MsQY0wi7ekGjBiOohJ5EKL5l5qDcalW2TB0qBHgNFfP/7Rb63VnlwpzbbwcVOToy74Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709264854; c=relaxed/simple; bh=SJCpqDpJSEgHDV5tQDF3yUR/bwYgJ4fDZGCiE46Z7X0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=Uk7xRIjEimE2KM1ZFim2EaCNhb7x06tECk+1uaGUzif/dW/IQN84CtRCJ4UqVYLmPitiQgoj/YJezHIchrdAXXhCr3Qm4AhGEmv/epJPyLMR7ci0D54oysAHV4w7mKWpyt1Gc3WCChuW9nBReyTKQrMxfa+o0OeS7fwpOqzVZfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=crTZllqg; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="crTZllqg" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6901114742bso4486816d6.2 for ; Thu, 29 Feb 2024 19:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1709264851; x=1709869651; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Ir94IXljskTATdQD9ZYQYe2IqsDn2CAqbjyFa/bExS8=; b=crTZllqgfLAdCjAr9U0yj+xpC4zfMf45RBEwW0aPCi+3yJFZMI59MnZXYsVIyEauMh cLfsu0OSqiCOFRiMiojnI6yQGRaYJOKQ9tELJahw80kzJtLPwY+dJjtMsDrX4SA516b/ JxHYm9XajT5YxjhHcm7o/GN6o+QXVQV8VaRRCtVyzWmjseql2mXBKJqSuT1Hk03/Rojw 1dDySYOkOj9T21GO7MtMcYzF/VzrSo8wMSk6ZAm1IhweP2wKYCVzZubXy1RCmme85H2n 3Auq7DaE5oZoYR1FI0mcwl3ISQbYr8FPtmDowonD5/fTx7yR8DxhPGikC/ezGIwoFA/b SZ0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709264851; x=1709869651; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ir94IXljskTATdQD9ZYQYe2IqsDn2CAqbjyFa/bExS8=; b=irohsR1Mkpj4TwRApd+QgD43Ke2mE7JJ/VTa5Rw8P0RyJSIofeaJFSd/WNDpjD30+M Us7j6h4ETkr8W2i1PPRaAriWd55B4LIxMMJT2W6Z9HDce7jpnrjNWGCMcgtOSJhwvgJ8 jDIXPmRoHPoKtekX/khvonlK/Wc84pfn5xpIqtOd/tu0RUpA1LOm8PzkPBCI9H4Tv1KP WEbRiQgBYH9BvO/x+rIdnYXPJ1rgzoUeuxtyu5F3k6Ax02bME6nPJaYfn2UNHUUI/Roa MEln6UOq+cBn4aW2qefqXx5H7nXO/giEvCjSH0pOtOebNZswDooltF3FWm9rl3Gmvykc IPRw== X-Forwarded-Encrypted: i=1; AJvYcCULmbn41zx0DrqX6UUp5OXwYTJJtynZbY4gm8VqFKM2J2wbGMA/C9+bJMV/dfrxb86I1/KTKuSQ92Xk2hDMSLOGn8e9tTtFG8JVh79T X-Gm-Message-State: AOJu0YzvqfetF/W2METmO6A48NupnXCMjFluKgvkxFJu8DwHdYDfUy5A pCFyFUcH1sqO6XXCOUgESYiFN1WXJhatYhWbVJ3FJzkbfepOj0Fj8ObZg8cT9Tk= X-Google-Smtp-Source: AGHT+IHBV4j0XvZKRjdEXGH77v8/UWe0r7iiAV8Gl34A3ObsJ5NNm4GAwjkOVJ2t5W472XbKjrF4aw== X-Received: by 2002:a05:6214:12e:b0:68f:e766:5ee4 with SMTP id w14-20020a056214012e00b0068fe7665ee4mr657937qvs.25.1709264851278; Thu, 29 Feb 2024 19:47:31 -0800 (PST) Received: from debian.debian ([2a09:bac5:7a49:f91::18d:13]) by smtp.gmail.com with ESMTPSA id qo13-20020a056214590d00b0068d11cf887bsm1441728qvb.55.2024.02.29.19.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 19:47:30 -0800 (PST) Date: Thu, 29 Feb 2024 19:47:27 -0800 From: Yan Zhai To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jiri Pirko , Simon Horman , Daniel Borkmann , Lorenzo Bianconi , Coco Li , Wei Wang , Alexander Duyck , Hannes Frederic Sowa , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, bpf@vger.kernel.org, kernel-team@cloudflare.com, Joel Fernandes , "Paul E. McKenney" , Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= , Alexei Starovoitov , Steven Rostedt , mark.rutland@arm.com Subject: [PATCH v2] net: raise RCU qs after each threaded NAPI poll Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We noticed task RCUs being blocked when threaded NAPIs are very busy at workloads: detaching any BPF tracing programs, i.e. removing a ftrace trampoline, will simply block for very long in rcu_tasks_wait_gp. This ranges from hundreds of seconds to even an hour, severely harming any observability tools that rely on BPF tracing programs. It can be easily reproduced locally with following setup: ip netns add test1 ip netns add test2 ip -n test1 link add veth1 type veth peer name veth2 netns test2 ip -n test1 link set veth1 up ip -n test1 link set lo up ip -n test2 link set veth2 up ip -n test2 link set lo up ip -n test1 addr add 192.168.1.2/31 dev veth1 ip -n test1 addr add 1.1.1.1/32 dev lo ip -n test2 addr add 192.168.1.3/31 dev veth2 ip -n test2 addr add 2.2.2.2/31 dev lo ip -n test1 route add default via 192.168.1.3 ip -n test2 route add default via 192.168.1.2 for i in `seq 10 210`; do for j in `seq 10 210`; do ip netns exec test2 iptables -I INPUT -s 3.3.$i.$j -p udp --dport 5201 done done ip netns exec test2 ethtool -K veth2 gro on ip netns exec test2 bash -c 'echo 1 > /sys/class/net/veth2/threaded' ip netns exec test1 ethtool -K veth1 tso off Then run an iperf3 client/server and a bpftrace script can trigger it: ip netns exec test2 iperf3 -s -B 2.2.2.2 >/dev/null& ip netns exec test1 iperf3 -c 2.2.2.2 -B 1.1.1.1 -u -l 1500 -b 3g -t 100 >/= dev/null& bpftrace -e 'kfunc:__napi_poll{@=3Dcount();} interval:s:1{exit();}' Above reproduce for net-next kernel with following RCU and preempt configuraitons: # RCU Subsystem CONFIG_TREE_RCU=3Dy CONFIG_PREEMPT_RCU=3Dy # CONFIG_RCU_EXPERT is not set CONFIG_SRCU=3Dy CONFIG_TREE_SRCU=3Dy CONFIG_TASKS_RCU_GENERIC=3Dy CONFIG_TASKS_RCU=3Dy CONFIG_TASKS_RUDE_RCU=3Dy CONFIG_TASKS_TRACE_RCU=3Dy CONFIG_RCU_STALL_COMMON=3Dy CONFIG_RCU_NEED_SEGCBLIST=3Dy # end of RCU Subsystem # RCU Debugging # CONFIG_RCU_SCALE_TEST is not set # CONFIG_RCU_TORTURE_TEST is not set # CONFIG_RCU_REF_SCALE_TEST is not set CONFIG_RCU_CPU_STALL_TIMEOUT=3D21 CONFIG_RCU_EXP_CPU_STALL_TIMEOUT=3D0 # CONFIG_RCU_TRACE is not set # CONFIG_RCU_EQS_DEBUG is not set # end of RCU Debugging CONFIG_PREEMPT_BUILD=3Dy # CONFIG_PREEMPT_NONE is not set CONFIG_PREEMPT_VOLUNTARY=3Dy # CONFIG_PREEMPT is not set CONFIG_PREEMPT_COUNT=3Dy CONFIG_PREEMPTION=3Dy CONFIG_PREEMPT_DYNAMIC=3Dy CONFIG_PREEMPT_RCU=3Dy CONFIG_HAVE_PREEMPT_DYNAMIC=3Dy CONFIG_HAVE_PREEMPT_DYNAMIC_CALL=3Dy CONFIG_PREEMPT_NOTIFIERS=3Dy # CONFIG_DEBUG_PREEMPT is not set # CONFIG_PREEMPT_TRACER is not set # CONFIG_PREEMPTIRQ_DELAY_TEST is not set An interesting observation is that, while tasks RCUs are blocked, related NAPI thread is still being scheduled (even across cores) regularly. Looking at the gp conditions, I am inclining to cond_resched after each __napi_poll being the problem: cond_resched enters the scheduler with PREEMPT bit, which does not account as a gp for tasks RCUs. Meanwhile, since the thread has been frequently resched, the normal scheduling point (no PREEMPT bit, accounted as a task RCU gp) seems to have very little chance to kick in. Given the nature of "busy polling" program, such NAPI thread won't have task->nvcsw or task->on_rq updated (other gp conditions), the result is that such NAPI thread is put on RCU holdouts list for indefinitely long time. This is simply fixed by adapting similar behavior of ksoftirqd: after the thread repolls for a while, raise a RCU QS to help expedite the tasks RCU grace period. No more blocking afterwards. Some brief iperf3 throughput testing in my VM with net-next kernel shows no noteable perf difference with 1500 byte MTU for 10 repeat runs each: Before: UDP: 3.073Gbps (+-0.070Gbps) TCP: 37.850Gbps (+-1.947Gbps) After: UDP: 3.077Gbps (+-0.121 Gbps) TCP: 38.120Gbps (+-2.272 Gbps) Note I didn't enable GRO for UDP so its throughput is lower than TCP. Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support") Suggested-by: Paul E. McKenney Reviewed-by: Joel Fernandes (Google) Signed-off-by: Yan Zhai --- v1->v2: moved rcu_softirq_qs out from bh critical section, and only raise it after a second of repolling. Added some brief perf test result. --- net/core/dev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 275fd5259a4a..76cff3849e1f 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6751,9 +6751,12 @@ static int napi_threaded_poll(void *data) { struct napi_struct *napi =3D data; struct softnet_data *sd; + unsigned long next_qs; void *have; =20 while (!napi_thread_wait(napi)) { + next_qs =3D jiffies + HZ; + for (;;) { bool repoll =3D false; =20 @@ -6778,6 +6781,21 @@ static int napi_threaded_poll(void *data) if (!repoll) break; =20 + /* cond_resched cannot unblock tasks RCU writers, so it + * is necessary to relax periodically and raise a QS to + * avoid starving writers under frequent repoll, e.g. + * ftrace trampoline clean up work. When not repoll, + * napi_thread_wait will enter sleep and have the same + * QS effect. + */ + if (!IS_ENABLED(CONFIG_PREEMPT_RT) && + time_after(jiffies, next_qs)) { + preempt_disable(); + rcu_softirq_qs(); + preempt_enable(); + next_qs =3D jiffies + HZ; + } + cond_resched(); } } --=20 2.30.2