mm/slab.h
Source file repositories/reference/linux-study-clean/mm/slab.h
File Facts
- System
- Linux kernel
- Corpus path
mm/slab.h- Extension
.h- Size
- 21500 bytes
- Lines
- 760
- Domain
- Core OS
- Bucket
- Memory Management
- 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.
- 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/reciprocal_div.hlinux/list_lru.hlinux/local_lock.hlinux/random.hlinux/kobject.hlinux/sched/mm.hlinux/memcontrol.hlinux/kfence.hlinux/kasan.hlinux/slab.h
Detected Declarations
struct freelist_countersstruct slabstruct freelist_countersstruct kmem_cache_order_objectsstruct kmem_cache_per_node_ptrsstruct kmem_cachestruct seq_filestruct filestruct slabinfostruct kmem_obj_infoenum slab_statefunction alloc_flags_allow_spinningfunction __alloc_sizefunction slab_nidfunction slab_orderfunction slab_sizefunction cache_has_sheavesfunction sysfs_slab_unlinkfunction __obj_to_indexfunction obj_to_indexfunction objs_per_slabfunction size_index_elemfunction kmalloc_slabfunction is_kmalloc_cachefunction is_kmalloc_normalfunction __slub_debug_enabledfunction print_trackingfunction kmem_cache_debug_flagsfunction slab_in_kunit_testfunction metadata_access_enablefunction metadata_access_disablefunction slab_obj_extsfunction get_slab_obj_extsfunction put_slab_obj_extsfunction slab_set_stridefunction slab_get_stridefunction slab_set_stridefunction slab_get_stridefunction slab_obj_extsfunction slab_set_stridefunction cache_vmstat_idxfunction large_kmalloc_orderfunction large_kmalloc_sizefunction dump_unreclaimable_slabfunction cache_random_seq_createfunction cache_random_seq_destroyfunction slab_want_init_on_freefunction debugfs_slab_release
Annotated Snippet
struct freelist_counters {
union {
struct {
void *freelist;
union {
unsigned long counters;
struct {
unsigned inuse:16;
unsigned objects:15;
/*
* If slab debugging is enabled then the
* frozen bit can be reused to indicate
* that the slab was corrupted
*/
unsigned frozen:1;
#ifdef CONFIG_64BIT
/*
* Some optimizations use free bits in 'counters' field
* to save memory. In case ->stride field is not available,
* such optimizations are disabled.
*/
unsigned int stride;
#endif
};
};
};
#ifdef system_has_freelist_aba
freelist_full_t freelist_counters;
#endif
};
};
/* Reuses the bits in struct page */
struct slab {
memdesc_flags_t flags;
struct kmem_cache *slab_cache;
union {
struct {
struct list_head slab_list;
/* Double-word boundary */
struct freelist_counters;
};
struct rcu_head rcu_head;
};
unsigned int __page_type;
atomic_t __page_refcount;
#ifdef CONFIG_SLAB_OBJ_EXT
unsigned long obj_exts;
#endif
};
#define SLAB_MATCH(pg, sl) \
static_assert(offsetof(struct page, pg) == offsetof(struct slab, sl))
SLAB_MATCH(flags, flags);
SLAB_MATCH(compound_info, slab_cache); /* Ensure bit 0 is clear */
SLAB_MATCH(_refcount, __page_refcount);
#ifdef CONFIG_MEMCG
SLAB_MATCH(memcg_data, obj_exts);
#elif defined(CONFIG_SLAB_OBJ_EXT)
SLAB_MATCH(_unused_slab_obj_exts, obj_exts);
#endif
#undef SLAB_MATCH
static_assert(sizeof(struct slab) <= sizeof(struct page));
#if defined(system_has_freelist_aba)
static_assert(IS_ALIGNED(offsetof(struct slab, freelist), sizeof(struct freelist_counters)));
#endif
/**
* slab_folio - The folio allocated for a slab
* @s: The slab.
*
* Slabs are allocated as folios that contain the individual objects and are
* using some fields in the first struct page of the folio - those fields are
* now accessed by struct slab. It is occasionally necessary to convert back to
* a folio in order to communicate with the rest of the mm. Please use this
* helper function instead of casting yourself, as the implementation may change
* in the future.
*/
#define slab_folio(s) (_Generic((s), \
const struct slab *: (const struct folio *)s, \
struct slab *: (struct folio *)s))
/**
* page_slab - Converts from struct page to its slab.
* @page: A page which may or may not belong to a slab.
*
* Return: The slab which contains this page or NULL if the page does
* not belong to a slab. This includes pages returned from large kmalloc.
Annotation
- Immediate include surface: `linux/reciprocal_div.h`, `linux/list_lru.h`, `linux/local_lock.h`, `linux/random.h`, `linux/kobject.h`, `linux/sched/mm.h`, `linux/memcontrol.h`, `linux/kfence.h`.
- Detected declarations: `struct freelist_counters`, `struct slab`, `struct freelist_counters`, `struct kmem_cache_order_objects`, `struct kmem_cache_per_node_ptrs`, `struct kmem_cache`, `struct seq_file`, `struct file`, `struct slabinfo`, `struct kmem_obj_info`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source 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.