Page (computer memory)

"Page size" redirects here. For information on paper, see paper size.

A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described by a single entry in the page table. It is the smallest unit of data for memory management in a virtual memory operating system.

Virtual memory allows a page that does not currently reside in main memory to be addressed and used. If a program tries to access a location in such a page, an exception called a page fault is generated. The hardware or operating system is notified and loads the required page from the auxiliary store (hard disk) automatically. A program addressing the memory has no knowledge of a page fault or a process following it. Thus a program can address more (virtual) RAM than physically exists in the computer. Virtual memory is a scheme that gives users the illusion of working with a large block of contiguous memory space (perhaps even larger than real memory), when in actuality most of their work is on auxiliary storage (disk). Fixed-size blocks (pages) or variable-size blocks of the job are read into main memory as needed.

A transfer of pages between main memory and an auxiliary store, such as a hard disk drive, is referred to as paging or swapping.[1]

Page size trade-off

Page size is usually determined by processor architecture. Traditionally, pages in a system had uniform size, for example 4096 bytes. However, processor designs often allow two or more, sometimes simultaneous, page sizes due to the benefits and penalties. There are several points that can factor into choosing the best page size.[2]

Page size versus page table size
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.
Page size versus TLB usage
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 page tables must be searched manually (either in hardware 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 the costly TLB misses.
Internal fragmentation of pages
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 increase the potential for wasted memory this way, as more potentially unused portions of memory are loaded into 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 KiB. If a process allocates 1025 KiB, two pages must be used, resulting in 1023 KiB of unused space (where one page fully consumes 1024 KiB and the other only 1 KiB).
Page size versus disk access
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.

Determining the page size in a program

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 and POSIX-based operating systems

Unix and POSIX-based systems may use the system function sysconf(),[3][4][5][6][7] 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 systems the command line utility getconf can be used.[8][9][10] For example, getconf PAGESIZE will return the page size in bytes.

Windows-based operating systems

Win32-based operating systems, such as those in the Windows 9x and Windows NT families, may use the system function GetSystemInfo()[11][12] 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;
}

Huge pages

Huge page size depends on processor architecture, processor type, and operating (addressing) mode. The operating system selects one from the sizes supported by the architecture. Note that not all processors implement all defined Huge/Large page sizes.

Page sizes among architectures[13]
Architecture Page size Huge page size Large page size
32-bit x86 4 KiB 4 MiB (2 MiB in PAE mode)[14]
x86-64 4 KiB 2 MiB 1 GiB (only when the CPU has PDPE1GiB flag)
IA-64 (Itanium) 4 KiB 8 KiB, 64 KiB, 256 KiB, 1 MiB, 4 MiB, 16 MiB, 256 MiB[14] -
Power Architecture[15] 4 KiB 64 KiB, 16 MiB 16 G
SPARC 8 KiB - 64 KiB, 4 MiB, 256 MiB, 2 GiB
ARMv7 4 KiB 1 MiB, 16 MiB (defined by a particular implementation) -

Some instruction set architectures can support multiple page sizes, including pages significantly larger than the standard page size. Starting with the Pentium Pro, 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[16] 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. This support for huge pages (known as superpages in FreeBSD, and large pages in Microsoft Windows terminology) allows for "the best of both worlds", reducing the pressure on the TLB cache (sometimes increasing speed by as much as 15%, depending on the application and the allocation size) for large allocations while still keeping memory usage at a reasonable level for small allocations.

Huge pages, despite being available in the processors used in most contemporary personal computers, are not in common use except in large servers and computational clusters. 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.[17]

Linux has supported huge pages on several architectures since the 2.6 series via the hugetlbfs filesystem[18] and without hugetlbfs since 2.6.38.[19] Windows Server 2003 (SP1 and newer), Windows Vista and Windows Server 2008 support huge pages under the name of large pages. Windows 2000 and Windows XP support large pages internally,[20] but do not expose them to applications. Solaris beginning with version 9 supports large pages on SPARC and x86.[21][22] FreeBSD 7.2-RELEASE features superpages.[23] 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.[24] 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.[23]

See also

References

  1. Belzer, Jack; Holzman, Albert G.; Kent, Allen, eds. (1981), "Virtual memory systems", Encyclopedia of computer science and technology 14, CRC Press, p. 32, ISBN 0-8247-2214-0
  2. "Using 4KB Page Size for Virtual Memory is Obsolete". IEEE. 2009-08-10. CiteSeerX: 10.1.1.154.2023.
  3. limits.h  Base Definitions Reference, The Single UNIX® Specification, Issue 7 from The Open Group
  4. sysconf  System Interfaces Reference, The Single UNIX® Specification, Issue 7 from The Open Group
  5. sysconf(3)  Linux Library Functions Manual
  6. sysconf(3)  Darwin and OS X Library Functions Manual
  7. sysconf(3C)  Solaris 10 Basic Library Functions Reference Manual
  8. getconf  Commands & Utilities Reference, The Single UNIX® Specification, Issue 7 from The Open Group
  9. getconf(1)  Linux User Commands Manual
  10. getconf(1)  Darwin and OS X General Commands Manual
  11. "GetSystemInfo function". Microsoft.
  12. "SYSTEM_INFO structure". Microsoft.
  13. "Hugepages - Debian Wiki". Wiki.debian.org. 2011-06-21. Retrieved 2014-02-06.
  14. 1 2 "Documentation/vm/hugetlbpage.txt". Linux kernel documentation. kernel.org. Retrieved 2014-02-06.
  15. IBM Power Systems Performance Guide: Implementing and Optimizing. IBM Redbooks. February 2013. Retrieved 2014-03-17.
  16. "The Intel Xeon 5670: Six Improved Cores". AnandTech. Retrieved 2012-11-03.
  17. "General Purpose Operating System Support for Multiple Page Sizes" (PDF). static.usenix.org. Retrieved 2012-11-02.
  18. "Pages - dankwiki, the wiki of nick black". Dank.qemfd.net. Retrieved 2012-11-03.
  19. "Transparent huge pages in 2.6.38". Lwn.net. Retrieved 2012-11-03.
  20. "AGP program may hang when using page size extension on Athlon processor". Support.microsoft.com. 2007-01-27. Retrieved 2012-11-03.
  21. "Supporting Multiple Page Sizes in the Solaris Operating System" (PDF). Sun BluePrints Online. Sun Microsystems. Retrieved 2008-01-19.
  22. "Supporting Multiple Page Sizes in the Solaris Operating System Appendix" (PDF). Sun BluePrints Online. Sun Microsystems. Retrieved 2008-01-19.
  23. 1 2 "FreeBSD 7.2-RELEASE Release Notes". FreeBSD Foundation. Retrieved 2009-05-03.
  24. Corbet, Jonathan. "Transparent huge pages in 2.6.38". LWN. Retrieved 2011-03-02.

Further reading

This article is issued from Wikipedia - version of the Friday, February 26, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.