Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction:

i) Kmemleak is a Linux kernel feature designed to detect and report memory leaks in the kernel code. Memory leaks occur when a program allocates memory dynamically but fails to release it when it is no longer needed. This can result in a gradual loss of memory over time, eventually leading to system instability or even crashes.

...

iii)Kmemleak is a useful tool for kernel developers and system administrators who want to ensure that their systems are stable and free of memory leaks. It can be enabled in the kernel configuration, and once enabled, it will run automatically in the background, periodically scanning the kernel memory for leaks.

Required kernel configs need to enable :

CONFIG_HAVE_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK=y
CONFIG_DEBUG_KMEMLEAK_TEST=m

Integrating Kmemleak tool  for RPI3

i) Create kmemleak.cfg file under meta-cmf-raspberrypi/recipes-kernel/linux/files with below kernel configs.

...


v) Once enabled kmemleak we will get kernel memory leaks in /sys/kernel/debug/kmemleak file if leaks are reported.

Testing kmemleak tool with kmemleak-test module in rpi3:

Note: kmemleak-test.ko by default in rpi3 this module not compiled , there is no kmemleak-test.ko module , so enable to build as a module and generated module file.
kmemleak-test.ko

Step 1 : Copy kmemleak-test.ko module to this path /lib/modules/5.10.52-v7/  in box .
Step 2 : load the module to kernel space with insmod command.
Ex:

...


View file
namekmemleak_report_for_kmeleak_test_module.txt
height250
View file
namekmemleak-test.ko
height250


Limitations and Drawbacks

While kmemleak can be a useful tool for detecting and reporting memory leaks in the Linux kernel, there are several limitations and drawbacks to consider:
The main drawback is the reduced performance of memory allocation and freeing. To avoid other penalties, the memory scanning is only performed when the /sys/kernel/debug/kmemleak file is read. Anyway, this tool is intended for debugging purposes where the performance might not be the most important requirement.

...