3

I have enable the "Kernel memory leak detector" option inside kernel hacking and rebuilt/reboot the system, for now the kmemleak file exists inside the /sys/kernel/debug folder but seems like I cannot trigger the scan by "echo scan > /sys/kernel/debug/kmemleak", I have mounted debugfs onto /sys/kernel/debug, but when I try to trigger the scan it gives me "-bash: echo: write error: Device or resource busy". My guessing is that this is because I do not have write permission inside /sys folder even I'm a root user. Any suggestion how to solve this issue? Thanks a lot.

I have tried

Boooooo
  • 157
  • 3
  • 12
  • The kmemleak sysfs write handler returns `EBUSY` if kmemleak is disabled. Did you turn off kmemleak by echo-ing `off`? If not, is the Linux kernel built with `CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y` ? Have you tried booting `kmemleak=on` passed on the Linux kernel bootargs/cmdline? – TheCodeArtist Apr 19 '19 at 16:52
  • I did not echo off, the CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set (I have checked my .config file), also I have tried reboot "kmemleak=on" and I did "echo scan > /sys/kernel/debug/kmemleak" as soon as I rebooted, but it still gives me same error. – Boooooo Apr 19 '19 at 17:06

1 Answers1

4

You need to check few things when using kmemleak.

Check whether any bootargs or commandline parameter kmemleak=off is being passed.

In your boot log, check if you have got any kmemleak related logs, especially something like below logs

kmemleak: Kernel memory leak detector disabled
kmemleak: Early log buffer exceeded (919), please increase DEBUG_KMEMLEAK_EARLY_LOG_SIZE

Most probably, I think you need to configure CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE. If during boot, the log size for kmemleak increases beyond the limit set in linux kernel config, kmemleak is disabled.

So, configure CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE and increase the size. This option is also under kernel hacking. I am using kernel source 4.19.9 and attaching the screenshot for reference. Maximum kmemleak early log entries is the field, you may need to set it to some higher value(e.g 4096).

enter image description here

bornfree
  • 2,308
  • 1
  • 23
  • 33
  • Btw, CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE was renamed to CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE in 5.5. Also, i found that explicitly passing kmemleak=on solved the issue at hand... – kaiwan Nov 27 '21 at 03:35