On Thu, Dec 12, 2024 at 01:48:17PM +0100, Peter Zijlstra wrote: > On Thu, Dec 12, 2024 at 12:56:04PM +0100, Christian Brauner wrote: > > > @@ -146,6 +147,7 @@ static void mnt_ns_tree_add(struct mnt_namespace *ns) > > > > mnt_ns_tree_write_lock(); > > node = rb_find_add_rcu(&ns->mnt_ns_tree_node, &mnt_ns_tree, mnt_ns_cmp); > > + list_add_tail_rcu(&ns->mnt_ns_list, &mnt_ns_list); > > mnt_ns_tree_write_unlock(); > > This only works if the entries are inserted in order -- if not, you can > do something like: If I understand your concern correctly then the entries should always be inserted in order. Mount namespaces are sequentially allocated serialized on the namespace semaphore "namespace_sem. So each mount namespace receives a unique 64bit sequence number. If ten mount namespaces are created with 1, 2, 3, ..., 10 then they are inserted into the rbtree in that order. And so they should be added to that list in the same order. That's why I kept it that simple. Although I need to drop "fs: add mount namespace to rbtree late" to keep that guarantee. Did I understand you correctly? > > prev = rb_prev(&ns->mnt_ns_tree_node); > if (!prev) { > // no previous, add to head > list_add(&ns->mnt_ns_list, &mnt_ns_list); > } else { > // add after the previous tree node > prev_ns = container_of(prev, struct mnt_namespace, mnt_ns_tree_node); > list_add_tail(&ns->mnt_ns_list, &prev_ns->mnt_ns_list); > }