mm/zpdesc.h
Source file repositories/reference/linux-study-clean/mm/zpdesc.h
File Facts
- System
- Linux kernel
- Corpus path
mm/zpdesc.h- Extension
.h- Size
- 5057 bytes
- Lines
- 175
- 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/migrate.hlinux/pagemap.h
Detected Declarations
struct zpdescfunction zpdesc_lockfunction zpdesc_trylockfunction zpdesc_unlockfunction zpdesc_wait_lockedfunction zpdesc_getfunction zpdesc_putfunction zpdesc_pfnfunction __zpdesc_set_movablefunction __zpdesc_set_zsmallocfunction zpdesc_is_locked
Annotated Snippet
struct zpdesc {
unsigned long flags;
struct list_head lru;
unsigned long movable_ops;
union {
struct zpdesc *next;
unsigned long handle;
};
struct zspage *zspage;
/*
* Only the lower 24 bits are available for offset, limiting a page
* to 16 MiB. The upper 8 bits are reserved for PGTY_zsmalloc.
*
* Do not access this field directly.
* Instead, use {get,set}_first_obj_offset() helpers.
*/
unsigned int first_obj_offset;
atomic_t _refcount;
};
#define ZPDESC_MATCH(pg, zp) \
static_assert(offsetof(struct page, pg) == offsetof(struct zpdesc, zp))
ZPDESC_MATCH(flags, flags);
ZPDESC_MATCH(lru, lru);
ZPDESC_MATCH(mapping, movable_ops);
ZPDESC_MATCH(__folio_index, next);
ZPDESC_MATCH(__folio_index, handle);
ZPDESC_MATCH(private, zspage);
ZPDESC_MATCH(page_type, first_obj_offset);
ZPDESC_MATCH(_refcount, _refcount);
#undef ZPDESC_MATCH
static_assert(sizeof(struct zpdesc) <= sizeof(struct page));
/*
* zpdesc_page - The first struct page allocated for a zpdesc
* @zp: The zpdesc.
*
* A convenience wrapper for converting zpdesc to the first struct page of the
* underlying folio, to communicate with code not yet converted to folio or
* struct zpdesc.
*
*/
#define zpdesc_page(zp) (_Generic((zp), \
const struct zpdesc *: (const struct page *)(zp), \
struct zpdesc *: (struct page *)(zp)))
/**
* zpdesc_folio - The folio allocated for a zpdesc
* @zp: The zpdesc.
*
* Zpdescs are descriptors for zsmalloc memory. The memory itself is allocated
* as folios that contain the zsmalloc objects, and zpdesc uses specific
* fields in the first struct page of the folio - those fields are now accessed
* by struct zpdesc.
*
* It is occasionally necessary convert to 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 zpdesc_folio(zp) (_Generic((zp), \
const struct zpdesc *: (const struct folio *)(zp), \
struct zpdesc *: (struct folio *)(zp)))
/**
* page_zpdesc - Converts from first struct page to zpdesc.
* @p: The first (either head of compound or single) page of zpdesc.
*
* A temporary wrapper to convert struct page to struct zpdesc in situations
* where we know the page is the compound head, or single order-0 page.
*
* Long-term ideally everything would work with struct zpdesc directly or go
* through folio to struct zpdesc.
*
* Return: The zpdesc which contains this page
*/
#define page_zpdesc(p) (_Generic((p), \
const struct page *: (const struct zpdesc *)(p), \
struct page *: (struct zpdesc *)(p)))
static inline void zpdesc_lock(struct zpdesc *zpdesc)
{
folio_lock(zpdesc_folio(zpdesc));
}
static inline bool zpdesc_trylock(struct zpdesc *zpdesc)
{
return folio_trylock(zpdesc_folio(zpdesc));
}
static inline void zpdesc_unlock(struct zpdesc *zpdesc)
{
Annotation
- Immediate include surface: `linux/migrate.h`, `linux/pagemap.h`.
- Detected declarations: `struct zpdesc`, `function zpdesc_lock`, `function zpdesc_trylock`, `function zpdesc_unlock`, `function zpdesc_wait_locked`, `function zpdesc_get`, `function zpdesc_put`, `function zpdesc_pfn`, `function __zpdesc_set_movable`, `function __zpdesc_set_zsmalloc`.
- 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.