page_size

A tiny, cross-platform Rust crate for retrieving the system memory page size

Library
Cargo
v0.6.0
15stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
22/100Needs Attention
Development Activity0
Maintenance0
Community16
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture60
Code Quality68
Innovation45
Learning Curve90

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 call
  • page_size::get_granularity() — Windows allocation granularity, which can differ from the page size
  • A no_std-compatible build path (via the optional no_std feature and spin crate) for allocator/embedded use
  • Zero-dependency-by-default design outside the platform-specific libc/winapi bindings

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_std embedded 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search