diff options
author | Srikar Dronamraju <srikar@linux.vnet.ibm.com> | 2012-03-30 14:26:46 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-03-31 05:50:02 -0400 |
commit | 682968e0c425c60f0dde37977e5beb2b12ddc4cc (patch) | |
tree | 875eb289aa0e08189b2cf7dc99ee522f91e647e7 /mm/mmap.c | |
parent | d4b3b6384f98f8692ad0209891ccdbc7e78bbefe (diff) |
uprobes/core: Optimize probe hits with the help of a counter
Maintain a per-mm counter: number of uprobes that are inserted
on this process address space.
This counter can be used at probe hit time to determine if we
need a lookup in the uprobes rbtree. Everytime a probe gets
inserted successfully, the probe count is incremented and
everytime a probe gets removed, the probe count is decremented.
The new uprobe_munmap hook ensures the count is correct on a
unmap or remap of a region. We expect that once a
uprobe_munmap() is called, the vma goes away. So
uprobe_unregister() finding a probe to unregister would either
mean unmap event hasnt occurred yet or a mmap event on the same
executable file occured after a unmap event.
Additionally, uprobe_mmap hook now also gets called:
a. on every executable vma that is COWed at fork.
b. a vma of interest is newly mapped; breakpoint insertion also
happens at the required address.
On process creation, make sure the probes count in the child is
set correctly.
Special cases that are taken care include:
a. mremap
b. VM_DONTCOPY vmas on fork()
c. insertion/removal races in the parent during fork().
Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jim Keniston <jkenisto@linux.vnet.ibm.com>
Cc: Linux-mm <linux-mm@kvack.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Anton Arapov <anton@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20120330182646.10018.85805.sendpatchset@srdronam.in.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'mm/mmap.c')
-rw-r--r-- | mm/mmap.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -218,6 +218,7 @@ void unlink_file_vma(struct vm_area_struct *vma) | |||
218 | mutex_lock(&mapping->i_mmap_mutex); | 218 | mutex_lock(&mapping->i_mmap_mutex); |
219 | __remove_shared_vm_struct(vma, file, mapping); | 219 | __remove_shared_vm_struct(vma, file, mapping); |
220 | mutex_unlock(&mapping->i_mmap_mutex); | 220 | mutex_unlock(&mapping->i_mmap_mutex); |
221 | uprobe_munmap(vma); | ||
221 | } | 222 | } |
222 | } | 223 | } |
223 | 224 | ||
@@ -546,8 +547,14 @@ again: remove_next = 1 + (end > next->vm_end); | |||
546 | 547 | ||
547 | if (file) { | 548 | if (file) { |
548 | mapping = file->f_mapping; | 549 | mapping = file->f_mapping; |
549 | if (!(vma->vm_flags & VM_NONLINEAR)) | 550 | if (!(vma->vm_flags & VM_NONLINEAR)) { |
550 | root = &mapping->i_mmap; | 551 | root = &mapping->i_mmap; |
552 | uprobe_munmap(vma); | ||
553 | |||
554 | if (adjust_next) | ||
555 | uprobe_munmap(next); | ||
556 | } | ||
557 | |||
551 | mutex_lock(&mapping->i_mmap_mutex); | 558 | mutex_lock(&mapping->i_mmap_mutex); |
552 | if (insert) { | 559 | if (insert) { |
553 | /* | 560 | /* |
@@ -626,6 +633,7 @@ again: remove_next = 1 + (end > next->vm_end); | |||
626 | 633 | ||
627 | if (remove_next) { | 634 | if (remove_next) { |
628 | if (file) { | 635 | if (file) { |
636 | uprobe_munmap(next); | ||
629 | fput(file); | 637 | fput(file); |
630 | if (next->vm_flags & VM_EXECUTABLE) | 638 | if (next->vm_flags & VM_EXECUTABLE) |
631 | removed_exe_file_vma(mm); | 639 | removed_exe_file_vma(mm); |