lkml.org 
[lkml]   [2012]   [Oct]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [patch for-3.7 v2] mm, mempolicy: avoid taking mutex inside spinlock when reading numa_maps
    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!


    \
     
     \ /
      Last update: 2012-10-18 07:21    [W:5.871 / U:0.528 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site