Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1421562lqt; Wed, 20 Mar 2024 03:40:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXe3+pZioZGVV0dHKGpk5tJw+TvHncskRpArrX/fbc2jn766rMu4vpq9S9IIruvUU6pAXQQA9lrH1rI75wYsiaLl5hueuALcVHJUexH5g== X-Google-Smtp-Source: AGHT+IHjpnOd3Kggtyoyzo3Igyxj5QDKzCfXpwjuLe0yRw51OWE7kFJ/0/BWHLu6Kni+FON+cUm2 X-Received: by 2002:a05:6808:3998:b0:3c3:9d49:1de7 with SMTP id gq24-20020a056808399800b003c39d491de7mr4708611oib.27.1710931229825; Wed, 20 Mar 2024 03:40:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710931229; cv=pass; d=google.com; s=arc-20160816; b=hJ0xbqncKEVLZCgfzRGigb7T6hFHnh/jWBG5yZvi69fweea3VT8cHjWJJ7fi+XKnAm DCrTQ4Yyzc7Okw8MGIm7K9DUp79q1i2xSIqskfyMnDPJ9jBW6Yrz6oegtRfRDo3DojCi y6YVa+jp1adrVFSqQ+U05vb74GLt06dzlLqtTILAtjX2P59bJ4V/uo6nEC4qX3NLp8rs idjNjoDVdMW1KtTbGEVLjhHmlMQuola6l5PppqeTrp8GlxEHIVZB3TqrmyKQTi+51Z7V rYT0ROYvwxyDMu8vEDkyVgw447BOze+UQ2gHCx1UlTCwQCfg7AfU4pHj/bXrRTPygVls 2YMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=kZGvJqfxbAg29MYB5Yqfhg+01m6z8ETeopfX9P3mhYA=; fh=SUMhvSnfToiC51Wk3vch1lkVMvVWFUvo0gvWBUgFfDc=; b=YdZKJ77JRZHJmAWpTUO0Xz4ZIGxLqrwaHBx9tWepV5OZ+MNWXiF5LZLWNtf3Q7CogU D9MtT5IAWNCk9jkFdr+F6F0wg2cwhKbrqLTGTB/mC93h5XlD6hCSaI4OHJtQ4GIKIZJe STimIN4e5tgIL89WCKCnUFRgs7vCKQqIV5TPLaRtJUCmtaH6rO4K6CeK4d2OBX+gKoDO TLsVxH6xFMwer0BJ7ov/dctY5vA45G5O4HeILywbISeMTaqpJR2j0y7LrNMibWNCWq3l GUzjaw5ps5wlObfCFS7lsajWHViCnXu4ouVzRT2uourKNJOTsJ4h9C0HFqHRYzXMcV8+ Heww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ol7/ItQM"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r14-20020a62e40e000000b006e696c73784si12523079pfh.192.2024.03.20.03.40.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 03:40:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Ol7/ItQM"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BC01AB24AAB for ; Wed, 20 Mar 2024 10:34:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 751EA38DDC; Wed, 20 Mar 2024 10:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ol7/ItQM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AFC51E48E; Wed, 20 Mar 2024 10:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710930628; cv=none; b=XRdzK1Ei13NYG3HaqFu5uw//kb/v2mlAoP5VoXmeZd6K1d2JSJSytqhnjssS9oAerYNK9ynqHpiYl7iP/BTmQKFz0b5jApfHBsk7KcFwCu2sS/SoPdV+nT1U25nBSYmPuc2LzqcMS/ZuxqVi22DQGaUKgOFVa6sr1gVwbMwfHMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710930628; c=relaxed/simple; bh=Ng5N4KT0SCm8Zb4mwGaTwyWKHKjaLEy2Wm0KyGEcEto=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aykgGPaDT4JDYFTpikBAJurw3JalHSw43vsltg4eG46i4KpPnVFG5UP3yIGOe5MCWOa0Gsc0AGVfPNyzGEapA4xlbhjOPyHHf/5UKULFWTiYZFObyjs7wyF+3xKXVW7iY4Iw97YacsutKWL0o1TXwj07gIXd34nbjBXZ0x3azW0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ol7/ItQM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 920B6C433C7; Wed, 20 Mar 2024 10:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710930628; bh=Ng5N4KT0SCm8Zb4mwGaTwyWKHKjaLEy2Wm0KyGEcEto=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Ol7/ItQM72RsqGXTgcikxJy4dTlaUDho4Kqr5tT+d6X3xM8PArvo61vgr5a1KFSSu QCjmG1YljRplfNm4JTZdB2xsYsks86a1/z/hL8c7Lsw/X3x6RuLLJ/6VQ25cWsSznv HyRsrTEIQPmSvit7T+Fj7A3tTy8+9TLd6vrU0J87HGRbeD+XJrEQVod323EJiUUzk+ JIbajnxGaDABod60v59IdWD0zGBcjeSZxM0uVoDsL7UOVz6U2AD8X4NDTAtghd5esM sgVmRO2DateKvrWQrhbbjte8mLladypCMuXXtDYl39pSNLHVqzjS4Z1/41fOyjRmyA Fx6LA7Zqb842g== Message-ID: <4e251463-8cfb-4cc6-b9b6-ce1dcd7c7052@kernel.org> Date: Wed, 20 Mar 2024 11:30:21 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 net 0/3] Report RCU QS for busy network kthreads To: Yan Zhai , 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 , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, bpf@vger.kernel.org, kernel-team@cloudflare.com, Joel Fernandes , "Paul E. McKenney" , =?UTF-8?Q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Alexei Starovoitov , Steven Rostedt , mark.rutland@arm.com, Sebastian Andrzej Siewior References: Content-Language: en-US From: Jesper Dangaard Brouer In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 19/03/2024 21.44, Yan Zhai wrote: > This changeset fixes a common problem for busy networking kthreads. > These threads, e.g. NAPI threads, typically will do: > > * polling a batch of packets > * if there are more work, call cond_resched() to allow scheduling > * continue to poll more packets when rx queue is not empty > > We observed this being a problem in production, since it can block RCU > tasks from making progress under heavy load. Investigation indicates > that just calling cond_resched() is insufficient for RCU tasks to reach > quiescent states. This also has the side effect of frequently clearing > the TIF_NEED_RESCHED flag on voluntary preempt kernels. As a result, > schedule() will not be called in these circumstances, despite schedule() > in fact provides required quiescent states. This at least affects NAPI > threads, napi_busy_loop, and also cpumap kthread. > > By reporting RCU QSes in these kthreads periodically before cond_resched, the > blocked RCU waiters can correctly progress. Instead of just reporting QS for > RCU tasks, these code share the same concern as noted in the commit > d28139c4e967 ("rcu: Apply RCU-bh QSes to RCU-sched and RCU-preempt when safe"). > So report a consolidated QS for safety. > > It is worth noting that, although this problem is reproducible in > napi_busy_loop, it only shows up when setting the polling interval to as high > as 2ms, which is far larger than recommended 50us-100us in the documentation. > So napi_busy_loop is left untouched. > > Lastly, this does not affect RT kernels, which does not enter the scheduler > through cond_resched(). Without the mentioned side effect, schedule() will > be called time by time, and clear the RCU task holdouts. > > V4: https://lore.kernel.org/bpf/cover.1710525524.git.yan@cloudflare.com/ > V3: https://lore.kernel.org/lkml/20240314145459.7b3aedf1@kernel.org/t/ > V2: https://lore.kernel.org/bpf/ZeFPz4D121TgvCje@debian.debian/ > V1: https://lore.kernel.org/lkml/Zd4DXTyCf17lcTfq@debian.debian/#t > > changes since v4: > * polished comments and docs for the RCU helper as Paul McKenney suggested > > changes since v3: > * fixed kernel-doc errors > > changes since v2: > * created a helper in rcu header to abstract the behavior > * fixed cpumap kthread in addition > > changes since v1: > * disable preemption first as Paul McKenney suggested > > Yan Zhai (3): > rcu: add a helper to report consolidated flavor QS > net: report RCU QS on threaded NAPI repolling > bpf: report RCU QS in cpumap kthread > > include/linux/rcupdate.h | 31 +++++++++++++++++++++++++++++++ > kernel/bpf/cpumap.c | 3 +++ > net/core/dev.c | 3 +++ > 3 files changed, 37 insertions(+) > Acked-by: Jesper Dangaard Brouer