include/linux/page_ref.h
Source file repositories/reference/linux-study-clean/include/linux/page_ref.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/page_ref.h- Extension
.h- Size
- 8649 bytes
- Lines
- 313
- 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.
- 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/atomic.hlinux/mm_types.hlinux/page-flags.hlinux/tracepoint-defs.h
Detected Declarations
function __page_ref_setfunction folio_getfunction page_countfunction set_page_countfunction folio_set_countfunction timefunction page_ref_addfunction folio_ref_addfunction page_ref_subfunction folio_ref_subfunction folio_ref_sub_returnfunction page_ref_incfunction folio_ref_incfunction page_ref_decfunction folio_ref_decfunction page_ref_sub_and_testfunction folio_ref_sub_and_testfunction page_ref_inc_returnfunction folio_ref_inc_returnfunction page_ref_dec_and_testfunction folio_ref_dec_and_testfunction page_ref_dec_returnfunction folio_ref_dec_returnfunction page_ref_add_unless_zerofunction folio_ref_add_unless_zerofunction folio_try_getfunction folio_ref_try_addfunction page_ref_freezefunction folio_ref_freezefunction page_ref_unfreezefunction folio_ref_unfreeze
Annotated Snippet
#ifndef _LINUX_PAGE_REF_H
#define _LINUX_PAGE_REF_H
#include <linux/atomic.h>
#include <linux/mm_types.h>
#include <linux/page-flags.h>
#include <linux/tracepoint-defs.h>
DECLARE_TRACEPOINT(page_ref_set);
DECLARE_TRACEPOINT(page_ref_mod);
DECLARE_TRACEPOINT(page_ref_mod_and_test);
DECLARE_TRACEPOINT(page_ref_mod_and_return);
DECLARE_TRACEPOINT(page_ref_mod_unless);
DECLARE_TRACEPOINT(page_ref_freeze);
DECLARE_TRACEPOINT(page_ref_unfreeze);
#ifdef CONFIG_DEBUG_PAGE_REF
/*
* Ideally we would want to use the trace_<tracepoint>_enabled() helper
* functions. But due to include header file issues, that is not
* feasible. Instead we have to open code the static key functions.
*
* See trace_##name##_enabled(void) in include/linux/tracepoint.h
*/
#define page_ref_tracepoint_active(t) tracepoint_enabled(t)
extern void __page_ref_set(struct page *page, int v);
extern void __page_ref_mod(struct page *page, int v);
extern void __page_ref_mod_and_test(struct page *page, int v, int ret);
extern void __page_ref_mod_and_return(struct page *page, int v, int ret);
extern void __page_ref_mod_unless(struct page *page, int v, int u);
extern void __page_ref_freeze(struct page *page, int v, int ret);
extern void __page_ref_unfreeze(struct page *page, int v);
#else
#define page_ref_tracepoint_active(t) false
static inline void __page_ref_set(struct page *page, int v)
{
}
static inline void __page_ref_mod(struct page *page, int v)
{
}
static inline void __page_ref_mod_and_test(struct page *page, int v, int ret)
{
}
static inline void __page_ref_mod_and_return(struct page *page, int v, int ret)
{
}
static inline void __page_ref_mod_unless(struct page *page, int v, int u)
{
}
static inline void __page_ref_freeze(struct page *page, int v, int ret)
{
}
static inline void __page_ref_unfreeze(struct page *page, int v)
{
}
#endif
static inline int page_ref_count(const struct page *page)
{
return atomic_read(&page->_refcount);
}
/**
* folio_ref_count - The reference count on this folio.
* @folio: The folio.
*
* Folios contain a reference count. When that reference count reaches
* zero, the folio is referred to as frozen. At this point, it will
* usually be returned to the memory allocator, but some parts of the
* kernel freeze folios in order to perform unusual operations on them
* such as splitting or migration.
*
* The refcount is usually incremented by calls to folio_get() and
* decremented by calls to folio_put(). Some typical users of the
* folio refcount:
*
* - Each reference from a page table
* - The page cache
* - Filesystem private data
* - The LRU list
* - Pipes
* - Direct IO which references this page in the process address space
*
* The reference count has three components: expected, temporary and
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/mm_types.h`, `linux/page-flags.h`, `linux/tracepoint-defs.h`.
- Detected declarations: `function __page_ref_set`, `function folio_get`, `function page_count`, `function set_page_count`, `function folio_set_count`, `function time`, `function page_ref_add`, `function folio_ref_add`, `function page_ref_sub`, `function folio_ref_sub`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.