0

Is there a way to measure memory fragmentation in a linux kernel driver? I tried /proc/buddyinfo and /proc/slabinfo, but they provide an overall picture. I am looking for something for a particular driver.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
AR26
  • 29
  • 6
  • memory fragmentation in a kernel driver ? Or caused by a kernel driver ? Kernel memory is managed by the kernel, not by drivers. Can you be a bit clearer about what you mean ? – secret squirrel Jul 28 '20 at 09:06
  • Yes I mean caused by a kernel driver. I am using kmalloc in a driver and I want to measure how much that kmalloc contributes to the overall memory fragmentation in the kernel. – AR26 Jul 28 '20 at 13:38
  • if you just want to monitor it over time to see the effect of your driver, see this: https://stackoverflow.com/a/4863812/5639126. If you want to quantify your driver's kmalloc calls, enable kmem tracing: see https://01.org/linuxgraphics/gfx-docs/drm/trace/events-kmem.html – secret squirrel Jul 28 '20 at 14:16
  • Since (except for NUMA architectures) access to any page is equal to access to any other page, the kernel is free to map any virtual address to any physical address. Due to caching, almost all physical memory should be mapped all the time and re-used on an LRU basis. This should lead to high fragmentation. What's the downside? – stark Jul 28 '20 at 17:37
  • @secretsquirrel I am trying to use tracepoint events. I added kmalloc to the trace and when I turn the trace ON, it does not have kmalloc calls in it. I am following the instructions here https://kernel.googlesource.com/pub/scm/linux/kernel/git/cjb/mmc/+/b4c43993f448d0e25fe40690d9e9c81a8ebda623/Documentation/trace/events.txt and https://elinux.org/Kernel_dynamic_memory_analysis#About_kmem_trace_events. Any pointers? – AR26 Jul 30 '20 at 14:20

0 Answers0