]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
2 | Subject: LTTng instrumentation - memory page faults | |
3 | ||
4 | Original patch header: | |
5 | LTTng instrumentation - memory page faults | |
6 | ||
7 | Instrument the page fault entry and exit. Useful to detect delays caused by page | |
8 | faults and bad memory usage patterns. | |
9 | ||
10 | Those tracepoints are used by LTTng. | |
11 | ||
12 | About the performance impact of tracepoints (which is comparable to markers), | |
13 | even without immediate values optimizations, tests done by Hideo Aoki on ia64 | |
14 | show no regression. His test case was using hackbench on a kernel where | |
15 | scheduler instrumentation (about 5 events in code scheduler code) was added. | |
16 | See the "Tracepoints" patch header for performance result detail. | |
17 | ||
18 | Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | |
19 | CC: Andi Kleen <andi-suse@firstfloor.org> | |
20 | CC: linux-mm@kvack.org | |
21 | CC: Dave Hansen <haveblue@us.ibm.com> | |
22 | CC: Masami Hiramatsu <mhiramat@redhat.com> | |
23 | CC: 'Peter Zijlstra' <peterz@infradead.org> | |
24 | CC: "Frank Ch. Eigler" <fche@redhat.com> | |
25 | CC: 'Ingo Molnar' <mingo@elte.hu> | |
26 | CC: 'Hideo AOKI' <haoki@redhat.com> | |
27 | CC: Takashi Nishiie <t-nishiie@np.css.fujitsu.com> | |
28 | CC: 'Steven Rostedt' <rostedt@goodmis.org> | |
29 | CC: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> | |
30 | ||
31 | Acked-by: Jan Blunck <jblunck@suse.de> | |
32 | --- | |
33 | --- | |
34 | include/trace/memory.h | 14 ++++++++++++++ | |
35 | mm/memory.c | 33 ++++++++++++++++++++++++--------- | |
36 | 2 files changed, 38 insertions(+), 9 deletions(-) | |
37 | ||
38 | --- /dev/null | |
39 | +++ b/include/trace/memory.h | |
40 | @@ -0,0 +1,14 @@ | |
41 | +#ifndef _TRACE_MEMORY_H | |
42 | +#define _TRACE_MEMORY_H | |
43 | + | |
44 | +#include <linux/tracepoint.h> | |
45 | + | |
46 | +DEFINE_TRACE(memory_handle_fault_entry, | |
47 | + TPPROTO(struct mm_struct *mm, struct vm_area_struct *vma, | |
48 | + unsigned long address, int write_access), | |
49 | + TPARGS(mm, vma, address, write_access)); | |
50 | +DEFINE_TRACE(memory_handle_fault_exit, | |
51 | + TPPROTO(int res), | |
52 | + TPARGS(res)); | |
53 | + | |
54 | +#endif | |
55 | --- a/mm/memory.c | |
56 | +++ b/mm/memory.c | |
57 | @@ -61,6 +61,7 @@ | |
58 | ||
59 | #include <linux/swapops.h> | |
60 | #include <linux/elf.h> | |
61 | +#include <trace/memory.h> | |
62 | ||
63 | #include "internal.h" | |
64 | ||
65 | @@ -2869,30 +2870,44 @@ unlock: | |
66 | int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, | |
67 | unsigned long address, int write_access) | |
68 | { | |
69 | + int res; | |
70 | pgd_t *pgd; | |
71 | pud_t *pud; | |
72 | pmd_t *pmd; | |
73 | pte_t *pte; | |
74 | ||
75 | + trace_memory_handle_fault_entry(mm, vma, address, write_access); | |
76 | + | |
77 | __set_current_state(TASK_RUNNING); | |
78 | ||
79 | count_vm_event(PGFAULT); | |
80 | ||
81 | - if (unlikely(is_vm_hugetlb_page(vma))) | |
82 | - return hugetlb_fault(mm, vma, address, write_access); | |
83 | + if (unlikely(is_vm_hugetlb_page(vma))) { | |
84 | + res = hugetlb_fault(mm, vma, address, write_access); | |
85 | + goto end; | |
86 | + } | |
87 | ||
88 | pgd = pgd_offset(mm, address); | |
89 | pud = pud_alloc(mm, pgd, address); | |
90 | - if (!pud) | |
91 | - return VM_FAULT_OOM; | |
92 | + if (!pud) { | |
93 | + res = VM_FAULT_OOM; | |
94 | + goto end; | |
95 | + } | |
96 | pmd = pmd_alloc(mm, pud, address); | |
97 | - if (!pmd) | |
98 | - return VM_FAULT_OOM; | |
99 | + if (!pmd) { | |
100 | + res = VM_FAULT_OOM; | |
101 | + goto end; | |
102 | + } | |
103 | pte = pte_alloc_map(mm, pmd, address); | |
104 | - if (!pte) | |
105 | - return VM_FAULT_OOM; | |
106 | + if (!pte) { | |
107 | + res = VM_FAULT_OOM; | |
108 | + goto end; | |
109 | + } | |
110 | ||
111 | - return handle_pte_fault(mm, vma, address, pte, pmd, write_access); | |
112 | + res = handle_pte_fault(mm, vma, address, pte, pmd, write_access); | |
113 | +end: | |
114 | + trace_memory_handle_fault_exit(res); | |
115 | + return res; | |
116 | } | |
117 | EXPORT_SYMBOL_GPL(handle_mm_fault); /* For MoL */ | |
118 |