Method and device for processing zero page in physical memory, equipment and storage medium
By identifying and recycling zero pages generated when virtual machine startup, the problem of excessive physical memory usage during virtual machine startup is solved, and the operation efficiency of the host is improved.
Patent Information
- Application Number
- CN202311279721.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-27
- Publication Date
- 2025-03-28
AI Technical Summary
When the virtual machine starts up, it applies for physical memory to the host and clears it, causing a large number of zero pages to occupy physical memory, causing the host to run stutter.
By identifying the operation of generating zero pages, recording the zero page mark, and detecting the pages recorded with zero page marks in the physical memory page to recycle, reducing the physical memory usage.
It effectively reduces the physical memory usage, prevents the host from running stuttering, and simplifies the process of removing zero pages, improving the efficiency of removing zero pages.
Smart Images

Figure CN119718610A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for processing zero pages in a physical memory. Background Art
[0002] With the development of computer technology, virtual machines have been widely used. A virtual machine is a complete computer system that has complete hardware system functions and runs in a completely isolated environment, which is simulated by software. All the work that can be done in a physical computer can be done in a virtual machine.
[0003] When the virtual machine starts, it requests a certain amount of physical memory from the host. Then it clears the physical memory page, that is, sets all the page data to zero. In this way, a large number of zero pages will be generated in the physical memory. Zero pages are pages that store all zero data.
[0004] A large amount of physical memory occupied by zero pages can cause the host to run slowly. Summary of the invention
[0005] The present disclosure provides a method, apparatus, device and storage medium for processing zero pages in physical memory, which can improve the efficiency of processing zero pages in physical memory.
[0006] In a first aspect, a method for processing zero pages in physical memory is provided, the method comprising: first identifying an operation for generating a zero page; then determining the zero page corresponding to the operation, and recording a zero page mark for the zero page; then detecting a page with a zero page mark in the physical memory page; and finally recycling the page with a zero page mark. A zero page is a physical memory page containing data that is all zero, and recycling is to set the page to an unallocated state.
[0007] In the above operation, the process of detecting the zero page mark can be triggered periodically, manually, or by a certain specified process. The process of detecting the zero page mark can be for all physical memory pages or for some physical memory pages.
[0008] In this way, zero pages can be recycled to reduce the physical memory usage and prevent host operation from stalling. In addition, compared with removing zero pages by deduplication of pages, directly recycling zero pages can effectively simplify specific processing, for example, it can reduce the number of refreshes of the translation lookaside buffer (TLB), eliminate the need for page table write protection, etc. Thus, the efficiency of removing zero pages can be effectively improved.
[0009] In one possible implementation, the reference count of a page recorded with a zero page mark is reduced by a first value, wherein the reference count is used to indicate the number of entities using the page, and the entities include processes and / or threads; if the reduced reference count is equal to a second value, the page recorded with the zero page mark is reclaimed.
[0010] The first value may be any preset value such as 1, 2, etc. Correspondingly, when the virtual machine applies to use the page, the reference technology also increases the first value. The second value may be 0.
[0011] In this way, the page recovery is triggered by reducing the reference count by a fixed value. If other processes or threads are also using the page at this time, the reference count will not be reduced to zero after being reduced, the page will not be recovered, and the use of the page by other processes or threads will not be affected. If other processes or threads are not using the page at this time, the reference count will be reduced to zero after being reduced, and the page will be recovered.
[0012] In a possible implementation, the operation for generating a zero page includes: executing a first hardware instruction, wherein the first hardware instruction is a hardware instruction for clearing a physical memory page to zero.
[0013] The first hardware instruction may be a newly defined hardware instruction. When the processor executes the hardware instruction, it may perform an operation of clearing the target page to obtain a zero page, and mark the zero page.
[0014] In this way, the processor can complete the complex operation steps involved in the generation and recycling of zero pages by executing the first hardware instruction, thereby simplifying the operations of zero page generation and recycling.
[0015] In one possible implementation, before identifying an operation for generating a zero page, during the process of compiling the client code, a first code segment to be compiled is obtained, and if it is identified that the first code segment is a code segment for clearing a physical memory page, the first code segment is compiled into a first hardware instruction.
[0016] The client code is any program code used to run in the client. Compilation can occur at any time before the code is executed. The compiled code can be temporarily not executed until the execution instruction is received. Compilation can be performed by any device. Code compilation and code execution can occur on different devices or on the same device. In addition, compilation can also occur when the code is executed.
[0017] In this way, the first code segment for clearing the physical page is compiled into the first hardware instruction, and the processor can complete the complex operation steps involved in the generation and recycling of the zero page by executing the first hardware instruction, thereby simplifying the operations of zero page generation and recycling.
[0018] In a possible implementation, the first code segment is a first function, a function name of the first function is a specified function name, and a function corresponding to the specified function name is a function for clearing a physical memory page.
[0019] The specified function name may be memset (a function name) or RtlZeroMemory (a function name), etc.
[0020] In this way, by matching the function name, the code segment used to zero the physical memory page can be identified. The processing method is relatively simple and occupies less processor resources.
[0021] In a possible implementation, the operation for generating a zero page includes: calling a second code segment, wherein the second code segment is a code segment for clearing a physical memory page to zero.
[0022] The second code segment is a code segment for clearing the memory page to zero, and this code segment can be a function or a non-function.
[0023] In this way, at the stage of calling the code segment, the operation for generating the zero page can be identified, and the generation of the zero page can be determined more timely.
[0024] In one possible implementation, the second code segment is a second function, the function name of the second function is a specified function name, and the function corresponding to the specified function name is a function used to clear physical memory pages; or, the second code segment is a second function, the function name of the second function is the specified function name, and the current input parameters of the second function meet the page clearing judgment condition corresponding to the specified function name.
[0025] The guest operating system (GuestOS) can pre-store a correspondence table between function names and page zeroing judgment conditions. The functions involved in the correspondence table are functions that can clear memory pages, such as memset and RtlZeroMemory. These functions can clear memory pages when the input parameters meet certain conditions, which are the page zeroing judgment conditions in the table.
[0026] In this way, the processing method of directly matching the function name occupies less processor resources. Combining function name matching and input parameter judgment to identify the operation used to generate zero pages has a higher recognition accuracy.
[0027] In a possible implementation, the operation for generating a zero page includes: translating a second hardware instruction provided by the client operating system to obtain a third hardware instruction, wherein the third hardware instruction is a hardware instruction for clearing a physical memory page.
[0028] In this way, in the hardware instruction translation stage, the operation used to generate the zero page can be identified, and the generation of the zero page can be determined more timely.
[0029] In one possible implementation, the third hardware instruction is a specified hardware instruction, and the current input parameters of the third hardware instruction meet the page clearing judgment condition corresponding to the specified hardware instruction; or, the third hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
[0030] In this way, the processing method of directly matching the hardware instructions occupies less processor resources. Combining hardware instruction matching and input parameter judgment to identify the operation used to generate zero pages has a higher recognition accuracy.
[0031] In a possible implementation, the operation for generating a zero page includes: obtaining a fourth hardware instruction to be executed, wherein the fourth hardware instruction is a hardware instruction for clearing a physical memory page to zero.
[0032] During the execution of the client code, the processor determines that the fourth hardware instruction to be executed is a hardware instruction for clearing a memory page, and performs debugging on the fourth hardware instruction so that the hypervisor obtains the fourth hardware instruction. The hypervisor determines the corresponding zero page.
[0033] In this way, the processor identifies the operation for generating a zero page by hardware, which has higher processing efficiency than the software identification method.
[0034] In one possible implementation, the fourth hardware instruction is a specified hardware instruction, and the current input parameter of the fourth hardware instruction satisfies the page clearing judgment condition corresponding to the specified hardware instruction; or, the fourth hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
[0035] In this way, the processing method of directly matching the hardware instructions occupies less processor resources. Combining hardware instruction matching and input parameter judgment to identify the operation used to generate zero pages has a higher recognition accuracy.
[0036] In a possible implementation, the zero page marker is recorded in a nested page table of the zero page.
[0037] In this way, there is no need to establish other information tables or data structures to record the zero page mark.
[0038] In a possible implementation, before detecting a page with a zero page mark recorded in a physical memory page, after recording a zero page mark for a zero page, if a write operation to the zero page is detected, the zero page mark recorded for the zero page is cancelled.
[0039] In this way, whether a page is a zero page can be directly determined through the zero page mark, which can improve the efficiency of zero page detection.
[0040] In a possible implementation, after determining the zero page corresponding to the operation, the dirty bit corresponding to the zero page in the nested page table is set to an unset state. When it is detected that the dirty bit is set to a set state, the zero page mark of the zero page record is cancelled. The dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page. If the dirty bit changes from an unset state to a set state after being set to an unset state, it means that a write operation has occurred on the page corresponding to the dirty bit after it was set to an unset state.
[0041] When recording the zero page mark for the target page, the dirty bit of the page table entry corresponding to the target page in the nested page table can be set to 0. After recording the zero page mark for the zero page, when the page is written again, the dirty bit is automatically set to 1, and the zero page mark recorded for the zero page is cancelled.
[0042] In this way, by using dirty bit identification to determine whether a page has a write operation, the content to be identified is relatively simple and occupies less processing resources.
[0043] In a possible implementation, after determining the zero page corresponding to the operation, the dirty bit corresponding to the zero page in the nested page table is set to an unset state. Based on the fact that the dirty bit corresponding to the page with the zero page mark in the nested page table has not changed to a set state, the page with the zero page mark is recycled. The dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page. If the dirty bit changes from an unset state to a set state after being set to an unset state, it means that a write operation has occurred on the page corresponding to the dirty bit after the dirty bit is set to an unset state.
[0044] When recording the zero page mark for the target page, the dirty bit of the page table entry corresponding to the target page can be set to 0 in the nested page table. There is no need to cancel the zero page mark or perform the corresponding cancellation operation. When performing zero page identification, for any page, if the page records the zero page mark and the value of the dirty bit corresponding to the page is 0, then the page can be determined to be a zero page. If the page does not record the zero page mark, or the value of the dirty bit corresponding to the page is 1, then the page can be determined not to be a zero page.
[0045] In this way, after a page is written, there is no need to cancel the zero page mark, which simplifies the operation.
[0046] In a second aspect, a device for processing zero pages in physical memory is provided, the device comprising at least one module, and the at least one module is used to implement the method provided by the above-mentioned first aspect and its possible implementation methods.
[0047] In a third aspect, a computer device is provided, the computer device comprising a memory and a processor, the memory being used to store computer instructions. The processor executes the computer instructions stored in the memory, so that the computer device executes the method provided in the first aspect and possible implementations thereof.
[0048] In a fourth aspect, a mobile terminal is provided, the mobile terminal comprising a memory and a processor, the memory being used to store computer instructions. The processor executes the computer instructions stored in the memory to enable the mobile terminal to execute the method provided in the first aspect and possible implementations thereof.
[0049] In a fifth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code. When the computer program code is executed by a computer device, the computer device executes the method provided by the first aspect and its possible implementation methods.
[0050] In a sixth aspect, a computer program product is provided, the computer program product comprising a computer program code, and when the computer program code is executed by a computer device, the computer device executes the method provided by the first aspect and its possible implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 is a page table entry of an EPT provided by an embodiment of the present disclosure;
[0052] Figure 2 is a stage-2 page table entry provided by an embodiment of the present disclosure;
[0053] Figure 3 is a schematic diagram of the structure of a terminal device provided by an embodiment of the present disclosure;
[0054] Figure 4 It is a flowchart of a method for processing a physical memory zero page provided by an embodiment of the present disclosure;
[0055] Figure 5 is a schematic diagram of a processing flow for determining a zero page provided by an embodiment of the present disclosure;
[0056] Figure 6 is a schematic diagram of a processing flow for determining a zero page provided by an embodiment of the present disclosure;
[0057] Figure 7 is a schematic diagram of a processing flow for determining a zero page provided by an embodiment of the present disclosure;
[0058] Figure 8 is a schematic diagram of a processing flow for determining a zero page provided by an embodiment of the present disclosure;
[0059] Fig. 9A page table entry for configuring a zero page mark bit provided by an embodiment of the present disclosure;
[0060] Fig.10 It is a structural diagram of a device for processing a physical memory zero page provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0061] The embodiment of the present disclosure provides a method for processing zero pages in physical memory, which is used to reduce the occupation of memory resources by zero pages. The following is an explanation of some terms in the processing process of the method:
[0062] Physical Memory
[0063] Physical memory, also known as main memory or random access memory, is the hardware device used to store data and instructions in a computer system.
[0064] page
[0065] A page is a basic unit of storage space in physical memory.
[0066] Zero Page
[0067] Zero page refers to a physical memory page whose data is all zero. Generally, zero page is mainly generated during the operation of virtual machine.
[0068] Zeroing a physical memory page means changing all the data in the page in the physical memory to zero, making the page a zero page.
[0069] Page zeroing instruction
[0070] A page zeroing instruction is an instruction that can be directly executed by a central processing unit (CPU). The instruction can clear the memory page at a specified physical address according to a given page size.
[0071] Virtual Machines
[0072] A virtual machine is a complete computer system with complete hardware system functions that is simulated by software. A virtual machine can also be called a client, and the physical machine that runs the virtual machine can be called a host.
[0073] Hypervisor
[0074] A hypervisor can be considered as a program that allocates hardware resources such as memory to virtual machines running on a host and manages the operation of virtual machines. A hypervisor can be a virtual machine monitor (VMM) or a kernel-based virtual machine (KVM).
[0075] Guest operating system (GuestOS)
[0076] The operating system installed and running on the client.
[0077] Host operating system (HostOS)
[0078] The operating system installed and running on the host.
[0079] Page table (PT)
[0080] The page table is used to record the mapping information between the physical address and the virtual address of the page. The page table may include multiple page table entries, each of which corresponds to a page in the memory.
[0081] The page table recorded by GuestOS can be used to record the mapping information between the guest virtual address (GVA) and the guest physical address (GPA), where GPA is the physical address in the client. Although it is called a physical address, it is not a real physical address. The page table recorded by the hypervisor can be used to record the mapping information between GPA and the host physical address (HPA), which is generally called a nested page table (NPT). When there are multiple virtual machines in the host, each virtual machine corresponds to a hypervisor, and the hypervisor records the nested page table corresponding to the virtual machine it manages.
[0082] Nested page tables (NPT)
[0083] The page table entry of the nested page table includes multiple bits, each bit can have a field of a specified length (number of bits), and the multiple bits can include bits for recording physical addresses, bits for recording some related parameters (such as stolen bits, memory type bits), etc. The page table entry can also include reserved fields (reserved). The reserved fields are fields that are not yet defined in the protocol. According to actual needs, some or all of the fields in the reserved fields can be defined as new bits to expand the functionality of the nested page table.
[0084] In the embodiment of the present disclosure, related operations are performed on the nested page tables in the hypervisor. Common nested page tables include extended page tables (EPT) and stage-2 page tables. The page table entries of EPT are as follows: Figure 1 As shown in the figure, bits 9-11 are reserved fields. The parameters of each field in the figure are not introduced one by one. In the figure, Reseverd represents the reserved field and D represents the stolen bit. The page table entry of stage-2 is as follows Figure 2 As shown, among the 2-5 bits occupied by the memory type field, some fields are reserved fields, and the parameters of each field in the figure are not introduced one by one.
[0085] Dirty bit
[0086] The dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page, that is, it is used to indicate whether the content in the page has changed. The dirty bit is used in the following way: if the dirty bit changes from an unset state to a set state after being set to an unset state, it indicates that a write operation has occurred on the corresponding page after being set to an unset state. In other words, the unset state indicates that the content of the page has not changed, and the set state indicates that the content of the page has changed. Generally, the unset state can be represented by a value of 0, and setting the dirty bit to an unset state can also be said to be setting the dirty bit to 0. The set state can be represented by a value of 1, and setting the dirty bit to a set state can also be said to be setting the dirty bit to 1. For example, based on a certain business logic, in a certain case, the dirty bit corresponding to a certain page is set to 0. In the subsequent processing process, if the content of the page changes, the dirty bit is set to 1. In this way, it is possible to determine whether the content of the page has changed after the dirty bit is set to 0 by detecting the dirty bit value.
[0087] Recycle
[0088] Reclamation is the process of changing a physical memory page from an allocated state to a non-allocated state.
[0089] Reference counting
[0090] The reference count is used to indicate the number of times a page of physical memory is referenced. It can also be said that the reference count is used to indicate the number of entities (which may include processes and / or threads) that use the page. Because the number of times different entities use a page is generally 1, the number and the number can be considered equivalent. Various processes or threads will use their own mechanisms to add 1 or subtract 1 to the reference technology based on their own business needs. For example, a page can be shared by multiple virtual machines. When a virtual machine uses a page, it can create a page table entry for the page in the nested page table of the virtual machine, record the corresponding address mapping information, and the corresponding reference count of the page will also be increased by 1. When multiple virtual machines share the same page, the page table entry of the page will be created in the nested page tables of these virtual machines, and the corresponding reference count of the page will be equal to the number of virtual machines sharing the page.
[0091] Debug
[0092] Debug is a function in hardware-assisted virtualization technology. The general mechanism of hardware-assisted virtualization technology is: because the virtual machine does not have the highest authority in the processor, some hardware instructions that the virtual machine wants to execute may be rejected by the processor. In this case, hardware-assisted virtualization technology can let the hypervisor know the hardware instructions that are rejected and the reasons for rejection. The hypervisor can ensure the normal execution of these hardware instructions in some way. The working principle of the debug function is: the processor can add a mark (called a breakpoint) to any hardware instruction to be executed. The marked hardware instructions will be rejected by the processor. Then, based on the general mechanism of hardware-assisted virtualization technology, the hypervisor will know that the hardware instruction is rejected and the reason for rejection.
[0093] With the help of the debug function, some hardware instructions can be processed through the hypervisor according to business needs, such as instruction analysis.
[0094] The method for processing zero pages in physical memory provided by the embodiment of the present disclosure can be implemented by a computer device. The computer device can be any device equipped with a virtual machine. The computer device can be a terminal device or a server. The terminal device can be a mobile phone, iPad, desktop computer, laptop computer, etc. The server can be a server of a certain application, a server of a cloud service, or a server for completing certain computing tasks, etc. Taking a terminal device as an example, a Windows operating system can be run on the terminal device, and a virtual machine can be run under the Windows operating system, and another Windows operating system or other operating systems can be run in the virtual machine.
[0095] Virtual machines are widely used on terminal devices, so the embodiment of the present disclosure takes the computer device as a terminal device as an example to explain the solution in detail. Other situations are similar and will not be described in detail.
[0096] like Figure 3 As shown, the terminal device may include a processor 310, a memory 320, a communication component 330, a display component 340, and the like.
[0097] The processor 310 may be a central processing unit (CPU), and the processor may be used to execute various operation instructions. For example, the processor may be used to mark and recycle zero pages in the physical memory.
[0098] The memory 320 may be various volatile memories or non-volatile memories, such as a solid state disk (SSD), a dynamic random access memory (DRAM), etc. The memory may be used to store pre-stored data, intermediate data, and result data related to the processing process, such as a nested page table, etc.
[0099] The communication component 330 may be a wired network connector, a wireless fidelity (WiFi) module, a Bluetooth module, a cellular network communication module, etc. The communication component may be used to transmit data with other devices, for example, the communication component may be used to receive an operation instruction of a processor, and may also be used to send an address of a memory page to a virtual machine, and so on.
[0100] The display component 340 can be an independent screen, or a screen integrated with the terminal body, a projector, etc. The screen can be a touch screen or a non-touch screen (which can be remotely written on). The display component 340 is used to display the system interface, application interface, etc. For example, the display component 340 can display the current memory usage of the terminal device.
[0101] In addition to the processor 310, the memory 320, the communication component 330 and the display component 340, the terminal device may also include an audio collection component 350, an audio output component 360, an image collection component 370 and various operation input components 380.
[0102] The audio collection component 350 may be a microphone for collecting the user's voice. The audio output component 360 may be a speaker, earphones, etc. for playing audio. The image collection component 370 may be a camera for taking images. The operation input component 380 may include a mouse, keyboard, touch pad, handwriting board, etc.
[0103] When a virtual machine is started, the host allocates physical memory to the virtual machine according to the virtual machine's needs and clears the physical memory that is not used by the current virtual machine. However, the physical memory actually used by the virtual machine when it is just started is very small, far less than the allocated physical memory. At this time, there will be a large number of zero pages in the allocated but unused physical memory. These zero pages cannot be used by the host or other virtual machines on the host. A large number of zero pages in the physical memory will waste physical memory resources.
[0104] In the method for processing physical memory zero pages provided in the embodiment of the present disclosure, the generated zero pages are recycled. Figure 4 The process flow of the method may include the following steps:
[0105] 401 , identifying an operation for generating a zero page, and determining a zero page corresponding to the operation.
[0106] Based on different identification methods, this step can have a variety of specific processing methods. The following is a brief introduction to several of them.
[0107] Method 1: During the compilation of the client code, the compiler compiles the first code segment for clearing the physical memory page into a first hardware instruction (the first hardware instruction is the page clearing instruction introduced above). During the execution of the compiled client code, when the page clearing instruction is executed, the processor determines the target page (i.e., zero page) corresponding to the page clearing instruction. The specific process is as follows: Figure 5 The processing flow shown is described in detail.
[0108] Method 2: During the execution of the client code, the GuestOS obtains the second code segment currently being called. When the GuestOS determines that the second code segment is a code segment for clearing the physical memory page, it determines the target page (i.e., zero page) to be cleared by the second code segment and notifies the HostOS. The specific process is as follows: Figure 6 The processing flow shown is described in detail.
[0109] Method 3: During the execution of the client code, the hypervisor translates the second hardware instruction provided by the GuestOS to obtain a third hardware instruction supported by the processor. The hypervisor determines that the translated third hardware instruction is a hardware instruction for clearing a physical memory page, determines the target page to be cleared by the third hardware instruction (i.e., zero page), and notifies the HostOS. The specific process is as follows: Figure 7 The processing flow shown is described in detail.
[0110] Method 4: During the execution of the client code, the processor determines that the fourth hardware instruction to be executed is a hardware instruction for clearing the physical memory page, and debugs the fourth hardware instruction so that the hypervisor can obtain the fourth hardware instruction. The hypervisor determines the target page (i.e., zero page) to be cleared by the fourth hardware instruction and notifies the HostOS. The specific process is as follows: Figure 8 The processing flow shown is described in detail.
[0111] 402, record a zero page mark for the zero page.
[0112] Recording method 1: Record the zero page mark in the nested page table.
[0113] A zero page mark bit can be configured in advance in the nested page table, and the zero page mark bit can be configured in a reserved field. Fig. 9 As shown in FIG. 1 , bits 9 to 11 in the page table entry are reserved fields, and bit 9 can be configured as a zero page mark bit, represented by the letter Z in the figure. For another example, Figure 2 As shown, the 0x05 bit in the memory type is configured as the zero page mark bit, which is represented by Zero in the figure.
[0114] The value of the zero page mark can be set manually. For example, the initial value in the zero page mark bit of the page table entry corresponding to any page is 0. At this time, it can be considered that there is no zero page mark recorded for the page. When the page is cleared, the value of the zero page mark bit is set to 1, that is, the zero page mark is recorded for the page.
[0115] When the value in the zero page mark bit is 0, it indicates that the corresponding page is not a zero page. When the value in the zero page mark bit is 1, it indicates that the corresponding page is a zero page.
[0116] Recording method 2: Record the zero page mark outside the nested page table.
[0117] An array can be created, where each value in the array corresponds to a page, and each value is used to indicate whether the corresponding page is a zero page. The zero page mark corresponds to a specified value (such as 1), that is, when a value in the array is the specified value, the page corresponding to the value is a zero page. For example, the first value in the array corresponds to page 0, the second value corresponds to page 1, and so on. In the initial state of the array, all values are set to 0. When a page is cleared, the value corresponding to the page is set to 1, that is, the zero page mark is recorded for the page.
[0118] Alternatively, an array may be created to record the page identifier of the zero page. The array is initially empty, and when a page is cleared to zero, the page identifier of the page is added to the array, that is, the zero page mark is recorded for the page.
[0119] The above array recording zero page mark method can establish an array corresponding to each virtual machine, and the array corresponding to each virtual machine is used to record the zero page mark involved in the virtual machine.
[0120] In the above-mentioned process of recording the zero page mark through an array, the array is also established corresponding to the virtual machine, and different virtual machines can respectively establish their own corresponding arrays.
[0121] The above steps 401-402 give the process of adding a zero page mark. Alternatively, for the target page to which the zero page mark is added, when a write operation to the target page is detected, the zero page mark recorded on the target page can be canceled. Specifically, the zero page mark can be directly canceled when the write operation occurs, or the zero page mark can be canceled when a change in the target page content is detected by other means, such as by dirty bit detection, which will be described in detail later. Regarding the processing method for canceling the zero page mark, for example, for the above recording method one, the zero page mark position can be set to 0.
[0122] 403. HostOS detects a page with a zero page mark in the physical memory page.
[0123] The processing of this step can be performed periodically. For the above-mentioned recording method 1, HostOS can traverse the nested page tables corresponding to each virtual machine currently running on the host, and traverse the zero page mark bit in each page table entry in each nested page table to determine the zero page in each page. For the above-mentioned recording method 2, HostOS can traverse the above-mentioned array to determine the zero page in each page.
[0124] 404, HostOS reclaims the page with zero page mark.
[0125] After detecting the zero page mark of a page, HostOS decrements the reference count of the page by 1 (other preset values may also be used), and determines whether the reference count after decrement is 0 (other preset values may also be used). If it is 0, the page will be automatically triggered to be recycled. If it is not 0, it will not be recycled for the time being. Because in addition to the mechanism in this method, there may be other mechanisms to add and subtract the reference count of the page, so the reference count after decrement is not necessarily equal to 0, and the page can be recycled when the subsequent reference count is 0. For example, when multiple virtual machines share a page, the reference count of the page is equal to the number of virtual machines that share the page. After the zero page mark of the page is detected in the nested page table or array of a virtual machine, the reference count can be decremented by 1. The reference count after decrement is not equal to 0. The zero page mark of the page is detected again in the nested page table or array of other virtual machines, and the reference count of the page will be decremented by 1 again until the reference count is reduced to 0, which triggers the recycling of the page. While recycling the page, HostOS can release the page table entry corresponding to the page in the nested page table.
[0126] The execution of step 401 will trigger step 402, but steps 401-402 and steps 403-404 may be executed asynchronously, that is, steps 401-402 will not trigger step 403, and step 403 may be triggered and executed according to a fixed cycle. The execution of step 403 will trigger step 404.
[0127] In the above process, the dirty bit in the page table entry can be used together with the zero page mark to realize the identification of the zero page. Accordingly, there are many possible methods, two of which are introduced below:
[0128] Method 1: Use the dirty bit to determine the write operation of the page, and then cancel the zero page mark. When identifying the zero page, only the zero page mark needs to be identified.
[0129] When recording the zero page mark for the target page, the dirty bit of the page table entry corresponding to the target page can be set to 0 in the nested page table. Subsequently, the dirty bit of the page table entry can be periodically detected. When it is detected that the value of the dirty bit becomes 1, it is determined that the content of the target page has changed, that is, the target page is no longer a zero page. At this time, the zero page mark of the target page is cancelled. When performing zero page identification, for any page, if the corresponding record has a zero page mark, it can be determined to be a zero page. If there is no corresponding record with a zero page mark, it can be determined to be not a zero page.
[0130] Method 2: Do not set the cancellation logic for the zero page mark. When identifying the zero page, the dirty bit and the zero page mark can be combined for judgment.
[0131] When recording the zero page mark for the target page, the dirty bit of the page table entry corresponding to the target page can be set to 0 in the nested page table. There is no need to cancel the zero page mark or perform the corresponding cancellation operation. When performing zero page identification, for any page, if the page records the zero page mark and the value of the dirty bit corresponding to the page is 0, then the page can be determined to be a zero page. If the page does not record the zero page mark, or the value of the dirty bit corresponding to the page is 1, then the page can be determined not to be a zero page.
[0132] In the embodiment of the present disclosure, when an operation for generating a zero page is identified, the zero page corresponding to the operation is determined and the zero page is marked. In addition, a page with a zero page mark is detected in the physical memory page and recycled. Thus, the corresponding physical memory can be released to reduce the occupation of the physical memory and prevent the host from running stuck.
[0133] In addition, compared with removing zero pages by deduplication of pages, directly reclaiming zero pages can effectively simplify specific processing, for example, it can reduce the number of times the translation lookaside buffer (TLB) is refreshed, and there is no need to perform page table write protection processing, etc. Therefore, the efficiency of removing zero pages can be effectively improved.
[0134] In the embodiment of the present disclosure, the detailed processing flow of method 1 of step 401 is as follows: Figure 5 As shown, the following steps may be included:
[0135] 501. During the process of compiling the client code, the device (device performing code compilation) determines that the first code segment to be compiled is a code segment for clearing a physical memory page.
[0136] The client code is any program code that is used to run in the client.
[0137] Compilation can occur at any time before the code is executed. The compiled code can be temporarily suspended until the execution instruction is received. Compilation can be performed by any device. Code compilation and code running can occur on different devices. Or compilation can also occur when the code is executed. The code is traversed during the compilation process, so the code segment included in the client code for clearing the physical memory page can be determined during this process. There are many corresponding processing methods. The following are two possible processing methods as examples:
[0138] Method 1: Match the function name.
[0139] The device determines that a function name corresponding to a function in the client code is the same as a specified function name, wherein the function corresponding to the specified function name is a function for clearing a physical memory page to zero. The specified function name may be memset (a function name) and RtlZeroMemory (a function name), etc.
[0140] The device may store a function list in advance, and the function name of the function used to clear the physical memory page (i.e., the specified function name) may be recorded in the function list. In the process of compiling the client code, when the device compiles any function, the function name of the function is searched in the function list. If the function name is found, it is determined that the function is a function used to clear the physical memory page, and it can be compiled into a page clear instruction.
[0141] Method 2: Code matching.
[0142] The device determines that the first code segment is the same as a specified code segment, wherein the specified code segment is a code segment for clearing a physical memory page.
[0143] The device may pre-store one or more code segments (ie, designated code segments) for clearing physical memory pages to zero. The code segments may be functions or non-functions.
[0144] In the process of compiling the client code, the comparison can be started from the first statement of the client code. If the statement is the same as the first statement of the specified code segment, the next statement of the client code is matched with the next statement of the specified code segment. If the last statement of the specified code segment can be matched continuously, the code segment in the client code is the code segment used to clear the physical memory page. If any statement in the client code is different from the corresponding statement of the specified code segment during this process, the matching stops. Then the same comparison operation is performed on the next code of the client code. Then the code segment used to clear the physical memory page in the client code is obtained.
[0145] 502, compile the first code segment into a page clear instruction.
[0146] Compiling client code is the process of converting it into hardware instructions. The page zeroing instruction is a hardware instruction that can directly clear a page. During the compilation process, as long as a function for clearing a physical memory page is detected, it will be compiled into a page zeroing instruction.
[0147] 503. During the running of the client code (after compilation), when a page clear instruction is executed, the processor determines a target page corresponding to the page clear instruction.
[0148] During the running of the client code (after compilation), the processor executes the hardware instruction obtained by compiling the client code. When the executed hardware instruction is a page clearing instruction, the processor determines the target page corresponding to the page clearing instruction, that is, the zero page. The processor can mark the target page. The marking can be performed using the method mentioned in step 402.
[0149] In the embodiment of the present disclosure, the detailed processing flow of the second method of step 401 is as follows: Figure 6 As shown, the following steps may be included:
[0150] 601, during the execution of the client code, the GuestOS obtains the second code segment currently called.
[0151] The second code segment may be a function.
[0152] During the process of executing the client code by the GuestOS, whenever a function call statement is executed, the currently called function can be determined.
[0153] 602. When the GuestOS determines that the second code segment is a code segment for clearing a physical memory page, the GuestOS determines a target page to be cleared by the second code segment and notifies the HostOS.
[0154] GuestOS can pre-store a correspondence table between function names and page zeroing judgment conditions. The functions involved in the correspondence table are functions that can clear physical memory pages, such as memset and RtlZeroMemory, etc., which can be pre-specified by technicians based on experience and added to the correspondence table. These functions can realize the operation of clearing physical memory pages when the input parameters meet certain conditions, which are the page zeroing judgment conditions in the table.
[0155] After GuestOS determines the name of the currently called function, GuestOS can determine whether the function name is included in the above correspondence table. If included, the page clearing judgment condition corresponding to the function name can be further determined in the correspondence table. In addition, the current input parameters of the function are obtained to determine whether the input parameters can meet the page clearing judgment condition. If satisfied, it is determined that the function is currently used to clear the physical memory page. At this time, the target page cleared by the function can be determined, and the physical address of the target page in the virtual machine (which can be the head physical address or the physical address range) is notified to HostOS. The communication means between GuestOS and HostOS include but are not limited to hypercall, virtual device communication, network communication, shared memory communication, etc. HostOS can perform subsequent marking processing on the target page.
[0156] In the above process, if the correspondence table does not include the name of the currently called function, or the current input parameter of the function does not meet the page clearing judgment condition, it is determined that the function is not used to clear the physical memory page.
[0157] The following is a detailed explanation using the memset function as an example.
[0158] The memset function is used to write a value to a string so that each bit of the string has the same value. The definition statement of the function is as follows:
[0159] Void*memset(void*s,int c,unsigned long n)
[0160] Introduction:
[0161] void*s: used to represent the starting address of the string.
[0162] int c: Used to indicate that each bit value in the string is set to the current value of variable c.
[0163] unsigned long n: used to indicate the length of a string.
[0164] The process of determining whether a zero page is generated is determined by the value of the input parameter:
[0165] The first step is to check whether c is 0. If it is not 0, no zero page is generated and the process ends.
[0166] The second step is to check whether n is greater than or equal to the page size. If it is less than, it means that the string of 0s cannot fill the entire page. Therefore, it is considered that no zero page is generated and the process ends.
[0167] The third step is to determine whether the address corresponding to *s (referred to as address A) is the same as the first address of any page. If there is a page first address that matches address A, the ratio of n to the page size is calculated. If the ratio is greater than or equal to 1, it is determined that a zero page is generated. The target page to be cleared can be determined based on address A and the value rounded down to the integer of the ratio (which can represent the number of zero pages). If the ratio is less than 1, no zero page is generated, and the process ends. If there is no page first address that matches address A, the first page first address to the right of the address is determined (referred to as address B), the increment m of address B relative to address A is determined, and the ratio of nm to the page size is calculated. If the ratio is greater than or equal to 1, it is determined that a zero page is generated. The target page to be cleared can be determined based on address B and the modulus of the ratio (which can represent the number of zero pages). If the ratio is less than 1, no zero page is generated, and the process ends.
[0168] The following is a more specific example (taking a page size of 4096 bytes as an example):
[0169] Example 1: "memset(0xf80000,0,4096)"
[0170] c is 0. n is 4096, which is equal to the page size. *s corresponds to the address 0xf80000, which can be the same as the first address of the page. The ratio of n to the page size is 4096 / 4096, and the result of this operation is 1, so a zero page can be generated, and the generated zero page is a page with a first address of 0xf80000.
[0171] Example 2: "memset(0xf80000,1,4096)"
[0172] If c is 1 and 1 is a non-zero number, no zero page is generated.
[0173] Example 3: "memset(0xf80000,0,2048)"
[0174] c is 0. n is 2048, which is smaller than the page size, so no zero page is generated.
[0175] Example 4: "memset(0xf80f00,0,6400)"
[0176] c is 0. n is 6400, which is larger than the page size. *s corresponds to the address 0xf80f00. There is no page with the same first address as this address. The first address of the first page to the right of this address is 0xf81000. The increment of 0xf81000 relative to 0xf80f00 is 256. The ratio of n-256 to the page size is (6400-256) / 4096. The result of rounding down this ratio is 1. Therefore, a zero page can be generated. The generated zero page is the page with the first address 0xf81000.
[0177] Example 5: "memset(0xf80f00,0,4100)"
[0178] c is 0. n is 4100, which is larger than the page size. *s corresponds to the address 0xf80f00. There is no page with the same first address as this address. The first page to the right of this address is 0xf81000. The increment of 0xf81000 relative to 0xf80f00 is 256. The ratio of n-256 to the page size is (4100-256) / 4096. The ratio is rounded down to 0. Therefore, no zero page is generated.
[0179] In addition, because some functions are generally only used for clearing physical memory pages when in use, it is also possible to use a method of matching only function names to determine whether the currently called function is used for clearing physical memory pages. The corresponding processing method is similar to the method 1 of step 401 and will not be repeated here.
[0180] In the embodiment of the present disclosure, the detailed process of method 3 of step 401 is as follows Figure 7 As shown, the following steps may be included:
[0181] 701, during the execution of the client code, the hypervisor translates the second hardware instruction provided by the GuestOS to obtain a third hardware instruction supported by the processor.
[0182] When the client code is executed, the GuestOS first compiles the client code into a second hardware instruction supported by the hypervisor, and the hypervisor translates the second hardware instruction to obtain a third hardware instruction supported by the processor.
[0183] 702 , the hypervisor determines that the third hardware instruction obtained by translation is a hardware instruction for clearing a physical memory page, determines a target page to be cleared by the third hardware instruction, and notifies the Host OS.
[0184] Mode 1: instruction matching: determining that the third hardware instruction is the same as a specified hardware instruction, wherein the specified hardware instruction is a hardware instruction for clearing a physical memory page.
[0185] The hypervisor may pre-store one or more instruction groups, each of which may include at least one hardware instruction, and each of which is used to execute an operation of clearing a physical memory page (ie, the above-mentioned specified hardware instruction).
[0186] The hypervisor can compare the translated hardware instructions with the stored instruction group. If the translated consecutive hardware instructions (i.e., the third hardware instruction mentioned above) match a certain instruction group, it can be determined that these hardware instructions are hardware instructions for clearing the physical memory page. The hypervisor can then determine the target page to be cleared by these hardware instructions, and notify the HostOS of the physical address of the target page (which can be the head physical address or the physical address range). The HostOS can perform subsequent marking processing on the target page.
[0187] The following is an example of an instruction set that can be used to zero a physical memory page:
[0188] loop:MOVNTPS 0x0(%ecx),%xmm0
[0189] MOVNTPS 0x10(%ecx),%xmm0
[0190] MOVNTPS 0x20(%ecx),%xmm0
[0191] MOVNTPS 0x30(%ecx),%xmm0
[0192] ADD %ecx,$0x40
[0193] DEC%edx
[0194] JNZ loop
[0195] The above instruction group is used to execute the operation of writing the same value in consecutive addresses of the memory. Among them, the %xmm0 register records the written value, which can be set to 0; the %ecx register records the starting address of the write operation, which can be set to the first address of a certain page; the %edx register records the number of loops. Each time this instruction group loops, the first four instructions are executed sequentially once to write 0 in 64 bytes. After 64 loops, a 4096-byte page can be cleared.
[0196] Here is another example of an instruction set that can be used to zero a page of physical memory:
[0197] loop: <rexw>MOVNTI(%rcx),%rax
[0198] <rexw>MOVNTI 0x8(%rcx),%rax
[0199] <rexw>MOVNTI 0x10(%rcx),%rax
[0200] <rexw>MOVNTI 0x18(%rcx),%rax
[0201] <rexw>MOVNTI 0x20(%rcx),%rax
[0202] <rexw>MOVNTI 0x28(%rcx),%rax
[0203] <rexw>MOVNTI 0x30(%rcx),%rax
[0204] <rexw>MOVNTI 0x38(%rcx),%rax
[0205] <rexw>ADD%rcx,$0x80
[0206] <rexw>MOVE 0xc0(%rcx),%rax
[0207] <rexw>MOVE 0xc8(%rcx),%rax
[0208] <rexw>MOVE 0xd0(%rcx),%rax
[0209] <rexw>MOVE 0xd8(%rcx),%rax
[0210] <rexw>MOVE 0xe0(%rcx),%rax
[0211] <rexw>MOVE 0xe8(%rcx),%rax
[0212] <rexw>MOVNTI 0xf0(%rcx),%rax
[0213] <rexw>MOVNTI 0xf8(%rcx),%rax
[0214] <rexw>DEC%rdx
[0215] JNZ loop
[0216] The principle of the instruction group in this example is similar to that of the instruction group in the previous example, and will not be explained in detail here.
[0217] Method 2, instruction matching combined with input parameter judgment: determine that the third hardware instruction is the same as the specified hardware instruction; determine the page clearing judgment condition corresponding to the specified hardware instruction; when the current input parameter of the third hardware instruction meets the page clearing judgment condition, determine that the third hardware instruction is a hardware instruction for clearing the physical memory page.
[0218] The processing of instruction matching is similar to that of method 1, and you can refer to the content of method 1. Regarding the processing of parameter input judgment, for all the pre-stored instruction groups mentioned above, a correspondence table between instruction groups and page clear judgment conditions can be pre-established, and parameter input judgment is performed based on the correspondence table. The corresponding processing is similar to the parameter input judgment in step 602. %ecx is similar to *s, %xmm0 is similar to c, and %edx is similar to n, so the specific processing method can refer to the relevant description of step 602.
[0219] In the embodiment of the present disclosure, the detailed processing flow of the fourth method of step 401 is as follows: Figure 8 As shown, the following steps may be included:
[0220] 801. During the execution of the client code, the processor determines that a fourth hardware instruction to be executed is a hardware instruction for clearing a physical memory page, and performs debugging on the fourth hardware instruction so that the hypervisor obtains the fourth hardware instruction.
[0221] The processor obtains the hardware instructions to be executed one by one, and detects the hardware instruction for clearing the physical memory page. The detection process is similar to step 602. Please refer to the relevant description of step 602. When it is detected that the fourth hardware instruction is a hardware instruction for clearing the physical memory page, a debug mark can be added to the fourth hardware instruction, and then the fourth hardware instruction is refused to be executed. At this time, the mechanism of the hardware-assisted virtualization technology is triggered, so that the hypervisor is informed of the rejected fourth hardware instruction and the reason for the rejection.
[0222] 802 , the hypervisor determines the target page to be cleared by the fourth hardware instruction, and notifies the Host OS.
[0223] On the one hand, the hypervisor ensures the normal execution of the fourth hardware instruction based on the mechanism of the hardware-assisted virtualization technology, and on the other hand, determines the target page to be cleared based on the input parameters of the fourth hardware instruction and notifies the HostOS.
[0224] Based on the same technical concept, the embodiment of the present disclosure provides a device for processing zero pages in physical memory, which is applied to the above-mentioned computer device, such as Fig.10 As shown, the device comprises:
[0225] The identification module 1010 is used to identify the operation for generating a zero page, wherein the zero page is a physical memory page containing all zero data. Specifically, the processing functions of the above steps 401, 501-503, 601-602, 701-702 and 801-802, as well as other implicit steps can be implemented.
[0226] The marking module 1020 is used to determine the zero page corresponding to the operation and record the zero page mark for the zero page. Specifically, it can implement the processing function of the above step 402 and other implicit steps.
[0227] The detection module 1030 is used to detect pages with zero page marks in the physical memory pages, and can specifically implement the processing function of the above step 403 and other implicit steps.
[0228] The recycling module 1040 is used to recycle pages with zero page marks, where recycling is to set the pages to an unallocated state. It is used to recycle pages with zero page marks. Specifically, it can implement the processing function of the above step 404 and other implicit steps.
[0229] In one possible implementation, the recycling module 1040 is used to: reduce the reference count of a page recorded with a zero page mark by a first value, wherein the reference count is used to indicate the number of entities using the page, and the entities include processes and / or threads; if the reduced reference count is equal to a second value, then the page recorded with the zero page mark is recycled.
[0230] In a possible implementation, the identification module 1010 is used to: identify and execute a first hardware instruction, where the first hardware instruction is a hardware instruction for clearing a physical memory page.
[0231] In one possible implementation, the identification module 1010 is further used to: during the compilation of the client code, obtain the first code segment to be compiled; if the first code segment is identified as a code segment for clearing a physical memory page, compile the first code segment into a first hardware instruction.
[0232] In a possible implementation, the first code segment is a first function, a function name of the first function is a specified function name, and a function corresponding to the specified function name is a function for clearing a physical memory page.
[0233] In a possible implementation, the identification module 1010 is used to: identify the call to the second code segment, where the second code segment is a code segment used to clear a physical memory page.
[0234] In one possible implementation, the second code segment is a second function, the function name of the second function is a specified function name, and the function corresponding to the specified function name is a function used to clear physical memory pages, or the second code segment is a second function, the function name of the second function is the specified function name, and the current input parameters of the second function meet the page clearing judgment condition corresponding to the specified function name.
[0235] In a possible implementation, the identification module 1010 is used to: identify and translate a second hardware instruction provided by the client operating system to obtain a third hardware instruction, where the third hardware instruction is a hardware instruction for clearing a physical memory page.
[0236] In one possible implementation, the third hardware instruction is a specified hardware instruction, and the current input parameter of the third hardware instruction satisfies the page clearing judgment condition corresponding to the specified hardware instruction, or the third hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
[0237] In a possible implementation, the identification module 1010 is used to: identify and obtain a fourth hardware instruction to be executed, where the fourth hardware instruction is a hardware instruction for clearing a physical memory page.
[0238] In one possible implementation, the fourth hardware instruction is a specified hardware instruction, and the current input parameter of the fourth hardware instruction satisfies the page clearing judgment condition corresponding to the specified hardware instruction, or the fourth hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
[0239] In a possible implementation, the zero page marker is recorded in a nested page table of the zero page.
[0240] In a possible implementation, the marking module 1020 is further configured to: cancel the zero page mark of the zero page record when a write operation to the zero page is detected.
[0241] In one possible implementation, the marking module 1020 is further used to: set the dirty bit corresponding to the zero page in the nested page table to an unset state, wherein the dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page, and if the dirty bit changes from an unset state to a set state after being set to the unset state, it indicates that a write operation has occurred on the page corresponding to the dirty bit after the dirty bit was set to the unset state; the marking module 1020 is used to: cancel the zero page mark of the zero page record when it is detected that the dirty bit is set to a set state.
[0242] In one possible implementation, the marking module 1020 is further used to: after determining the zero page corresponding to the operation, set the dirty bit corresponding to the zero page in the nested page table to an unset state, wherein the dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page, and if the dirty bit changes from an unset state to a set state after being set to the unset state, it indicates that a write operation has occurred on the page corresponding to the dirty bit after the dirty bit was set to the unset state; the recycling module 1040 is used to: recycle the page recorded with the zero page mark based on the fact that the dirty bit corresponding to the page recorded with the zero page mark in the nested page table has not changed to a set state.
[0243] The above-mentioned identification module 1010, marking module 1020, detection module 1030, and recovery module 1040 can be implemented by a processor, or by a processor in conjunction with a memory and a communication component.
[0244] In the embodiment of the present disclosure, when an operation for generating a zero page is identified, the zero page corresponding to the operation is determined and the zero page is marked. In addition, a page with a zero page mark is detected in the physical memory page and recycled. Thus, the corresponding physical memory can be released to reduce the occupation of the physical memory and prevent the host from running stuck.
[0245] The device for processing zero pages in physical memory provided in the above embodiment only uses the division of the above functional modules as an example when processing. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the terminal device is divided into different functional modules to complete all or part of the functions described above. In addition, the device for processing zero pages in physical memory provided in the above embodiment and the method embodiment for processing zero pages in physical memory belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0246] The embodiments of the present disclosure also provide a computer-readable storage medium. The computer-readable storage medium may be any available medium that can be stored by a computing device or a data storage device such as a data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a digital video disk (DVD)), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct a computing device to perform a business processing method, or instructs a computing device to perform a business processing method.
[0247] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present disclosure.< / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw> < / rexw>
Claims
1. A method for processing zero pages in physical memory, characterized in that: The method comprises: identifying an operation for generating a zero page, wherein the zero page is a physical memory page containing data that is all zero; Determine the zero page corresponding to the operation, and record a zero page mark for the zero page; Detecting a page having the zero page mark recorded therein in a physical memory page; The page having the zero page mark recorded thereon is reclaimed, wherein the reclaiming is to set the page to an unallocated state.
2. The method according to claim 1, characterized in that The reclaiming the page having the zero page mark recorded therein comprises: Decrease the reference count of the page having the zero page mark recorded thereon by a first value, wherein the reference count is used to indicate the number of entities using the page, the entities including processes and / or threads; If the reduced reference count is equal to the second value, the page recorded with the zero page mark is recycled.
3. The method according to claim 1 or 2, characterized in that: The operation for generating a zero page includes: A first hardware instruction is executed, where the first hardware instruction is a hardware instruction for clearing a physical memory page.
4. The method according to claim 3, characterized in that Prior to identifying an operation for generating a zero page, the method further includes: In the process of compiling the client code, obtaining a first code segment to be compiled; If it is identified that the first code segment is a code segment for clearing a physical memory page, the first code segment is compiled into the first hardware instruction.
5. The method according to claim 4, characterized in that The first code segment is a first function, the function name of the first function is a specified function name, and the function corresponding to the specified function name is a function for clearing a physical memory page.
6. The method according to claim 1 or 2, characterized in that: The operation for generating a zero page includes: A second code segment is called, where the second code segment is a code segment for clearing a physical memory page.
7. The method according to claim 6, characterized in that The second code segment is a second function, the function name of the second function is a specified function name, and the function corresponding to the specified function name is a function for clearing a physical memory page; or, The second code segment is a second function, the function name of the second function is a specified function name, and the current input parameter of the second function satisfies the page clearing judgment condition corresponding to the specified function name.
8. The method according to claim 1 or 2, characterized in that: The operation for generating a zero page includes: The second hardware instruction provided by the client operating system is translated to obtain a third hardware instruction, where the third hardware instruction is a hardware instruction for clearing a physical memory page.
9. The method according to claim 8, characterized in that The third hardware instruction is a specified hardware instruction, and the current input parameter of the third hardware instruction meets the page clearing judgment condition corresponding to the specified hardware instruction; or, The third hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
10. The method according to claim 1 or 2, characterized in that: The operation for generating a zero page includes: A fourth hardware instruction to be executed is obtained, where the fourth hardware instruction is a hardware instruction for clearing a physical memory page.
11. The method according to claim 10, characterized in that The fourth hardware instruction is a designated hardware instruction, and the current input parameter of the fourth hardware instruction satisfies the page clearing judgment condition corresponding to the designated hardware instruction; or, The fourth hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
12. The method according to any one of claims 1 to 11, characterized in that: The zero page marker is recorded in the nested page table of the zero page.
13. The method according to any one of claims 1 to 12, characterized in that: Before detecting the page having the zero page mark recorded in the physical memory page, the method further includes: After the zero page mark is recorded on the zero page, in a case where a write operation on the zero page is detected, the zero page mark recorded on the zero page is cancelled.
14. The method according to claim 13, characterized in that After determining the zero page corresponding to the operation, the method further includes: Setting a dirty bit corresponding to the zero page in the nested page table to an unset state, wherein the dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page, and if the dirty bit changes from an unset state to a set state after being set to the unset state, it indicates that a write operation has occurred on the page corresponding to the dirty bit after the dirty bit has been set to the unset state; In the case where a write operation to the zero page is detected, canceling the zero page mark of the zero page record includes: When it is detected that the dirty bit is set to the set state, the zero page mark of the zero page record is cancelled.
15. The method according to any one of claims 1 to 12, characterized in that: After determining the zero page corresponding to the operation, the method further includes: Setting a dirty bit corresponding to the zero page in the nested page table to an unset state, wherein the dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page, and if the dirty bit changes from an unset state to a set state after being set to the unset state, it indicates that a write operation has occurred on the page corresponding to the dirty bit after the dirty bit has been set to the unset state; The reclaiming the page having the zero page mark recorded therein comprises: According to the dirty bit corresponding to the page recorded with the zero page mark in the nested page table not being changed to a set state, the page recorded with the zero page mark is recycled.
16. A device for processing zero pages in physical memory, characterized in that: The device comprises: an identification module, configured to identify an operation for generating a zero page, wherein the zero page is a physical memory page containing data that is all zero; A marking module, used for determining the zero page corresponding to the operation, and recording a zero page mark for the zero page; A detection module, used for detecting a page having the zero page mark recorded therein in a physical memory page; A recycling module is used to recycle the page recorded with the zero page mark, wherein the recycling is to set the page to an unallocated state.
17. The device according to claim 16, characterized in that The recovery module is used for: Decrease the reference count of the page having the zero page mark recorded thereon by a first value, wherein the reference count is used to indicate the number of entities using the page, the entities including processes and / or threads; If the reduced reference count is equal to the second value, the page recorded with the zero page mark is recycled.
18. The device according to claim 16 or 17, characterized in that The identification module is used to: A first hardware instruction is identified and executed, where the first hardware instruction is a hardware instruction for clearing a physical memory page.
19. The device according to claim 18, characterized in that The identification module is further used for: In the process of compiling the client code, obtaining a first code segment to be compiled; If it is identified that the first code segment is a code segment for clearing a physical memory page, the first code segment is compiled into the first hardware instruction.
20. The device according to claim 19, characterized in that The first code segment is a first function, the function name of the first function is a specified function name, and the function corresponding to the specified function name is a function for clearing a physical memory page.
21. The device according to claim 16 or 17, characterized in that The identification module is used to: A call to a second code segment is identified, where the second code segment is a code segment for clearing a physical memory page.
22. The device according to claim 21, characterized in that The second code segment is a second function, the function name of the second function is a specified function name, and the function corresponding to the specified function name is a function for clearing a physical memory page; or, The second code segment is a second function, the function name of the second function is a specified function name, and the current input parameter of the second function satisfies the page clearing judgment condition corresponding to the specified function name.
23. The device according to claim 16 or 17, characterized in that The identification module is used to: A third hardware instruction is obtained by translating a second hardware instruction provided by the client operating system, where the third hardware instruction is a hardware instruction for clearing a physical memory page.
24. The device according to claim 23, characterized in that The third hardware instruction is a specified hardware instruction, and the current input parameter of the third hardware instruction meets the page clearing judgment condition corresponding to the specified hardware instruction; or, The third hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
25. The device according to claim 16 or 17, characterized in that The identification module is used to: A fourth hardware instruction to be executed is identified and obtained, where the fourth hardware instruction is a hardware instruction for clearing a physical memory page.
26. The device according to claim 25, characterized in that The fourth hardware instruction is a designated hardware instruction, and the current input parameter of the fourth hardware instruction satisfies the page clearing judgment condition corresponding to the designated hardware instruction; or, The fourth hardware instruction is a specified hardware instruction, and the specified hardware instruction is a hardware instruction used to clear a physical memory page.
27. The device according to any one of claims 16 to 26, characterized in that The zero page marker is recorded in the nested page table of the zero page.
28. The device according to any one of claims 16 to 27, characterized in that The marking module is also used for: When a write operation to the zero page is detected, the zero page mark recorded on the zero page is cancelled.
29. The device according to claim 28, characterized in that The marking module is also used for: Setting a dirty bit corresponding to the zero page in the nested page table to an unset state, wherein the dirty bit is a parameter bit used to indicate whether a write operation has occurred on the corresponding page, and if the dirty bit changes from an unset state to a set state after being set to the unset state, it indicates that a write operation has occurred on the page corresponding to the dirty bit after the dirty bit has been set to the unset state; The marking module is used for: When it is detected that the dirty bit is set to the set state, the zero page mark of the zero page record is cancelled.
30. The device according to any one of claims 16 to 27, characterized in that The marking module is also used for: After determining the zero page corresponding to the operation, setting a dirty bit corresponding to the zero page in the nested page table to an unset state, wherein the dirty bit is a parameter bit used to indicate whether a write operation occurs on the corresponding page, and if the dirty bit changes from an unset state to a set state after being set to the unset state, it indicates that a write operation occurs on the page corresponding to the dirty bit after the dirty bit is set to the unset state; The recovery module is used for: According to the dirty bit corresponding to the page recorded with the zero page mark in the nested page table not being changed to a set state, the page recorded with the zero page mark is recycled.
31. A computer device, characterized in that: The computer device comprises a memory and a processor, wherein the memory is used to store computer instructions; The processor executes the computer instructions stored in the memory to enable the computer device to perform the method according to any one of claims 1 to 15.
32. A mobile terminal, characterized in that: The mobile terminal includes a memory and a processor, wherein the memory is used to store computer instructions; The processor executes the computer instructions stored in the memory to enable the mobile terminal to perform the method according to any one of claims 1 to 15.
33. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program code. When the computer program code is executed by a computer device, the computer device executes the method according to any one of claims 1 to 15.
Citation Information
Cited By
Method and apparatus for processing zero page in physical memory, and device and storage medium
EP4764857A1
Method and apparatus for processing zero page in physical memory, and device and storage medium
WO2025066387A1