Skip to content

Commit

Permalink
symbols: skip the module if the given address is not within its addre…
Browse files Browse the repository at this point in the history
…ss range

Previously, to find a module symbol and its offset by an arbitrary address,
all symbols within the module will be iterated by address ascending order
until the last symbol with a smaller address been noticed.

However if the address is not within the module address range, e.g.
the address is higher than the module's last symbol's address, then
the module can be surely skipped, because its symbol iteration is
unnecessary. This can speed up the kernel module symbols finding and improve
the overall performance.

Without the patch:
  $ time echo "bt 8993" | ~/crash-dev/crash vmcore vmlinux
  crash> bt 8993
  PID: 8993     TASK: ffff927569cc2100  CPU: 2    COMMAND: "WriterPool0"
   #0 [ffff927569cd76f0] __schedule at ffffffffb3db78d8
   crash-utility#1 [ffff927569cd7758] schedule_preempt_disabled at ffffffffb3db8bf9
   crash-utility#2 [ffff927569cd7768] __mutex_lock_slowpath at ffffffffb3db6ca7
   crash-utility#3 [ffff927569cd77c0] mutex_lock at ffffffffb3db602f
   crash-utility#4 [ffff927569cd77d8] ucache_retrieve at ffffffffc0cf4409 [secfs2]
   ...snip the stacktrace of the same module...
   crash-utility#11 [ffff927569cd7ba0] cskal_path_vfs_getattr_nosec at ffffffffc05cae76 [falcon_kal]
   ...snip...
   crash-utility#13 [ffff927569cd7c40] _ZdlPv at ffffffffc086e751 [falcon_lsm_serviceable]
   ...snip...
   crash-utility#20 [ffff927569cd7ef8] unload_network_ops_symbols at ffffffffc06f11c0 [falcon_lsm_pinned_14713]
   crash-utility#21 [ffff927569cd7f50] system_call_fastpath at ffffffffb3dc539a
      RIP: 00007f2b28ed4023  RSP: 00007f2a45fe7f80  RFLAGS: 00000206
      RAX: 0000000000000012  RBX: 00007f2a68302e00  RCX: 00007f2a682546d8
      RDX: 0000000000000826  RSI: 00007eb57ea6a000  RDI: 00000000000000e3
      RBP: 00007eb57ea6a000   R8: 0000000000000826   R9: 00000002670bdfd2
      R10: 00000002670bdfd2  R11: 0000000000000293  R12: 00000002670bdfd2
      R13: 00007f29d501a480  R14: 0000000000000826  R15: 00000002670bdfd2
      ORIG_RAX: 0000000000000012  CS: 0033  SS: 002b
  crash>
  real	7m14.826s
  user	7m12.502s
  sys	0m1.091s

With the patch:
  $ time echo "bt 8993" | ~/crash-dev/crash vmcore vmlinux
  crash> bt 8993
  PID: 8993     TASK: ffff927569cc2100  CPU: 2    COMMAND: "WriterPool0"
   #0 [ffff927569cd76f0] __schedule at ffffffffb3db78d8
   crash-utility#1 [ffff927569cd7758] schedule_preempt_disabled at ffffffffb3db8bf9
   ...snip the same output...
  crash>
  real	0m8.827s
  user	0m7.896s
  sys	0m0.938s

Signed-off-by: Tao Liu <[email protected]>
  • Loading branch information
liutgnu committed Dec 1, 2024
1 parent 96031c4 commit 796f8f8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -5561,7 +5561,7 @@ value_search_module_6_4(ulong value, ulong *offset)
sp = lm->symtable[t];
sp_end = lm->symend[t];

if (value < sp->value)
if (value < sp->value || value > sp_end->value)
continue;

splast = NULL;
Expand Down Expand Up @@ -5646,6 +5646,9 @@ value_search_module(ulong value, ulong *offset)
if (sp->value > value) /* invalid -- between modules */
break;

if (sp_end->value < value) /* not within the module */
continue;

/*
* splast will contain the last module symbol encountered.
* Note: "__insmod_"-type symbols will be set in splast only
Expand Down

0 comments on commit 796f8f8

Please sign in to comment.