Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751836Ab2JREf5 (ORCPT ); Thu, 18 Oct 2012 00:35:57 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:42817 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751137Ab2JREfz (ORCPT ); Thu, 18 Oct 2012 00:35:55 -0400 Date: Wed, 17 Oct 2012 21:35:53 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Kamezawa Hiroyuki cc: Linus Torvalds , Andrew Morton , Dave Jones , KOSAKI Motohiro , bhutchings@solarflare.com, Konstantin Khlebnikov , Naoya Horiguchi , Hugh Dickins , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch for-3.7 v2] mm, mempolicy: avoid taking mutex inside spinlock when reading numa_maps In-Reply-To: <507F803A.8000900@jp.fujitsu.com> Message-ID: References: <20121017040515.GA13505@redhat.com> <20121017181413.GA16805@redhat.com> <20121017193229.GC16805@redhat.com> <20121017194501.GA24400@redhat.com> <507F803A.8000900@jp.fujitsu.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2336 Lines: 67 On Thu, 18 Oct 2012, Kamezawa Hiroyuki wrote: > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c > index 14df880..d92e868 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -94,6 +94,11 @@ static void vma_stop(struct proc_maps_private *priv, struct > vm_area_struct *vma) > { > if (vma && vma != priv->tail_vma) { > struct mm_struct *mm = vma->vm_mm; > +#ifdef CONFIG_NUMA > + task_lock(priv->task); > + __mpol_put(priv->task->mempolicy); > + task_unlock(priv->task); > +#endif > up_read(&mm->mmap_sem); > mmput(mm); > } > @@ -130,6 +135,16 @@ static void *m_start(struct seq_file *m, loff_t *pos) > return mm; > down_read(&mm->mmap_sem); > + /* > + * task->mempolicy can be freed even if mmap_sem is down (see > kernel/exit.c) > + * We grab refcount for stable access. > + * repleacement of task->mmpolicy is guarded by mmap_sem. > + */ > +#ifdef CONFIG_NUMA > + task_lock(priv->task); > + mpol_get(priv->task->mempolicy); > + task_unlock(priv->task); > +#endif > tail_vma = get_gate_vma(priv->task->mm); > priv->tail_vma = tail_vma; > @@ -161,6 +176,11 @@ out: > /* End of vmas has been reached */ > m->version = (tail_vma != NULL)? 0: -1UL; > +#ifdef CONFIG_NUMA > + task_lock(priv->task); > + __mpol_put(priv->task->mempolicy); > + task_unlock(priv->task); > +#endif > up_read(&mm->mmap_sem); > mmput(mm); > return tail_vma; Yes, I must admit that this is better than my version and it looks like all the ->show() functions that use these start, next, stop functions don't take task_lock() and this would generally be useful: we already hold current->mm->mmap_sem so there is little harm in holding task_lock(current) when reading these files as long as we're not touching the fastpath. These routines seem like it would nicely be added to mempolicy.h since we depend on CONFIG_NUMA there already. Please fix up the mess I made in show_numa_map() in 32f8516a8c73 ("mm, mempolicy: fix printing stack contents in numa_maps") by simply removing the task_lock() and task_unlock() as part of your patch. Thanks Kame! -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/