lkml.org 
[lkml]   [2009]   [Dec]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [RFC PATCH] asynchronous page fault.
    From
    Date
    On Fri, 2009-12-25 at 10:51 +0900, KAMEZAWA Hiroyuki wrote:
    > /*
    > + * Returns vma which contains given address. This scans rb-tree in speculative
    > + * way and increment a reference count if found. Even if vma exists in rb-tree,
    > + * this function may return NULL in racy case. So, this function cannot be used
    > + * for checking whether given address is valid or not.
    > + */
    > +struct vm_area_struct *
    > +find_vma_speculative(struct mm_struct *mm, unsigned long addr)
    > +{
    > + struct vm_area_struct *vma = NULL;
    > + struct vm_area_struct *vma_tmp;
    > + struct rb_node *rb_node;
    > +
    > + if (unlikely(!mm))
    > + return NULL;;
    > +
    > + rcu_read_lock();
    > + rb_node = rcu_dereference(mm->mm_rb.rb_node);
    > + vma = NULL;
    > + while (rb_node) {
    > + vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
    > +
    > + if (vma_tmp->vm_end > addr) {
    > + vma = vma_tmp;
    > + if (vma_tmp->vm_start <= addr)
    > + break;
    > + rb_node = rcu_dereference(rb_node->rb_left);
    > + } else
    > + rb_node = rcu_dereference(rb_node->rb_right);
    > + }
    > + if (vma) {
    > + if ((vma->vm_start <= addr) && (addr < vma->vm_end)) {
    > + if (!atomic_inc_not_zero(&vma->refcnt))

    And here you destroy pretty much all advantage of having done the
    lockless lookup ;-)

    The idea is to let the RCU lock span whatever length you need the vma
    for, the easy way is to simply use PREEMPT_RCU=y for now, the hard way
    is to also incorporate the drop-mmap_sem on blocking patches from a
    while ago.

    > + vma = NULL;
    > + } else
    > + vma = NULL;
    > + }
    > + rcu_read_unlock();
    > + return vma;
    > +}



    \
     
     \ /
      Last update: 2009-12-27 13:07    [W:0.027 / U:0.864 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site