Kernel dynamic memory analysis

This page has notes and results from the project Kernel dynamic memory allocation tracking and reduction

[This page is fairly random at the moment...]

Instrumentation

 * slab_accounting patches
 * uses __builtin_return_address(0) to record the address of the caller
 * this is same mechanism used by kmem events
 * if gcc decides to inline automatically, you get the wrong call site
 * can disable automatic inlinining with a compiler flag
 * starts from very first allocation


 * kmem events
 * does not start until ftrace system is initialized, after some allocations are already performed
 * supported in mainline - no need to add our own instrumentation

Focus of work (on instrumentation) right now is to see if kmem events can be used to find early allocations. Also, to see if early allocations account for significant memory usage. If not, it may not be that important to capture them. [Is another possibility some way to use a printk approach for very early allocations, and somehow coalesce the data into the final report?]

Reporting

 * extracting data to host
 * tool for extraction (perf?, cat /debugfs/tracing/ ?)
 * post-processing the data
 * grouping allocations (assigning to different subsystems, processes, or functional areas)
 * idea to post-process kmem events and correlate with */built-in.o
 * reporting on wasted bytes
 * reporting on memory fragmentation

Visualization

 * possible use of treemap to visualize the data

Mainline status
[place links to patches, or git commit ids, here]
 * is anything added to mainline via this project?
 * subject: trace: Move trace event enable from fs_initcall to early_initcall
 * https://lkml.org/lkml/2012/8/17/218

Results so far (in random order)

 * There's a lot of fragmentation using the SLAB allocator. [how much?]
 * SLxB accounting is a dead-end (it won't be accepted into mainline)

more???