问题
Is it possible to change the virtual memory page size? I'm asking this because in the X86_64 part of the MMU article on wikipedia, it talks about different page sizes. If the page size can indeed be changed, how it is changed?
回答1:
On x86_64 you can explicitly request 2 MiB pages instead of the usual 4 KiB pages with the help of hugetlbfs. On modern kernels with transparent huge page support a small pages can automagically concatenated to huge pages in the background, given that the memory fragmentation isn't to big and enough memory is still free.
回答2:
As far as I know, no operating system allows the applications to request a page size. The x86_64 paging system provides the ability to mix pages of different sizes, but this is generally only used if a large amount of memory is allocated at once.
On x86_64 (and x86), virtual addresses are mapped to physical addresses through a series of page tables. Each table provides a certain number of bits for the physical virtual address. x86_64 currently can use up to 4 tables for each mapping, each providing 9 virtual address bits, and the low 12 bits specify the offset within the page. The first 3 tables each point to the physical address of the next table, and the last points to the physical address of the actual page.
| PML4T entry |-+
V
+-| PDPT entry |
V
| PDT entry |-+
V
| PT entry |-> Physical address (4kB page)
However, the second and third table entries also contain a bit, which if set indicates there are no further tables and that entry provides the physical address. When this occurs, the bits which would be provided by the other tables are moved into the physical page offset, multiplying the page size by 512 for each table removed.
| PML4T entry |-+
V
+-| PDPT entry |
V
| PDT entry (PS=1) | -> Physical address (2MB page)
By changing the number of tables used to map to a given virtual address, the operating system can create pages of 4kB (4 tables), 2MB (3 tables), or 1GB (2 tables). Since the bit is provided in each table entry, different page sizes can be mixed, so for example a 2MB page could be followed by a 4kB page.
回答3:
Yes and no.
The page size is fixed. But the size of a virtual memory region is not (on x86 architecture). When you create a virtual memory region that's not equal in size to a page, it's called a segment.
回答4:
Following are some interesting links on this topic...
http://linuxgazette.net/155/krishnakumar.html
http://unixfoo.blogspot.com/2007/10/hugepages.html
http://forums.opensuse.org/english/get-technical-help-here/install-boot-login/437078-changing-pagesize-kernel.html
http://forums.opensuse.org/english/get-technical-help-here/install-boot-login/437078-changing-pagesize-kernel.html
回答5:
Windows: http://windows.microsoft.com/en-US/windows-vista/Change-the-size-of-virtual-memory
Linux:
In /usr/src/linux/include/asm-generic/page.h you can find the following lines:
/* PAGE_SHIFT determines the page size */
define PAGE_SHIFT 12
The below article explains in the comments section.
http://www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/
The /proc/sys/vm/swappiness parameter, which changes the balance between swapping out runtime memory, as opposed to dropping pages from the system page cache.
来源:https://stackoverflow.com/questions/10235990/is-it-possible-to-change-virtual-memory-page-size