ksm.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM ksm
  4. #if !defined(_TRACE_KSM_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_KSM_H
  6. #include <linux/tracepoint.h>
  7. /**
  8. * ksm_scan_template - called for start / stop scan
  9. *
  10. * @seq: sequence number of scan
  11. * @rmap_entries: actual number of rmap entries
  12. *
  13. * Allows to trace the start / stop of a ksm scan.
  14. */
  15. DECLARE_EVENT_CLASS(ksm_scan_template,
  16. TP_PROTO(int seq, u32 rmap_entries),
  17. TP_ARGS(seq, rmap_entries),
  18. TP_STRUCT__entry(
  19. __field(int, seq)
  20. __field(u32, rmap_entries)
  21. ),
  22. TP_fast_assign(
  23. __entry->seq = seq;
  24. __entry->rmap_entries = rmap_entries;
  25. ),
  26. TP_printk("seq %d rmap size %d",
  27. __entry->seq, __entry->rmap_entries)
  28. );
  29. /**
  30. * ksm_start_scan - called after a new ksm scan is started
  31. *
  32. * @seq: sequence number of scan
  33. * @rmap_entries: actual number of rmap entries
  34. *
  35. * Allows to trace the start of a ksm scan.
  36. */
  37. DEFINE_EVENT(ksm_scan_template, ksm_start_scan,
  38. TP_PROTO(int seq, u32 rmap_entries),
  39. TP_ARGS(seq, rmap_entries)
  40. );
  41. /**
  42. * ksm_stop_scan - called after a new ksm scan has completed
  43. *
  44. * @seq: sequence number of scan
  45. * @rmap_entries: actual number of rmap entries
  46. *
  47. * Allows to trace the completion of a ksm scan.
  48. */
  49. DEFINE_EVENT(ksm_scan_template, ksm_stop_scan,
  50. TP_PROTO(int seq, u32 rmap_entries),
  51. TP_ARGS(seq, rmap_entries)
  52. );
  53. /**
  54. * ksm_enter - called after a new process has been added / removed from ksm
  55. *
  56. * @mm: address of the mm object of the process
  57. *
  58. * Allows to trace the when a process has been added or removed from ksm.
  59. */
  60. DECLARE_EVENT_CLASS(ksm_enter_exit_template,
  61. TP_PROTO(void *mm),
  62. TP_ARGS(mm),
  63. TP_STRUCT__entry(
  64. __field(void *, mm)
  65. ),
  66. TP_fast_assign(
  67. __entry->mm = mm;
  68. ),
  69. TP_printk("mm %p", __entry->mm)
  70. );
  71. /**
  72. * ksm_enter - called after a new process has been added to ksm
  73. *
  74. * @mm: address of the mm object of the process
  75. *
  76. * Allows to trace the when a process has been added to ksm.
  77. */
  78. DEFINE_EVENT(ksm_enter_exit_template, ksm_enter,
  79. TP_PROTO(void *mm),
  80. TP_ARGS(mm)
  81. );
  82. /**
  83. * ksm_exit - called after a new process has been removed from ksm
  84. *
  85. * @mm: address of the mm object of the process
  86. *
  87. * Allows to trace the when a process has been removed from ksm.
  88. */
  89. DEFINE_EVENT(ksm_enter_exit_template, ksm_exit,
  90. TP_PROTO(void *mm),
  91. TP_ARGS(mm)
  92. );
  93. /**
  94. * ksm_merge_one_page - called after a page has been merged
  95. *
  96. * @pfn: page frame number of ksm page
  97. * @rmap_item: address of rmap_item object
  98. * @mm: address of the process mm struct
  99. * @err: success
  100. *
  101. * Allows to trace the ksm merging of individual pages.
  102. */
  103. TRACE_EVENT(ksm_merge_one_page,
  104. TP_PROTO(unsigned long pfn, void *rmap_item, void *mm, int err),
  105. TP_ARGS(pfn, rmap_item, mm, err),
  106. TP_STRUCT__entry(
  107. __field(unsigned long, pfn)
  108. __field(void *, rmap_item)
  109. __field(void *, mm)
  110. __field(int, err)
  111. ),
  112. TP_fast_assign(
  113. __entry->pfn = pfn;
  114. __entry->rmap_item = rmap_item;
  115. __entry->mm = mm;
  116. __entry->err = err;
  117. ),
  118. TP_printk("ksm pfn %lu rmap_item %p mm %p error %d",
  119. __entry->pfn, __entry->rmap_item, __entry->mm, __entry->err)
  120. );
  121. /**
  122. * ksm_merge_with_ksm_page - called after a page has been merged with a ksm page
  123. *
  124. * @ksm_page: address ksm page
  125. * @pfn: page frame number of ksm page
  126. * @rmap_item: address of rmap_item object
  127. * @mm: address of the mm object of the process
  128. * @err: success
  129. *
  130. * Allows to trace the merging of a page with a ksm page.
  131. */
  132. TRACE_EVENT(ksm_merge_with_ksm_page,
  133. TP_PROTO(void *ksm_page, unsigned long pfn, void *rmap_item, void *mm, int err),
  134. TP_ARGS(ksm_page, pfn, rmap_item, mm, err),
  135. TP_STRUCT__entry(
  136. __field(void *, ksm_page)
  137. __field(unsigned long, pfn)
  138. __field(void *, rmap_item)
  139. __field(void *, mm)
  140. __field(int, err)
  141. ),
  142. TP_fast_assign(
  143. __entry->ksm_page = ksm_page;
  144. __entry->pfn = pfn;
  145. __entry->rmap_item = rmap_item;
  146. __entry->mm = mm;
  147. __entry->err = err;
  148. ),
  149. TP_printk("%spfn %lu rmap_item %p mm %p error %d",
  150. (__entry->ksm_page ? "ksm " : ""),
  151. __entry->pfn, __entry->rmap_item, __entry->mm, __entry->err)
  152. );
  153. /**
  154. * ksm_remove_ksm_page - called after a ksm page has been removed
  155. *
  156. * @pfn: page frame number of ksm page
  157. *
  158. * Allows to trace the removing of stable ksm pages.
  159. */
  160. TRACE_EVENT(ksm_remove_ksm_page,
  161. TP_PROTO(unsigned long pfn),
  162. TP_ARGS(pfn),
  163. TP_STRUCT__entry(
  164. __field(unsigned long, pfn)
  165. ),
  166. TP_fast_assign(
  167. __entry->pfn = pfn;
  168. ),
  169. TP_printk("pfn %lu", __entry->pfn)
  170. );
  171. /**
  172. * ksm_remove_rmap_item - called after a rmap_item has been removed from the
  173. * stable tree
  174. *
  175. * @pfn: page frame number of ksm page
  176. * @rmap_item: address of rmap_item object
  177. * @mm: address of the process mm struct
  178. *
  179. * Allows to trace the removal of pages from the stable tree list.
  180. */
  181. TRACE_EVENT(ksm_remove_rmap_item,
  182. TP_PROTO(unsigned long pfn, void *rmap_item, void *mm),
  183. TP_ARGS(pfn, rmap_item, mm),
  184. TP_STRUCT__entry(
  185. __field(unsigned long, pfn)
  186. __field(void *, rmap_item)
  187. __field(void *, mm)
  188. ),
  189. TP_fast_assign(
  190. __entry->pfn = pfn;
  191. __entry->rmap_item = rmap_item;
  192. __entry->mm = mm;
  193. ),
  194. TP_printk("pfn %lu rmap_item %p mm %p",
  195. __entry->pfn, __entry->rmap_item, __entry->mm)
  196. );
  197. /**
  198. * ksm_advisor - called after the advisor has run
  199. *
  200. * @scan_time: scan time in seconds
  201. * @pages_to_scan: new pages_to_scan value
  202. * @cpu_percent: cpu usage in percent
  203. *
  204. * Allows to trace the ksm advisor.
  205. */
  206. TRACE_EVENT(ksm_advisor,
  207. TP_PROTO(s64 scan_time, unsigned long pages_to_scan,
  208. unsigned int cpu_percent),
  209. TP_ARGS(scan_time, pages_to_scan, cpu_percent),
  210. TP_STRUCT__entry(
  211. __field(s64, scan_time)
  212. __field(unsigned long, pages_to_scan)
  213. __field(unsigned int, cpu_percent)
  214. ),
  215. TP_fast_assign(
  216. __entry->scan_time = scan_time;
  217. __entry->pages_to_scan = pages_to_scan;
  218. __entry->cpu_percent = cpu_percent;
  219. ),
  220. TP_printk("ksm scan time %lld pages_to_scan %lu cpu percent %u",
  221. __entry->scan_time, __entry->pages_to_scan,
  222. __entry->cpu_percent)
  223. );
  224. #endif /* _TRACE_KSM_H */
  225. /* This part must be outside protection */
  226. #include <trace/define_trace.h>