A method for translating a virtual memory address into a physical memory address includes parsing the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset. The page directory entry offset is combined with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field and a page table block base address. The page table entry offset and the page table block base address are combined to locate a page table entry, wherein the page table entry includes a physical memory page base address and a size of the physical memory page is indicated by the native page table size field. The access offset and the physical memory page base address are combined to determine the physical memory address.
|
8. A method for determining a number of page table entries needed to address a given virtual address space, comprising:
determining a page size of each page table entry pointed to by a page directory entry based upon a page directory entry native page table size;
determining a page directory entry address space pointed to; and
determining the number of page table entries by dividing the page directory entry address space pointed to by the page size of each page table entry, wherein each of the page table entries includes a base address of a physical memory page and a fragment field, wherein the size of the physical memory page is indicated by a native page table size field of the page directory entry and a size of the fragment field is larger than the native page table size field.
1. A method for translating a virtual memory address into a physical memory address, comprising:
parsing the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset;
combining the page directory entry offset with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field and a base address of a page table block, wherein the native page table size field indicates a size of a corresponding physical memory page;
combining the page table entry offset and the base address of the page table block to locate a page table entry, wherein the page table entry includes a base address of a physical memory page and a fragment field, wherein the size of the physical memory page is indicated by the native page table size field and a size of the fragment field is larger than the native page table size field; and
combining the access offset and the base address of the physical memory page based on the fragment field to determine the physical memory address.
5. A processor configured to translate a virtual memory address into a physical memory address, comprising:
circuitry configured to parse the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset; and
circuitry configured to:
combine the page directory entry offset with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field and a base address of a page table block, wherein the native page table size field indicates a size of a corresponding physical memory page;
combine the page table entry offset and the base address of the page table block to locate a page table entry, wherein the page table entry includes a base address of a physical memory page and a fragment field, wherein the size of the physical memory page is indicated by the native page table size field and a size of the fragment field is larger than the native page table size field; and
combine the access offset and the base address of the physical memory page based on the fragment field to determine the physical memory address.
6. A non-transitory computer-readable storage medium storing a set of instructions for execution by a general purpose computer to translate a virtual memory address into a physical memory address, the set of instructions comprising:
a parsing code segment for parsing the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset;
a first combining code segment for combining the page directory entry offset with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field, a fragment field and a base address of a page table block, wherein the native page table size field indicates a size of a corresponding physical memory page and a size of the fragment field is larger than the native page table size field;
a second combining code segment for combining the page table entry offset and the base address of the page table block to locate a second page table entry based on the fragment field, wherein the second page table entry includes a second base address of a second physical memory page and a second fragment field, wherein the size of the second physical memory page is indicated by the native page table size field; and
a third combining code segment for combining the access offset and the second base address of the second physical memory page to determine the physical memory address.
2. The method according to
3. The method according to
4. The method according to
7. The non-transitory computer-readable storage medium of
9. The method according to
10. The method according to
|
The present invention is generally directed to virtual memory, and in particular, to providing flexible page sizes for virtual memory.
Virtual memory may be used when the physical memory of a computer system is not large enough to hold all of the desired content. A virtual memory address is used to access the physical memory location where the content is stored. The physical memory location may be identified by a physical memory page (by specifying a base address of the physical memory page) and an offset within the physical memory page. The relationship between the virtual memory address and the corresponding physical memory address is stored in a page table.
The virtual memory page-translation mechanism enables system software to create separate address spaces for each process or application. These address spaces are known as virtual address spaces. The system software uses the paging mechanism to selectively map individual pages of physical memory into the virtual address space using a set of hierarchical address-translation tables known collectively as page tables. Virtual memory may be implemented with any processor, including, but not limited to, a central processing unit (CPU), a graphics processing unit (GPU), and an accelerated processing unit (APU).
The page table footprint (size of the page table) to map a large memory space can become significant in size. One exemplary system contains 4 KB, 64 KB, and potentially larger page sizes. With the current page table format, a page table footprint is created that assumes that all page sizes are 4 KB. For example, a non-sparse 16 GB memory mapped using 4 KB pages requires 32 MB of space to store the page table. But if all the pages were 64 KB pages and if 64 KB page table entries (PTEs) could be stored natively in the page table, the page table size could be reduced to 8 MB.
Because the virtual memory space is larger than the physical memory of a system, some of the virtual memory might not be mapped (referred to discontiguous regions of mapped memory). Using a multiple-layer page table allows a smaller page table footprint by not mapping some areas of the virtual memory. In one example implementation, the x86 (CPU) processor page table format allows only three sizes of page tables: 4 KB, 2 MB, and 1 GB. To support the 2 MB and 1 GB formats, there is a bit indicating that the next level is not a page table block, but rather another PTE. In contrast, a flat page table means that the entire virtual memory address range would need to be mapped.
The table may be cached, for example, in a translation look-aside buffer (TLB). For caching, it is better to use larger pages. One example GPU virtual memory scheme uses fragments (which may be larger or smaller than a full page in size), which addresses the caching problem (by using larger page sizes), but not the page table footprint problem.
A method for translating a virtual memory address into a physical memory address includes parsing the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset. The page directory entry offset is combined with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field and a page table block base address. The page table entry offset and the page table block base address are combined to locate a page table entry, wherein the page table entry includes a physical memory page base address and a size of the physical memory page is indicated by the native page table size field. The access offset and the physical memory page base address are combined to determine the physical memory address.
A processor configured to translate a virtual memory address into a physical memory address includes circuitry configured to parse the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset. The processor further includes circuitry configured to: combine the page directory entry offset with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field and a base address of a page table block; combine the page table entry offset and the base address of the page table block to locate a page table entry, wherein the page table entry includes a base address of a physical memory page and a size of the physical memory page is indicated by the native page table size field; and combine the access offset and the base address of the physical memory page to determine the physical memory address.
A non-transitory computer-readable storage medium storing a set of instructions for execution by a general purpose computer to translate a virtual memory address into a physical memory address, the set of instructions including a parsing code segment and three combining code segments. The parsing code segment parses the virtual memory address into a page directory entry offset, a page table entry offset, and an access offset. The first combining code segment combines the page directory entry offset with a virtual memory base address to locate a page directory entry in a page directory block, wherein the page directory entry includes a native page table size field and a base address of a page table block. The second combining code segment combines the page table entry offset and the base address of the page table block to locate a page table entry, wherein the page table entry includes a base address of a physical memory page and a size of the physical memory page is indicated by the native page table size field. The third combining code segment combines the access offset and the base address of the physical memory page to determine the physical memory address.
A method for determining a number of page table entries needed to address a given virtual address space includes determining a page size of each page table entry pointed to by a page directory entry; determining a page directory entry address space pointed to; and determining the number of page table entries by dividing the page directory entry address space pointed to by the page size of each page table entry.
A page directory entry for use in translating a virtual memory address into a physical memory address includes a native page table size field, indicating a size of a corresponding physical memory page; and a base address of the physical memory page.
A more detailed understanding may be had from the following description, given by way of example in conjunction with the accompanying drawings, wherein:
To optimize the footprint of the page table, it would be beneficial to store each page in its native page size. Storing PTEs in their native sizes allows for hardware prefetch optimizations to read in multiple adjacent pages, which increases performance.
The processor 102 may include a central processing unit (CPU), a graphics processing unit (GPU), a CPU and GPU located on the same die, or one or more processor cores, wherein each processor core may be a CPU or a GPU. The memory 104 may be located on the same die as the processor 102, or may be located separately from the processor 102. The memory 104 may include a volatile or non-volatile memory, for example, random access memory (RAM), dynamic RAM, or a cache.
The storage 106 may include a fixed or removable storage, for example, a hard disk drive, a solid state drive, an optical disk, or a flash drive. The input devices 108 may include a keyboard, a keypad, a touch screen, a touch pad, a detector, a microphone, an accelerometer, a gyroscope, a biometric scanner, or a network connection (e.g., a wireless local area network card for transmission and/or reception of wireless IEEE 802 signals). The output devices 110 may include a display, a speaker, a printer, a haptic feedback device, one or more lights, an antenna, or a network connection (e.g., a wireless local area network card for transmission and/or reception of wireless IEEE 802 signals).
The input driver 112 communicates with the processor 102 and the input devices 108, and permits the processor 102 to receive input from the input devices 108. The output driver 114 communicates with the processor 102 and the output devices 110, and permits the processor 102 to send output to the output devices 110. It is noted that the input driver 112 and the output driver 114 are optional components, and that the device 100 will operate in the same manner if the input driver 112 and the output driver 114 are not present.
The phrase “walking the page table” refers to the process of finding a physical address from a virtual address. The virtual address includes a page directory entry (PDE) offset, a page table entry (PTE) offset, and an access offset. The PDE offset is an offset into a page directory block (PDB), which is used to locate the PDE. The PDE contains the base address of a page table block (PTB). The PTE offset is an offset into the PTB, and combined with the base address of the PTB, is used to locate the PTE. The PTE contains the base address of the physical memory page. The access offset is the offset within the physical memory page, and combined with the base address of the physical memory page, gives the physical address.
A PDB 210 contains all of the PDEs. A virtual memory identifier (VMID) base address 212 of the PDB 210 is already known to the system. The PDE offset 204 combined with the base address 212 of the PDB 210 is used to locate the PDE 214. The PDE 214 contains a base address 222 of a PTB 220. The PTE offset 206 from the virtual address 202 is combined with the base address 222 of the PTB 220 to find the PTE 224. The PTE 224 contains a base address 232 of a physical memory page in a system memory 230 where the information is located. The access offset 208 from the virtual address 202 is combined with the base address 232 of the physical memory page to find a memory location 234 where the information is located.
Using flexible page sizes for virtual memory allows the page table footprint to be reduced. The page table is constructed so that only one entry is required for each page of mapping. The flexible PDE format described below includes a field indicating the native size of the PTEs contained in the PTB. Different PTBs can contain pages of different native sizes. For example, one PTB can point to 4 KB physical memory pages, and a separate PTB can point to 2 MB physical memory pages. This PDE format does not change the page table walking mechanism, but only changes the math of calculating the addresses. This format is easy to implement and is flexible in the way the pages are set up.
Storing the pages in their native sizes allows the hardware to read in multiple adjacent PTEs with a single memory read and have those PTEs point to different areas of memory. Currently, if there is a large fragment, adjacent PTEs are identical and most of the data in the memory read used to walk the page tables is discarded.
Each PDE stores a pointer to the physical base address of a PTB where the PTEs can be found, and describes the native page size of the PTEs in the PTB. Every PTB maps a constant size of memory that is set once (at boot time), and is referred to as the Native Page Table Size. Programming the PTB to point to a larger memory size allows native PTE sizes to be larger than 2 MB and also reduces the number of PDEs necessary to map the memory.
In a GPU implementation, there is a single PDB per running application. The base address of each PDB is defined by a 4-bit VMID field, and up to 16 PDBs can be defined per virtual memory layer. Bits 39:21 of each 64-bit virtual memory address specify the location of a PDE in a PDB block. Therefore, each PDB could have up to 219 (512K) 64-bit PDE entries, although the normal case would to be have far fewer PDEs in each block.
The valid bit field 302 is used to indicate whether the PDE is valid. For example, if V=1, then PDE is valid, and if V=0, then the PDE is not valid. The physical base address of PTB field 306 points to the physical base address of a PTB (the V bit 302 is ignored for addressing and is considered to be 0). Bits 5:0 are all considered as zeros for the addressing, thus the address granularity is 64 bytes. Because each PTE is 64 bits wide (8 bytes), this field can point to every eighth PTE.
The physical base address of PTB field 306 is large enough (in one implementation, this field uses bits 39:6) to address page sizes larger than 4 KB, so the address space does not need to be 4 KB-aligned, like in x86-type systems. This permits multiple PTBs on a single page, such that multiple PTEs could point to different parts of the same page. This means that a page can be suballocated, and each PTB does not have to be 4 KB-aligned (like in an x86-type system). Without the 4 KB-aligned PTB, any size page can be accessed by using only a two-level page walking mechanism.
x86-type virtual memory systems use one bit to indicate whether the address is to another PTB or to the physical memory page itself, which may result in needing more than two levels of page walking to address certain page sizes. For example, because of the 4 KB alignment requirement, multiple levels are needed to address the 2 MB and 1 GB page sizes. By specifying the physical memory page size in the PDE, fewer PTEs are needed in the PTB, because each PTE points to a larger physical memory page.
For the Native Page Table Size field 310, 2 raised to the power of this field multiplied by 4 KB indicates the native address space for each of the component PTEs in the PTB pointed to by the PDE. For example, if the PDE Native Page Table Size=9, then the native address space, or page size, pointed to by a PTE is:
PTE adress space=2NativePageTableSize×4 KB=29×4 KB=512×4 KB=2 MB
If the Native Page Table Size=4, then the page size represented by a PTE would be 64 KB. If the Native Page Table Size=0, then the page size=4 KB (the legacy case).
The PTB contains 512 64-bit PTEs and occupies a 4 KB memory footprint. In the legacy case, a PTE points to a 4 KB memory page, such that all 512 PTEs in the PTB are needed to address a 2 MB memory space (512×4 KB=2 MB). With the flexible page size, this changes. For example, if the PDE Native Page Table Size field=4, each PTE points to a 64 KB page, such that only 32 PTEs of the 512 PTEs in the PTB are now required to address a 2 MB memory space (32×64 KB=2 MB). In this case, the 4 KB PTB can be shared by up to 16 different PDEs. If the PDE Native Page Table Size=9, each PTE points to a 2 MB memory space such that only one PTE of the 512 PTEs in the PTB is required to address a 2 MB memory space. In this case, the 4 KB PTB can be shared by up to 512 different PDEs. The result is that the memory footprint of the PTB can be reduced by specifying larger pages using the PDE Native Page Table Size field.
The fragment field 404 is a 4-bit field that supplies a directive to the page table unit about the size of the fragment in which the designated page lies. It is a power of 2, such that a value of 0 indicates a fragment size of one page or 4 KB, a value of 1 corresponds to a two page or 8 KB fragment, a value of 2 means a four page or 16 KB fragment, and so on. It is noted that the PTE fragment field value 404 must be larger than the PDE Native Page Table Size field 310. The PTE fragment size is not based on or relative to the PDE Native Page Table Size; it is treated as an absolute fragment size. The PDE Native Page Table Size represents the physical footprint of each PTE pointed to by that PDE, while the PTE fragment size represents the maximum logical address space shared by a collective of similar contiguous PTEs. In general, the following formula shows how the fragment field 404 relates to the size of the fragment:
Logical/Physical fragment size in bytes=2(12+fragment)
The 4 KB physical page base address field 406 is the physical base address of the memory page. The PTE format does not change, regardless of the page size. The 4 KB physical page base address field 406 has enough bits to address page sizes larger than 4 KB. The smallest page size supported is 4 KB. In one implementation, with 18 bits, this field can address 218×4 KB=1 TB of memory. This field is affected by the PDE Native Page Table Size field. For example, if the Native Page Table Size is 9, then the granularity of this field is 2 MB instead of 4 KB.
A PDB 510 contains all of the PDEs. A VMID base address 512 of the PDB 510 is already known to the system. The PDE offset 504 combined with the base address 512 of the PDB 510 is used to locate the PDE 514. The PDE 514 contains a base address 522 of a PTB 520. The PTE offset 506 from the virtual address 502 is combined with the base address 522 of the PTB 520 to find the PTE 524. The PTE 524 contains a base address 532 of a physical memory page in a system memory 530 where the information is located. The access offset 508 from the virtual address 502 is combined with the base address 532 of the physical memory page to find a memory location 534 where the information is located.
It is noted that the page table walking mechanism is the same in both
The PAGE_TABLE_BLOCK_SIZE register field is located in a separate configuration register and is used to determine how much address space is represented by a PDE. The PDE address space divided by the PTE page size for that PDE determines how many PTEs are required to represent all of the PDE address space.
The legacy meaning of the PAGE_TABLE_BLOCK_SIZE register field is that it indicates log2(number of 4 KB pages in a PTB). With the flexible page table size, the amount of address space pointed to by the PDE is log2(PDE_ADDRESS_SPACE/2 MB). This PDE address space is in power-of-two multiples of 2 MB (PDE_ADDRESS_SPACE=(2 MB×2PAGE_TABLE_BLOCK_SIZE)). The PTB is no longer a minimum 4 KB page worth of PTEs (at 8 bytes per PTE, that would have been a minimum of 512 PTEs). Instead, it is the number of PTEs with a given footprint indicated by the value of the PDE Native Page Table Size field required to represent the PDE address space indicated with the PAGE_TABLE_BLOCK_SIZE field.
The PAGE_TABLE_BLOCK_SIZE and PDE Native Page Table Size are independent, but they work together to define the number of PTEs necessary to represent the address space pointed to by the PDE:
Number of PTEs=(2 MB×2PAGE_TABLE_BLOCK_SIZE)/(4 KB×2PDE Native Page Table Size).
Because of the PDE address pointer alignment restriction, a minimum of eight PTEs must be in a page table block; however, all but the first may be unused.
First, determine the page size of each PTE pointed to by a PDE (step 702). For example, if the PDE Native Page Table Size=9, then the native address space, or page size, pointed to by a PTE is:
PTE address space=2Native Page Table Size×4 KB=29×4 KB=512×4 KB=2 MB
Next, determine the PDE address space pointed to (step 704). Multiply the PTE page size by 2PAGE_TABLE_BLOCK_SIZE, as follows (for this example of a 2 MB page size):
PDE address space pointed to=2 MB×2PAGE_TABLE_BLOCK_SIZE
For example, if the PAGE_TABLE_BLOCK_SIZE is 3:
PDE address space pointed to=2 MB×23=16 MB.
Then determine the number of PTEs=(2 MB×2PAGE_TABLE_BLOCK_SIZE)/(4 KB×2Native Page Table Size)=16 MB/2 MB=8 (step 706).
The result is that eight PTEs are required to represent the 16 MB address space. As previously mentioned, the granularity with which a PDE can address a physical PTE location is 64 bytes, so a PDE can only point to every eighth PTE. In this case, all eight PTEs are used to represent the 16 MB address space.
If, for example, the PAGE_TABLE_BLOCK_SIZE field=0, then the total address space represented by a PDE is 2 MB. If the PDE Native Page Table Size=9, each PTE still points to a 2 MB page, so only one PTE is needed to represent the 2 MB address space. Because the next PTE base address that the PDE can point to is 64 bytes away, the intervening seven PTEs cannot be used for anything and are thus wasted. If the number of PTEs required to fill the memory space represented by a PDE is less than eight, there will be reduced memory storage efficiency.
It should be understood that the methods described herein may be implemented in a CPU, a GPU, an APU, or any other processor that uses virtual memory and that many variations are possible based on the disclosure herein. Although features and elements are described above in particular combinations, each feature or element may be used alone without the other features and elements or in various combinations with or without other features and elements.
The methods provided may be implemented in a general purpose computer, a processor, or a processor core. Suitable processors include, by way of example, a general purpose processor, a special purpose processor, a conventional processor, a digital signal processor (DSP), a plurality of microprocessors, one or more microprocessors in association with a DSP core, a controller, a microcontroller, Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) circuits, any other type of integrated circuit (IC), and/or a state machine. Such processors may be manufactured by configuring a manufacturing process using the results of processed hardware description language (HDL) instructions and other intermediary data including netlists (such instructions capable of being stored on a computer readable media). The results of such processing may be maskworks that are then used in a semiconductor manufacturing process to manufacture a processor which implements aspects of the present invention.
The methods or flow charts provided herein may be implemented in a computer program, software, or firmware incorporated in a non-transitory computer-readable storage medium for execution by a general purpose computer or a processor. Examples of non-transitory computer-readable storage mediums include a read only memory (ROM), a random access memory (RAM), a register, cache memory, semiconductor memory devices, magnetic media such as internal hard disks and removable disks, magneto-optical media, and optical media such as CD-ROM disks, and digital versatile disks (DVDs).
Terry, Elene, Partap Singh Rana, Dhirendra
Patent | Priority | Assignee | Title |
10754795, | Nov 26 2018 | Qualcomm Incorporated | MMU assisted address sanitizer |
10908827, | Jan 02 2018 | Samsung Electronics Co., Ltd. | Semiconductor memory devices, and memory systems and electronic apparatuses having the same |
11860793, | Apr 27 2021 | Samsung Electronics Co., Ltd.; Industry-Academic Cooperation Foundation, Yonsei University | Controller, computing system including the same, and method of creating and searching page table entry for the same |
Patent | Priority | Assignee | Title |
4410941, | Dec 29 1980 | SAMSUNG ELECTRONICS CO , LTD | Computer having an indexed local ram to store previously translated virtual addresses |
5794228, | Apr 16 1993 | SYBASE, INC , A CORP OF DE | Database system with buffer manager providing per page native data compression and decompression |
5835963, | Sep 09 1994 | Hitachi, LTD | Processor with an addressable address translation buffer operative in associative and non-associative modes |
6079004, | Jan 27 1995 | International Business Machines Corporation | Method of indexing a TLB using a routing code in a virtual address |
6189074, | Mar 19 1997 | GLOBALFOUNDRIES Inc | Mechanism for storing system level attributes in a translation lookaside buffer |
6643759, | Mar 30 2001 | ARM Finance Overseas Limited | Mechanism to extend computer memory protection schemes |
6671791, | Aug 09 2000 | Advanced Micro Devices, Inc. | Processor including a translation unit for selectively translating virtual addresses of different sizes using a plurality of paging tables and mapping mechanisms |
6823433, | Nov 13 2001 | GLOBALFOUNDRIES U S INC | Memory management system and method for providing physical address based memory access security |
8041923, | Jan 11 2008 | International Business Machines Corporation | Load page table entry address instruction execution based on an address translation format control field |
20050086650, | |||
20060004983, | |||
20060149919, | |||
20090077306, | |||
20090172344, | |||
20100235831, | |||
20110029961, | |||
20110071813, | |||
20110087858, | |||
20130246709, | |||
20140019689, |
Executed on | Assignor | Assignee | Conveyance | Frame | Reel | Doc |
Nov 21 2012 | PARTAP SINGH RANA, DHIRENDRA | ATI Technologies ULC | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 029398 | /0757 | |
Nov 26 2012 | TERRY, ELENE | Advanced Micro Devices, INC | ASSIGNMENT OF ASSIGNORS INTEREST SEE DOCUMENT FOR DETAILS | 029398 | /0722 | |
Dec 04 2012 | Advanced Micro Devices, Inc. | (assignment on the face of the patent) | / | |||
Dec 04 2012 | ATI Technologies, ULC | (assignment on the face of the patent) | / |
Date | Maintenance Fee Events |
Aug 27 2020 | M1551: Payment of Maintenance Fee, 4th Year, Large Entity. |
Aug 28 2024 | M1552: Payment of Maintenance Fee, 8th Year, Large Entity. |
Date | Maintenance Schedule |
Mar 07 2020 | 4 years fee payment window open |
Sep 07 2020 | 6 months grace period start (w surcharge) |
Mar 07 2021 | patent expiry (for year 4) |
Mar 07 2023 | 2 years to revive unintentionally abandoned end. (for year 4) |
Mar 07 2024 | 8 years fee payment window open |
Sep 07 2024 | 6 months grace period start (w surcharge) |
Mar 07 2025 | patent expiry (for year 8) |
Mar 07 2027 | 2 years to revive unintentionally abandoned end. (for year 8) |
Mar 07 2028 | 12 years fee payment window open |
Sep 07 2028 | 6 months grace period start (w surcharge) |
Mar 07 2029 | patent expiry (for year 12) |
Mar 07 2031 | 2 years to revive unintentionally abandoned end. (for year 12) |