getpagesize(2)

๐Ÿ’– getpagesize โ€” bestie, what even IS a page ๐Ÿ’–

okay so this is getpagesize(2) from the System Calls Manual, section 2, and honestly? it's a tiny little function with a lot of lore. let's get into it ๐Ÿซถ


โœจ NAME โœจ

getpagesize โ€” get memory page size

basically: it tells you how big a memory page is. that's it. that's the whole job. queen behavior honestly ๐Ÿ‘‘


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)

so you're linking against the classic. nothing exotic. ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <unistd.h>

int getpagesize(void);

no arguments, returns an int. she takes nothing and gives everything ๐Ÿ˜Œ

๐ŸŽ€ Feature Test Macro Requirements for glibc ๐ŸŽ€

(see feature_test_macros(7) for the full tea โ˜•)

getpagesize():

  • Since glibc 2.20:
    • _DEFAULT_SOURCE || ! (_POSIX_C_SOURCE >= 200112L)
  • glibc 2.12 to glibc 2.19:
    • _BSD_SOURCE || ! (_POSIX_C_SOURCE >= 200112L)
  • Before glibc 2.12:
    • _BSD_SOURCE || _XOPEN_SOURCE >= 500

likeโ€ฆ the macros changed over the years, that's just how glibc girlies are ๐Ÿ’€ don't @ me, check which version you're on.


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so getpagesize() returns the number of bytes in a memory page. and what's a "page", you ask? it's a fixed-length block โ€” the unit used for memory allocation and for file mapping done by mmap(2). ๐Ÿ—บ๏ธ

that's the whole vibe. pages are the little bricks, and this function tells you how big the bricks are.


๐ŸŒˆ VERSIONS ๐ŸŒˆ

okay this part is important, bestie, pay attention:

a user program should not hard-code a page size. not as a literal, and not using the PAGE_SIZE macro. why? because some architectures support multiple page sizes. ๐Ÿšจ

like imagine hardcoding a number and then running on a machine where that's just wrong. embarrassing. don't do it. ๐Ÿ™ˆ

and here's a fun fact about why this page lives in section 2 instead of section 3: Alpha, SPARC, and SPARC64 all have an actual Linux system call getpagesize(). the other architectures do not โ€” they use the ELF auxiliary vector instead. so it counts as a system call page. iykyk โœจ


๐Ÿ‘‘ STANDARDS ๐Ÿ‘‘

None.

that's it. no standards. nothing. she's free. she's ungoverned. iconic ๐Ÿ”ฅ


๐Ÿ’œ HISTORY ๐Ÿ’œ

  • 4.2BSD, SVr4, SUSv1.
  • in SUSv2 the getpagesize() call was labeled LEGACY, and then it got removed in POSIX.1-2001. rip bestie ๐Ÿ˜ญ
  • glibc 2.0 returned a constant even on architectures with multiple page sizes. (which, as we discussed above, is a whole problem. not great. ๐Ÿ’€)

๐Ÿ“ SEE ALSO ๐Ÿ“

go read those if you wanna know more about pages and how to ask the system things politely ๐Ÿ’–


and that's the page, bestie!! this one came from Linux man-pages 6.20, dated 2026-02-08 โ€” go off, documentation queens ๐Ÿ‘‘โœจ mwah ๐Ÿ’…๐Ÿฆ‹๐ŸŒธ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms