| 1 |
// memory/vm related tapset |
| 2 |
// Copyright (C) 2005, 2006 IBM Corp. |
| 3 |
// Copyright (C) 2006 Intel Corporation. |
| 4 |
// Copyright (C) 2014-2019 Red Hat Inc. |
| 5 |
// |
| 6 |
// This file is part of systemtap, and is free software. You can |
| 7 |
// redistribute it and/or modify it under the terms of the GNU General |
| 8 |
// Public License (GPL); either version 2, or (at your option) any |
| 9 |
// later version. |
| 10 |
// <tapsetdescription> |
| 11 |
// This family of probe points is used to probe memory-related events. |
| 12 |
// </tapsetdescription> |
| 13 |
%{ |
| 14 |
#include <linux/mm.h> |
| 15 |
%} |
| 16 |
|
| 17 |
global VM_FAULT_OOM=0, VM_FAULT_SIGBUS=1, VM_FAULT_MINOR=2, VM_FAULT_MAJOR=3 |
| 18 |
global VM_FAULT_NOPAGE=4, VM_FAULT_LOCKED=5, VM_FAULT_ERROR=6 |
| 19 |
global FAULT_FLAG_WRITE=1 |
| 20 |
|
| 21 |
/** |
| 22 |
* sfunction vm_fault_contains - Test return value for page fault reason |
| 23 |
* |
| 24 |
* @value: the fault_type returned by vm.page_fault.return |
| 25 |
* @test: the type of fault to test for (VM_FAULT_OOM or similar) |
| 26 |
*/ |
| 27 |
function vm_fault_contains:long (value:long, test:long) |
| 28 |
%{ |
| 29 |
int res; |
| 30 |
switch (STAP_ARG_test){ |
| 31 |
case 0: res = STAP_ARG_value & VM_FAULT_OOM; break; |
| 32 |
case 1: res = STAP_ARG_value & VM_FAULT_SIGBUS; break; |
| 33 |
#if !defined(VM_FAULT_MINOR) || (defined(VM_FAULT_MINOR) && VM_FAULT_MINOR == 0) |
| 34 |
case 2: /* VM_FAULT_MINOR infered by that flags off */ |
| 35 |
res = !((VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_MAJOR) & |
| 36 |
STAP_ARG_value); |
| 37 |
break; |
| 38 |
#else |
| 39 |
case 2: res = STAP_ARG_value == VM_FAULT_MINOR; break; |
| 40 |
#endif |
| 41 |
case 3: res = STAP_ARG_value & VM_FAULT_MAJOR; break; |
| 42 |
#ifdef VM_FAULT_NOPAGE |
| 43 |
case 4: res = STAP_ARG_value & VM_FAULT_NOPAGE; break; |
| 44 |
#endif |
| 45 |
#ifdef VM_FAULT_LOCKED |
| 46 |
case 5: res = STAP_ARG_value & VM_FAULT_LOCKED; break; |
| 47 |
#endif |
| 48 |
#ifdef VM_FAULT_ERROR |
| 49 |
case 6: res = STAP_ARG_value & VM_FAULT_ERROR; break; |
| 50 |
#endif |
| 51 |
default: res = 0; break; |
| 52 |
} |
| 53 |
STAP_RETVALUE = (res != 0); |
| 54 |
return; |
| 55 |
%} |
| 56 |
|
| 57 |
/** |
| 58 |
* probe vm.pagefault - Records that a page fault occurred |
| 59 |
* |
| 60 |
* @name: name of the probe point |
| 61 |
* @address: the address of the faulting memory access; i.e. the address that caused the page fault |
| 62 |
* @write_access: indicates whether this was a write or read access; 1 indicates a write, |
| 63 |
* while 0 indicates a read |
| 64 |
* |
| 65 |
* Context: The process which triggered the fault |
| 66 |
*/ |
| 67 |
probe vm.pagefault = kernel.function("handle_mm_fault@mm/memory.c").call !, |
| 68 |
kernel.function("__handle_mm_fault@mm/memory.c").call |
| 69 |
{ |
| 70 |
name = "pagefault" |
| 71 |
write_access = (@defined($flags) |
| 72 |
? $flags & FAULT_FLAG_WRITE : $write_access) |
| 73 |
address = $address |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* probe vm.pagefault.return - Indicates what type of fault occurred |
| 78 |
* |
| 79 |
* @name: name of the probe point |
| 80 |
* @fault_type: returns either |
| 81 |
* 0 (VM_FAULT_OOM) for out of memory faults, |
| 82 |
* 2 (VM_FAULT_MINOR) for minor faults, 3 (VM_FAULT_MAJOR) for |
| 83 |
* major faults, or 1 (VM_FAULT_SIGBUS) if the fault was neither OOM, minor fault, |
| 84 |
* nor major fault. |
| 85 |
*/ |
| 86 |
probe vm.pagefault.return = |
| 87 |
kernel.function("handle_mm_fault@mm/memory.c").return !, |
| 88 |
kernel.function("__handle_mm_fault@mm/memory.c").return |
| 89 |
{ |
| 90 |
name = "pagefault" |
| 91 |
fault_type = $return |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* sfunction addr_to_node - Returns which node a given address belongs to within a NUMA system |
| 96 |
* |
| 97 |
* @addr: the address of the faulting memory access |
| 98 |
* |
| 99 |
* Description: This function accepts an address, and returns the |
| 100 |
* node that the given address belongs to in a NUMA system. |
| 101 |
*/ |
| 102 |
function addr_to_node:long(addr:long) %{ /* pure */ |
| 103 |
int nid; |
| 104 |
int pfn; |
| 105 |
if (! virt_addr_valid((void*) (uintptr_t) STAP_ARG_addr)) { |
| 106 |
snprintf (CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 107 |
"invalid kernel virtual address 0x%p", (void *) (uintptr_t) STAP_ARG_addr); |
| 108 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 109 |
goto out; |
| 110 |
} |
| 111 |
pfn = __pa(STAP_ARG_addr) >> PAGE_SHIFT; |
| 112 |
#ifdef for_each_online_node |
| 113 |
for_each_online_node(nid) |
| 114 |
#else |
| 115 |
for (nid=0; nid<MAX_NUMNODES; nid++) |
| 116 |
if (NODE_DATA(nid)) /* approximately: if (node_online(nid)) */ |
| 117 |
#endif |
| 118 |
if ( NODE_DATA(nid)->node_start_pfn <= pfn && |
| 119 |
pfn < (NODE_DATA(nid)->node_start_pfn + |
| 120 |
NODE_DATA(nid)->node_spanned_pages) ) |
| 121 |
{ |
| 122 |
STAP_RETVALUE = nid; |
| 123 |
break; |
| 124 |
} |
| 125 |
%} |
| 126 |
|
| 127 |
// Return whether a page to be copied is a zero page. |
| 128 |
@__private30 function _IS_ZERO_PAGE:long(from:long, vaddr:long) %{ /* pure */ |
| 129 |
STAP_RETVALUE = (STAP_ARG_from == (long) ZERO_PAGE(STAP_ARG_vaddr)); |
| 130 |
%} |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* probe vm.write_shared - Attempts at writing to a shared page |
| 135 |
* |
| 136 |
* @name: name of the probe point |
| 137 |
* @address: the address of the shared write |
| 138 |
* |
| 139 |
* Context: |
| 140 |
* The context is the process attempting the write. |
| 141 |
* |
| 142 |
* Fires when a process attempts to write to a shared page. |
| 143 |
* If a copy is necessary, this will be followed by a |
| 144 |
* vm.write_shared_copy. |
| 145 |
*/ |
| 146 |
probe vm.write_shared = kernel.function("do_wp_page") { |
| 147 |
name = "write_shared" |
| 148 |
address = @choose_defined($vmf->address,$address) |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* probe vm.write_shared_copy - Page copy for shared page write |
| 153 |
* |
| 154 |
* @name: Name of the probe point |
| 155 |
* @address: The address of the shared write |
| 156 |
* @zero: boolean indicating whether it is a zero page |
| 157 |
* (can do a clear instead of a copy) |
| 158 |
* |
| 159 |
* Context: |
| 160 |
* The process attempting the write. |
| 161 |
* |
| 162 |
* Fires when a write to a shared page requires a page copy. This is |
| 163 |
* always preceded by a vm.write_shared. |
| 164 |
*/ |
| 165 |
probe vm.write_shared_copy = kernel.function("cow_user_page") ?, |
| 166 |
kernel.function("copy_cow_page") ? |
| 167 |
{ |
| 168 |
name = "write_shared_copy" |
| 169 |
if (@defined($va)) { |
| 170 |
address = $va |
| 171 |
zero = _IS_ZERO_PAGE($src, $va); |
| 172 |
} else { |
| 173 |
address = $address |
| 174 |
zero = _IS_ZERO_PAGE($from, $address); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
/** |
| 180 |
* probe vm.mmap - Fires when an mmap is requested |
| 181 |
* |
| 182 |
* @name: name of the probe point |
| 183 |
* @address: the requested address |
| 184 |
* @length: the length of the memory segment |
| 185 |
* |
| 186 |
* Context: |
| 187 |
* The process calling mmap. |
| 188 |
*/ |
| 189 |
probe vm.mmap = kernel.function("vm_mmap") !, |
| 190 |
kernel.function("do_mmap_pgoff") !, |
| 191 |
kernel.function("do_mmap") ?, kernel.function("do_mmap2") ? |
| 192 |
{ |
| 193 |
name = "mmap" |
| 194 |
address = $addr |
| 195 |
length = $len |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
/** |
| 200 |
* probe vm.munmap - Fires when an munmap is requested |
| 201 |
* |
| 202 |
* @name: name of the probe point |
| 203 |
* @address: the requested address |
| 204 |
* @length: the length of the memory segment |
| 205 |
* |
| 206 |
* Context: |
| 207 |
* The process calling munmap. |
| 208 |
*/ |
| 209 |
probe vm.munmap = kernel.function("do_munmap") { |
| 210 |
name = "munmap" |
| 211 |
address = $start |
| 212 |
length = $len |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* probe vm.brk - Fires when a brk is requested (i.e. the heap will be resized) |
| 217 |
* |
| 218 |
* @name: name of the probe point |
| 219 |
* @address: the requested address |
| 220 |
* @length: the length of the memory segment |
| 221 |
* |
| 222 |
* Context: |
| 223 |
* The process calling brk. |
| 224 |
*/ |
| 225 |
probe vm.brk = kernel.function("do_brk_flags")!, kernel.function("do_brk") { |
| 226 |
name = "brk" |
| 227 |
address = $addr |
| 228 |
length = $len |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* probe vm.oom_kill - Fires when a thread is selected for termination by the OOM killer |
| 233 |
* |
| 234 |
* @name: name of the probe point |
| 235 |
* @task: the task being killed |
| 236 |
* |
| 237 |
* Context: |
| 238 |
* The process that tried to consume excessive memory, and thus |
| 239 |
* triggered the OOM. |
| 240 |
*/ |
| 241 |
probe vm.oom_kill = kernel.function("oom_kill_process") !, |
| 242 |
kernel.function("__oom_kill_task") |
| 243 |
{ |
| 244 |
name = "oom_kill" |
| 245 |
if (@defined($p)) { |
| 246 |
task = $p |
| 247 |
} |
| 248 |
else { |
| 249 |
task = $oc->chosen |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
@__private30 function GFP_KERNEL:long() |
| 254 |
{ |
| 255 |
return @const("GFP_KERNEL") |
| 256 |
} |
| 257 |
|
| 258 |
@__private30 function __gfp_flag_str:string(gfp_flag:long) |
| 259 |
%{ |
| 260 |
long gfp_flag = STAP_ARG_gfp_flag; |
| 261 |
STAP_RETVALUE[0] = '\0'; |
| 262 |
|
| 263 |
/* Older kernels < 2.6.32 didn't have some of these GFP defines yet. */ |
| 264 |
#ifndef __GFP_DMA32 |
| 265 |
#define __GFP_DMA32 ((__force gfp_t)0x04u) |
| 266 |
#endif |
| 267 |
#ifndef GFP_DMA32 |
| 268 |
#define GFP_DMA32 __GFP_DMA32 |
| 269 |
#endif |
| 270 |
|
| 271 |
#ifndef __GFP_MOVABLE |
| 272 |
#define __GFP_MOVABLE ((__force gfp_t)0x08u) /* Page is movable */ |
| 273 |
#endif |
| 274 |
|
| 275 |
#ifndef GFP_ZONEMASK |
| 276 |
#define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) |
| 277 |
#endif |
| 278 |
|
| 279 |
#ifndef __GFP_NOTRACK |
| 280 |
#ifdef CONFIG_KMEMCHECK |
| 281 |
#define __GFP_NOTRACK ((__force gfp_t)0x200000u) /* Don't track with kmemcheck */ |
| 282 |
#else |
| 283 |
#define __GFP_NOTRACK ((__force gfp_t)0) |
| 284 |
#endif |
| 285 |
#endif |
| 286 |
|
| 287 |
#ifndef __GFP_THISNODE |
| 288 |
#define __GFP_THISNODE ((__force gfp_t)0x40000u) |
| 289 |
#endif |
| 290 |
|
| 291 |
#ifndef __GFP_RECLAIMABLE |
| 292 |
#define __GFP_RECLAIMABLE ((__force gfp_t)0x80000u) |
| 293 |
#endif |
| 294 |
|
| 295 |
#ifndef __GFP_ZERO |
| 296 |
#define __GFP_ZERO ((__force gfp_t)0x8000u) |
| 297 |
#endif |
| 298 |
|
| 299 |
#ifndef __GFP_NOMEMALLOC |
| 300 |
#define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) |
| 301 |
#endif |
| 302 |
|
| 303 |
#ifndef __GFP_HARDWALL |
| 304 |
#define __GFP_HARDWALL ((__force gfp_t)0x20000u) |
| 305 |
#endif |
| 306 |
|
| 307 |
#ifndef __GFP_WAIT |
| 308 |
#define __GFP_WAIT __GFP_RECLAIM |
| 309 |
#endif |
| 310 |
|
| 311 |
#ifndef GFP_TEMPORARY |
| 312 |
#define GFP_TEMPORARY (__GFP_WAIT | __GFP_IO | __GFP_FS | \ |
| 313 |
__GFP_RECLAIMABLE) |
| 314 |
#endif |
| 315 |
|
| 316 |
#ifndef GFP_HIGHUSER_MOVABLE |
| 317 |
#define GFP_HIGHUSER_MOVABLE (__GFP_WAIT | __GFP_IO | __GFP_FS | \ |
| 318 |
__GFP_HARDWALL | __GFP_HIGHMEM | \ |
| 319 |
__GFP_MOVABLE) |
| 320 |
#endif |
| 321 |
|
| 322 |
#ifndef GFP_THISNODE |
| 323 |
#ifdef CONFIG_NUMA |
| 324 |
#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY) |
| 325 |
#else |
| 326 |
#define GFP_THISNODE ((__force gfp_t)0) |
| 327 |
#endif |
| 328 |
#endif |
| 329 |
|
| 330 |
/* Macro for GFP Bitmasks. */ |
| 331 |
/* The resulted GFP_FLAGS may be either single or concatenation of the multiple bitmasks. */ |
| 332 |
|
| 333 |
|
| 334 |
#define __GFP_BITMASKS(FLAG) if(gfp_flag & FLAG) { if(STAP_RETVALUE[0] != '\0') \ |
| 335 |
strlcat(STAP_RETVALUE, " | "#FLAG, MAXSTRINGLEN); \ |
| 336 |
else strlcat(STAP_RETVALUE, #FLAG, MAXSTRINGLEN); } |
| 337 |
|
| 338 |
|
| 339 |
/* Macro for Composite Flags. */ |
| 340 |
/* Each Composite GFP_FLAG is the combination of multiple bitmasks. */ |
| 341 |
|
| 342 |
|
| 343 |
#define __GFP_COMPOSITE_FLAG(FLAG) if(gfp_flag == FLAG) { \ |
| 344 |
strlcat(STAP_RETVALUE, #FLAG, MAXSTRINGLEN); return; } |
| 345 |
|
| 346 |
|
| 347 |
/* Composite GFP FLAGS of the BitMasks. */ |
| 348 |
|
| 349 |
__GFP_COMPOSITE_FLAG(GFP_ZONEMASK) |
| 350 |
__GFP_COMPOSITE_FLAG(GFP_ATOMIC) |
| 351 |
__GFP_COMPOSITE_FLAG(GFP_NOIO) |
| 352 |
__GFP_COMPOSITE_FLAG(GFP_NOFS) |
| 353 |
__GFP_COMPOSITE_FLAG(GFP_KERNEL) |
| 354 |
__GFP_COMPOSITE_FLAG(GFP_TEMPORARY) |
| 355 |
__GFP_COMPOSITE_FLAG(GFP_USER) |
| 356 |
__GFP_COMPOSITE_FLAG(GFP_HIGHUSER) |
| 357 |
__GFP_COMPOSITE_FLAG(GFP_HIGHUSER_MOVABLE) |
| 358 |
__GFP_COMPOSITE_FLAG(GFP_THISNODE) |
| 359 |
__GFP_COMPOSITE_FLAG(GFP_DMA) |
| 360 |
__GFP_COMPOSITE_FLAG(GFP_DMA32) |
| 361 |
|
| 362 |
/* GFP BitMasks */ |
| 363 |
|
| 364 |
__GFP_BITMASKS(__GFP_DMA) |
| 365 |
__GFP_BITMASKS(__GFP_HIGHMEM) |
| 366 |
__GFP_BITMASKS(__GFP_DMA32) |
| 367 |
__GFP_BITMASKS(__GFP_MOVABLE) |
| 368 |
__GFP_BITMASKS(__GFP_RECLAIMABLE) |
| 369 |
#ifdef __GFP_WAIT |
| 370 |
__GFP_BITMASKS(__GFP_WAIT) |
| 371 |
#endif |
| 372 |
__GFP_BITMASKS(__GFP_HIGH) |
| 373 |
__GFP_BITMASKS(__GFP_IO) |
| 374 |
__GFP_BITMASKS(__GFP_FS) |
| 375 |
#ifdef __GFP_COLD |
| 376 |
__GFP_BITMASKS(__GFP_COLD) |
| 377 |
#endif |
| 378 |
__GFP_BITMASKS(__GFP_NOWARN) |
| 379 |
#ifdef __GFP_RETRY_MAYFAIL |
| 380 |
__GFP_BITMASKS(__GFP_RETRY_MAYFAIL) |
| 381 |
#endif |
| 382 |
#ifdef __GFP_REPEAT |
| 383 |
__GFP_BITMASKS(__GFP_REPEAT) |
| 384 |
#endif |
| 385 |
__GFP_BITMASKS(__GFP_NOFAIL) |
| 386 |
#ifdef __GFP_NORETRY |
| 387 |
__GFP_BITMASKS(__GFP_NORETRY) |
| 388 |
#endif |
| 389 |
#ifdef __GFP_MEMALLOC |
| 390 |
__GFP_BITMASKS(__GFP_MEMALLOC) |
| 391 |
#endif |
| 392 |
__GFP_BITMASKS(__GFP_COMP) |
| 393 |
__GFP_BITMASKS(__GFP_ZERO) |
| 394 |
__GFP_BITMASKS(__GFP_NOMEMALLOC) |
| 395 |
__GFP_BITMASKS(__GFP_HARDWALL) |
| 396 |
__GFP_BITMASKS(__GFP_THISNODE) |
| 397 |
|
| 398 |
#ifdef ___GFP_ATOMIC |
| 399 |
__GFP_BITMASKS(__GFP_ATOMIC) |
| 400 |
#endif |
| 401 |
#ifdef ___GFP_ACCOUNT |
| 402 |
__GFP_BITMASKS(__GFP_ACCOUNT) |
| 403 |
#endif |
| 404 |
__GFP_BITMASKS(__GFP_NOTRACK) |
| 405 |
#ifdef ___GFP_DIRECT_RECLAIM |
| 406 |
__GFP_BITMASKS(__GFP_DIRECT_RECLAIM) |
| 407 |
#endif |
| 408 |
#ifdef ___GFP_WRITE |
| 409 |
__GFP_BITMASKS(__GFP_WRITE) |
| 410 |
#endif |
| 411 |
#ifdef ___GFP_KSWAPD_RECLAIM |
| 412 |
__GFP_BITMASKS(__GFP_KSWAPD_RECLAIM) |
| 413 |
#endif |
| 414 |
#ifdef ___GFP_NOLOCKDEP |
| 415 |
__GFP_BITMASKS(__GFP_NOLOCKDEP) |
| 416 |
#endif |
| 417 |
|
| 418 |
#undef __GFP_BITMASKS |
| 419 |
#undef __GFP_COMPOSITE_FLAG |
| 420 |
%} |
| 421 |
|
| 422 |
/* The Formal Parameters will be displayed if available, otherwise \ |
| 423 |
"0" or "unknown" will be displayed */ |
| 424 |
|
| 425 |
probe __vm.kmalloc.tp = kernel.trace("kmalloc") |
| 426 |
{ |
| 427 |
call_site = $call_site |
| 428 |
caller_function = symname(call_site) |
| 429 |
bytes_req = $bytes_req |
| 430 |
bytes_alloc = $bytes_alloc |
| 431 |
gfp_flags = $gfp_flags |
| 432 |
gfp_flag_name = __gfp_flag_str($gfp_flags) |
| 433 |
ptr = $ptr |
| 434 |
} |
| 435 |
|
| 436 |
/* |
| 437 |
* It is unsafe to invoke __builtin_return_address() presently (to get |
| 438 |
* call_site for kprobe based probes) and that it can be improved |
| 439 |
* later when fix for bugs bz#6961 and bz#6580 is available. |
| 440 |
*/ |
| 441 |
|
| 442 |
probe __vm.kmalloc.kp = kernel.function("kmem_cache_alloc_notrace").return !, |
| 443 |
kernel.function("kmem_cache_alloc").return |
| 444 |
{ |
| 445 |
call_site = 0 |
| 446 |
caller_function = "unknown" |
| 447 |
// Note that 'bytes_req' could be wrong. By the time |
| 448 |
// kmem_cache_alloc* gets called the requested size could have |
| 449 |
// rounded up to the nearest cache alloc size. |
| 450 |
if (@defined(@entry($s))) { |
| 451 |
bytes_req = @entry($s->size) |
| 452 |
bytes_alloc = bytes_req |
| 453 |
} |
| 454 |
else if (@defined(@entry($cachep->buffer_size))) { |
| 455 |
bytes_req = @entry($cachep->buffer_size) |
| 456 |
bytes_alloc = bytes_req |
| 457 |
} |
| 458 |
else { |
| 459 |
bytes_req = @entry($cachep->objsize) |
| 460 |
bytes_alloc = bytes_req |
| 461 |
} |
| 462 |
if (@defined(@entry($gfpflags))) { |
| 463 |
gfp_flags = @entry($gfpflags) |
| 464 |
gfp_flag_name = __gfp_flag_str(gfp_flags) |
| 465 |
} |
| 466 |
else { |
| 467 |
gfp_flags = @entry($flags) |
| 468 |
gfp_flag_name = __gfp_flag_str(gfp_flags) |
| 469 |
} |
| 470 |
ptr = $return |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* probe vm.kmalloc - Fires when kmalloc is requested |
| 475 |
* |
| 476 |
* @name: name of the probe point |
| 477 |
* @call_site: address of the kmemory function |
| 478 |
* @caller_function: name of the caller function |
| 479 |
* @bytes_req: requested Bytes |
| 480 |
* @bytes_alloc: allocated Bytes |
| 481 |
* @gfp_flags: type of kmemory to allocate |
| 482 |
* @gfp_flag_name: type of kmemory to allocate (in String format) |
| 483 |
* @ptr: pointer to the kmemory allocated |
| 484 |
*/ |
| 485 |
probe vm.kmalloc = __vm.kmalloc.tp !, __vm.kmalloc.kp |
| 486 |
{ |
| 487 |
name = "kmalloc" |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
probe __vm.kmem_cache_alloc.tp = kernel.trace("kmem_cache_alloc") |
| 492 |
{ |
| 493 |
call_site = $call_site |
| 494 |
caller_function = symname(call_site) |
| 495 |
bytes_req = @defined($s) ? @cast($s, "kmem_cache", "kernel")->object_size |
| 496 |
: $bytes_req |
| 497 |
bytes_alloc = @defined($s) ? @cast($s, "kmem_cache", "kernel")->size |
| 498 |
: $bytes_alloc |
| 499 |
gfp_flags = $gfp_flags |
| 500 |
gfp_flag_name = __gfp_flag_str($gfp_flags) |
| 501 |
ptr = $ptr |
| 502 |
} |
| 503 |
|
| 504 |
probe __vm.kmem_cache_alloc.kp = kernel.function("kmem_cache_alloc").return |
| 505 |
{ |
| 506 |
call_site = 0 |
| 507 |
caller_function = "unknown" |
| 508 |
// Note that 'bytes_req' could be wrong. By the time |
| 509 |
// kmem_cache_alloc* gets called the requested size could have |
| 510 |
// rounded up to the nearest cache alloc size. |
| 511 |
if (@defined(@entry($s))) { |
| 512 |
bytes_req = @entry($s->size) |
| 513 |
bytes_alloc = bytes_req |
| 514 |
} |
| 515 |
else if (@defined(@entry($cachep->buffer_size))) { |
| 516 |
bytes_req = @entry($cachep->buffer_size) |
| 517 |
bytes_alloc = bytes_req |
| 518 |
} |
| 519 |
else { |
| 520 |
bytes_req = @entry($cachep->objsize) |
| 521 |
bytes_alloc = bytes_req |
| 522 |
} |
| 523 |
if (@defined(@entry($gfpflags))) { |
| 524 |
gfp_flags = @entry($gfpflags) |
| 525 |
gfp_flag_name = __gfp_flag_str(gfp_flags) |
| 526 |
} |
| 527 |
else { |
| 528 |
gfp_flags = @entry($flags) |
| 529 |
gfp_flag_name = __gfp_flag_str(gfp_flags) |
| 530 |
} |
| 531 |
ptr = $return |
| 532 |
} |
| 533 |
|
| 534 |
/** |
| 535 |
* probe vm.kmem_cache_alloc - Fires when kmem_cache_alloc is requested |
| 536 |
* |
| 537 |
* @name: name of the probe point |
| 538 |
* @call_site: address of the function calling this kmemory function. |
| 539 |
* @caller_function: name of the caller function. |
| 540 |
* @bytes_req: requested Bytes |
| 541 |
* @bytes_alloc: allocated Bytes |
| 542 |
* @gfp_flags: type of kmemory to allocate |
| 543 |
* @gfp_flag_name: type of kmemory to allocate(in string format) |
| 544 |
* @ptr: pointer to the kmemory allocated |
| 545 |
*/ |
| 546 |
|
| 547 |
probe vm.kmem_cache_alloc = __vm.kmem_cache_alloc.tp !, |
| 548 |
__vm.kmem_cache_alloc.kp |
| 549 |
{ |
| 550 |
name = "kmem_cache_alloc" |
| 551 |
} |
| 552 |
|
| 553 |
probe __vm.kmalloc_node.tp = kernel.trace("kmalloc_node") ? |
| 554 |
{ |
| 555 |
call_site = $call_site |
| 556 |
caller_function = symname(call_site) |
| 557 |
bytes_req = $bytes_req |
| 558 |
bytes_alloc = $bytes_alloc |
| 559 |
gfp_flags = $gfp_flags |
| 560 |
gfp_flag_name = __gfp_flag_str($gfp_flags) |
| 561 |
ptr = $ptr |
| 562 |
} |
| 563 |
|
| 564 |
probe __vm.kmalloc_node.kp = kernel.function("kmalloc_node").return ? |
| 565 |
{ |
| 566 |
call_site = 0 |
| 567 |
caller_function = "unknown" |
| 568 |
bytes_req = @entry($size) |
| 569 |
bytes_alloc = bytes_req // pretend they are always the same |
| 570 |
|
| 571 |
# Unfortunately, on i686 f11 (2.6.29.4-167.fc11.i686.PAE), we |
| 572 |
# can't see the '$flags' argument (even though we can see the |
| 573 |
# '$size' argument above). Note that we can see the '$flags' |
| 574 |
# argument on x86_64 f11 (2.6.29.4-167.fc11.x86_64). So, the |
| 575 |
# best we can do here is just use 0 when $flags isn't defined. |
| 576 |
gfp_flags = @choose_defined(@entry($flags), 0) |
| 577 |
gfp_flag_name = __gfp_flag_str(@choose_defined(@entry($flags), 0)) |
| 578 |
|
| 579 |
ptr = $return |
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* probe vm.kmalloc_node - Fires when kmalloc_node is requested |
| 584 |
* |
| 585 |
* @name: name of the probe point |
| 586 |
* @call_site: address of the function caling this kmemory function |
| 587 |
* @caller_function: name of the caller function |
| 588 |
* @bytes_req: requested Bytes |
| 589 |
* @bytes_alloc: allocated Bytes |
| 590 |
* @gfp_flags: type of kmemory to allocate |
| 591 |
* @gfp_flag_name: type of kmemory to allocate(in string format) |
| 592 |
* @ptr: pointer to the kmemory allocated |
| 593 |
*/ |
| 594 |
probe vm.kmalloc_node = __vm.kmalloc_node.tp !, __vm.kmalloc_node.kp ? |
| 595 |
{ |
| 596 |
name = "kmalloc_node" |
| 597 |
} |
| 598 |
|
| 599 |
probe __vm.kmem_cache_alloc_node.tp = kernel.trace("kmem_cache_alloc_node") ? |
| 600 |
{ |
| 601 |
call_site = $call_site |
| 602 |
caller_function = symname(call_site) |
| 603 |
bytes_req = $bytes_req |
| 604 |
bytes_alloc = $bytes_alloc |
| 605 |
gfp_flags = $gfp_flags |
| 606 |
gfp_flag_name = __gfp_flag_str($gfp_flags) |
| 607 |
ptr = $ptr |
| 608 |
} |
| 609 |
|
| 610 |
probe __vm.kmem_cache_alloc_node.kp = |
| 611 |
kernel.function("kmem_cache_alloc_node").return ? |
| 612 |
{ |
| 613 |
call_site = 0 |
| 614 |
caller_function = "unknown" |
| 615 |
// Note that 'bytes_req' could be wrong. By the time |
| 616 |
// kmem_cache_alloc* gets called the requested size could have |
| 617 |
// rounded up to the nearest cache alloc size. |
| 618 |
if (@defined(@entry($s))) { |
| 619 |
bytes_req = @entry($s->size) |
| 620 |
bytes_alloc = bytes_req |
| 621 |
} |
| 622 |
else if (@defined(@entry($cachep->buffer_size))) { |
| 623 |
bytes_req = @entry($cachep->buffer_size) |
| 624 |
bytes_alloc = bytes_req |
| 625 |
} |
| 626 |
else { |
| 627 |
bytes_req = @entry($cachep->objsize) |
| 628 |
bytes_alloc = bytes_req |
| 629 |
} |
| 630 |
|
| 631 |
// kmem_cache_alloc_node() doesn't get a flags argument. But, |
| 632 |
// internally it uses GFP_KERNEL(). |
| 633 |
gfp_flags = GFP_KERNEL() |
| 634 |
gfp_flag_name = __gfp_flag_str(gfp_flags) |
| 635 |
ptr = $return |
| 636 |
} |
| 637 |
|
| 638 |
/** |
| 639 |
* probe vm.kmem_cache_alloc_node - Fires when kmem_cache_alloc_node is requested |
| 640 |
* |
| 641 |
* @name: name of the probe point |
| 642 |
* @call_site: address of the function calling this kmemory function |
| 643 |
* @caller_function: name of the caller function |
| 644 |
* @bytes_req: requested Bytes |
| 645 |
* @bytes_alloc: allocated Bytes |
| 646 |
* @gfp_flags: type of kmemory to allocate |
| 647 |
* @gfp_flag_name: type of kmemory to allocate(in string format) |
| 648 |
* @ptr: pointer to the kmemory allocated |
| 649 |
*/ |
| 650 |
probe vm.kmem_cache_alloc_node = __vm.kmem_cache_alloc_node.tp !, |
| 651 |
__vm.kmem_cache_alloc_node.kp ? |
| 652 |
{ |
| 653 |
name = "kmem_cache_alloc_node" |
| 654 |
} |
| 655 |
|
| 656 |
probe __vm.kfree.tp = kernel.trace("kfree") |
| 657 |
{ |
| 658 |
call_site = $call_site |
| 659 |
caller_function = symname(call_site) |
| 660 |
ptr = $ptr |
| 661 |
} |
| 662 |
|
| 663 |
probe __vm.kfree.kp = kernel.function("kfree").return |
| 664 |
{ |
| 665 |
call_site = 0 |
| 666 |
caller_function = "unknown" |
| 667 |
ptr = @entry(@choose_defined($x, $objp)) |
| 668 |
} |
| 669 |
|
| 670 |
/** |
| 671 |
* probe vm.kfree - Fires when kfree is requested |
| 672 |
* |
| 673 |
* @name: name of the probe point |
| 674 |
* @call_site: address of the function calling this kmemory function |
| 675 |
* @caller_function: name of the caller function. |
| 676 |
* @ptr: pointer to the kmemory allocated which is returned by kmalloc |
| 677 |
*/ |
| 678 |
probe vm.kfree = __vm.kfree.tp !, __vm.kfree.kp |
| 679 |
{ |
| 680 |
name = "kfree" |
| 681 |
} |
| 682 |
|
| 683 |
probe __vm.kmem_cache_free.tp = kernel.trace("kmem_cache_free") |
| 684 |
{ |
| 685 |
call_site = $call_site |
| 686 |
caller_function = symname(call_site) |
| 687 |
ptr = $ptr |
| 688 |
} |
| 689 |
probe __vm.kmem_cache_free.kp = kernel.function("kmem_cache_free").return |
| 690 |
{ |
| 691 |
call_site = 0 |
| 692 |
caller_function = "unknown" |
| 693 |
ptr = @entry(@choose_defined($x, $objp)) |
| 694 |
} |
| 695 |
|
| 696 |
/** |
| 697 |
* probe vm.kmem_cache_free - Fires when kmem_cache_free is requested |
| 698 |
* |
| 699 |
* @name: Name of the probe point |
| 700 |
* @call_site: Address of the function calling this kmemory function |
| 701 |
* @caller_function: Name of the caller function. |
| 702 |
* @ptr: Pointer to the kmemory allocated which is returned by kmem_cache |
| 703 |
*/ |
| 704 |
probe vm.kmem_cache_free = __vm.kmem_cache_free.tp !, __vm.kmem_cache_free.kp |
| 705 |
{ |
| 706 |
name = "kmem_cache_free" |
| 707 |
} |