Page fault handling method, apparatus, and computer storage medium
By directly writing the physical address of the external page into the page table entry when memory is insufficient to provide enough free physical pages, the problem of low process efficiency caused by full memory and modified physical pages is solved, achieving more efficient access request response and process performance guarantee.
Patent Information
- Application Number
- PCT/CN2026/083832
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-05-09
- Filing Date
- 2026-03-17
- Publication Date
- 2026-11-12
AI Technical Summary
When a process accesses a virtual address, if the memory is full and the selected physical page has been modified, existing technologies require interrupting the process to perform swap-in and/or swap-out operations, which reduces the process's running efficiency.
When memory cannot provide enough free physical pages, the physical address of the external page is directly written into the page table entry corresponding to the virtual page, and the external page is accessed. This avoids waiting for the preparation of free physical pages and improves the efficiency of access request response.
By directly accessing external pages, the efficiency of process execution is improved, process interruption and waiting time for blank physical pages are avoided, and the system response speed is increased.
Smart Images

Figure CN2026083832_12112026_PF_FP_ABST
Abstract
Description
Page fault handling methods, devices, and computer storage media
[0001] This application claims priority to Chinese Patent Application No. 202510600980.7, filed on May 9, 2025, entitled “Page Fault Handling Method, Apparatus and Computer Storage Medium”, the entire contents of which are incorporated herein by reference. Technical Field
[0002] This invention relates to the field of computer technology, and more specifically to a page fault handling method, apparatus, and computer storage medium. Background Technology
[0003] When a process accesses a virtual address, if the CPU determines that the virtual address is not configured with a physical address, it will generate a page fault interrupt. Then, the CPU will enter kernel mode to check the fault type. If the fault type is a page fault and memory is full, a replacement algorithm needs to be used to select a physical page. If the physical page has been modified, a swap-out operation and / or swap-in operation is required. The swap-out operation is used to write the contents of the swapped-out physical page back to disk, making the physical page a blank page. The swap-in operation is used to write the contents of the page faulty page from disk into memory.
[0004] However, each time a page fault occurs, if memory is full and the selected physical page has been modified, the process needs to be interrupted to perform swap-in and / or swap-out operations, which reduces the process's running efficiency. Summary of the Invention
[0005] This application provides a page fault handling method, apparatus, and computer storage medium. When a process accesses a virtual address, if the memory cannot provide a blank physical page larger than or equal to the size of the virtual page indicated by the virtual address, an external page outside the memory that the processor can directly access can be determined. The physical address corresponding to the external page is written to the page table entry corresponding to the virtual page, and the access request is directed to the external page. There is no need to wait for the preparation of a blank physical page, which improves the response efficiency of the access request and ensures the running efficiency of the process.
[0006] In a first aspect, embodiments of this application provide a page fault handling method applied to a processor. The processor is connected to memory and external storage. The memory stores a page table, which includes a first page table entry corresponding to a first virtual address, including:
[0007] First, a first access request is obtained; this first access request may originate from a process and includes a first virtual address, which indicates any location within a first virtual page. Then, it is determined whether the physical address corresponding to the first virtual address is configured in a first page table entry. If the physical address corresponding to the first virtual address is not configured in the first page table entry, a page fault is identified. Next, it is determined whether memory can provide a first blank physical page. If memory cannot provide a first blank physical page, the first physical address is filled into the first page table entry; the size of the first blank physical page is greater than or equal to the size of the first virtual page. The first physical address indicates a first external page, which is a page in external storage that the processor can directly access. Subsequently, without waiting for the first blank physical page, the processor can directly respond to the first access request and access the first external page based on the first physical address.
[0008] In this scheme, when a process accesses a virtual address, if the memory cannot provide a blank physical page larger than or equal to the size of the virtual page indicated by the virtual address, an external page outside the memory that the processor can directly access can be determined. The physical address corresponding to the external page is written to the page table entry corresponding to the virtual page, and the access request is guided to the external page. There is no need to wait for the preparation of a blank physical page, which improves the response efficiency of the access request and ensures the running efficiency of the process.
[0009] In one possible implementation, the method further includes: obtaining a third access request; wherein the third access request includes a first virtual address; determining a first physical address in a first page table entry based on the first virtual address; and accessing a first external page based on the first physical address in response to the third access request.
[0010] In this solution, after accessing the external page via a virtual address, subsequent accesses to the virtual address can directly access the external page based on the physical address corresponding to the virtual address. Since the external page is accessed based on the physical address, it will be recognized as "memory", thus preventing page faults such as Major Faults.
[0011] In one possible implementation, the method also includes:
[0012] Determine the target physical page in memory; wherein the size of the target physical page is greater than or equal to the size of the first virtual page; write the contents of the target physical page to the external storage area; delete the contents of the target physical page; write the contents of the first external page to the target physical page; replace the first physical address in the first page table entry with the second physical address corresponding to the target physical page.
[0013] In this scheme, the processor first uses external pages as a temporary cache to avoid process interruption, while simultaneously replacing physical pages in memory. After a blank physical page in memory is prepared, the contents of the external page are migrated to the prepared blank physical page in memory, thereby ensuring process performance while taking into account process running efficiency.
[0014] In one example of this implementation, before determining the target physical page in memory, the method further includes: determining that the first external page is a hot page; and determining that there is no second blank physical page in memory; wherein the size of the second blank physical page is greater than or equal to that of the first external page. It should be noted that if a second blank physical page exists in memory, the contents of the first external page can be written to the second blank physical page, and the first physical address in the first page table entry can be replaced with the fifth physical address corresponding to the second blank physical page.
[0015] In this scheme, if the processor determines that the first external page is a hot page, it needs to write the first external page into memory in order to ensure the performance of the process.
[0016] In one example of this implementation, before filling the first physical address into the first page table entry, it also includes: determining that the target physical page has been modified.
[0017] In this scheme, once it is determined that the target physical page has been modified, a swap-out operation of the target physical page is required. At this time, in order to avoid process interruption, an external page outside of memory that the processor can directly access can be identified. The physical address of the external page is written into the page table entry corresponding to the virtual page, and the access request is guided to the external page. There is no need to wait for the preparation of the blank physical page, which improves the response efficiency of the access request and ensures the running efficiency of the process.
[0018] In one example of this implementation, the target physical page includes a first physical page, which is a modified physical page; the page table includes a second page table entry, which includes a third physical address corresponding to the first physical page.
[0019] Write the contents of the target physical page to external storage, including:
[0020] Write the contents of the first physical page to the second external page; the second external page is a page in the external storage area that the processor can directly access; replace the third physical address in the second page table entry with the fourth physical address corresponding to the second external page.
[0021] In this scheme, the smaller pages within a larger page are written into an external page that the processor can directly access. Subsequently, the external page can be accessed directly based on its physical address, without needing to load the contents of the external page into the processor first, thereby improving access efficiency.
[0022] In one example of this example, the method further includes: obtaining a second access request; wherein the second access request includes a second virtual address, the second virtual address being used to indicate any location of a second virtual page, the second virtual address corresponding to a second page table entry; determining a fourth physical address in a second page table entry based on the second virtual address; and accessing a second external page based on the fourth physical address in response to the access request.
[0023] In this scheme, after writing the smaller pages in the larger page into the external page that the processor can directly access, the external page can then be accessed directly based on the physical address. Since the external page is accessed based on the physical address, it will be recognized as "memory", and therefore page faults such as Major Faults will not occur.
[0024] For example, the method further includes: if the second external page is determined to be a hot page, determining a third blank physical page in memory; wherein the size of the third blank physical page is greater than or equal to the size of the second external page; writing the contents of the second external page into the third blank physical page, and replacing the fourth physical address in the second page table entry with the sixth physical address of the third blank physical page.
[0025] In this scheme, if the processor determines that the second external page is a hot page, it needs to write the second external page into memory in order to ensure the performance of the process.
[0026] In one possible implementation, the first page table entry includes a first value and a second flag bit; the first value is used to indicate that the first virtual page is not configured with a physical address;
[0027] Writing the first physical address into the first page table entry includes: updating the first value of the first flag bit to a second value; wherein the second value is used to indicate that the first virtual page is configured with a physical address; and writing the first physical address into the second flag bit.
[0028] Secondly, embodiments of the present invention provide a page fault handling device, which includes several modules. Each module is used to execute various steps in the page fault handling method provided in the first aspect of the present invention. The division of modules is not limited here. For the specific functions performed by each module of this page fault handling device and the beneficial effects achieved, please refer to the functions of each step of the display method provided in the first aspect of the present invention; further details will not be repeated here.
[0029] For example, a page fault handling device is used to execute the page fault handling method provided in the embodiments of the present invention. The page fault handling device is connected to memory and external storage area. The memory stores page tables, and the page tables include first page table entries, each corresponding to a first virtual address. The page fault handling device may include:
[0030] The request acquisition module is used to acquire a first access request; wherein, the first access request includes a first virtual address, and the first virtual address is used to indicate any location in the first virtual page;
[0031] The fault analysis module is used to determine if a page fault has occurred when the physical address corresponding to the first virtual address is not configured in the first page table entry.
[0032] The address mapping module is used to fill the first physical address into the first page table entry when the memory fails to provide the first blank physical page; wherein the size of the first blank physical page is greater than or equal to the size of the first virtual page; the first physical address is used to indicate the first external page, which is a page in the external storage area that the processor can directly access;
[0033] The access module is used to access the first external page based on the first physical address in response to the first access request.
[0034] In one possible implementation, the device further includes:
[0035] The swapping module is used to determine the target physical page in memory; wherein the size of the target physical page is greater than or equal to the size of the first virtual page; write the contents of the target physical page to the external storage area; delete the contents of the target physical page; write the contents of the first external page to the target physical page; and replace the first physical address in the first page table entry with the second physical address corresponding to the target physical page.
[0036] In one example of this implementation, the address mapping module is used to fill the first physical address into the first page table entry when it is determined that the target physical page has been modified.
[0037] In one example of this implementation, the apparatus further includes: a hot page processing module, configured to determine that the first external page is a hot page; and to determine that a second blank physical page does not exist in memory; wherein the size of the second blank physical page is greater than or equal to that of the first external page, and to execute a swapping module. It should be noted that if a second blank physical page exists in memory, the contents of the first external page can be written to the second blank physical page, and the first physical address in the first page table entry can be replaced with the fifth physical address corresponding to the second blank physical page.
[0038] In one example of this implementation, the target physical page includes a first physical page, which is the modified physical page;
[0039] The page table includes a second page table entry, and the second page table entry includes the third physical address corresponding to the first physical page;
[0040] The swapping module is used to write the contents of the first physical page to the second external page; wherein the second external page is a page in the external storage area that the processor can directly access; and to replace the third physical address in the second page table entry with the fourth physical address corresponding to the second external page.
[0041] In one example of this example, a request retrieval module is used to retrieve a second access request; wherein the second access request includes a second virtual address, the second virtual address is used to indicate any location of a second virtual page, and the second virtual address corresponds to a table entry of the second page;
[0042] The access module is used to determine the fourth physical address in the second page table entry based on the second virtual address; and in response to an access request, to access the second external page based on the fourth physical address.
[0043] For example, the apparatus further includes: a hot page processing module, configured to determine a third blank physical page in memory when the second external page is determined to be a hot page; wherein the size of the third blank physical page is greater than or equal to the size of the second external page; write the contents of the second external page into the third blank physical page; and replace the fourth physical address in the second page table entry with the sixth physical address of the third blank physical page.
[0044] In one possible implementation, a request acquisition module is used to acquire a third access request; wherein the third access request includes a first virtual address;
[0045] The access module is used to determine the first physical address in the first page table entry based on the first virtual address; and in response to a third access request, to access the first external page based on the first physical address.
[0046] In one possible implementation, the first page table entry includes a first value and a second flag bit; the first value is used to indicate that the first virtual page is not configured with a physical address;
[0047] The address mapping module is used to update the first value of the first flag bit to the second value; wherein the second value is used to indicate that the first virtual page is configured with a physical address; and the first physical address is written into the second flag bit.
[0048] In one possible implementation, the external storage area includes at least one of the following:
[0049] Solid-state drives, phase-change memory, and memory based on interconnect bus protocols.
[0050] Thirdly, embodiments of this application provide a page fault handling apparatus, comprising: at least one memory for storing a program; and at least one processor for executing the program stored in the memory, wherein when the program stored in the memory is executed, the processor is used to execute the method provided in the first aspect.
[0051] Fourthly, embodiments of this application provide a page fault handling apparatus, characterized in that the apparatus executes computer program instructions to perform the method provided in the first aspect. Exemplarily, the apparatus may be a chip or a processor.
[0052] In one example, the device may include a processor that can be coupled to memory, read instructions from the memory, and execute the methods provided in the first aspect according to those instructions. The memory may be integrated into the chip or processor, or it may be independent of the chip or processor.
[0053] Fifthly, embodiments of this application provide a computer storage medium storing instructions that, when executed on a computer, cause the computer to perform the method provided in the first aspect.
[0054] In a sixth aspect, embodiments of this application provide a computer program product containing instructions that, when executed on a computer, cause the computer to perform the method provided in the first aspect. Attached Figure Description
[0055] Figure 1 is a system architecture diagram of the computing system provided in an embodiment of this application;
[0056] Figure 2a is a schematic diagram of a first computing system provided in an embodiment of this application;
[0057] Figure 2b is a schematic diagram of a second computing system provided in an embodiment of this application;
[0058] Figure 2c is a schematic diagram of a third computing system provided in an embodiment of this application;
[0059] Figure 3a is a schematic diagram of the page table provided in an embodiment of this application;
[0060] Figure 3b is a schematic diagram of the page table query method of Figure 3a provided in an embodiment of this application;
[0061] Figure 4a is a schematic diagram of the first page fault handling scenario provided in the embodiments of this application;
[0062] Figure 4b is a flowchart illustrating the first page fault handling method provided in the embodiments of this application;
[0063] Figure 5a is a schematic diagram of a second page fault handling scenario provided in an embodiment of this application;
[0064] Figure 5b is a flowchart illustrating the second page fault handling method provided in the embodiments of this application;
[0065] Figure 6a is a schematic diagram of the third page fault handling scenario provided in the embodiments of this application;
[0066] Figure 6b is a flowchart illustrating the third page fault handling method provided in the embodiments of this application;
[0067] Figure 7 is a schematic diagram of the first physical page swapping out scenario in the target physical page provided in the embodiments of this application;
[0068] Figure 8 is a flowchart illustrating the fourth page fault handling scenario provided in the embodiments of this application;
[0069] Figure 9 is a schematic diagram of accessing external page 2 based on Figure 8;
[0070] Figure 10 is a flowchart illustrating the fifth page fault handling scenario provided in the embodiments of this application;
[0071] Figure 11 is a schematic diagram of a page fault handling device provided in an embodiment of this application;
[0072] Figure 12 is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0073] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be described below with reference to the accompanying drawings.
[0074] In the description of the embodiments of this application, the words "exemplary," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the words "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a specific manner.
[0075] In the description of the embodiments in this application, the term "and / or" is merely a description of the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, B existing alone, and A and B existing simultaneously. Furthermore, unless otherwise stated, the term "multiple" means two or more. For example, multiple systems refer to two or more systems, and multiple terminals refer to two or more terminals.
[0076] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and their variations all mean "including but not limited to," unless otherwise specifically emphasized.
[0077] The following explanations cover some of the terms used in this embodiment. It should be noted that these explanations are for the convenience of those skilled in the art and are not intended to limit the scope of protection claimed by this invention.
[0078] To facilitate understanding of the embodiments of this application, several technical terms involved in the embodiments of this application will be explained below.
[0079] Central Processing Unit (CPU): The core of a computer system for computation and control; it is the final execution unit for information processing and program execution.
[0080] Virtual address (VA): For a running process, the address pointed to by pointers in code instructions, the function entry address, the return address, etc., the addresses that the process can directly see are virtual addresses.
[0081] Physical address (PA): For a physical CPU, when the CPU executes a specific instruction, it needs to obtain specific data information from some addresses. The address it accesses at this time is the physical address.
[0082] Physical Page: Physical storage space is divided into physical pages (PP), also known as page frames, or simply real pages, with a size of P = 2^n bytes. These are used to store memory addresses for instruction streams and data.
[0083] Page frame number (PFN): A page frame refers to a region of physical memory, divided into areas the size of a page. Each page is assigned a number, which is the PFN. If physical memory starts at address 0, then the page frame with PFN 0 is the page starting at address 0 (physical address). If physical memory starts at address x, then the first page frame number is (x >> PAGE_SHIFT).
[0084] Virtual Page (VP): A virtual page is divided into fixed-size virtual pages (VP), or simply virtual pages. Each virtual page is P = 2^n bytes in size. In this embodiment, the virtual pages of the virtual machine are referred to as physical pages.
[0085] Virtual page number (VPN): The page number of a virtual page (VP), which can also be considered as the virtual page frame number.
[0086] Address translation: The task of converting a virtual address into a physical address is called address translation. The CPU accesses main memory by generating a virtual address (VA), which is translated into an appropriate physical address before being sent to main memory. Address translation utilizes dedicated hardware in the Memory Management Unit (MMU) to dynamically translate virtual addresses using a lookup table stored in main memory. The contents of this table are managed by the operating system.
[0087] Page Table: A page table is a data structure in memory that includes multiple page table entries. Each page table entry indicates the mapping relationship between virtual page numbers and physical page numbers. A computing device can determine the physical page corresponding to the virtual page containing a virtual address based on the mapping relationship between virtual and physical page numbers, and then determine the physical address corresponding to the virtual address based on the offset in the virtual address.
[0088] Page Table Entry (PTE): One of the core data structures in virtual memory management, it contains mapping information from virtual addresses to physical addresses. Each page table entry typically includes multiple flags to describe the state of the virtual page, access permissions, and whether it is mapped to a physical page or other storage device.
[0089] Dirty page: This is a concept in the Linux kernel. Because the read and write speed of the hard drive is far slower than that of the memory, the system puts frequently read and written data into memory in advance to improve the read and write speed. This is called caching. Linux uses pages as the unit of caching. When a process modifies the data in the cache, the page is marked as a dirty page by the kernel.
[0090] A process is a program's execution activity on a certain set of data in a computer. It is the basic unit for system resource allocation and the foundation of the operating system structure.
[0091] Operating System (OS): A built-in program that works with various computer hardware components to interact with the user. Common examples include Windows, macOS, and open-source Linux and Huawei's HarmonyOS.
[0092] The Basic Input Output System (BIOS) is a set of programs embedded in a read-only memory (ROM) chip on the computer's motherboard. It stores the computer's most important basic input / output programs, power-on self-test (POST) programs, and system startup programs. It can read and write specific system settings information from Complementary Metal-Oxide Semiconductor (CMOS) chips. Its main function is to provide the lowest-level, most direct hardware settings and control for the computer. In addition, the BIOS provides some system parameters to the operating system. Changes to system hardware are hidden by the BIOS; programs use BIOS functions rather than directly controlling the hardware. Modern operating systems often bypass the abstraction layer provided by the BIOS and directly control hardware components.
[0093] BIOS initialization refers to a series of detection and configuration operations performed by the BIOS on the computer hardware during the computer startup process.
[0094] Minor Fault (minor page fault): A minor fault is triggered when the physical page corresponding to a virtual address accessed by the CPU already exists in memory but is not in the cache. In this case, the system only needs to load the page from the cache into physical memory and update the page table mapping.
[0095] Major Fault (major page fault): A major fault is triggered when the physical page corresponding to the virtual address accessed by the CPU does not exist in memory. This usually means that data needs to be loaded from disk into physical memory, or a new physical page needs to be allocated.
[0096] The page fault handling method provided in this embodiment of the invention may be applied to a computing system. Figure 1 shows an example architecture diagram of a computing system provided in this embodiment of the invention. The page fault handling method provided in this embodiment of the invention can be applied to the system architecture diagram shown in Figure 1. As shown in Figure 1, the computing system includes a CPU 101, memory 102, and external storage area 103.
[0097] CPU101 is merely an example of a processor and does not constitute a specific limitation. A processor can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. CPU101 runs processes and an operating system.
[0098] Memory 102 is volatile memory, such as random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0099] External storage area 103 can be an auxiliary storage area outside of memory 102.
[0100] For example, external storage area 103 can be non-volatile memory, such as a solid-state drive (SSD) and / or phase-change memory (PCM). In some possible scenarios, as shown in Figure 2a, N (a positive integer greater than or equal to 2) nodes and multiple SDDs are interconnected via a bus. Each node includes a CPU and memory. Node 1 can use each SDD connected to the bus, and nodes 2, ..., N are similar.
[0101] For example, external storage area 103 can be extended memory, such as Compute Express Link (CXL) memory. In some possible scenarios, as shown in Figure 2b, N nodes are interconnected via a bus that follows the Compute Express Link (CXL) protocol. Each node includes a CPU and memory. For node 1, the memory of other nodes connected via the bus can be used; the memory of the other nodes is extended memory. In other possible scenarios, as shown in Figure 2c, N nodes are connected via a switch to M extended memory modules. For node 1, each of the M extended memory modules can be connected via the switch; each of the M extended memory modules is external storage area 103.
[0102] In this embodiment, memory 102 stores page tables. The page tables are used to store the correspondence between physical addresses (PA) and virtual addresses (VA).
[0103] It's important to note that the mapping between virtual addresses (VA) and physical addresses (PA) is primarily implemented through a paging mechanism. The memory paging mechanism divides the virtual address space and the physical address space (the space provided by memory 102) into multiple storage units of equal capacity (also called blocks or pages). The storage units allocated from the virtual address space are called virtual pages, and the storage units allocated from the physical address space are called physical pages. Virtual pages and physical pages have equal capacities. The capacity of a virtual page or physical page can be 4 kilobytes (KB), 8 kilobytes (KB), 2 megabytes (MB), or 1 gigabyte (GB), etc.
[0104] The virtual address (VA) can include a virtual page number and an offset. The virtual page number indicates the virtual page containing the virtual address, and the offset in the virtual address refers to the offset of the virtual address relative to the starting address of the virtual page it belongs to. For example, in a 32-bit system with a page size of 4KB, the high 20 bits (0x12345) of the virtual address 0x12345678 are the page number, and the low 12 bits (0x678) are the offset within the page.
[0105] The physical address (PA) can include a physical page number and an offset. The physical page number indicates the physical page containing the physical address, and the offset in the physical address refers to the offset of the physical address relative to the starting address of the physical page containing that physical address. For example, the physical page number 0x54321 and the offset 0x678 combine to form the physical address 0x54321678.
[0106] Additionally, the operating system (OS) can store the mapping between virtual page numbers and physical page numbers through a page table. For example, virtual page number 0x12345 may correspond to physical page number 0x54321.
[0107] The page table can be multi-level (such as the three-level page table in Linux), thereby reducing memory usage through a hierarchical structure.
[0108] A page table comprises multiple page table entries (PTEs), where each page table entry (PET) corresponds to a virtual address (VA). For example, a page table can be multi-level, with the number of levels determined by the size of the physical page. For instance, a page table with 4 levels might be used when the physical page size is 4KB, while a page table with 3 levels might be used when the physical page size is 2MB. For example, as shown in Figure 3a, a page table can include 3-level, 2-level, and 1-level page tables. A 3-level page table has one page, a 2-level page table can have 512 pages (Figure 3a only shows two pages), and a 1-level page table can have 512 * 512 = 262,144 pages (Figure 3a only shows 4 pages). Each page can include 512 entries (Figure 3a only shows 2 entries), each entry being 8 bytes, meaning each page has 512 * 8 = 4096 bytes, or 4KB. In this application, each entry in the Level 3 page table corresponds to each page in the Level 2 page table. Similarly, each entry in the Level 2 page table corresponds to each page in the Level 1 page table, and each entry in the Level 1 page table corresponds to a physical page. In this embodiment, the Level 1 entries are referred to as Page Table Entries (PTEs).
[0109] Next, the content of the PTE will be introduced. Specifically, as shown in Figure 3b, the PTE includes address bits, a valid bit, a dirty bit, and other bits (not relevant to this application and will not be described in detail). The address bits can be n bits, where n is a positive integer greater than or equal to 2. The dirty bit is used to mark whether the physical page has been modified. For example, when the dirty bit = 1, it indicates that it has been modified, and when the dirty bit = 0, it indicates that it has not been modified. Assuming that the PTE corresponds to a virtual address (VA), the virtual address (VA) can be used to indicate a virtual page, for example, the virtual address (VA) is the virtual page number (VPN). The valid bit indicates whether the virtual space, such as the virtual page, is currently cached in memory 102. If the valid bit is set, for example, the valid bit = 1, then the address bits represent the starting position of the corresponding physical space, such as the physical page, in memory 102, and the content of the virtual space, such as the virtual page, is cached in the corresponding physical space, such as the physical page. If the valid bit is not set, for example, the valid bit = 0, then an empty address bit indicates that this virtual page has not yet been allocated. Assuming the valid bit of PTE0 is 0, it means that the physical page corresponding to the virtual address (VA) of the current virtual page 1 cannot be found; assuming the valid bit of PTE2 is 1, the physical page corresponding to the current virtual page 2 is available. If we use the virtual address (VA) of virtual page 1 to look up this page table, and the valid bit of PET0 is 0, it means there is no corresponding PA address, resulting in a page fault operation. If we use the virtual address (VA) of virtual page 2 to look up this page table, and the valid bit of PET2 is 1, it means there is a corresponding PA address, indicating that the VA to PA mapping is successful. It should be noted that the address bit can be called the second flag bit, and the valid bit can be called the first flag bit.
[0110] Next, we will explain how the CPU101 determines the physical address (PA) corresponding to the virtual address (VA) based on the page table.
[0111] In practical implementation, the CPU determines the physical page number (PFN) corresponding to the virtual page number (VPN) level by level based on the virtual page number (VPN) in the virtual address (PA) and the page tables at each level. For each level of page table, both the page and the entry of that page need to be determined. The page of that level can be determined based on the entry of the page table at the previous level, and the entry of that page can be derived from the virtual page number in the virtual address (PA). For example, as shown in Figure 3b, the virtual page number can be divided into three levels of directories: Level 1, Level 2, and Level 3. The Level 1 directory is used to determine the entries in the Level 3 page table. Based on the entries in the Level 3 page table, the pages in the Level 2 page table are determined. Based on the Level 2 directory, the entries in the pages in the Level 2 page table are determined. Based on the entries in the pages in the Level 2 page table, the pages in the Level 1 page table are determined. Based on the Level 3 directory, the page table entries in the pages in the Level 1 page table are determined.
[0112] Next, in conjunction with the computing system provided above, a page fault handling method provided by an embodiment of the present invention will be described in detail.
[0113] As shown in Figure 4a, this embodiment of the invention proposes a page fault handling method including: CPU 101 obtains a first access request from a process, determines a first virtual address in the first access request, the first virtual address being used to indicate any location of a first virtual page; then, it determines a first page table entry corresponding to the first virtual address; if no physical page corresponding to the first virtual page is configured in the first page table entry, and no first blank physical page (larger than or equal to the size of the first virtual page) exists in memory 102, it determines a first external page that can be directly accessed, and writes the first physical address of the first external page into the first page table entry, for example, by setting the valid bit = 1 and writing the first physical address into the address bit. In summary, in the case of accessing a virtual address, if memory 102 cannot provide a blank physical page larger than or equal to the size of the virtual page indicated by the virtual address, this solution can determine an external page outside memory 102 that CPU 101 can directly access, write the physical address corresponding to the external page into the page table entry corresponding to the virtual page, and guide the access request to the external page without waiting for the preparation of a blank physical page, thereby improving the response efficiency of the access request. This is only a brief description of the method; for details of the method, please refer to the description below.
[0114] Figure 4b is a schematic flowchart of a page fault handling method provided in an embodiment of this application. This embodiment can be applied to CPU 101.
[0115] As shown in Figure 4b, the page fault handling method provided in this application embodiment includes at least the following steps:
[0116] Step 401: CPU 101 obtains a first access request; wherein, the first access request includes a first virtual address, which is used to indicate any location in the first virtual page.
[0117] In this embodiment, the CPU 101 can run a process, which can issue a first access request. The first access request can be used to request access to virtual storage space, for example, to write content to virtual storage space or to read content from virtual storage space. For example, the first access request can include the starting virtual address (i.e., the first virtual address) of virtual storage space and the size of virtual storage space. For example, the first access request can include the starting virtual address (i.e., the first virtual address) and the ending virtual address of virtual storage space.
[0118] The first virtual address is used to indicate any location of any virtual page (i.e., the first virtual page) that the processor can access. For example, in the scenario where a process issues a first access request, the first virtual page is any virtual page that the process can access. The virtual page that the process can access can be a virtual page that the operating system allocates to the process after it requests it from the operating system.
[0119] For example, the first virtual address can be a virtual page number and an offset, wherein the virtual page number is used to indicate the first virtual page, and the offset is used to indicate the distance from the starting point of the first virtual page to the current access point. The offset can be used to determine a certain position in the first virtual page.
[0120] Step 402: If the physical address corresponding to the first virtual address is not configured in the first page table entry, CPU101 determines that a page fault has occurred.
[0121] In this embodiment, after receiving the first access address, the CPU 101 will trigger the address translation process of the first virtual address. The address translation process may include: querying the page table based on the first virtual address to determine the first page table entry corresponding to the first virtual address. If the valid bit in the first page table entry is the first data, such as 0, and the address bit is empty, it indicates that the physical address corresponding to the first virtual address is not configured in the first page table entry, and a page fault is determined to have occurred. This page fault is a Minor Fault.
[0122] Step 403: If the memory 102 fails to provide a first blank physical page, the CPU 101 fills the first physical address into the first page table entry; wherein, the size of the first blank physical page is greater than or equal to the size of the first virtual page; the first physical address is used to indicate the first external page, which is a page in the external storage area that the CPU 101 can directly access.
[0123] The first blank physical page can be understood as an unallocated physical page in memory 102, that is, a physical page in memory 101 that is in a free state. The size of the first blank physical page is greater than or equal to the size of the first virtual page. For example, the size of the first blank physical page and the first virtual page are the same.
[0124] The external storage area 103 is a storage area outside of the memory 102 that the CPU 101 can directly access. The external storage area 103 can be directly accessed by the CPU 101, which means that the CPU 101 can directly read or write data from the external storage area 103 without first writing the data in the external storage area 103 to the memory 102 and then reading the data from the memory 102, or writing the data to the memory 102 and then writing the data in the memory 102 to the external storage area 103. The external storage area 103 can include multiple pages (which can be called external pages for ease of description and distinction). The external storage area 103 can be obtained by dividing at least a portion of the physical storage space in the external storage area 103. The total size of the multiple external pages is less than or equal to the size of the external storage area 103, and the size of each external page can be inconsistent with the size of the physical pages in the memory 101. Since CPU 101 can directly access external storage area 103, it can also directly access external pages within external storage area 103. These external pages are equivalent to "physical pages in memory." It should be noted that the connection between external storage area 103 and CPU 101 is similar to the connection between CPU 101 and memory 102, allowing CPU 101 to directly access any external page in external storage area 103. In some optional implementations, during BIOS initialization, CPU 101 can configure a register (referred to as the target register for ease of description and distinction) to establish a mapping relationship between a region in external storage area 102 (referred to as the external region for ease of description and distinction) and the main memory area. This mapping relationship indicates the start and end addresses of the external region, as well as the start and end physical addresses of the main memory area. The external region and the main memory area are the same size. The target register can be a system address decoding register. (decoder); The main memory area can be understood as an unallocated logical space managed by page tables and directly accessible by CPU 101. The logical space is a collection of contiguous physical addresses. Subsequently, CPU 101 can divide the external region into multiple external pages. For example, the external region can be divided into multiple external pages of equal capacity according to the size of the physical pages in memory 102 (e.g., 2M). The main memory area is divided according to the external region division method to obtain the logical space corresponding to each external page. The logical space is encoded to obtain the physical address corresponding to the external page of the logical space. The physical address corresponding to the external page can be the starting address (also called the base address) of the external page. For example, the physical address corresponding to the external page can be used to indicate the page number and size of the external page.
[0125] The first physical address can be used to indicate the first external page. For example, the first physical address can be the physical address corresponding to the first external page (indicating the starting address of the first external page). The first external page is any external page in the external storage area 103 that the CPU 101 can directly access. The first external page can be understood as an unallocated external page in the external storage area 103, that is, a blank external page in the external storage area 103 (in an idle state). The size of the first external page is greater than or equal to the size of the first virtual page. For example, the size of the first external page and the first virtual page are the same.
[0126] In this embodiment, the CPU 101 can determine whether the memory 102 can provide a first blank physical page. If the first blank physical page cannot be provided, the CPU 101 determines a free first external page from the external storage area 103, determines the first physical address corresponding to the first external page, and writes the first physical address into the first page table entry corresponding to the first virtual address.
[0127] For example, a first page table entry may include a valid bit set to a first value, such as 0, and an address bit set to empty. In this case, the CPU 101 may write the first physical address into the first page table entry corresponding to the first virtual address by modifying the first value of the valid bit (e.g., 0) to a second value, such as 1, and then writing the first physical address into the address bit. The second value indicates that the first virtual page is configured with a physical address.
[0128] Step 404: In response to the first access request, CPU101 accesses the first external page based on the first physical address.
[0129] In this embodiment, optionally, the first access request can be a write request, which includes content to be written. In one example, CPU 101 can determine the location in the first external page based on the offset between the first physical address and the first virtual address, and start writing the content to be written from that location. In another example, CPU 101 can cache a portion of the content to be written; it can determine the location in the first external page based on the offset between the first physical address and the first virtual address, and start writing another portion of the content to be written from that location. In yet another example, CPU 101 can cache the entire content to be written. If the cache space is insufficient, it can determine the location in the first external page based on the offset between the first physical address and the first virtual address, and start writing the content to be written that CPU 101 cannot cache from that location.
[0130] Alternatively, in another scenario in this embodiment, the first access request can be a read request. In one example, the CPU 101 can determine the location in the first external page based on the offset in the first physical address and the first virtual address, and start reading from that location.
[0131] It should be noted that when CPU101 determines that a page fault has occurred, it will enter the page fault handling process. After completing step 403, it can exit the page fault handling process, respond to the access request, and access the first external page based on the first physical address.
[0132] In this embodiment, when accessing a virtual address, if memory 102 cannot provide a blank physical page larger than or equal to the size of the virtual page indicated by the virtual address, an external page outside memory 102 that CPU 101 can directly access can be determined. The physical address corresponding to the external page is written to the page table entry corresponding to the virtual page, and the access request is directed to the external page. There is no need to wait for the preparation of a blank physical page, thereby improving the response efficiency of the access request.
[0133] After the first access request is directed to the first external page, if the first virtual address is accessed again subsequently, the CPU 101 can directly access the first external page. For example, as shown in FIG5a, the CPU 101 can obtain the third access request issued by the process and determine the first virtual address in the third access request. Then, it can determine the first page table entry corresponding to the first virtual address. The first page table entry includes the first physical address. After obtaining the first physical address, the first external page can be accessed based on the first physical address.
[0134] Figure 5b shows a flowchart of another page fault handling method provided in an embodiment of this application.
[0135] As shown in Figure 5b, based on steps 401 to 404 shown in Figure 4b, this embodiment of the application further includes at least the following steps:
[0136] Step 501: CPU 101 obtains a third access request; wherein, the third access request includes the first virtual address.
[0137] The third access request can be used to access the first virtual address again. For example, the third access request can be used to request access to the virtual storage space, such as to write content to the virtual storage space or to read content from the virtual storage space. The starting virtual address of the virtual storage space is the first virtual address. For example, the third access request can include the starting virtual address (i.e., the first virtual address) of the virtual storage space and the size of the virtual storage space. For example, the third access request can include the starting virtual address (i.e., the first virtual address) and the ending virtual address of the virtual storage space.
[0138] Step 502: CPU101 determines the first physical address in the first page table entry based on the first virtual address.
[0139] In this embodiment, the CPU 101 triggers an address translation process based on the first virtual address: querying the page table to obtain the first page table entry corresponding to the first virtual address, and determining the first physical address in the first page table entry. It should be noted that during the address translation process, the first external page corresponding to the first physical address is equivalent to memory; therefore, a Major Fault will not occur, thus eliminating the Major Fault.
[0140] Step 503: In response to the third access request, CPU101 accesses the first external page based on the first physical address.
[0141] In this embodiment, optionally, the third access request can be a write request, which includes content to be written. In one example, CPU 101 can determine the location in the first external page based on the offset between the first physical address and the first virtual address, and start writing the content to be written from that location. In another example, CPU 101 can cache a portion of the content to be written; it can determine the location in the first external page based on the offset between the first physical address and the first virtual address, and start writing another portion of the content to be written from that location. In yet another example, CPU 101 can cache the entire content to be written. If the cache space is insufficient, it can determine the location in the first external page based on the offset between the first physical address and the first virtual address, and start writing the content to be written that CPU 101 cannot cache from that location.
[0142] Alternatively, in another scenario in this embodiment, the third access request can be a read request. In one example, the CPU 101 can determine the location in the first external page based on the offset in the first physical address and the first virtual address, and start reading from that location.
[0143] In this embodiment, when the virtual address corresponding to the external page is accessed again, the processor can directly access the external page based on the physical address of the external page, thereby eliminating the Major Fault.
[0144] After the first access request is redirected to the first external page, a swap-out operation of the physical page in memory 102 can be performed simultaneously to obtain a prepared blank physical page. The content of the first external page is then migrated to the prepared blank physical page, and the first physical address in the first page table entry corresponding to the first virtual address is replaced with the physical address of the blank physical page, thereby restoring process performance. For example, as shown in Figure 6a: 1. CPU 101 can determine the target physical page, which is a modified physical page. The target physical page corresponds to a target page table entry, which includes the second physical address corresponding to the target physical page; 2. CPU 101 can persist the content of the target physical page, for example, by writing it to external storage area 103; 3. CPU 101 deletes the content of the first physical page and writes the content of the first external page to the target physical page; 4. The first physical address in the first page table entry is replaced with the second physical address of the target physical page.
[0145] Figure 6b shows a flowchart of another page fault handling method provided in an embodiment of this application.
[0146] As shown in Figure 6b, based on steps 401 to 404 shown in Figure 4b, this embodiment of the application further includes at least the following steps:
[0147] Step 601: CPU 101 determines the target physical page in memory 102; wherein the size of the target physical page is greater than or equal to the size of the first virtual page.
[0148] The target physical page can be any physical page in memory 102. The size of the target physical page is greater than or equal to the size of the first virtual page. For example, the size of the target physical page is an integer multiple of the size of the first virtual page. For instance, if the size of the target physical page is equal to the size of the first virtual page, then the size of the target physical page is 1 times the size of the first virtual page. Or, for another example, the size of the target physical page is 2 times the size of the first virtual page.
[0149] In this embodiment, the CPU 101 can select the target physical page to be swapped out based on the page selection algorithm and the size of the first virtual page. The page selection algorithm can be the Least Recently Used (LRU) algorithm, which is based on the assumption that recently used data is more likely to be used again in the future, while data that has not been used for a long time is less likely to be used in the future.
[0150] Step 602: CPU 101 writes the contents of the target physical page to the external storage area.
[0151] In this embodiment, the CPU 101 can determine whether the target physical page has been modified. If it is determined that the target physical page has been modified, the content in the target physical page is persisted, for example, by writing the content of the target physical page to an external storage area. It should be noted that if the content of the target physical page has been modified, it means that the content of the target physical page is different from the original data to be persisted. The original data to be persisted is data stored in non-volatile memory, which can be a hard disk drive (HDD) and / or an SDD, etc., that can permanently store data.
[0152] Optionally, in one example, the page table entry may also include a dirty bit, which is used to mark whether the physical page has been modified. For example, when the dirty bit = 1, it indicates that it has been modified, and when the dirty bit = 0, it indicates that it has not been modified. The page table may include the page table entry corresponding to the target physical page (for ease of description and distinction, it can be called the target page table entry). Then, the CPU101 may determine whether the target physical page has been modified by: judging whether the target physical page has been modified based on the dirty bit in the target page table entry corresponding to the target physical page. For example, if the dirty bit in the target page table entry = 1, it means that the target physical page has been modified.
[0153] Alternatively, in another example, the target physical page may include multiple physical pages (each physical page being smaller than the target physical page). For instance, if the target physical page is 2MB, it may include 512 physical pages of size 4KB each. For ease of description, any modified physical page within the target physical page is designated as the first physical page. The page table includes a page table entry corresponding to the first physical page (which can be referred to as the second page table entry for ease of description and distinction). The address bits in the second page table entry are the physical address corresponding to the first physical page (which can be referred to as the third physical address for ease of description and distinction). The third physical address can be used to indicate the starting location of the first physical page. As shown in Figure 7, the CPU 101 can persist the contents of the target physical page by writing the contents of the first physical page to a blank external page in the external storage area 103 (which can be called the second external page for ease of description and distinction). The second external page is an external page in the external storage area that the CPU 101 can directly access. In order for the CPU 101 to be able to directly access the second external page, the third physical address in the second page table entry corresponding to the first physical page also needs to be replaced with the physical address corresponding to the second external page (which can be called the fourth physical address for ease of description and distinction). The fourth physical address can be used to indicate the starting address of the second external page.
[0154] In a scenario where the content of the first physical page in the target physical page is written to the second external page, and the third physical address in the second page table entry corresponding to the first physical page is replaced with the fourth physical address corresponding to the second external page, the CPU 101 can obtain a second access request. The second access request includes a second virtual address, which is used to indicate any location of the second virtual page. The second virtual address corresponds to the second page table entry. Then, based on the second virtual address, the fourth physical address in the second page table entry is determined. In response to the access request, the second external page is accessed based on the fourth physical address.
[0155] The second access request can be used to request access to the virtual storage space, for example, to write content to the virtual storage space or to read content from the virtual storage space; for example, the second access request can include the starting virtual address (i.e., the second virtual address) and the size of the virtual storage space; for example, the second access request can include the starting virtual address (i.e., the second virtual address) and the ending virtual address of the virtual storage space.
[0156] The second virtual address is used to indicate any location of any virtual page (i.e., the second virtual page) that the processor can access. For example, in the scenario where a process issues a second access request, the second virtual page is any virtual page that the process can access. The virtual page that the process can access can be a virtual page that the operating system allocates to the process after it requests it from the operating system.
[0157] The fourth physical address can be used to indicate the second external page. For example, the fourth physical address can be the physical address corresponding to the second external page (indicating the starting address of the second external page). The second external page is any external page in the external storage area 103 that the CPU 101 can directly access. The second external page can be understood as an unallocated external page in the external storage area 103, that is, an external page in the external storage area 103 that is in a free state. The size of the second external page is greater than or equal to the size of the second virtual page. For example, the size of the second external page and the second virtual page are the same.
[0158] For example, the second virtual address can be a virtual page number and an offset, wherein the virtual page number is used to indicate the second virtual page, and the offset is used to indicate the distance from the starting point of the second virtual page to the current access point. The offset can be used to determine a certain position in the second virtual page.
[0159] For example, the second access request can be a write request, which includes content to be written. In one example, CPU 101 can determine the location in the second external page based on the offsets in the second physical address and the second virtual address, and start writing the content to be written from that location. In another example, CPU 101 can cache a portion of the content to be written; it can determine the location in the second external page based on the offsets in the second physical address and the second virtual address, and start writing another portion of the content to be written from that location. In yet another example, CPU 101 can cache the entire content to be written. If the cache space is insufficient, it can determine the location in the second external page based on the offsets in the second physical address and the second virtual address, and start writing the content to be written that CPU 101 cannot cache from that location.
[0160] For example, the second access request can be a read request. In one example, CPU 101 can determine the location in the second external page based on the offset in the second physical address and the second virtual address, and start reading from that location.
[0161] It should be noted that the implementation shown in Figure 7 is merely an example. In other possible scenarios, the target physical page corresponds to a page table entry (which can be called the target page table entry for ease of description and distinction). The CPU 101's persistence of the content in the target physical page may include: writing the content of the target physical page to a blank external page in the external storage area 103 (which can be called the target external page for ease of description and distinction). The target external page is an external page in the external storage area that the CPU 101 can directly access. To enable the CPU 101 to directly access the target external page, the second physical address in the target page table entry corresponding to the target physical page also needs to be replaced with the physical address corresponding to the target external page (which can be called the target physical address for ease of description and distinction). The target physical address can be used to indicate the starting address of the target external page. It should be noted that the target external page and target physical address are merely possible naming conventions and do not constitute specific limitations. For example, the target external page can also be called the third external page, and the target physical address can be called the fifth physical address.
[0162] Step 603: CPU101 deletes the contents of the target physical page.
[0163] In this embodiment, CPU101 can clear the contents already stored in the target physical page.
[0164] Step 604: CPU 101 writes the contents of the first external page to the target physical page.
[0165] In this embodiment, the CPU 101 can pause the process using the target physical page, read the contents of the first external page, and then write them to the target physical page. This embodiment does not intend to limit the way the CPU 101 writes the contents of the first external page to the target physical page, and can be flexibly designed according to the actual situation.
[0166] Step 605: CPU101 replaces the first physical address in the first page table entry with the second physical address corresponding to the target physical page.
[0167] In this embodiment, after the CPU 101 writes the contents of the first external page to the target physical page, it replaces the first physical address (indicating the first external page) in the first page table entry with the second physical address corresponding to the target physical page, thereby enabling the process to use the physical page in memory 102. Subsequently, the CPU 101 can resume the execution of the process, use the target physical page to store data, or read data from the target physical page.
[0168] In this solution, CPU101 first uses external pages as a temporary cache to avoid process interruption, while simultaneously replacing physical pages in memory 102. After blank physical pages are prepared in memory 102, the contents of the external pages are migrated to memory 102, thus ensuring process performance while taking into account process running efficiency.
[0169] It should be noted that in some possible scenarios, CPU 101 determines whether an already used external page in external storage area 103 (which can be referred to as the target external page for ease of description and distinction) is a hot page. For example, it determines the access frequency of the content in the target external page. If the access frequency is greater than a preset value, the target external page is determined to be a hot page. To ensure business performance, the hot page can be migrated to a physical page in memory 102. Optionally, in some implementations, if memory 102 can provide a target blank physical page (the size of which is greater than or equal to the size of the target external page), CPU 101 can directly... The contents of the target external page are migrated to the target blank physical page. If memory 102 cannot provide a target blank physical page (its size is greater than or equal to the size of the target external page), a cold page in memory 102 is identified (for ease of description and distinction, it can be called a target cold page). A target cold page can be understood as a physical page that has not been accessed for a long time. The size of the target cold page is greater than or equal to the size of the target external page. The contents of the target cold page are persisted. Then, the contents of the target cold page are deleted, the contents of the target external page are written into the target cold page, and the physical address in the page table entry corresponding to the target external page is replaced with the physical address corresponding to the target cold page.
[0170] The target cold page corresponds to a page table entry (which can be called a third page table entry for ease of description and distinction). Persisting the content of the target cold page can include: writing the content of the target cold page to a blank external page in the external storage area 103 (which can be called a third external page for ease of description and distinction), the size of the third external page being the same as the size of the target cold page, and replacing the physical address in the third page table entry corresponding to the target cold page with the physical address corresponding to the third external page.
[0171] The methods for identifying cold pages can include the following three:
[0172] The first method is to determine the access frequency of the content on the physical page. If the access frequency is greater than a preset value, the physical page can be identified as a cold page.
[0173] The second method for identifying cold pages can be: determining the duration of the most recent access to the physical page (i.e., the duration between the last two accesses). If the duration of the most recent access is greater than a preset value, the physical page can be identified as a cold page.
[0174] The third method for identifying cold pages can include: judging the access frequency of the content in the physical page and the duration of the most recent access to the physical page (i.e., the duration between the last two accesses). If the access frequency is greater than a preset value, or the duration of the most recent access is greater than a preset value, the physical page can be identified as a cold page.
[0175] For example, the target cold page can be the aforementioned first external page. Before executing step 601, this embodiment may further include: CPU 101 determining that the first external page is a hot page; and determining that there is no second blank physical page in memory; wherein the size of the second blank physical page is greater than or equal to that of the first external page. It should be noted that if there is a second blank physical page in memory, the content of the first external page can be written into the second blank physical page, and the first physical address in the first page table entry can be replaced with the fifth physical address corresponding to the second blank physical page.
[0176] For example, in a scenario where the content of the first physical page in the target physical page is written to the second external page, and the third physical address in the second page table entry corresponding to the first physical page is replaced with the fourth physical address corresponding to the second external page, the target cold page can be the second external page; this embodiment may also include: when the CPU 101 determines that the second external page is a hot page, it determines a third blank physical page in memory; wherein the size of the third blank physical page is greater than or equal to that of the second external page, the content of the second external page is written to the third blank physical page, and the fourth physical address in the second page table entry is replaced with the sixth physical address of the third blank physical page.
[0177] Based on the page fault handling method provided above, the specific application of the page fault handling method will be explained.
[0178] In some possible scenarios, CPU101 determines the external page corresponding to each of multiple physical addresses; assuming the process requests 6MB of virtual memory.
[0179] Figure 8 is a flowchart illustrating a specific application scenario provided by this invention. As shown in Figure 8, the specific content includes:
[0180] S1. CPU101 obtains access request 1 issued by the process. Access request 1 is used to request writing target content 1 in the virtual space. The starting address of the virtual space is virtual address 1. Virtual address 1 is used to indicate any position in the virtual page 1. For example, access request 1 includes target content 1, virtual address 1, and space size.
[0181] S2. CPU101 triggers the address translation process for virtual address 1; the address translation process includes:
[0182] S21. Based on virtual address 1, query the page table to determine that the page table entry corresponding to virtual address 1 is PET1.
[0183] S22. If the valid bit in PET1 is 0 and the address bit is empty, it means that the physical address is not configured, and a page fault (Major Fault) has occurred.
[0184] S3. CPU101 determines that memory 102 cannot provide a blank physical page of the same size as virtual page 1; for example, it checks whether memory 102 has a blank physical page of the same size as virtual page 1. If not, it means that memory 102 cannot provide a blank physical page of the same size as virtual page 1.
[0185] Therefore, CPU101 can determine that a Major Fault has occurred, and memory 102 cannot provide a blank physical page of the same size as virtual page 1, so the following two processes can be executed in parallel.
[0186] Process 1:
[0187] S4a, CPU101 identifies an available external page 1. External page 1 is the same size as virtual page 1.
[0188] S5a and CPU101 write the physical address 1 corresponding to external page 1 to the address bit in PET1.
[0189] S6a: CPU 101 caches a portion 1 of target memory 1 and writes a portion 2 of target content 1 into outer page 1. S6a is merely an example; in other scenarios, CPU 101 can cache target content 1, and subsequently, if cache space is insufficient, CPU 101 can write at least a portion of the cached target content 1 into outer page 1. In still other scenarios, CPU 101 writes target content 1 into outer page 1.
[0190] In one possible scenario under process 1, the process can access virtual address 1 again, and in this case, it can directly access external page 1. The specific process is as follows:
[0191] S7a, CPU101, obtain access request 2 issued by the process. Access request 2 is used to request access to the virtual space, and the starting address of the virtual space is virtual address 1.
[0192] S8a and CPU101 trigger the address translation process of virtual address 1 to obtain physical address 1 in PET1.
[0193] S9a and CPU101 access external page 1 based on physical address 1, for example, to read or write content.
[0194] Process 2:
[0195] S4b and CPU101 determine physical page 1 in memory 102, which is the same size as virtual page 1. Physical page 1 corresponds to physical address 2. Physical page 1 includes dirty page 1. Dirty page 1 corresponds to PET2. PET2 includes physical address 3. Physical address 3 is used to indicate the starting address of dirty page 1.
[0196] S5b and CPU101 store the contents of dirty page 1 in physical page 1 into free external page 2.
[0197] S6b and CPU101 replace the physical address 3 in PET2 corresponding to dirty page 1 with the physical address 4 of external page 2.
[0198] S7b and CPU101 delete the contents of dirty page 1, making physical page 1 a blank physical page. Then, the contents of external page 1 are written into the blank physical page 1.
[0199] S8b and CPU101 replace physical address 1 in PET1 with physical address 2 of physical page 1.
[0200] Subsequently, the process can read the contents of subpage 1. As shown in Figure 9, the specific process is as follows:
[0201] S1, CPU101 receives access request 3 from the process. Access request 3 is used to read target content 2 from the virtual space, and the starting address of the virtual space is virtual address 2. Virtual address 2 is used to indicate any location of virtual page 2.
[0202] S2, CPU101 triggers the address translation process for virtual address 2; the address translation process includes:
[0203] S21. Based on virtual address 2, query the page table to determine that the page table entry corresponding to virtual address 2 is PET2.
[0204] S22. Determine that the effective bit in PET1 is 1 and the address bit is physical address 4.
[0205] S3 and CPU101 access external page 2 based on physical address 4, for example, to read or write content.
[0206] Figure 10 is a flowchart illustrating another specific application scenario provided by the present invention. As shown in Figure 10, the difference between the flowchart shown in Figure 8 and the flowchart is that before determining the free external page 1, the CPU 101 needs to first determine the physical page 1 in memory 102 that is the same size as the virtual page 1, and determine that the physical page 1 includes the dirty page 1; then it determines the blank external page 1, and at the same time writes the contents of the dirty page 1 into the external page 2.
[0207] It should be noted that the CPU101 as the execution entity is merely one possible example. In other possible implementations, the method steps in the embodiments of this application can also be executed by an operating system, or by a processor executing software instructions. The software instructions can consist of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, portable hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can reside in an ASIC.
[0208] Based on the same concept as the method embodiments of the present invention, the present invention also provides a page fault handling device. The page fault handling device includes several modules, each module being used to execute various steps in the page fault handling method provided in the embodiments of the present invention. The division of modules is not limited here. Those skilled in the art will clearly understand that in practical applications, the various steps in the page fault handling method provided in the embodiments of the present invention can be assigned to different modules as needed, that is, the internal structure of the device can be divided into different modules to complete all or part of the functions described above. The modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more modules can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the modules are only for easy differentiation and are not intended to limit the scope of protection of the present invention. The specific working process of the modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0209] For example, a page fault handling device is used to execute the page fault handling method provided in the embodiments of the present invention. The page fault handling device is connected to memory and external storage area. The memory stores page tables, and the page tables include first page table entries, each corresponding to a first virtual address. Figure 11 is a schematic diagram of the structure of the page fault handling device provided in the embodiments of the present application. As shown in Figure 11, the page fault handling device provided in the embodiments of the present application includes:
[0210] The request acquisition module 1101 is used to acquire a first access request; wherein, the first access request includes the first virtual address, and the first virtual address is used to indicate any location in the first virtual page;
[0211] The fault analysis module 1102 is used to determine that a page fault has occurred when the physical address corresponding to the first virtual address is not configured in the first page table entry.
[0212] Address mapping module 1103 is used to fill the first physical address into the first page table entry when the memory fails to provide the first blank physical page; wherein the size of the first blank physical page is greater than or equal to the size of the first virtual page; the first physical address is used to indicate a first external page, which is a page in the external storage area that the processor can directly access;
[0213] Access module 1104 is used to access the first external page based on the first physical address in response to the first access request.
[0214] In one possible implementation, the device further includes:
[0215] The swapping module is used to determine the target physical page in memory; wherein the size of the target physical page is greater than or equal to the size of the first virtual page; write the contents of the target physical page to the external storage area; delete the contents of the target physical page; write the contents of the first external page to the target physical page; and replace the first physical address in the first page table entry with the second physical address corresponding to the target physical page.
[0216] In one possible implementation, the address mapping module 1103 is used to fill the first physical address into the first page table entry when it is determined that the target physical page has been modified.
[0217] In one example of this implementation, the apparatus further includes: a hot page processing module, configured to determine that the first external page is a hot page; and to determine that a second blank physical page does not exist in memory; wherein the size of the second blank physical page is greater than or equal to that of the first external page, and to execute a swapping module. It should be noted that if a second blank physical page exists in memory, the contents of the first external page can be written to the second blank physical page, and the first physical address in the first page table entry can be replaced with the fifth physical address corresponding to the second blank physical page.
[0218] In one example of this implementation, the target physical page includes a first physical page, which is the modified physical page;
[0219] The page table includes a second page table entry, and the second page table entry includes the third physical address corresponding to the first physical page;
[0220] The swapping module is used to write the contents of the first physical page to the second external page; wherein the second external page is a page in the external storage area that the processor can directly access; and to replace the third physical address in the second page table entry with the fourth physical address corresponding to the second external page.
[0221] In one example of this example, the request retrieval module 1101 is used to retrieve a second access request; wherein the second access request includes a second virtual address, the second virtual address is used to indicate any location of a second virtual page, and the second virtual address corresponds to a second page table entry;
[0222] Access module 1104 is used to determine the fourth physical address in the second page table entry based on the second virtual address; and in response to an access request, access the second external page based on the fourth physical address.
[0223] For example, the apparatus further includes: a hot page processing module, configured to determine a third blank physical page in memory when the second external page is determined to be a hot page; wherein the size of the third blank physical page is greater than or equal to the size of the second external page; write the contents of the second external page into the third blank physical page; and replace the fourth physical address in the second page table entry with the sixth physical address of the third blank physical page.
[0224] In one possible implementation, the request acquisition module 1101 is used to acquire a third access request; wherein the third access request includes a first virtual address;
[0225] Access module 1104 is used to determine the first physical address in the first page table entry based on the first virtual address; and in response to a third access request, access the first external page based on the first physical address.
[0226] In one possible implementation, the first page table entry includes a first value and a second flag bit; the first value is used to indicate that the first virtual page is not configured with a physical address;
[0227] The address mapping module 1103 is used to update the first value of the first flag bit to a second value; wherein the second value is used to indicate that the first virtual page is configured with a physical address; and the first physical address is written into the second flag bit.
[0228] In one possible implementation, the external storage area includes at least one of the following:
[0229] Solid-state drives, phase-change memory, and memory based on interconnect bus protocols.
[0230] Based on the same concept as the embodiments of the method of the present invention, embodiments of the present invention also provide an electronic device. This electronic device can be a server or a terminal device. The terminal device can be a mobile phone, tablet computer, wearable device, smart TV, Huawei smart screen, smart speaker, in-vehicle system, etc.
[0231] Figure 12 is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0232] As shown in Figure 12, the electronic device 1200 includes a processor 1201, a memory 1202, and a network interface 1203.
[0233] The processor 1201 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0234] Memory 1202 may include volatile and non-volatile memory; wherein, the non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may be random access memory (RAM), which serves as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0235] In this embodiment, the volatile memory may include the aforementioned memory 102, and the non-volatile memory may include the external storage area 103.
[0236] For example, a computer program may be stored in the memory 1202. When the processor 1201 executes the computer program, it implements the steps in the above-described page fault handling method embodiments, such as steps 401 to 404 shown in FIG. 4b, steps 501 to 503 shown in FIG. 5b, and steps 601 to 604 shown in FIG. 6b. Alternatively, when the processor 1201 executes the computer program, it implements the functions of each module in the above-described device embodiments. Exemplarily, the computer program may be divided into one or more modules / units. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions. The one or more modules / units are stored in the memory 1202 and executed by the processor 1201 to complete the present invention. For example, the computer program may be divided into a request acquisition module 1101, a fault analysis module 1102, an address mapping module 1103, and an access module 1104. The specific functions of each module are described above.
[0237] The network interface 1203 is used to send and receive data, for example, to send data processed by the processor 1201 to other electronic devices, or to receive data sent by other electronic devices.
[0238] In addition to the methods, apparatus, and electronic devices described above, embodiments of this application may also provide a computer program product comprising computer program instructions. When executed by a processor, these computer program instructions cause the processor to perform the steps of the page fault handling methods described in the various embodiments of this application in the "Method" section of this specification. The computer program product may be written in any combination of one or more programming languages to execute computer program code for performing the operations of the embodiments of this application. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The computer program code may be in source code form, object code form, executable file, or some intermediate form. The computer program code may be executed entirely on a user's computing device, partially on a user's device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0239] Furthermore, embodiments of this application may also provide a computer-readable storage medium storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps of the display control method according to various embodiments of this disclosure as described in the "Method" section above. The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may include, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. It should be noted that the content contained in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, a computer-readable medium may not include electrical carrier signals and telecommunication signals.
[0240] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0241] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0242] The basic principles of this application have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this application are merely examples and not limitations, and should not be considered as essential features of the various embodiments of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the specific details described above.
[0243] The block diagrams of devices, apparatuses, devices, and systems disclosed herein are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.
[0244] It should also be noted that in the apparatus, devices, and methods of this disclosure, the components or steps can be disassembled and / or recombined. These disassemblies and / or recombinations should be considered as equivalent solutions to this disclosure.
[0245] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.
[0246] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application.
Claims
1. A method for handling page faults, characterized in that, Applied to a processor, the processor is connected to memory and external storage areas, the memory stores page tables, the page tables include first page table entries, the first page table entries corresponding to a first virtual address, including: Obtain a first access request; wherein the first access request includes the first virtual address, and the first virtual address is used to indicate any location in the first virtual page; If the physical address corresponding to the first virtual address is not configured in the first page table entry, a page fault is determined to have occurred. If the memory fails to provide a first blank physical page, the first physical address is filled into the first page table entry; wherein the size of the first blank physical page is greater than or equal to the size of the first virtual page; the first physical address is used to indicate a first external page, which is a page in the external storage area that the processor can directly access; In response to the first access request, the first external page is accessed based on the first physical address.
2. The method according to claim 1, characterized in that, The method further includes: Determine the target physical page in the memory; wherein the size of the target physical page is greater than or equal to the size of the first virtual page; Write the contents of the target physical page to the external storage area; Delete the contents of the target physical page; Write the contents of the first external page into the target physical page; Replace the first physical address in the first page table entry with the second physical address corresponding to the target physical page.
3. The method according to claim 2, characterized in that, Before filling the first physical address into the first page table entry, the method further includes: It has been determined that the target physical page has been modified.
4. The method according to claim 2 or 3, characterized in that, The target physical page includes a first physical page, which is a modified physical page; The page table includes a second page table entry, and the second page table entry includes a third physical address corresponding to the first physical page; The step of writing the content of the target physical page to the external storage area includes: Write the contents of the first physical page to the second external page; wherein the second external page is a page in the external storage area that the processor can directly access; Replace the third physical address in the second page table entry with the fourth physical address corresponding to the second external page.
5. The method according to claim 4, characterized in that, The method further includes: Obtain a second access request; wherein the second access request includes a second virtual address, the second virtual address is used to indicate any location of the second virtual page, and the second virtual address corresponds to the second page table entry; Based on the second virtual address, determine the fourth physical address in the second page table entry; In response to the access request, the second external page is accessed based on the fourth physical address.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Obtain a third access request; wherein the third access request includes the first virtual address; Based on the first virtual address, determine the first physical address in the first page table entry; In response to the third access request, the first external page is accessed based on the first physical address.
7. The method according to any one of claims 1 to 6, characterized in that, The first page table entry includes a first value and a second flag bit; the first value is used to indicate that the first virtual page is not configured with a physical address; The step of writing the first physical address into the first page table entry includes: Update the first value of the first flag bit to the second value; wherein the second value is used to indicate that the first virtual page is configured with a physical address; Write the first physical address into the second flag bit.
8. The method according to any one of claims 1 to 7, characterized in that, The external storage area includes at least one of the following: Solid-state drives, phase-change memory, and memory based on interconnect bus protocols.
9. A page fault handling device, characterized in that, The page fault handling device is connected to memory and external storage area. The memory stores page tables, and the page tables include first page table entries, each corresponding to a first virtual address. The device includes: A request acquisition module is used to acquire a first access request; wherein the first access request includes the first virtual address, and the first virtual address is used to indicate any location in the first virtual page; The fault analysis module is used to determine that a page fault has occurred when the physical address corresponding to the first virtual address is not configured in the first page table entry. The address mapping module is used to fill the first physical address into the first page table entry when the memory fails to provide a first blank physical page; wherein the size of the first blank physical page is greater than or equal to the size of the first virtual page; the first physical address is used to indicate a first external page, which is a page in the external storage area that the processor can directly access; An access module is configured to access the first external page based on the first physical address in response to the first access request.
10. The apparatus according to claim 9, characterized in that, The device further includes: A swapping module is used to determine a target physical page in the memory; wherein the size of the target physical page is greater than or equal to the size of the first virtual page; write the content of the target physical page to the external storage area; delete the content of the target physical page; write the content of the first external page to the target physical page; and replace the first physical address in the first page table entry with the second physical address corresponding to the target physical page.
11. The apparatus according to claim 10, characterized in that, The address mapping module is used to fill the first physical address into the first page table entry when it is determined that the target physical page has been modified.
12. The apparatus according to claim 10 or 11, characterized in that, The target physical page includes a first physical page, which is a modified physical page; The page table includes a second page table entry, and the second page table entry includes a third physical address corresponding to the first physical page; The switching module is used to write the contents of the first physical page to a second external page; wherein the second external page is a page in the external storage area that the processor can directly access; and to replace the third physical address in the second page table entry with the fourth physical address corresponding to the second external page.
13. The apparatus according to claim 12, characterized in that, The request acquisition module is used to acquire a second access request; wherein the second access request includes a second virtual address, the second virtual address is used to indicate any position of the second virtual page, and the second virtual address corresponds to the second page table entry; The access module is configured to determine a fourth physical address in the second page table entry based on the second virtual address; and in response to the access request, access the second external page based on the fourth physical address.
14. The apparatus according to any one of claims 9 to 13, characterized in that, The request acquisition module is used to acquire a third access request; wherein the third access request includes the first virtual address; The access module is configured to determine the first physical address in the first page table entry based on the first virtual address; and in response to the third access request, access the first external page based on the first physical address.
15. The apparatus according to any one of claims 9 to 14, characterized in that, The first page table entry includes a first value and a second flag bit; the first value is used to indicate that the first virtual page is not configured with a physical address; The address mapping module is used to update the first value of the first flag bit to a second value; wherein the second value is used to indicate that the first virtual page is configured with a physical address; and the first physical address is written into the second flag bit.
16. The apparatus according to any one of claims 9 to 15, characterized in that, The external storage area includes at least one of the following: Solid-state drives, phase-change memory, and memory based on interconnect bus protocols.
17. A page fault handling device, characterized in that, include: At least one memory for storing programs; At least one processor is configured to execute a program stored in the memory, wherein when the program stored in the memory is executed, the processor is configured to perform the method as described in any one of claims 1-8.
18. A page fault handling device, characterized in that, The device executes computer program instructions to perform the method as described in any one of claims 1-8.
19. A computer storage medium, characterized in that, The computer storage medium stores instructions that, when executed on the computer, cause the computer to perform the method as described in any one of claims 1-8.
20. A computer program product containing instructions, characterized in that, When the instructions are executed on a computer, the computer causes the computer to perform the method as described in any one of claims 1-8.
