mm/page_frag_cache.c
Source file repositories/reference/linux-study-clean/mm/page_frag_cache.c
File Facts
- System
- Linux kernel
- Corpus path
mm/page_frag_cache.c- Extension
.c- Size
- 4897 bytes
- Lines
- 172
- Domain
- Core OS
- Bucket
- Memory Management
- 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.
- 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/build_bug.hlinux/export.hlinux/gfp_types.hlinux/init.hlinux/mm.hlinux/page_frag_cache.hinternal.h
Detected Declarations
function encoded_page_createfunction encoded_page_decode_orderfunction page_frag_cache_drainfunction __page_frag_cache_drainfunction page_frag_freeexport page_frag_cache_drainexport __page_frag_cache_drainexport __page_frag_alloc_alignexport page_frag_free
Annotated Snippet
if (unlikely(fragsz > PAGE_SIZE)) {
/*
* The caller is trying to allocate a fragment
* with fragsz > PAGE_SIZE but the cache isn't big
* enough to satisfy the request, this may
* happen in low memory conditions.
* We don't release the cache page because
* it could make memory pressure worse
* so we simply return NULL here.
*/
return NULL;
}
page = encoded_page_decode_page(encoded_page);
if (!page_ref_sub_and_test(page, nc->pagecnt_bias))
goto refill;
if (unlikely(encoded_page_decode_pfmemalloc(encoded_page))) {
free_frozen_pages(page,
encoded_page_decode_order(encoded_page));
goto refill;
}
/* OK, page count is 0, we can safely set it */
set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1);
/* reset page count bias and offset to start of new frag */
nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1;
offset = 0;
}
nc->pagecnt_bias--;
nc->offset = offset + fragsz;
return encoded_page_decode_virt(encoded_page) + offset;
}
EXPORT_SYMBOL(__page_frag_alloc_align);
/*
* Frees a page fragment allocated out of either a compound or order 0 page.
*/
void page_frag_free(void *addr)
{
struct page *page = virt_to_head_page(addr);
if (unlikely(put_page_testzero(page)))
free_frozen_pages(page, compound_order(page));
}
EXPORT_SYMBOL(page_frag_free);
Annotation
- Immediate include surface: `linux/build_bug.h`, `linux/export.h`, `linux/gfp_types.h`, `linux/init.h`, `linux/mm.h`, `linux/page_frag_cache.h`, `internal.h`.
- Detected declarations: `function encoded_page_create`, `function encoded_page_decode_order`, `function page_frag_cache_drain`, `function __page_frag_cache_drain`, `function page_frag_free`, `export page_frag_cache_drain`, `export __page_frag_cache_drain`, `export __page_frag_alloc_align`, `export page_frag_free`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration 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.