mm/slub.c
Source file repositories/reference/linux-study-clean/mm/slub.c
File Facts
- System
- Linux kernel
- Corpus path
mm/slub.c- Extension
.c- Size
- 255004 bytes
- Lines
- 10032
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
linux/mm.hlinux/swap.hlinux/module.hlinux/bit_spinlock.hlinux/interrupt.hlinux/swab.hlinux/bitops.hlinux/slab.hslab.hlinux/vmalloc.hlinux/proc_fs.hlinux/seq_file.hlinux/kasan.hlinux/node.hlinux/kmsan.hlinux/cpu.hlinux/cpuset.hlinux/mempolicy.hlinux/ctype.hlinux/stackdepot.hlinux/debugobjects.hlinux/kallsyms.hlinux/kfence.hlinux/memory.hlinux/math64.hlinux/fault-inject.hlinux/kmemleak.hlinux/stacktrace.hlinux/prefetch.hlinux/memcontrol.hlinux/random.hlinux/prandom.h
Detected Declarations
struct slab_alloc_contextstruct partial_bulk_contextstruct slab_obj_iterstruct trackstruct kmem_cache_statsstruct node_barnstruct slab_sheafstruct slub_percpu_sheavesstruct kmem_cache_nodestruct slub_flush_workstruct rcu_delayed_freestruct defer_freestruct detached_freeliststruct locationstruct loc_trackstruct slab_attributestruct saved_aliasenum slab_flagsenum track_itemenum add_modeenum stat_itemenum slab_stat_typefunction kmem_cache_debugfunction sysfs_slab_addfunction debugfs_slab_addfunction statfunction stat_addfunction pointerfunction set_freepointerfunction calculate_sizesfunction get_info_endfunction order_objectsfunction oo_makefunction oo_orderfunction oo_objectsfunction slab_test_pfmemallocfunction slab_set_pfmemallocfunction __slab_clear_pfmemallocfunction slab_lockfunction slab_unlockfunction __update_freelist_fastfunction __update_freelist_slowfunction disabledfunction slab_update_freelistfunction sizesfunction get_orig_sizefunction need_slab_obj_extsfunction obj_exts_size_in_slab
Annotated Snippet
static const struct file_operations slab_debugfs_fops = {
.open = slab_debug_trace_open,
.read = seq_read,
.llseek = seq_lseek,
.release = slab_debug_trace_release,
};
static void debugfs_slab_add(struct kmem_cache *s)
{
struct dentry *slab_cache_dir;
if (unlikely(!slab_debugfs_root))
return;
slab_cache_dir = debugfs_create_dir(s->name, slab_debugfs_root);
debugfs_create_file_aux_num("alloc_traces", 0400, slab_cache_dir, s,
TRACK_ALLOC, &slab_debugfs_fops);
debugfs_create_file_aux_num("free_traces", 0400, slab_cache_dir, s,
TRACK_FREE, &slab_debugfs_fops);
}
void debugfs_slab_release(struct kmem_cache *s)
{
debugfs_lookup_and_remove(s->name, slab_debugfs_root);
}
static int __init slab_debugfs_init(void)
{
struct kmem_cache *s;
slab_debugfs_root = debugfs_create_dir("slab", NULL);
list_for_each_entry(s, &slab_caches, list)
if (s->flags & SLAB_STORE_USER)
debugfs_slab_add(s);
return 0;
}
__initcall(slab_debugfs_init);
#endif
/*
* The /proc/slabinfo ABI
*/
#ifdef CONFIG_SLUB_DEBUG
void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
{
unsigned long nr_slabs = 0;
unsigned long nr_objs = 0;
unsigned long nr_free = 0;
int node;
struct kmem_cache_node *n;
for_each_kmem_cache_node(s, node, n) {
nr_slabs += node_nr_slabs(n);
nr_objs += node_nr_objs(n);
nr_free += count_partial_free_approx(n);
}
sinfo->active_objs = nr_objs - nr_free;
sinfo->num_objs = nr_objs;
sinfo->active_slabs = nr_slabs;
sinfo->num_slabs = nr_slabs;
sinfo->objects_per_slab = oo_objects(s->oo);
sinfo->cache_order = oo_order(s->oo);
}
#endif /* CONFIG_SLUB_DEBUG */
Annotation
- Immediate include surface: `linux/mm.h`, `linux/swap.h`, `linux/module.h`, `linux/bit_spinlock.h`, `linux/interrupt.h`, `linux/swab.h`, `linux/bitops.h`, `linux/slab.h`.
- Detected declarations: `struct slab_alloc_context`, `struct partial_bulk_context`, `struct slab_obj_iter`, `struct track`, `struct kmem_cache_stats`, `struct node_barn`, `struct slab_sheaf`, `struct slub_percpu_sheaves`, `struct kmem_cache_node`, `struct slub_flush_work`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.