* [PATCH 1/1] mmap.c: find_vma: remove unnecessary if(mm) check
@ 2012-04-21 13:42 Rajman Mekaco
2012-04-21 23:48 ` KOSAKI Motohiro
2012-04-23 21:39 ` Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Rajman Mekaco @ 2012-04-21 13:42 UTC (permalink / raw)
To: Andrew Morton, Hugh Dickins, Al Viro, KAMEZAWA Hiroyuki, KOSAKI Motohiro
Cc: linux-mm, linux-kernel, Rajman Mekaco, Kautuk Consul
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.
Removing 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.
Signed-off-by: Rajman Mekaco <rajman.mekaco@gmail.com>
Cc: Kautuk Consul <consul.kautuk@gmail.com>
---
mm/mmap.c | 53 +++++++++++++++++++++++++++--------------------------
1 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index b38b47e..1c3ef5d 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1616,33 +1616,34 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
{
struct vm_area_struct *vma = NULL;
- if (mm) {
- /* Check the cache first. */
- /* (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;
- vma = NULL;
-
- while (rb_node) {
- struct vm_area_struct * vma_tmp;
-
- 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 = rb_node->rb_left;
- } else
- rb_node = rb_node->rb_right;
- }
- if (vma)
- mm->mmap_cache = vma;
+ if (WARN_ON_ONCE(!mm))
+ return NULL;
+
+ /* Check the cache first. */
+ /* (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;
+ vma = NULL;
+
+ while (rb_node) {
+ struct vm_area_struct *vma_tmp;
+
+ 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 = rb_node->rb_left;
+ } else
+ rb_node = rb_node->rb_right;
}
+ if (vma)
+ mm->mmap_cache = vma;
}
return vma;
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] mmap.c: find_vma: remove unnecessary if(mm) check
2012-04-21 13:42 [PATCH 1/1] mmap.c: find_vma: remove unnecessary if(mm) check Rajman Mekaco
@ 2012-04-21 23:48 ` KOSAKI Motohiro
2012-04-23 21:39 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: KOSAKI Motohiro @ 2012-04-21 23:48 UTC (permalink / raw)
To: Rajman Mekaco
Cc: Andrew Morton, Hugh Dickins, Al Viro, KAMEZAWA Hiroyuki,
linux-mm, linux-kernel, Kautuk Consul
On Sat, Apr 21, 2012 at 9:42 AM, Rajman Mekaco <rajman.mekaco@gmail.com> wrote:
> 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.
>
> Removing 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.
>
> Signed-off-by: Rajman Mekaco <rajman.mekaco@gmail.com>
> Cc: Kautuk Consul <consul.kautuk@gmail.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] mmap.c: find_vma: remove unnecessary if(mm) check
2012-04-21 13:42 [PATCH 1/1] mmap.c: find_vma: remove unnecessary if(mm) check Rajman Mekaco
2012-04-21 23:48 ` KOSAKI Motohiro
@ 2012-04-23 21:39 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2012-04-23 21:39 UTC (permalink / raw)
To: Rajman Mekaco
Cc: Hugh Dickins, Al Viro, KAMEZAWA Hiroyuki, KOSAKI Motohiro,
linux-mm, linux-kernel, Kautuk Consul
On Sat, 21 Apr 2012 19:12:35 +0530
Rajman Mekaco <rajman.mekaco@gmail.com> wrote:
> 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.
>
> Removing the if(mm) check and adding the a WARN_ONCE(!mm)
> for now.
Lets do this as well:
--- a/mm/mmap.c~mm-mmapc-find_vma-remove-unnecessary-ifmm-check-fix
+++ a/mm/mmap.c
@@ -1639,7 +1639,7 @@ struct vm_area_struct *find_vma(struct m
{
struct vm_area_struct *vma = NULL;
- if (WARN_ON_ONCE(!mm))
+ if (WARN_ON_ONCE(!mm)) /* Remove this in linux-3.6 */
return NULL;
/* Check the cache first. */
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-23 21:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-21 13:42 [PATCH 1/1] mmap.c: find_vma: remove unnecessary if(mm) check Rajman Mekaco
2012-04-21 23:48 ` KOSAKI Motohiro
2012-04-23 21:39 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).