Re: [PATCH 1/2][resend] pid: tighten pidmap spinlock criticalsection by removing kfree()

From: Andrew Morton
Date: Fri Dec 04 2009 - 17:38:32 EST


On Thu, 3 Dec 2009 12:53:37 -0200
Andr__ Goddard Rosa <andre.goddard@xxxxxxxxx> wrote:

> Avoid calling kfree() under pidmap spinlock, calling it afterwards.
>
> Normally kfree() is fast, but sometimes it can be slow, so avoid
> calling it under the spinlock if we can do it.
>
> Signed-off-by: Andr__ Goddard Rosa <andre.goddard@xxxxxxxxx>
> cc: Pekka Enberg <penberg@xxxxxxxxxxxxxx>
> ---
> kernel/pid.c | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/pid.c b/kernel/pid.c
> index d3f722d..55fd590 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -141,11 +141,12 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
> * installing it:
> */
> spin_lock_irq(&pidmap_lock);
> - if (map->page)
> - kfree(page);
> - else
> + if (!map->page) {
> map->page = page;
> + page = NULL;
> + }
> spin_unlock_irq(&pidmap_lock);
> + kfree(page);
> if (unlikely(!map->page))
> break;
> }

um, OK, but the chances of that kfree() actually being executed are
very small.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/