public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "André Goddard Rosa" <andre.goddard@gmail.com>
Cc: "linux list" <linux-kernel@vger.kernel.org>,
	Pekka Enberg <penberg@cs.helsinki.fi>
Subject: Re: [PATCH 1/2][resend] pid: tighten pidmap spinlock critical section by removing kfree()
Date: Fri, 4 Dec 2009 14:38:02 -0800	[thread overview]
Message-ID: <20091204143802.17f3fded.akpm@linux-foundation.org> (raw)
In-Reply-To: <0e91f1c4ecc5bc5000f729ccb56e9b6e1fbd4bd3.1258805412.git.andre.goddard@gmail.com>

On Thu,  3 Dec 2009 12:53:37 -0200
Andr__ Goddard Rosa <andre.goddard@gmail.com> 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@gmail.com>
> cc: Pekka Enberg <penberg@cs.helsinki.fi>
> ---
>  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.


  parent reply	other threads:[~2009-12-04 22:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-21 12:16 [PATCH 0/2] pid: tighten pidmap spinlock section and clean up André Goddard Rosa
2009-11-21 12:16 ` [PATCH 1/2] pid: tighten pidmap spinlock critical section by removing kfree() André Goddard Rosa
2009-11-23  9:38   ` Pekka Enberg
2009-11-23 14:03     ` Oleg Nesterov
2009-11-23 15:26       ` André Goddard Rosa
2009-12-04 22:38   ` Andrew Morton [this message]
2009-11-21 12:16 ` [PATCH 2/2] pid: reduce code size by using a pointer to iterate over array André Goddard Rosa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091204143802.17f3fded.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andre.goddard@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox