linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Rientjes <rientjes@google.com>
To: Kautuk Consul <consul.kautuk@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Joe Perches <joe@perches.com>,
	Minchan Kim <minchan.kim@gmail.com>,
	David Vrabel <david.vrabel@citrix.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] vmalloc: purge_fragmented_blocks: Acquire spinlock before reading vmap_block
Date: Wed, 7 Dec 2011 23:07:12 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.00.1112072304010.28419@chino.kir.corp.google.com> (raw)
In-Reply-To: <1323327732-30817-1-git-send-email-consul.kautuk@gmail.com>

On Thu, 8 Dec 2011, Kautuk Consul wrote:

> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 3231bf3..2228971 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -855,11 +855,14 @@ static void purge_fragmented_blocks(int cpu)
>  
>  	rcu_read_lock();
>  	list_for_each_entry_rcu(vb, &vbq->free, free_list) {
> +		spin_lock(&vb->lock);
>  
> -		if (!(vb->free + vb->dirty == VMAP_BBMAP_BITS && vb->dirty != VMAP_BBMAP_BITS))
> +		if (!(vb->free + vb->dirty == VMAP_BBMAP_BITS &&
> +			  vb->dirty != VMAP_BBMAP_BITS)) {
> +			spin_unlock(&vb->lock);
>  			continue;
> +		}
>  
> -		spin_lock(&vb->lock);
>  		if (vb->free + vb->dirty == VMAP_BBMAP_BITS && vb->dirty != VMAP_BBMAP_BITS) {
>  			vb->free = 0; /* prevent further allocs after releasing lock */
>  			vb->dirty = VMAP_BBMAP_BITS; /* prevent purging it again */

Nack, this is wrong because the if-clause you're modifying isn't the 
criteria that is used to determine whether the purge occurs or not.  It's 
merely an optimization to prevent doing exactly what your patch is doing: 
taking vb->lock unnecessarily.

In the original code, if the if-clause fails, the lock is only then taken 
and the exact same test occurs again while protected.  If the test now 
fails, the lock is immediately dropped.  A branch here is faster than a 
contented spinlock.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-12-08  7:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-08  7:02 Kautuk Consul
2011-12-08  7:07 ` David Rientjes [this message]
2011-12-08  7:13   ` Kautuk Consul
2011-12-08  7:18     ` David Rientjes
2011-12-08  7:26       ` Kautuk Consul

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=alpine.DEB.2.00.1112072304010.28419@chino.kir.corp.google.com \
    --to=rientjes@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=consul.kautuk@gmail.com \
    --cc=david.vrabel@citrix.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan.kim@gmail.com \
    /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