tools/perf/builtin-kmem.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-kmem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-kmem.c- Extension
.c- Size
- 48368 bytes
- Lines
- 2067
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
builtin.hutil/dso.hutil/evlist.hutil/evsel.hutil/config.hutil/map.hutil/symbol.hutil/thread.hutil/header.hutil/session.hutil/tool.hutil/callchain.hutil/time-utils.hlinux/err.hsubcmd/pager.hsubcmd/parse-options.hutil/trace-event.hutil/data.hutil/cpumap.hutil/debug.hutil/string2.hutil/util.hlinux/kernel.hlinux/numa.hlinux/rbtree.hlinux/string.hlinux/zalloc.herrno.hinttypes.hlocale.hregex.hlinux/ctype.h
Detected Declarations
struct alloc_statstruct alloc_statstruct page_statstruct alloc_funcstruct sort_dimensionstruct gfp_flagfunction insert_alloc_statfunction insert_caller_statfunction evsel__process_alloc_eventfunction evsel__process_free_eventfunction funcmpfunction callcmpfunction build_alloc_func_listfunction map__for_each_symbolfunction find_callsitefunction __page_stat__findnew_pagefunction __page_stat__findnew_allocfunction list_for_each_entryfunction __page_stat__findnew_callerfunction list_for_each_entryfunction valid_pagefunction gfpcmpfunction parse_gfp_flagsfunction evsel__process_page_alloc_eventfunction evsel__process_page_free_eventfunction perf_kmem__skip_samplefunction process_sample_eventfunction fragmentationfunction __print_slab_resultfunction __print_page_alloc_resultfunction __print_page_caller_resultfunction print_gfp_flagsfunction print_slab_summaryfunction print_page_summaryfunction print_slab_resultfunction print_page_resultfunction print_resultfunction sort_slab_insertfunction list_for_each_entryfunction __sort_slab_resultfunction sort_page_insertfunction list_for_each_entryfunction __sort_page_resultfunction sort_resultfunction __cmd_kmemfunction evlist__for_each_entryfunction ptr_cmpfunction slab_callsite_cmp
Annotated Snippet
struct alloc_stat {
u64 call_site;
u64 ptr;
u64 bytes_req;
u64 bytes_alloc;
u64 last_alloc;
u32 hit;
u32 pingpong;
short alloc_cpu;
struct rb_node node;
};
static struct rb_root root_alloc_stat;
static struct rb_root root_alloc_sorted;
static struct rb_root root_caller_stat;
static struct rb_root root_caller_sorted;
static unsigned long total_requested, total_allocated, total_freed;
static unsigned long nr_allocs, nr_cross_allocs;
/* filters for controlling start and stop of time of analysis */
static struct perf_time_interval ptime;
static const char *time_str;
static int insert_alloc_stat(unsigned long call_site, unsigned long ptr,
int bytes_req, int bytes_alloc, int cpu)
{
struct rb_node **node = &root_alloc_stat.rb_node;
struct rb_node *parent = NULL;
struct alloc_stat *data = NULL;
while (*node) {
parent = *node;
data = rb_entry(*node, struct alloc_stat, node);
if (ptr > data->ptr)
node = &(*node)->rb_right;
else if (ptr < data->ptr)
node = &(*node)->rb_left;
else
break;
}
if (data && data->ptr == ptr) {
data->hit++;
data->bytes_req += bytes_req;
data->bytes_alloc += bytes_alloc;
} else {
data = malloc(sizeof(*data));
if (!data) {
pr_err("%s: malloc failed\n", __func__);
return -1;
}
data->ptr = ptr;
data->pingpong = 0;
data->hit = 1;
data->bytes_req = bytes_req;
data->bytes_alloc = bytes_alloc;
rb_link_node(&data->node, parent, node);
rb_insert_color(&data->node, &root_alloc_stat);
}
data->call_site = call_site;
data->alloc_cpu = cpu;
data->last_alloc = bytes_alloc;
return 0;
}
static int insert_caller_stat(unsigned long call_site,
int bytes_req, int bytes_alloc)
{
struct rb_node **node = &root_caller_stat.rb_node;
struct rb_node *parent = NULL;
struct alloc_stat *data = NULL;
while (*node) {
parent = *node;
data = rb_entry(*node, struct alloc_stat, node);
if (call_site > data->call_site)
node = &(*node)->rb_right;
else if (call_site < data->call_site)
node = &(*node)->rb_left;
else
break;
}
Annotation
- Immediate include surface: `builtin.h`, `util/dso.h`, `util/evlist.h`, `util/evsel.h`, `util/config.h`, `util/map.h`, `util/symbol.h`, `util/thread.h`.
- Detected declarations: `struct alloc_stat`, `struct alloc_stat`, `struct page_stat`, `struct alloc_func`, `struct sort_dimension`, `struct gfp_flag`, `function insert_alloc_stat`, `function insert_caller_stat`, `function evsel__process_alloc_event`, `function evsel__process_free_event`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.