Messages in this thread | | | Subject | Re: [RFC PATCH] asynchronous page fault. | From | Peter Zijlstra <> | Date | Sun, 27 Dec 2009 13:03:11 +0100 |
| |
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; > +}
| |