From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 308B314F112 for ; Fri, 30 Jan 2026 02:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769741058; cv=none; b=jTvNmYaRaTZLxgxF8JPb2WPNFvZiE10bJort87+CdELub1b7Q44yEPUtWU0eq4JfLVVrLcR+J3u/IVf1Nv+XY3eYMKaahQzfQi9Z/9JWg0/paRL6v4C8rJJ6vUzAT0P15M8jnZLpq7SAselj5Q1OxqGdLLtgOjByu3CPuG7ioHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769741058; c=relaxed/simple; bh=77m54Z3r12BiXyISoAMiVNiKFAaYj429ngd+jaOhBlI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bpH2z+2MhSZWzp36yZE82vNRyCDacIaSK9Cn3XkQp+e2dHPjBENyaCVXej2/KNKtFo4HGwf/vswjIe+OpayXvXZHDMELP1eu21sINQtoM6U9c7LmS3Qnq+q22XX4xWsMybP7lCIUuVkHuLVw5Ru5qe/btf/LIracdS9tuspbGcw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gnje5YsJ; arc=none smtp.client-ip=74.125.82.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gnje5YsJ" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-2b7c5db431cso1004781eec.1 for ; Thu, 29 Jan 2026 18:44:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769741056; x=1770345856; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C+bKZuo8K+L898uhyxUoNjLAoFRKKRaFaoiyxFbBVrE=; b=gnje5YsJJu2h5teBKMRossdOTxwxRY1pR0kLPPpkGBYUOxrqyqaKtfthgEmmpqugFE cOpOw1h45K2+U5KqCSXY6IYkgXJU3MBlja//7jTetWrrbp3nggo/mIyal7b4Qn0g1u5u HcVUL+iGEMcGbQmZl4hTdc2UHP+ZMVhM2KndqZRzNc3+dvnshJX/7T+4TXTv0UUzGs8N 5FtrD68ZmIzRtu80lEOVi4OhaL7MD14s605lKPbTQkWbERH7G6wlZS0oSdviZD2V57gD uA6+gQcXbpWzQORGDMaWMbL84vcxsrNd/3Tm+gal3UhtaEOGmCWIZJcuSly5bQIXXsqS +08A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769741056; x=1770345856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=C+bKZuo8K+L898uhyxUoNjLAoFRKKRaFaoiyxFbBVrE=; b=jZ8DIukNq1HCURvpOC5Fd6SFguBaurUlII012T11W/QJ9D1tnev+LBjqugSprGsA+4 XjRd3bRXWWDdBuMe7q2x0QUE1ENzUrtq8XsLIXG83+nrUN22f+oajlMtIqHPXO0j5Dx3 jvKKqayy/q1IfYev0nVSj4GFXHkkl9AEAJEi63Zs/8rrBRGbF98SZ2DWl6UWv4Gg0kWI 7LqJ0kM/7ROZp+lUhxRkRQ8H+78yxSh3fEC26d/b2BLuMFs+c56f8XUA3vsNhC+BvqUt AAxamXeZKQzOPH/lk8uNhl+u3gjLyOjTZ249JdKFPfaXmSoe2DIpGErgZ7x9admjDrWi VCww== X-Forwarded-Encrypted: i=1; AJvYcCU8z3Ht16BNUNWX9gcXWs2tNNLyfli+6KN385vKXllk+rQSQjkQL5dT5QURAV4rXLxrQqKF7WHnbmQ8nQE=@vger.kernel.org X-Gm-Message-State: AOJu0Yxa75p1avxTFrUb3GeUUnRdUc3NCfa3HDMKaWxQ1w+RiS07KJ4x 6Z1MwP6KE+6Pihd19OA+RdnSdpAxv0FRNzYMeBN93oX/qLhXyaqzCRB+yPlAndqDaz4= X-Gm-Gg: AZuq6aK4ox+xeIuOFRplMg2uEVpJaSs/PMclum1z2RXA/XoIOfACJwRc5/QesycBwYp 6lmPdIqpovrM8Amk1Ch0O13L2KTg/ZJzGsDGuCe+YCHMTlqB4Z+mfgjGjT68slt9EXT9eYGKKum uLixHraInwXFAZOXXJE/Yxeyzuip+SUgTBsCqpoMICmUly0+11LeHXxOb2olCEl5fLQS6OCHcft fSMSgANBnsVPE4viFuyW3o/27Sem98+CUuNEIRCJ4+OzR+Z9KvyEVpJmCrhATt3XcUAhXbL5mXP UeDbzc6vekiHnu+Kt8adkR0MOZYOccKVLNWQOG/W+sZMx0rnnxnHjN3f3QqQAFou/EuEnC1LAaR 4gNtrYyTGDsnSPaCgnyw8ql5ZrKjG3s7zXJWV3Wfs4IP9godoFnFYXg6O5y9WxbjsXVqNUveQlq 1qXgY= X-Received: by 2002:a05:693c:2b12:b0:2b0:5b6b:6529 with SMTP id 5a478bee46e88-2b7c8940fa3mr687647eec.39.1769741056072; Thu, 29 Jan 2026 18:44:16 -0800 (PST) Received: from debian ([74.48.213.230]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b7a1abeb6asm10183448eec.19.2026.01.29.18.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 18:44:15 -0800 (PST) From: Qiliang Yuan To: kuniyu@google.com Cc: brauner@kernel.org, davem@davemloft.net, edumazet@google.com, horms@kernel.org, jlayton@kernel.org, kuba@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, pabeni@redhat.com, realwujing@gmail.com, sd@queasysnail.net, yuanql9@chinatelecom.cn Subject: Re: [PATCH net-next v3] netns: optimize netns cleaning by batching unhash_nsid calls Date: Thu, 29 Jan 2026 21:44:06 -0500 Message-ID: <20260130024410.2491051-1-realwujing@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Kuniyuki, Thank you for your valuable feedback! On Wed, 28 Jan 2026 09:13:59 -0800 Kuniyuki Iwashima wrote: > idr_for_each() sounds better to me. I have integrated this in v4. It indeed makes the IDR traversal much more idiomatic and efficient. > If we replace list_del_rcu(&net->list); with > list_del_init_rcu(&net->list);, we can check net->list.pprev > instead of adding dying_net, which is a bit racy since > idr_for_each() could return a net which would have been > processed in the next cleanup_net() invocation. To resolve this race, I've moved the setting of 'is_dying = true' inside cleanup_net() while still holding the net_rwsem write lock. This ensures all namespaces in the current kill_list are marked before we release the lock and perform the batch unhashing. Regarding list_del_init_rcu(), as it is not a standard API, I evaluated using list_del_rcu() followed by INIT_LIST_HEAD(). However, resetting list pointers is generally unsafe for RCU readers (e.g., in for_each_net_rcu), as it could cause them to enter an infinite loop. Using the 'is_dying' boolean under the existing lock seems to be the safest and simplest approach. I've also cleaned up the redundant nsid_lock and the duplicate Signed-off-by tags as you suggested. The complexity is now O(N_system * N_ids), effectively eliminating the O(M_batch) multiplier. I've just sent out the v4 patch. Looking forward to your thoughts. Thanks, Qiliang