Re: [PATCH v5] netns: optimize netns cleaning by batching unhash_nsid calls

From: Qiliang Yuan

Date: Wed Feb 04 2026 - 02:54:34 EST


Hi Kuniyuki,

Thanks for your review and suggestions!

On Tue, 3 Feb 2026 16:20:18 -0800 Kuniyuki Iwashima <kuniyu@xxxxxxxxxx> wrote:
> batch and system is a bit unclear, maybe M_dying_net,
> N_alive_net or something ?

Good point. I've updated the terminology in the commit message to
M_dying_net and N_alive_net for better clarity.

> Also, isn't __peernet2id() also O(N_ids) ?

Yes, you are right. __peernet2id() performs a linear search in the IDR,
so it is indeed O(N_id). I've corrected the complexity analysis in the
commit log. This actually makes the batching optimization even more
valuable.

> Please put this in a hole, maybe after after hash_mix :
>
> $ pahole -C net vmlinux

Updated. I've moved the 'is_dying' flag to the hole after 'hash_mix'
to avoid increasing the size of struct net.

> No need to move id up.

Fixed. I've scoped the 'id' variable locally within the traversal loop
to keep it cleaner.

> This can be done unconditionally as the id will never
> be assigned to dying nets.
>
> while (...) {
> id++;
>
> if (!net->dying)
> continue;
>
> /* do cleanup */
> }

Simplified as suggested. The loop logic is much cleaner now with the
unconditional increment.

I've sent out v6 with these changes.

v6 link: https://lore.kernel.org/all/20260204074854.3506916-1-realwujing@xxxxxxxxx/

Best regards,
Qiliang