STRUCT PERF_CTX_DATA(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct perf_ctx_data(9) β€” the Kernel API Manual glow-up

okay bestie, so this page is struct perf_ctx_data(9), and it's genuinely one of those little structs that's doing a LOT behind the scenes πŸ‘‘ β€” it's the PMU specific data for a task. Let's get into it ✨


🌸 NAME 🌸

struct perf_ctx_data β€” PMU specific data for a task. that's the whole vibe, no cap.


πŸŽ€ SYNOPSIS πŸŽ€

struct perf_ctx_data {
    struct rcu_head                 rcu_head;
    refcount_t refcount;
    int global;
    struct kmem_cache               *ctx_cache;
    void *data;
 };

yes the closing brace is indented by one space in the original, we are NOT fixing it, we respect the lore πŸ’€


πŸ¦‹ Members πŸ¦‹ (the cast, the main characters)

  • rcu_head β€” bestie this exists purely to avoid the race on free PMU specific data 😭 it's the bodyguard for the free path.
  • refcount β€” to track users. it's literally a headcount at the door 🫢
  • global β€” to track system-wide users. so when the whole system's using it, this lil field knows πŸ‘€
  • ctx_cache β€” the Kmem cache of PMU specific data. it's the cache holding the goods.
  • data β€” the PMU specific data itself. the actual payload, the star of the show ⭐

🌈 Description 🌈

So rn β€” currently β€” this struct is only used in Intel LBR call stack mode, where its whole job is to save/restore the call stack of a task on context switches. that's it, that's the assignment πŸ’…

The rcu_head is there to prevent the race on free the data β€” lowkey crucial. The data only gets allocated when Intel LBR call stack mode is enabled, and it gets freed when the mode is disabled. The content of the data will only be accessed in context switch, which should be protected by rcu_read_lock πŸ”’ so like, respect the lock, fr fr.

Because of the alignment requirement of Intel Arch LBR (she's picky, we love her), the Kmem cache is used to allocate the PMU specific data. The ctx_cache is what tracks the Kmem cache ✨

⚠️ Careful, bestie β€” struct perf_ctx_data is added as a pointer in struct task_struct. When system-wide Intel LBR call stack mode is enabled, a buffer with constant size will be allocated for each task. Also, system memory consumption can further grow when the size of struct perf_ctx_data enlarges. so like… every byte you add here? it multiplies across every task 😭 think before you grow the struct, okay? πŸ“

⭐ SEE ALSO ⭐

  • Kernel file ./include/linux/perf_event.h
  • struct hw_perf_event(9)
  • struct pmu(9)
  • struct perf_addr_filter(9)
  • struct perf_addr_filters_head(9)
  • struct perf_event(9)
  • struct perf_event_context(9)

go read the whole friend group, they're all linked 🫢


and that's the page!! πŸŽ€ this one lives in ./include/linux, and it's dated October 2026 β€” so like, future-core of the kernel docs πŸ’œ mwah, slay, periodt βœ¨πŸ‘‘

πŸ“¦ where this page comes from