fs/proc/page.c
Source file repositories/reference/linux-study-clean/fs/proc/page.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/page.c- Extension
.c- Size
- 7344 bytes
- Lines
- 300
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/memblock.hlinux/compiler.hlinux/fs.hlinux/init.hlinux/ksm.hlinux/mm.hlinux/mmzone.hlinux/huge_mm.hlinux/proc_fs.hlinux/seq_file.hlinux/hugetlb.hlinux/memremap.hlinux/memcontrol.hlinux/mmu_notifier.hlinux/page_idle.hlinux/kernel-page-flags.hlinux/uaccess.hinternal.h
Detected Declarations
enum kpage_operationfunction get_max_dump_pfnfunction get_kpage_countfunction kpage_readfunction kpagecount_readfunction kpf_copy_bitfunction stable_page_flagsfunction kpageflags_readfunction kpagecgroup_readfunction proc_page_initmodule init proc_page_initexport stable_page_flags
Annotated Snippet
if (page) {
switch (op) {
case KPAGE_FLAGS:
info = stable_page_flags(page);
break;
case KPAGE_COUNT:
info = get_kpage_count(page);
break;
case KPAGE_CGROUP:
info = page_cgroup_ino(page);
break;
default:
info = 0;
break;
}
} else
info = 0;
if (put_user(info, out)) {
ret = -EFAULT;
break;
}
pfn++;
out++;
count -= KPMSIZE;
cond_resched();
}
*ppos += (char __user *)out - buf;
if (!ret)
ret = (char __user *)out - buf;
return ret;
}
/* /proc/kpagecount - an array exposing page mapcounts
*
* Each entry is a u64 representing the corresponding
* physical page mapcount.
*/
static ssize_t kpagecount_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
return kpage_read(file, buf, count, ppos, KPAGE_COUNT);
}
static const struct proc_ops kpagecount_proc_ops = {
.proc_flags = PROC_ENTRY_PERMANENT,
.proc_lseek = mem_lseek,
.proc_read = kpagecount_read,
};
static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
{
return ((kflags >> kbit) & 1) << ubit;
}
u64 stable_page_flags(const struct page *page)
{
const struct folio *folio;
struct page_snapshot ps;
unsigned long k;
unsigned long mapping;
bool is_anon;
u64 u = 0;
/*
* pseudo flag: KPF_NOPAGE
* it differentiates a memory hole from a page with no flags
*/
if (!page)
return 1 << KPF_NOPAGE;
snapshot_page(&ps, page);
folio = &ps.folio_snapshot;
k = folio->flags.f;
mapping = (unsigned long)folio->mapping;
is_anon = mapping & FOLIO_MAPPING_ANON;
/*
* pseudo flags for the well known (anonymous) memory mapped pages
*/
if (folio_mapped(folio))
u |= 1 << KPF_MMAP;
if (is_anon) {
u |= 1 << KPF_ANON;
if (mapping & FOLIO_MAPPING_KSM)
Annotation
- Immediate include surface: `linux/memblock.h`, `linux/compiler.h`, `linux/fs.h`, `linux/init.h`, `linux/ksm.h`, `linux/mm.h`, `linux/mmzone.h`, `linux/huge_mm.h`.
- Detected declarations: `enum kpage_operation`, `function get_max_dump_pfn`, `function get_kpage_count`, `function kpage_read`, `function kpagecount_read`, `function kpf_copy_bit`, `function stable_page_flags`, `function kpageflags_read`, `function kpagecgroup_read`, `function proc_page_init`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.