page_size
A tiny, cross-platform Rust crate for retrieving the system memory page size
Repository Health
Technical Analysis
page_size is a small, focused Rust crate that answers one question reliably across platforms: how big is a memory page on this system? It wraps the platform-specific syscalls (sysconf/libc on Unix, GetSystemInfo via winapi on Windows) behind a single page_size::get() function, caching the result after the first call since the value never changes during a process’s lifetime.
Because manual memory management, allocators, and memory-mapped I/O code frequently need page-aligned sizes, page_size has become a common low-level dependency threaded through much larger crates — including memory-mapping and embedded-database libraries — rather than something most application developers call directly.
What You Get
page_size::get()— the system’s memory page size in bytes, cached after first callpage_size::get_granularity()— Windows allocation granularity, which can differ from the page size- A
no_std-compatible build path (via the optionalno_stdfeature andspincrate) for allocator/embedded use - Zero-dependency-by-default design outside the platform-specific
libc/winapibindings
Common Use Cases
- Aligning buffer sizes to the OS page size inside a custom memory allocator
- Computing correct offsets/sizes for memory-mapped file I/O (
mmap) code - Sizing arenas or slabs in a
no_stdembedded or kernel-adjacent context - Providing page-size metadata to lower-level storage engines (e.g. memory-mapped databases) as a transitive dependency
Under The Hood
Architecture: The entire crate lives in one file (src/lib.rs). Two public functions, get() and get_granularity(), each delegate to a private platform-specific helper gated by #[cfg(unix)] or #[cfg(windows)], and the result of each is memoized via std::sync::Once (or spin::Once when the no_std feature is active) so the underlying sysconf(_SC_PAGESIZE) or GetSystemInfo call executes at most once per process.
Tech Stack: Pure Rust with platform-conditional dependencies only: libc on Unix targets for sysconf, winapi (with the sysinfoapi feature) on Windows for GetSystemInfo, and an optional spin dependency behind the no_std feature flag for allocator-safe caching without the standard library.
Code Quality: The crate is intentionally minimal with inline doctest examples in every public function’s documentation, serving as its primary test coverage; there is no separate tests/ directory, consistent with the crate’s narrow, single-purpose scope. It has been stable for years with no reported correctness issues, reflected in its very high transitive download count relative to its small surface area.
API Design: The API is about as low-friction as a crate can be — page_size::get() with no setup, arguments, or error handling required, since the operation cannot meaningfully fail on supported platforms. This simplicity is the whole value proposition: teams needing page-size metadata pull in page_size instead of hand-rolling per-platform syscalls themselves.
Used by 2 apps in this directory
cocoindex
Data Engineering · AI Development
An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.