Recent from talks
Nothing was collected or created yet.
Page (computer memory)
View on WikipediaA page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described by a single entry in a page table. It is the smallest unit of data for memory management in an operating system that uses virtual memory. Similarly, a page frame is the smallest fixed-length contiguous block of physical memory into which memory pages are mapped by the operating system.[1][2][3]
A transfer of pages between main memory and an auxiliary store, such as a hard disk drive, is referred to as paging or swapping.[4]
Explanation
[edit]Computer memory is divided into pages so that information can be found more quickly.
The concept is named by analogy to the pages of a printed book. If a reader wanted to find, for example, the 5,000th word in the book, they could count from the first word. This would be time-consuming. It would be much faster if the reader had a listing of how many words are on each page. From this listing they could determine which page the 5,000th word appears on, and how many words to count on that page. This listing of the words per page of the book is analogous to a page table of a computer file system.[5]
Page size
[edit]Page size trade-off
[edit]This section needs additional citations for verification. (February 2015) |
Page size is usually determined by the processor architecture. Traditionally, pages in a system had uniform size, such as 4,096 bytes. However, processor designs often allow two or more, sometimes simultaneous, page sizes due to its benefits. There are several points that can factor into choosing the best page size.[6]
Page table size
[edit]A system with a smaller page size uses more pages, requiring a page table that occupies more space. For example, if a 232 virtual address space is mapped to 4 KiB (212 bytes) pages, the number of virtual pages is 220 = (232 / 212). However, if the page size is increased to 32 KiB (215 bytes), only 217 pages are required. A multi-level paging algorithm can decrease the memory cost of allocating a large page table for each process by further dividing the page table up into smaller tables, effectively paging the page table.
TLB usage
[edit]Since every access to memory must be mapped from virtual to physical address, reading the page table every time can be quite costly. Therefore, a very fast kind of cache, the translation lookaside buffer (TLB), is often used. The TLB is of limited size, and when it cannot satisfy a given request (a TLB miss) the mapping must be fetched from the page table (either by hardware, firmware, or software, depending on the architecture) for the correct mapping. Larger page sizes mean that a TLB cache of the same size can keep track of larger amounts of memory, which avoids costly TLB misses.
Internal fragmentation
[edit]Rarely do processes require the use of an exact number of pages. As a result, the last page will likely only be partially full, wasting some amount of memory. Larger page sizes lead to a large amount of wasted memory, as more potentially unused portions of memory are loaded into the main memory. Smaller page sizes ensure a closer match to the actual amount of memory required in an allocation.
As an example, assume the page size is 1024 B. If a process allocates 1025 B, two pages must be used, resulting in 1023 B of unused space (where one page fully consumes 1024 B and the other only 1 B).
Disk access
[edit]When transferring from a rotational disk, much of the delay is caused by seek time, the time it takes to correctly position the read/write heads above the disk platters. Because of this, large sequential transfers are more efficient than several smaller transfers. Transferring the same amount of data from disk to memory often requires less time with larger pages than with smaller pages.
Getting page size programmatically
[edit]Most operating systems allow programs to discover the page size at runtime. This allows programs to use memory more efficiently by aligning allocations to this size and reducing overall internal fragmentation of pages.
Unix-like operating systems
[edit]Unix-like systems may use the system function sysconf(),[7][8][9][10][11] as illustrated in the following example written in the C programming language.
#include <stdio.h>
#include <unistd.h> /* sysconf(3) */
int main(void)
{
printf("The page size for this system is %ld bytes.\n",
sysconf(_SC_PAGESIZE)); /* _SC_PAGE_SIZE is OK too. */
return 0;
}
In many Unix-like systems, the command-line utility getconf can be used.[12][13][14]
For example, getconf PAGESIZE will return the page size in bytes.
Windows-based operating systems
[edit]Win32-based operating systems, such as those in the Windows 9x and Windows NT families, may use the system function GetSystemInfo()[15][16] from kernel32.dll.
#include <stdio.h>
#include <windows.h>
int main(void)
{
SYSTEM_INFO si;
GetSystemInfo(&si);
printf("The page size for this system is %u bytes.\n", si.dwPageSize);
return 0;
}
Multiple page sizes
[edit]Some instruction set architectures can support multiple page sizes, including pages significantly larger than the standard page size. The available page sizes depend on the instruction set architecture, processor type, and operating (addressing) mode. The operating system selects one or more sizes from the sizes supported by the architecture. Note that not all processors implement all defined larger page sizes. This support for larger pages (known as "huge pages" in Linux, "superpages" in FreeBSD, and "large pages" in Microsoft Windows and IBM AIX terminology) allows for "the best of both worlds", reducing the pressure on the TLB cache (sometimes increasing speed by as much as 15%) for large allocations while still keeping memory usage at a reasonable level for small allocations.
| Architecture | Smallest page size | Larger page sizes |
|---|---|---|
| IA-32 (32-bit x86)[18] | 4 KiB | 4 MiB in PSE mode, 2 MiB in PAE mode[19] |
| x86-64[18] | 4 KiB | 2 MiB, 1 GiB (only when the CPU has PDPE1GB flag)
|
| IA-64 (Itanium)[20] | 4 KiB | 8 KiB, 64 KiB, 256 KiB, 1 MiB, 4 MiB, 16 MiB, 256 MiB[19] |
| Power ISA[21] | 4 KiB | 64 KiB, 16 MiB, 16 GiB |
| SPARC v8 with SPARC Reference MMU[22] | 4 KiB | 256 KiB, 16 MiB |
| UltraSPARC Architecture 2007[23] | 8 KiB | 64 KiB, 512 KiB (optional), 4 MiB, 32 MiB (optional), 256 MiB (optional), 2 GiB (optional), 16 GiB (optional) |
| ARMv7[24] | 4 KiB | 64 KiB, 1 MiB ("section"), 16 MiB ("supersection") (defined by a particular implementation) |
| AArch64[25] | 4 KiB | 16 KiB, 64 KiB, 2 MiB, 32 MiB, 512 MiB, 1 GiB |
| RISCV32[26] | 4 KiB | 4 MiB ("megapage") |
| RISCV64[26] | 4 KiB | 2 MiB ("megapage"), 1 GiB ("gigapage"), 512 GiB ("terapage", only for CPUs with 43-bit address space or more), 256 TiB ("petapage", only for CPUs with 57-bit address space or more), |
Starting with the Pentium Pro, and the AMD Athlon, x86 processors support 4 MiB pages (called Page Size Extension) (2 MiB pages if using PAE) in addition to their standard 4 KiB pages; newer x86-64 processors, such as AMD's newer AMD64 processors and Intel's Westmere[27] and later Xeon processors can use 1 GiB pages in long mode. IA-64 supports as many as eight different page sizes, from 4 KiB up to 256 MiB, and some other architectures have similar features.[specify]
Larger pages, despite being available in the processors used in most contemporary personal computers, are not in common use except in large-scale applications, the applications typically found in large servers and in computational clusters, and in the operating system itself. Commonly, their use requires elevated privileges, cooperation from the application making the large allocation (usually setting a flag to ask the operating system for huge pages), or manual administrator configuration; operating systems commonly, sometimes by design, cannot page them out to disk.
However, SGI IRIX has general-purpose support for multiple page sizes. Each individual process can provide hints and the operating system will automatically use the largest page size possible for a given region of address space.[28] Later work proposed transparent operating system support for using a mix of page sizes for unmodified applications through preemptible reservations, opportunistic promotions, speculative demotions, and fragmentation control.[29]
Linux has supported huge pages on several architectures since the 2.6 series via the hugetlbfs filesystem[30] and without hugetlbfs since 2.6.38.[31] Windows Server 2003 (SP1 and newer), Windows Vista and Windows Server 2008 support huge pages under the name of large pages.[32] Windows 2000 and Windows XP support large pages internally, but do not expose them to applications.[33] Reserving large pages under Windows requires a corresponding right that the system administrator must grant to the user because large pages cannot be swapped out under Windows. Beginning with version 9, Solaris supports large pages on SPARC and x86.[34][35]
FreeBSD 7.2-RELEASE features superpages.[36] Note that until recently in Linux, applications needed to be modified in order to use huge pages. The 2.6.38 kernel introduced support for transparent use of huge pages.[31] On Linux kernels supporting transparent huge pages, as well as FreeBSD and Solaris, applications take advantage of huge pages automatically, without the need for modification.[36]
See also
[edit]- Grant table
- Page fault
- Page table
- Memory paging
- Virtual memory
- Zero page - a (often 256-bytes large[37][38]) memory area at the very start of a processor's address room
- Zero page (CP/M) - a 256-byte[38] data structure at the start of a program
References
[edit]- ^ Christopher Kruegel (2012-12-03). "Operating Systems (CS170-08 course)" (PDF). cs.ucsb.edu. Archived (PDF) from the original on 2016-08-10. Retrieved 2016-06-13.
- ^ Martin C. Rinard (1998-08-22). "Operating Systems Lecture Notes, Lecture 9. Introduction to Paging". people.csail.mit.edu. Archived from the original on 2016-06-01. Retrieved 2016-06-13.
- ^ "Virtual Memory: pages and page frames". cs.miami.edu. 2012-10-31. Archived from the original on 2016-06-11. Retrieved 2016-06-13.
- ^ Belzer, Jack; Holzman, Albert G.; Kent, Allen, eds. (1981), "Virtual memory systems", Encyclopedia of computer science and technology, vol. 14, CRC Press, p. 32, ISBN 0-8247-2214-0
- ^ Kazemi, Darius (2019-01-11). "RFC-11". 365 RFCs.
- ^ Weisberg, P.; Wiseman, Y. (2009-08-10). Using 4KB Page Size for Virtual Memory is Obsolete. 2009 IEEE International Conference on Information Reuse & Integration. CiteSeerX 10.1.1.154.2023. doi:10.1109/IRI.2009.5211562.
- ^ – Base Definitions Reference, The Single UNIX Specification, Version 5 from The Open Group
- ^ – System Interfaces Reference, The Single UNIX Specification, Version 5 from The Open Group
- ^ – Linux Library Functions Manual
- ^ – Darwin and macOS Library Functions Manual
- ^ – Solaris 11.4 Basic Library Functions Reference Manual
- ^ – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group
- ^ – Linux User Commands Manual
- ^ – Darwin and macOS General Commands Manual
- ^ "GetSystemInfo function". Microsoft. 2021-10-13.
- ^ "SYSTEM_INFO structure". Microsoft. 2022-09-23.
- ^ "Hugepages - Debian Wiki". Wiki.debian.org. 2011-06-21. Retrieved 2014-02-06.
- ^ a b "Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3 (3A, 3B, 3C & 3D): System Programming Guide" (PDF). December 2016. p. 4-2.
- ^ a b "Documentation/vm/hugetlbpage.txt". Linux kernel documentation. kernel.org. Retrieved 2014-02-06.
- ^ "Intel Itanium Architecture Software Developer's Manual Volume 2: System Architecture" (PDF). May 2010. p. 2:58.
- ^ IBM Power Systems Performance Guide: Implementing and Optimizing. IBM Redbooks. February 2013. ISBN 978-0-7384-3766-8. Retrieved 2014-03-17.
- ^ "The SPARC Architecture Manual, Version 8". 1992. p. 249.
- ^ "UltraSPARC Architecture 2007" (PDF). 2010-09-27. p. 427.
- ^ "ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition". Arm. 2014-05-20. p. B3-1324.
- ^ "Translation granule". Learn the architecture - AArch64 memory management. Arm. Retrieved 2022-08-19.
- ^ a b Waterman, Andrew; Asanović, Krste; Hauser, John (2021). The RISC-V Instruction Set Manual Volume II: Privileged Architecture (PDF). pp. 79–87.
- ^ "The Intel Xeon 5670: Six Improved Cores". AnandTech. Archived from the original on 2010-03-31. Retrieved 2012-11-03.
- ^ "General Purpose Operating System Support for Multiple Page Sizes" (PDF). static.usenix.org. Retrieved 2012-11-02.
- ^ Navarro, Juan; Iyer, Sitararn; Druschel, Peter; Cox, Alan (December 2002). Practical, Transparent Operating System Support for Superpages (PDF). 5th Usenix Symposium on Operating Systems Design and Implementation.
- ^ "Pages - dankwiki, the wiki of nick black". Retrieved 2023-06-17.
- ^ a b Corbet, Jonathan. "Transparent huge pages in 2.6.38". LWN. Retrieved 2011-03-02.
- ^ "Large-Page Support". Microsoft Docs. 2018-05-08.
- ^ "AGP program may hang when using page size extension on Athlon processor". Support.microsoft.com. 2007-01-27. Retrieved 2012-11-03.
- ^ "Supporting Multiple Page Sizes in the Solaris Operating System" (PDF). Sun BluePrints Online. Sun Microsystems. Archived from the original (PDF) on 2006-03-12. Retrieved 2008-01-19.
- ^ "Supporting Multiple Page Sizes in the Solaris Operating System Appendix" (PDF). Sun BluePrints Online. Sun Microsystems. Archived from the original (PDF) on 2007-01-01. Retrieved 2008-01-19.
- ^ a b "FreeBSD 7.2-RELEASE Release Notes". FreeBSD Foundation. Retrieved 2009-05-03.
- ^ "2.3.1 Read-Only Memory / 2.3.2 Program Random Access Memory". MCS-4 Assembly Language Programming Manual - The INTELLEC 4 Microcomputer System Programming Manual (PDF) (Preliminary ed.). Santa Clara, California, USA: Intel Corporation. December 1973. pp. 2-3 – 2-4. MCS-030-1273-1. Archived (PDF) from the original on 2020-03-01. Retrieved 2020-03-02.
[…] ROM is further divided into pages, each of which contains 256 bytes. Thus locations 0 through 255 comprise page 0 of ROM, location 256 through 511 comprise page 1 and so on. […] Program random access memory (RAM) is organized exactly like ROM. […]
- ^ a b "1. Introduction: Segment Alignment". 8086 Family Utilities - User's Guide for 8080/8085-Based Development Systems (PDF). Revision E (A620/5821 6K DD ed.). Santa Clara, California, USA: Intel Corporation. May 1982 [1980, 1978]. p. 1-6. Order Number: 9800639-04. Archived (PDF) from the original on 2020-02-29. Retrieved 2020-02-29.
Further reading
[edit]- Dandamudi, Sivarama P. (2003). Fundamentals of Computer Organization and Design (1st ed.). Springer. pp. 740–741. ISBN 0-387-95211-X.
Page (computer memory)
View on GrokipediaBasic Concepts
Definition and Purpose
In paging-based memory management schemes used in modern operating systems, a page is defined as a fixed-size block of contiguous memory into which both physical and virtual address spaces are divided. This division allows the operating system to treat memory as a collection of uniform units, facilitating efficient handling of processes that may exceed available physical RAM.[5][9][10] The primary purpose of pages is to enable virtual memory systems, which provide processes with the illusion of a large, contiguous address space despite physical memory constraints. By dividing memory into pages, the operating system can allocate non-contiguous physical frames to a process's virtual pages, abstracting away the limitations of RAM and allowing efficient swapping of inactive pages to secondary storage like disk. This approach supports demand paging, where only actively used pages are loaded into memory, thereby optimizing resource utilization and enabling multitasking without requiring contiguous allocation.[5][9][10] Key characteristics of pages include their role as the fundamental unit for memory allocation, protection mechanisms (such as read/write/execute permissions), and data transfer operations between RAM and secondary storage. Pages are typically 4 KB in size on common architectures like x86, though this can vary, and they ensure that memory management operations occur in discrete, predictable chunks to minimize fragmentation and simplify hardware support via mechanisms like the memory management unit (MMU).[5][9][10] For example, in a 32-bit virtual address space, a virtual address is split into a page number (the higher-order bits identifying which page) and an offset (the lower-order bits specifying the location within that page), allowing the operating system to map the page number to a physical frame via a page table.[9][5]Role in Virtual Memory Systems
In virtual memory systems, paging serves as a core mechanism for managing memory by dividing the virtual address space of a process into fixed-size units known as pages, while physical memory is similarly partitioned into page frames of the same size. These pages and frames enable a flexible mapping that allows the operating system to allocate non-contiguous physical memory to processes without the fragmentation issues associated with variable-sized allocations. The mappings between virtual pages and physical frames are stored in per-process page tables, which the operating system maintains to provide each process with the illusion of a large, contiguous, and private address space. This approach originated in early systems like the Atlas computer, where it was implemented as a one-level storage system to automate transfers between fast core memory and slower drum storage.[5][11] Address translation in paging relies on decomposing a virtual address into two components: the virtual page number (VPN), which identifies the page within the virtual address space, and the offset, which specifies the byte position within that page. The MMU, a hardware component integrated into the CPU, uses the VPN to index the process's page table and retrieve the corresponding physical frame number (PFN); the offset is then appended to the PFN to form the physical address. This hardware-accelerated translation ensures efficient access while enforcing isolation between processes, as each operates within its own virtual address space. The MMU also verifies the validity of the mapping before proceeding, raising an exception if the page is not present or accessible.[12] Paging provides key benefits to operating systems through techniques like demand paging, where pages are loaded into physical memory only upon first access, rather than pre-loading the entire address space. This is facilitated by a present bit in page table entries (PTEs) that indicates whether a page resides in memory; absent pages trigger a page fault handled by the OS to fetch the data from secondary storage. Additionally, copy-on-write optimization supports efficient process creation, such as during forking, by initially sharing pages between parent and child processes with read-only permissions; a private copy is created only when one process attempts to modify a page, minimizing unnecessary duplication. These mechanisms enhance resource utilization by supporting sparse address spaces and reducing memory overhead for common operations.[5][13] A primary advantage of paging is its support for memory protection and sharing at the granularity of individual pages. Each PTE includes permission bits that specify access rights, such as read, write, or execute, allowing the OS to enforce fine-grained controls and prevent unauthorized access or modifications. For instance, the MMU checks these bits during translation and signals a fault for violations, enabling isolation of processes while permitting safe sharing of read-only pages, such as code segments or shared libraries, across multiple processes that map to the same physical frame. This per-page control promotes security and efficiency in multiprogrammed environments without requiring complex segment descriptors.[13]Page Size Fundamentals
Common Page Sizes Across Systems
The most common page size in modern computing systems is 4 KB, serving as the standard base size for architectures such as x86 and ARM, as well as operating systems like Linux and Windows on these platforms.[14][15] This size balances memory management efficiency with hardware constraints, originating from the memory management unit (MMU) designs in these processors.[16] For instance, the x86 architecture fixes 4 KB as its granule size, while ARM supports it as one of several options but defaults to it in many Linux distributions on ARM64.[8][17] Operating system implementations often align with their primary hardware targets. Linux defaults to 4 KB pages on x86 systems, enabling fine-grained virtual memory mapping.[18] Windows similarly uses 4 KB as the standard page size across x86 and x86-64 processors, with support for larger pages only in specific configurations.[15] In contrast, macOS on Intel-based systems employs 4 KB pages, while Apple Silicon (ARM-based) macOS and iOS since the 64-bit transition (A7 and later) expose 16 KB pages to user space for improved performance in memory-intensive tasks.[19] Hardware architecture significantly influences base page sizes. The RISC-V specification mandates a minimum of 4 KB for its Sv32, Sv39, and Sv48 virtual memory modes, ensuring compatibility with standard MMU implementations.[20] PowerPC systems, particularly in 64-bit variants like ppc64, commonly use 64 KB as the default page size in Linux distributions such as Fedora and Debian, leveraging the architecture's support for larger granules to reduce translation overhead.[21] While 4 KB remains the default in most general-purpose systems, larger "huge" pages are supported as non-default variations for optimizing specific workloads, such as databases or virtualization. Common huge page sizes include 2 MB and 1 GB on x86-64 Linux and Windows, with ARM and RISC-V offering analogous superpages like 2 MB or 32 MB depending on the base granule.[22][23] These are typically enabled explicitly rather than as system defaults.Retrieving Page Size Programmatically
In Unix-like operating systems adhering to the POSIX standard, the page size can be retrieved at runtime using thesysconf function with the _SC_PAGESIZE parameter, which returns the size of a page in bytes as a long integer.[24] This approach is preferred over the older getpagesize syscall, which was deprecated in POSIX.1-2001 and removed in POSIX.1-2008, though it remains available in many implementations for backward compatibility and is equivalent to sysconf(_SC_PAGESIZE).[25] The following C code snippet demonstrates the usage:
#include <unistd.h>
#include <stdio.h>
int main() {
long page_size = sysconf(_SC_PAGESIZE);
if (page_size == -1) {
perror("sysconf failed");
return 1;
}
printf("Page size: %ld bytes\n", page_size);
return 0;
}
#include <unistd.h>
#include <stdio.h>
int main() {
long page_size = sysconf(_SC_PAGESIZE);
if (page_size == -1) {
perror("sysconf failed");
return 1;
}
printf("Page size: %ld bytes\n", page_size);
return 0;
}
GetSystemInfo API function from the Windows API, which populates a SYSTEM_INFO structure where the dwPageSize member holds the page size in bytes as a DWORD.[27] This call also provides additional system details like processor architecture but focuses here on the page size for memory management purposes.[28] The example below in C++ (compatible with C via appropriate includes) illustrates this:
#include <windows.h>
#include <iostream>
int main() {
SYSTEM_INFO si;
GetSystemInfo(&si);
std::cout << "Page size: " << si.dwPageSize << " bytes" << std::endl;
return 0;
}
#include <windows.h>
#include <iostream>
int main() {
SYSTEM_INFO si;
GetSystemInfo(&si);
std::cout << "Page size: " << si.dwPageSize << " bytes" << std::endl;
return 0;
}
sysconf on POSIX systems or GetSystemInfo on Windows, potentially wrapped in a library or macro for portability.[24] While the C standard library (<stdlib.h>) does not provide a direct query, headers like <unistd.h> on Unix-like systems facilitate this, and third-party libraries can abstract the differences for broader compatibility.[26]
These methods typically retrieve the system's default page size, assuming a uniform configuration; in environments supporting multiple page sizes, such as Linux with huge pages enabled, additional queries are needed, for instance, by parsing /proc/<pid>/smaps to inspect per-mapping page sizes like KernelPageSize or AnonymousHugePageSize.[29] This limitation requires developers to handle variability explicitly for advanced memory usage.
Support for Multiple Page Sizes
Modern operating systems support multiple page sizes to optimize memory management, allowing the use of superpages or huge pages—typically 2 MB or 1 GB—alongside the standard 4 KB base pages for improved efficiency in handling large memory regions.[23][30] This approach reduces the number of page table entries required for large contiguous memory allocations, thereby minimizing translation lookaside buffer (TLB) pressure in scenarios with extensive memory access patterns.[31] In Linux, support for multiple page sizes is implemented through two primary mechanisms: the HugeTLB filesystem for static huge pages and Transparent Huge Pages (THP) for dynamic allocation. HugeTLB enables explicit reservation of huge pages via kernel parameters such as/proc/sys/vm/nr_hugepages, which specifies the number of 2 MB or 1 GB pages to preallocate at boot or runtime, ensuring availability for applications without fragmentation risks if set early.[23] THP, introduced to automate huge page usage, promotes contiguous 4 KB pages to 2 MB (or larger with multi-size THP) for anonymous memory and tmpfs/shmem mappings, operating in modes like "always" for system-wide enabling or "madvise" for application-specific hints.[30] Userspace applications can allocate huge pages using the mmap system call with the MAP_HUGETLB flag, specifying the desired size via MAP_HUGETLB | (size << MAP_HUGE_SHIFT).[23]
Windows provides large page support primarily for 64-bit server applications, allowing allocations of 2 MB pages (or larger, depending on hardware) alongside standard pages to enhance performance in memory-intensive workloads.[32] To use large pages, processes must first acquire the SeLockMemoryPrivilege privilege using AdjustTokenPrivileges, then allocate memory via VirtualAlloc with the MEM_LARGE_PAGES flag, ensuring the allocation size and alignment are multiples of the minimum large page size obtained from GetLargePageMinimum. This non-pageable memory is locked in physical RAM, avoiding paging overhead but requiring early allocation to mitigate fragmentation.[32]
These mechanisms are particularly beneficial in use cases involving databases and virtual machines, where large memory footprints benefit from fewer TLB misses—for instance, Oracle Database leverages HugeTLB pages to manage large shared global areas (SGAs) more efficiently, reducing virtual memory overhead.[33] In virtualized environments, such as those using KVM on Linux, huge pages back guest VM memory to accelerate address translation and lower latency for workloads like PostgreSQL servers handling terabyte-scale data.[34][35]
