How Kernel‑Space Memory Profiling Works with Code Tagging (memprofiling)
The article explains a kernel‑space memory profiler that uses a compile‑time code‑tagging library and special linker sections to record allocation callers and byte counts with minimal CPU overhead, allowing the tool to be deployed in production.
This piece introduces a kernel‑space memory profiler (memprofiling) created by Kent Overstree and Suren Baghdasaryan, which visualizes which modules, files, functions and line numbers are responsible for kernel memory allocations.
The profiler relies on a code tagging library that records allocation callers in linear arrays, making iteration straightforward.
On top of the basic code tag, an alloc_tag structure adds a counter for the number of bytes allocated and the number of allocation calls at each code location. When the same location is hit again, the counter is incremented.
The profiler replaces each allocation function with a hook that records the tag at allocation time.
The key macro is DEFINE_ALLOC_TAG, which defines a static struct alloc_tag _alloc_tag placed in a dedicated linker section via __section(ALLOC_TAG_SECTION_NAME). Because the tags reside in a static section, their addresses are known at compile time.
To locate a specific tag, the profiler subtracts the start address of the ALLOC_TAG_SECTION_NAME section from the tag’s address, yielding its offset within the linear tag array without needing runtime debug information.
Overall, the memory‑allocation profiling implementation leverages compile‑time preprocessing and special linker‑section tricks to keep CPU overhead low, making the profiler suitable for both debugging and production deployment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
