mm/mmap.c: find_vma(): remove unnecessary if(mm) check
The "if (mm)" check is not required in find_vma, as the kernel code calls find_vma only when it is absolutely sure that the mm_struct arg to it is non-NULL. Remove the if(mm) check and adding the a WARN_ONCE(!mm) for now. This will serve the purpose of mandating that the execution context(user-mode/kernel-mode) be known before find_vma is called. Also fixed 2 checkpatch.pl errors in the declaration of the rb_node and vma_tmp local variables. I was browsing through the internet and read a discussion at https://lkml.org/lkml/2012/3/27/342 which discusses removal of the validation check within find_vma. Since no-one responded, I decided to send this patch with Andrew's suggestions. [akpm@linux-foundation.org: add remove-me comment] Signed-off-by: Rajman Mekaco <rajman.mekaco@gmail.com> Cc: Kautuk Consul <consul.kautuk@gmail.com> Cc: Hugh Dickins <hughd@google.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
4d67d86053
commit
841e31e5cc
45
mm/mmap.c
45
mm/mmap.c
|
@ -1639,33 +1639,34 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
|
||||||
{
|
{
|
||||||
struct vm_area_struct *vma = NULL;
|
struct vm_area_struct *vma = NULL;
|
||||||
|
|
||||||
if (mm) {
|
if (WARN_ON_ONCE(!mm)) /* Remove this in linux-3.6 */
|
||||||
/* Check the cache first. */
|
return NULL;
|
||||||
/* (Cache hit rate is typically around 35%.) */
|
|
||||||
vma = mm->mmap_cache;
|
|
||||||
if (!(vma && vma->vm_end > addr && vma->vm_start <= addr)) {
|
|
||||||
struct rb_node * rb_node;
|
|
||||||
|
|
||||||
rb_node = mm->mm_rb.rb_node;
|
/* Check the cache first. */
|
||||||
vma = NULL;
|
/* (Cache hit rate is typically around 35%.) */
|
||||||
|
vma = mm->mmap_cache;
|
||||||
|
if (!(vma && vma->vm_end > addr && vma->vm_start <= addr)) {
|
||||||
|
struct rb_node *rb_node;
|
||||||
|
|
||||||
while (rb_node) {
|
rb_node = mm->mm_rb.rb_node;
|
||||||
struct vm_area_struct * vma_tmp;
|
vma = NULL;
|
||||||
|
|
||||||
vma_tmp = rb_entry(rb_node,
|
while (rb_node) {
|
||||||
struct vm_area_struct, vm_rb);
|
struct vm_area_struct *vma_tmp;
|
||||||
|
|
||||||
if (vma_tmp->vm_end > addr) {
|
vma_tmp = rb_entry(rb_node,
|
||||||
vma = vma_tmp;
|
struct vm_area_struct, vm_rb);
|
||||||
if (vma_tmp->vm_start <= addr)
|
|
||||||
break;
|
if (vma_tmp->vm_end > addr) {
|
||||||
rb_node = rb_node->rb_left;
|
vma = vma_tmp;
|
||||||
} else
|
if (vma_tmp->vm_start <= addr)
|
||||||
rb_node = rb_node->rb_right;
|
break;
|
||||||
}
|
rb_node = rb_node->rb_left;
|
||||||
if (vma)
|
} else
|
||||||
mm->mmap_cache = vma;
|
rb_node = rb_node->rb_right;
|
||||||
}
|
}
|
||||||
|
if (vma)
|
||||||
|
mm->mmap_cache = vma;
|
||||||
}
|
}
|
||||||
return vma;
|
return vma;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue