kmem.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM kmem
  4. #if !defined(_TRACE_KMEM_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_KMEM_H
  6. #include <linux/types.h>
  7. #include <linux/tracepoint.h>
  8. #include <trace/events/mmflags.h>
  9. DECLARE_EVENT_CLASS(kmem_alloc,
  10. TP_PROTO(unsigned long call_site,
  11. const void *ptr,
  12. size_t bytes_req,
  13. size_t bytes_alloc,
  14. gfp_t gfp_flags),
  15. TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags),
  16. TP_STRUCT__entry(
  17. __field( unsigned long, call_site )
  18. __field( const void *, ptr )
  19. __field( size_t, bytes_req )
  20. __field( size_t, bytes_alloc )
  21. __field( gfp_t, gfp_flags )
  22. ),
  23. TP_fast_assign(
  24. __entry->call_site = call_site;
  25. __entry->ptr = ptr;
  26. __entry->bytes_req = bytes_req;
  27. __entry->bytes_alloc = bytes_alloc;
  28. __entry->gfp_flags = gfp_flags;
  29. ),
  30. TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
  31. __entry->call_site,
  32. __entry->ptr,
  33. __entry->bytes_req,
  34. __entry->bytes_alloc,
  35. show_gfp_flags(__entry->gfp_flags))
  36. );
  37. DEFINE_EVENT(kmem_alloc, kmalloc,
  38. TP_PROTO(unsigned long call_site, const void *ptr,
  39. size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
  40. TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags)
  41. );
  42. DEFINE_EVENT(kmem_alloc, kmem_cache_alloc,
  43. TP_PROTO(unsigned long call_site, const void *ptr,
  44. size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
  45. TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags)
  46. );
  47. DECLARE_EVENT_CLASS(kmem_alloc_node,
  48. TP_PROTO(unsigned long call_site,
  49. const void *ptr,
  50. size_t bytes_req,
  51. size_t bytes_alloc,
  52. gfp_t gfp_flags,
  53. int node),
  54. TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node),
  55. TP_STRUCT__entry(
  56. __field( unsigned long, call_site )
  57. __field( const void *, ptr )
  58. __field( size_t, bytes_req )
  59. __field( size_t, bytes_alloc )
  60. __field( gfp_t, gfp_flags )
  61. __field( int, node )
  62. ),
  63. TP_fast_assign(
  64. __entry->call_site = call_site;
  65. __entry->ptr = ptr;
  66. __entry->bytes_req = bytes_req;
  67. __entry->bytes_alloc = bytes_alloc;
  68. __entry->gfp_flags = gfp_flags;
  69. __entry->node = node;
  70. ),
  71. TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
  72. __entry->call_site,
  73. __entry->ptr,
  74. __entry->bytes_req,
  75. __entry->bytes_alloc,
  76. show_gfp_flags(__entry->gfp_flags),
  77. __entry->node)
  78. );
  79. DEFINE_EVENT(kmem_alloc_node, kmalloc_node,
  80. TP_PROTO(unsigned long call_site, const void *ptr,
  81. size_t bytes_req, size_t bytes_alloc,
  82. gfp_t gfp_flags, int node),
  83. TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node)
  84. );
  85. DEFINE_EVENT(kmem_alloc_node, kmem_cache_alloc_node,
  86. TP_PROTO(unsigned long call_site, const void *ptr,
  87. size_t bytes_req, size_t bytes_alloc,
  88. gfp_t gfp_flags, int node),
  89. TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node)
  90. );
  91. DECLARE_EVENT_CLASS(kmem_free,
  92. TP_PROTO(unsigned long call_site, const void *ptr),
  93. TP_ARGS(call_site, ptr),
  94. TP_STRUCT__entry(
  95. __field( unsigned long, call_site )
  96. __field( const void *, ptr )
  97. ),
  98. TP_fast_assign(
  99. __entry->call_site = call_site;
  100. __entry->ptr = ptr;
  101. ),
  102. TP_printk("call_site=%lx ptr=%p", __entry->call_site, __entry->ptr)
  103. );
  104. DEFINE_EVENT(kmem_free, kfree,
  105. TP_PROTO(unsigned long call_site, const void *ptr),
  106. TP_ARGS(call_site, ptr)
  107. );
  108. DEFINE_EVENT(kmem_free, kmem_cache_free,
  109. TP_PROTO(unsigned long call_site, const void *ptr),
  110. TP_ARGS(call_site, ptr)
  111. );
  112. TRACE_EVENT(mm_page_free,
  113. TP_PROTO(struct page *page, unsigned int order),
  114. TP_ARGS(page, order),
  115. TP_STRUCT__entry(
  116. __field( unsigned long, pfn )
  117. __field( unsigned int, order )
  118. ),
  119. TP_fast_assign(
  120. __entry->pfn = page_to_pfn(page);
  121. __entry->order = order;
  122. ),
  123. TP_printk("page=%p pfn=%lu order=%d",
  124. pfn_to_page(__entry->pfn),
  125. __entry->pfn,
  126. __entry->order)
  127. );
  128. TRACE_EVENT(mm_page_free_batched,
  129. TP_PROTO(struct page *page),
  130. TP_ARGS(page),
  131. TP_STRUCT__entry(
  132. __field( unsigned long, pfn )
  133. ),
  134. TP_fast_assign(
  135. __entry->pfn = page_to_pfn(page);
  136. ),
  137. TP_printk("page=%p pfn=%lu order=0",
  138. pfn_to_page(__entry->pfn),
  139. __entry->pfn)
  140. );
  141. TRACE_EVENT(mm_page_alloc,
  142. TP_PROTO(struct page *page, unsigned int order,
  143. gfp_t gfp_flags, int migratetype),
  144. TP_ARGS(page, order, gfp_flags, migratetype),
  145. TP_STRUCT__entry(
  146. __field( unsigned long, pfn )
  147. __field( unsigned int, order )
  148. __field( gfp_t, gfp_flags )
  149. __field( int, migratetype )
  150. ),
  151. TP_fast_assign(
  152. __entry->pfn = page ? page_to_pfn(page) : -1UL;
  153. __entry->order = order;
  154. __entry->gfp_flags = gfp_flags;
  155. __entry->migratetype = migratetype;
  156. ),
  157. TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s",
  158. __entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
  159. __entry->pfn != -1UL ? __entry->pfn : 0,
  160. __entry->order,
  161. __entry->migratetype,
  162. show_gfp_flags(__entry->gfp_flags))
  163. );
  164. DECLARE_EVENT_CLASS(mm_page,
  165. TP_PROTO(struct page *page, unsigned int order, int migratetype),
  166. TP_ARGS(page, order, migratetype),
  167. TP_STRUCT__entry(
  168. __field( unsigned long, pfn )
  169. __field( unsigned int, order )
  170. __field( int, migratetype )
  171. ),
  172. TP_fast_assign(
  173. __entry->pfn = page ? page_to_pfn(page) : -1UL;
  174. __entry->order = order;
  175. __entry->migratetype = migratetype;
  176. ),
  177. TP_printk("page=%p pfn=%lu order=%u migratetype=%d percpu_refill=%d",
  178. __entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
  179. __entry->pfn != -1UL ? __entry->pfn : 0,
  180. __entry->order,
  181. __entry->migratetype,
  182. __entry->order == 0)
  183. );
  184. DEFINE_EVENT(mm_page, mm_page_alloc_zone_locked,
  185. TP_PROTO(struct page *page, unsigned int order, int migratetype),
  186. TP_ARGS(page, order, migratetype)
  187. );
  188. TRACE_EVENT(mm_page_pcpu_drain,
  189. TP_PROTO(struct page *page, unsigned int order, int migratetype),
  190. TP_ARGS(page, order, migratetype),
  191. TP_STRUCT__entry(
  192. __field( unsigned long, pfn )
  193. __field( unsigned int, order )
  194. __field( int, migratetype )
  195. ),
  196. TP_fast_assign(
  197. __entry->pfn = page ? page_to_pfn(page) : -1UL;
  198. __entry->order = order;
  199. __entry->migratetype = migratetype;
  200. ),
  201. TP_printk("page=%p pfn=%lu order=%d migratetype=%d",
  202. pfn_to_page(__entry->pfn), __entry->pfn,
  203. __entry->order, __entry->migratetype)
  204. );
  205. TRACE_EVENT(mm_page_alloc_extfrag,
  206. TP_PROTO(struct page *page,
  207. int alloc_order, int fallback_order,
  208. int alloc_migratetype, int fallback_migratetype),
  209. TP_ARGS(page,
  210. alloc_order, fallback_order,
  211. alloc_migratetype, fallback_migratetype),
  212. TP_STRUCT__entry(
  213. __field( unsigned long, pfn )
  214. __field( int, alloc_order )
  215. __field( int, fallback_order )
  216. __field( int, alloc_migratetype )
  217. __field( int, fallback_migratetype )
  218. __field( int, change_ownership )
  219. ),
  220. TP_fast_assign(
  221. __entry->pfn = page_to_pfn(page);
  222. __entry->alloc_order = alloc_order;
  223. __entry->fallback_order = fallback_order;
  224. __entry->alloc_migratetype = alloc_migratetype;
  225. __entry->fallback_migratetype = fallback_migratetype;
  226. __entry->change_ownership = (alloc_migratetype ==
  227. get_pageblock_migratetype(page));
  228. ),
  229. TP_printk("page=%p pfn=%lu alloc_order=%d fallback_order=%d pageblock_order=%d alloc_migratetype=%d fallback_migratetype=%d fragmenting=%d change_ownership=%d",
  230. pfn_to_page(__entry->pfn),
  231. __entry->pfn,
  232. __entry->alloc_order,
  233. __entry->fallback_order,
  234. pageblock_order,
  235. __entry->alloc_migratetype,
  236. __entry->fallback_migratetype,
  237. __entry->fallback_order < pageblock_order,
  238. __entry->change_ownership)
  239. );
  240. #endif /* _TRACE_KMEM_H */
  241. /* This part must be outside protection */
  242. #include <trace/define_trace.h>