When working with memory management, performance tuning, or low-level programming, understanding the system's page size is essential. The page size determines the smallest unit of memory the Linux kernel uses for allocating and managing virtual memory. Most systems use 4096 bytes (4 KB) pages, but some architectures or configurations may differ - for example, 16 KB or 64 KB pages on certain ARM or PowerPC systems. This tutorial provides 2 methods how to get page size on Linux.
Method 1 - getconf command
The getconf
command can be used to get system configuration variables, including the page size:
getconf PAGE_SIZE
Example output:
4096
Method 2 - /proc/1/smaps file
Linux exposes detailed memory mapping information for each process under /proc/[pid]/smaps
. Here, [pid]
refers to the process ID whose memory mappings you want to inspect.
In this example, we use PID 1, which always corresponds to the init process - the very first process started by the Linux kernel during boot (often systemd
on modern systems). Because PID 1 always exists, it's a reliable choice for reading system-level information like page size.
Use the grep
command to extract the page size from the KernelPageSize
field:
sudo grep -m1 KernelPageSize /proc/1/smaps
Example output:
KernelPageSize: 4 kB
Leave a Comment
Cancel reply