[CRIU] Re: [PATCH] pidns: remove recursion from free_pid_ns
Oleg Nesterov
oleg at redhat.com
Fri Oct 5 10:47:29 EDT 2012
On 10/05, Andrew Vagin wrote:
>
> Here is a stack trace of recursion:
> free_pid_ns(parent)
> put_pid_ns(parent)
> kref_put(&ns->kref, free_pid_ns);
> free_pid_ns
>
> This patch turns recursion into loops.
I think the patch is correct, a couple of minor nits.
> +static inline int __kref_put(struct kref *kref)
> +{
> + return atomic_sub_and_test(1, &kref->refcount);
perhaps atomic_dec_and_test(&kref->refcount) makes more sense?
> +}
> @@ -138,11 +138,20 @@ void free_pid_ns(struct kref *kref)
>
> ns = container_of(kref, struct pid_namespace, kref);
>
> - parent = ns->parent;
> - destroy_pid_namespace(ns);
> + while (1) {
>
> - if (parent != NULL)
> - put_pid_ns(parent);
> + parent = ns->parent;
> + destroy_pid_namespace(ns);
> +
> + if (parent == NULL || parent == &init_pid_ns)
^^^^^^^^^^^^^^
Why ns->parent == NULL is only possible if ns == init_pid_ns, right?
But in this case we should not be here. The caller verifies that
initial ns != init_pid_ns, and this loops should stop once we reach
init_pid_ns.
Oleg.
More information about the CRIU
mailing list