include/linux/alloc_tag.h
Source file repositories/reference/linux-study-clean/include/linux/alloc_tag.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/alloc_tag.h- Extension
.h- Size
- 7150 bytes
- Lines
- 271
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bug.hlinux/codetag.hlinux/container_of.hlinux/preempt.hasm/percpu.hlinux/cpumask.hlinux/smp.hlinux/static_key.hlinux/irqflags.h
Detected Declarations
struct alloc_tag_countersstruct alloc_tagstruct alloc_tag_kernel_sectionstruct alloc_tag_module_sectionstruct codetag_bytesfunction is_codetag_emptyfunction set_codetag_emptyfunction is_codetag_emptyfunction set_codetag_emptyfunction mem_alloc_profiling_enabledfunction alloc_tag_readfunction for_each_possible_cpufunction alloc_tag_add_checkfunction alloc_tag_sub_checkfunction alloc_tag_add_checkfunction alloc_tag_ref_setfunction alloc_tag_addfunction alloc_tag_subfunction alloc_tag_set_inaccuratefunction alloc_tag_is_inaccuratefunction mem_alloc_profiling_enabledfunction alloc_tag_add
Annotated Snippet
struct alloc_tag_counters {
u64 bytes;
u64 calls;
};
/*
* An instance of this structure is created in a special ELF section at every
* allocation callsite. At runtime, the special section is treated as
* an array of these. Embedded codetag utilizes codetag framework.
*/
struct alloc_tag {
struct codetag ct;
struct alloc_tag_counters __percpu *counters;
} __aligned(8);
struct alloc_tag_kernel_section {
struct alloc_tag *first_tag;
unsigned long count;
};
struct alloc_tag_module_section {
union {
unsigned long start_addr;
struct alloc_tag *first_tag;
};
unsigned long end_addr;
/* used size */
unsigned long size;
};
#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG
#define CODETAG_EMPTY ((void *)1)
static inline bool is_codetag_empty(union codetag_ref *ref)
{
return ref->ct == CODETAG_EMPTY;
}
static inline void set_codetag_empty(union codetag_ref *ref)
{
if (ref)
ref->ct = CODETAG_EMPTY;
}
#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
static inline bool is_codetag_empty(union codetag_ref *ref) { return false; }
static inline void set_codetag_empty(union codetag_ref *ref)
{
if (ref)
ref->ct = NULL;
}
#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
#ifdef CONFIG_MEM_ALLOC_PROFILING
#define ALLOC_TAG_SECTION_NAME "alloc_tags"
struct codetag_bytes {
struct codetag *ct;
s64 bytes;
};
size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sleep);
static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct)
{
return container_of(ct, struct alloc_tag, ct);
}
#if defined(CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU) && defined(MODULE)
/*
* When percpu variables are required to be defined as weak, static percpu
* variables can't be used inside a function (see comments for DECLARE_PER_CPU_SECTION).
* Instead we will account all module allocations to a single counter.
*/
DECLARE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag);
#define DEFINE_ALLOC_TAG(_alloc_tag) \
static struct alloc_tag _alloc_tag __used __aligned(8) \
__section(ALLOC_TAG_SECTION_NAME) = { \
.ct = CODE_TAG_INIT, \
.counters = &_shared_alloc_tag };
#else /* CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU && MODULE */
#ifdef MODULE
Annotation
- Immediate include surface: `linux/bug.h`, `linux/codetag.h`, `linux/container_of.h`, `linux/preempt.h`, `asm/percpu.h`, `linux/cpumask.h`, `linux/smp.h`, `linux/static_key.h`.
- Detected declarations: `struct alloc_tag_counters`, `struct alloc_tag`, `struct alloc_tag_kernel_section`, `struct alloc_tag_module_section`, `struct codetag_bytes`, `function is_codetag_empty`, `function set_codetag_empty`, `function is_codetag_empty`, `function set_codetag_empty`, `function mem_alloc_profiling_enabled`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.