Memory data swapping method, memory data swap-out method, memory data swap-in method, and memory data swapping system
By switching between the host machine and the virtual machine operating system, and utilizing the virtualization management layer to perform memory data exchange tasks, the limitations of memory exchange in traditional operating systems are solved, achieving efficient management of memory data and performance improvement.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-08-14
- Publication Date
- 2026-04-02
AI Technical Summary
Traditional operating systems only support page swapping for user-mode processes and cannot support page swapping for kernel-mode processes, resulting in significant limitations in memory swapping.
By controlling the host machine to switch from running the host operating system to the virtual machine operating system, and utilizing the virtualization management layer to perform memory data exchange tasks between the host machine and the back-end storage medium, including active swap-out and passive swap-in tasks, efficient management of memory data can be achieved.
It enables precise control of memory data on the virtual machine operating system, reduces the limitations of memory swapping, supports kernel-mode page swapping, and improves memory resource utilization efficiency and system performance.
Smart Images

Figure CN2025114819_02042026_PF_FP_ABST
Abstract
Description
Memory data exchange method, memory data swap-out method, memory data swap-in method and memory data exchange system
[0001] Cross-reference to related applications
[0002] The present disclosure claims priority from a Chinese patent application No. 202411379664.3, filed on September 29, 2024, and entitled "Memory data exchange method, memory data swap-out method, memory data swap-in method and memory data exchange system", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD
[0003] The present disclosure relates to the technical field of data processing, and in particular, to a memory data exchange method, a memory data swap-out method, a memory data swap-in method and a memory data exchange system. BACKGROUND
[0004] In a traditional operating system, memory exchange is performed in the operating system. The memory exchange relies on the page replacement function and the memory exchange function of the running operating system, and the memory exchange function can usually only be performed on the pages of the user state process and does not support the exchange of the kernel state pages, thereby existing the technical problem of large memory exchange limitation.
[0005] At present, no effective solution has been proposed for the above problems. SUMMARY
[0006] The embodiments of the present disclosure provide a memory data exchange method, a memory data swap-out method, a memory data swap-in method and a memory data exchange system to at least solve the technical problem of large memory exchange limitation.
[0007] According to an aspect of an embodiment of the present disclosure, a memory data exchange method is provided. The method comprises: controlling a host machine to switch from running a host operating system to running a virtual machine operating system; obtaining a memory exchange request in the process of running the virtual machine operating system by the host machine, wherein the memory exchange request is used to request to exchange memory data between the physical memory of the host machine and the corresponding back-end storage medium of the host machine; in response to the memory exchange request, determining a task exchange category corresponding to the memory data; and performing an exchange task corresponding to the task exchange category between the physical memory of the host machine and the back-end storage medium for the memory data.
[0008] According to another aspect of the embodiments of the present disclosure, a method for swapping out memory data is provided. The method comprises: controlling a host to switch from running a host operating system to running a virtual machine operating system; obtaining a memory swap request during the process that the host runs the virtual machine operating system, wherein the memory swap request is used to request swapping memory data between a physical memory of the host and a back-end storage medium corresponding to the host; determining a task swap category corresponding to the memory data in response to the memory swap request; and performing an active swap-out task corresponding to the active swap-out task category on the memory data in response to the task swap category being an active swap-out task category of the host, wherein the active swap-out task category is used to represent a task category that a virtualization management layer running the virtual machine operating system actively triggers to swap the memory data from the physical memory of the host to the back-end storage medium.
[0009] According to another aspect of the embodiments of the present disclosure, a method for swapping in memory data is provided. The method comprises: controlling a host to switch from running a host operating system to running a virtual machine operating system; obtaining a memory swap request during the process that the host runs the virtual machine operating system, wherein the memory swap request is used to request swapping memory data between a physical memory of the host and a back-end storage medium corresponding to the host; determining a task swap category corresponding to the memory data in response to the memory swap request; and performing a passive swap-in task corresponding to the passive swap-in task category on the memory data in response to the task swap category being a passive swap-in task category of the host, wherein the passive swap-in task category is used to represent a task category that the virtual machine operating system passively triggers to swap the memory data from the back-end storage medium to the physical memory of the host.
[0010] According to another aspect of the embodiments of the present disclosure, a method for swapping in memory data is provided. The method comprises: controlling a host to switch from running a host operating system to running a virtual machine operating system; obtaining a memory swap request during the process that the host runs the virtual machine operating system, wherein the memory swap request is used to request swapping memory data between a physical memory of the host and a back-end storage medium corresponding to the host; determining a task swap category corresponding to the memory data in response to the memory swap request; and performing an active swap-in task corresponding to the active swap-in task category on the memory data in response to the task swap category being an active swap-in task category of the host, wherein the active swap-in task category is used to represent a task category that a virtualization management layer running the virtual machine operating system actively triggers to swap the memory data from the back-end storage medium to the physical memory of the host.
[0011] According to another aspect of the embodiments of the present disclosure, an apparatus for memory data swapping is also provided. The apparatus comprises: a first control component configured to control a host computer to switch from running a host operating system to running a virtual machine operating system; an obtaining component configured to obtain a memory swapping request during a process in which the host computer runs the virtual machine operating system, wherein the memory swapping request is used to request swapping memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; a first determining component configured to determine a task swapping category corresponding to the memory data in response to the memory swapping request; and a first executing component configured to perform a swapping task corresponding to the task swapping category between the physical memory of the host computer and the back-end storage medium for the memory data.
[0012] According to another aspect of the embodiments of the present disclosure, an apparatus for memory data swapping is also provided. The apparatus comprises: a first control component configured to control a host computer to switch from running a host operating system to running a virtual machine operating system; an obtaining component configured to obtain a memory swapping request during a process in which the host computer runs the virtual machine operating system, wherein the memory swapping request is used to request swapping memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; a first determining component configured to determine a task swapping category corresponding to the memory data in response to the memory swapping request; and a first executing component configured to perform a swapping task corresponding to the task swapping category between the physical memory of the host computer and the back-end storage medium for the memory data.
[0013] According to another aspect of the embodiments of the present disclosure, an apparatus for memory data swapping is also provided. The apparatus comprises: a first control component configured to control a host computer to switch from running a host operating system to running a virtual machine operating system; an obtaining component configured to obtain a memory swapping request during a process in which the host computer runs the virtual machine operating system, wherein the memory swapping request is used to request swapping memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; a first determining component configured to determine a task swapping category corresponding to the memory data in response to the memory swapping request; and a first executing component configured to perform a swapping task corresponding to the task swapping category between the physical memory of the host computer and the back-end storage medium for the memory data.
[0014] According to another aspect of the embodiments of the present disclosure, a memory data swap-in apparatus is further provided. The apparatus comprises: a fourth control component configured to control a host computer to switch from running a host computer operating system to running a virtual machine operating system; a fourth acquisition component configured to acquire a memory swap request during the process that the host computer runs the virtual machine operating system, wherein the memory swap request is used to request to swap memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; a fourth determination component configured to determine a task swap category corresponding to the memory data in response to the memory swap request; and a fourth execution component configured to perform an active swap-in task corresponding to the active swap-in task category on the memory data in response to the task swap category being the active swap-in task category of the host computer, wherein the active swap-in task category is used to represent a task category that a virtualization management layer running the virtual machine operating system actively triggers to swap the memory data from the back-end storage medium to the physical memory of the host computer.
[0015] According to another aspect of the embodiments of the present disclosure, a memory data swap system is further provided. The system comprises: an operating system running end configured to control a host computer to switch from running a host computer operating system to running a virtual machine operating system; a memory swap end configured to acquire a memory swap request during the process that the host computer runs the virtual machine operating system, wherein the memory swap request is used to request to swap memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; in response to the memory swap request, determine a task swap category corresponding to the memory data; and perform a swap task corresponding to the task swap category between the physical memory of the host computer and the back-end storage medium for the memory data.
[0016] According to another aspect of the embodiments of the present disclosure, an electronic device is further provided, comprising: a memory storing an executable program; and a processor configured to run the program, wherein the program performs the method in the embodiments of the present disclosure when running.
[0017] According to another aspect of the embodiments of the present disclosure, a computer readable storage medium is further provided, comprising a stored executable program, wherein the executable program controls the device where the computer readable storage medium is located to perform the method in the embodiments of the present disclosure when running.
[0018] According to another aspect of the embodiments of the present disclosure, a computer program product is further provided, comprising a computer program, which, when executed by a processor, implements the method in the embodiments of the present disclosure.
[0019] According to another aspect of the embodiments of the present disclosure, a computer program product is further provided, comprising a non-volatile computer readable storage medium, which stores a computer program, and the computer program, when executed by a processor, implements the method in the embodiments of the present disclosure.
[0020] According to a further aspect of the embodiments of the present disclosure, a computer program is also provided, which, when executed by a processor, implements the method in the various embodiments of the present disclosure.
[0021] In the embodiments of the present disclosure, the host machine is switched to the virtual machine operating system from the running host machine operating system, and the memory exchange function is started on this basis. In the process of running the virtual machine operating system by the host machine, the memory exchange request is obtained, which helps to efficiently manage the memory resources. By determining the task exchange category corresponding to the memory data, the exchange process of the memory data between the physical memory of the host machine and the back-end storage medium can be more accurately controlled, and the memory exchange function can be performed on the virtualization management layer running the virtual machine operating system, and it is not limited that the exchange object is the user state page or the kernel state page, thereby realizing the technical effect of reducing the limitation of memory exchange, avoiding the memory exchange function only for the pages of the user state process, and not supporting the exchange of the kernel state page, and further solving the technical problem of large limitation of memory exchange in the related art.
[0022] It is easy to note that the general description above and the detailed description below are merely for exemplifying and explaining the present disclosure, and do not constitute a limitation on the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0023] The drawings described herein are used to provide further understanding of the present disclosure, and form a part of the present disclosure. The illustrative embodiments of the present disclosure and their descriptions serve to explain the present disclosure, and do not constitute an improper limitation on the present disclosure. In the drawings:
[0024] FIG. 1 is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a memory data exchange method according to an embodiment of the present disclosure;
[0025] FIG. 2 is a schematic diagram of a computing environment according to an embodiment of the present disclosure;
[0026] FIG. 3 is a schematic diagram of a service mesh according to an embodiment of the present disclosure;
[0027] FIG. 4 is a flowchart of a memory data exchange method according to an embodiment of the present disclosure;
[0028] FIG. 5 is a flowchart of a memory data swap-out method according to an embodiment of the present disclosure;
[0029] FIG. 6 is a flowchart of a memory data swap-in method according to an embodiment of the present disclosure;
[0030] FIG. 7 is a flowchart of a memory data swap-in method according to an embodiment of the present disclosure;
[0031] FIG. 8 is a schematic diagram of a memory data exchange system according to an embodiment of the present disclosure;
[0032] FIG. 9 is a flowchart of a memory data exchange method according to an embodiment of the present disclosure;
[0033] FIG. 10 is a flowchart of an active swap-out method of memory data according to an embodiment of the present disclosure;
[0034] FIG. 11 is a flowchart of a passive swap-in method of memory data according to an embodiment of the present disclosure;
[0035] FIG. 12 is a flowchart of an active swap-in method of memory data according to an embodiment of the present disclosure;
[0036] FIG. 13 is a schematic diagram of a memory data exchange device according to an embodiment of the present disclosure;
[0037] FIG. 14 is a schematic diagram of a memory data swap-out device according to an embodiment of the present disclosure;
[0038] FIG. 15 is a schematic diagram of a memory data swap-in device according to an embodiment of the present disclosure;
[0039] FIG. 16 is a schematic diagram of a memory data swap-in device according to an embodiment of the present disclosure;
[0040] FIG. 17 is a structural block diagram of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0041] In order to enable persons skilled in the art to better understand the present disclosure, the technical solutions in the embodiments of the present disclosure will be described clearly and completely below with reference to the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by persons skilled in the art without creative labor should fall within the scope of protection of the present disclosure.
[0042] It should be noted that the terms "first", "second", and the like in the description and claims of the present disclosure and the above-described accompanying drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or apparatus including a series of steps or units does not have to be limited to only those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products, or apparatuses.
[0043] First, some nouns or terms appearing in the description of the embodiments of the present disclosure are applicable to the following explanations:
[0044] Memory swap request, used to request to exchange memory data between the physical memory of the host and the corresponding backend storage medium of the host, wherein the physical memory of the host and the backend storage medium are both real physical storage spaces;
[0045] Task swap category, used to distinguish whether the swap task to be executed is a swap-in task or a swap-out task;
[0046] Swap-out task, used to move a part of infrequently used memory pages in the physical memory of the host to the hard disk to free up space for other pages;
[0047] Swap-in task, used to trigger the swap-in task when the memory pages used by the process are stored on the hard disk, for swapping the memory pages used by the process from the hard disk to the physical memory;
[0048] Memory swap mechanism, a mechanism for using idle hard disk space as memory expansion, which can be used to implement the swap-in task and the swap-out task, wherein the memory swap mechanism includes two aspects, namely, a swap partition and a swap file;
[0049] Swap partition, obtained by dividing the idle backend storage space, wherein the backend storage space can include merged memory, compressed memory, disk, file, remote memory, etc., which is not limited here. The divided hard disk space is mounted as a swap partition through a swap partition mounting command, wherein the swap partition has the advantages of high speed and high stability, but the size of the swap partition needs to be planned in advance and cannot be dynamically adjusted;
[0050] Swap file, a file created on a common file system, used as swap space, the advantage of swap file is high flexibility, can dynamically adjust the size, convenient management, but the performance is slightly inferior to swap partition;
[0051] Swap space, usually set to two to three times the physical memory, if the physical memory in the operating system is sufficient, the use rate of the swap space is low, and the performance of the operating system will not be significantly affected, but if the physical memory of the operating system is insufficient, the use rate of the swap space will be high, which will seriously affect the performance of the operating system, that is, the performance of the swap space has a greater impact on the stability of the operating system.
[0052] According to the embodiments of the present disclosure, a memory data exchange method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0053] The method provided in the embodiment of the present disclosure can be executed in a mobile terminal, a computer terminal or a similar computing device. FIG. 1 is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a memory data exchange method according to an embodiment of the present disclosure. As shown in FIG. 1, the computer terminal 10 (or mobile device) can include one or more (in the figure, 102a, 102b, …, 102n are used to show) processors 102 (the processor 102 can include but not limited to a processing device such as a microcontroller unit (MCU) or a field-programmable gate array (FPGA)), a memory 104 for storing data, and a transmission device 106 for communication function. In addition, it can also include a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which can be included as one of the ports in the BUS bus), a network interface, a power supply and / or a camera. Those skilled in the art can understand that the structure shown in FIG. 1 is only schematic, and it does not limit the structure of the above-mentioned electronic device. For example, the computer terminal 10 can include more or fewer components than those shown in FIG. 1, or have a different configuration from that shown in FIG. 1.
[0054] It should be noted that the one or more processors 102 and / or other data processing circuitry described above can be generally referred to herein as "data processing circuitry". The data processing circuitry can be embodied in whole or in part as software, hardware, firmware, or any combination thereof. In addition, the data processing circuitry can be a single standalone processing module or incorporated in whole or in part within any of the other elements of the computer terminal 10 (or mobile device). As referred to in the embodiments of the present disclosure, the data processing circuitry functions as a processor to control, for example, the selection of the variable resistance terminal path connected to the interface.
[0055] The memory 104 can be used to store software programs of application software and modules, such as program instructions / data storage means corresponding to the method in the embodiments of the present disclosure. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, i.e. implements the method in the embodiments described above. The memory 104 can include a high-speed random access memory, and can also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 104 can further include a memory disposed remotely with respect to the processor 102, which can be connected to the computer terminal 10 through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0056] The transmission device 106 is used to receive or send data via a network. Specific examples of the network can include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (NIC) which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module which is used to communicate with the Internet in a wireless manner.
[0057] The display can be, for example, a touch screen type liquid crystal display (LCD) which can enable a user to interact with the user interface of the computer terminal 10 (or mobile device).
[0058] Figure 1 illustrates a hardware architecture diagram that can be used as an example of the computer terminal 10 (or mobile device) described above, as well as an example of the server described above. In an alternative embodiment, Figure 2 illustrates an embodiment of using the computer terminal 10 (or mobile device) described above in Figure 1 as a computing node in a computing environment 201. Figure 2 illustrates a hardware architecture diagram of a computing environment, as shown in Figure 2, the computing environment 201 includes a plurality of computing nodes (e.g., servers) running on a distributed network (shown as 210-1, 210-2,..., in the figure). The computing nodes all contain local processing and memory resources, and an end user 202 can remotely run applications or store data in the computing environment 201. Applications can be provided as a plurality of services 220-1, 220-2, 220-3, and 220-4 in the computing environment 201, representing services "A", "D", "E", and "H", respectively.
[0059] The end user 202 can provide and access services through a web browser or other software application on a client, and in some embodiments, the provisioning and / or requests of the end user 202 can be provided to an entry gateway 230. The entry gateway 230 can include a corresponding proxy to handle the provisioning and / or requests for services (one or more services provided in the computing environment 201).
[0060] Services are provided or deployed according to various virtualization technologies supported by the computing environment 201. In some embodiments, services can be provided according to virtual machine (VM) based virtualization, container-based virtualization, and / or the like. Virtual machine based virtualization can emulate a real computer by initializing a virtual machine to execute programs and applications without directly accessing any actual hardware resources. While the virtual machine virtualization machine, according to the container-based virtualization, a container can be started to virtualize an entire operating system (OS) so that multiple workloads can run on a single operating system instance.
[0061] In one embodiment based on container virtualization, several containers of a service can be assembled into a pod (e.g., a Kubernetes pod). For example, as shown in FIG. 2, service 220-2 can be equipped with one or more pods 240-1, 240-2, …, 240-N (collectively, pods). A pod can include a proxy 245 and one or more containers 242-1, 242-2, …, 242-M (collectively, containers). The one or more containers in a pod handle requests related to one or more respective functions of the service, and the proxy 245 generally controls network functions related to the service, such as routing, load balancing, etc. Other services can also be equipped with similar pods.
[0062] In operation, executing a user request from end user 202 can require invoking one or more services in computing environment 201, and executing one or more functions of a service can require invoking one or more functions of another service. As shown in FIG. 2, service “A” 220-1 receives a user request from end user 202 from ingress gateway 230, and service “A” 220-1 can invoke service “D” 220-2, which can request service “E” 220-3 to execute one or more functions.
[0063] The computing environment described above can be a cloud computing environment, in which allocation of resources is managed by a cloud service provider, allowing development of functions without considering implementation, tuning, or scaling of servers. The computing environment allows developers to execute code in response to events without building or maintaining complex infrastructure. Services can be split into a set of functions that can automatically scale independently, rather than scaling a single hardware device to handle potential load.
[0064] In another alternative embodiment, FIG. 3 illustrates, in a block diagram, an embodiment of using the computer terminal 10 (or mobile device) shown in FIG. 1 above as a service mesh. FIG. 3 illustrates a block diagram of a structure of a service mesh, as shown in FIG. 3, the service mesh 300 is mainly used to facilitate secure and reliable communication between multiple microservices, which refers to breaking down an application into multiple smaller services or instances and running them on different clusters / machines.
[0065] As shown in FIG. 3, the microservices can include application service instance E and application service instance F, which form a functional application layer of the service mesh 300. In one implementation, application service instance E is running in the form of container / process 308 on machine / workload pod 314 (Pod), and application service instance F is running in the form of container / process 310 on machine / workload pod 316 (Pod).
[0066] In one implementation, the application service instance E can be a memory swap request fetching service, and the application service instance F can be a memory swap task execution service.
[0067] As shown in FIG. 3, the application service instance E and the mesh proxy 303 coexist in the machine workload container group 314, and the application service instance F and the mesh proxy 305 coexist in the machine workload container 316. The mesh proxy 303 and the mesh proxy 305 form a data plane layer of the service mesh 300. Among them, the mesh proxy 303 and the mesh proxy 305 run in the form of containers / processes 304, 306 respectively, can receive the request 312 for commodity query service, and the mesh proxy 303 and the application service instance E can communicate bidirectionally, the mesh proxy 305 and the application service instance B can communicate bidirectionally. In addition, the mesh proxy 303 and the mesh proxy 305 can also communicate bidirectionally.
[0068] In one implementation, the traffic of the application service instance E is all routed to the appropriate destination through the mesh proxy 303, and the network traffic of the application service instance F is all routed to the appropriate destination through the mesh proxy 305. It should be noted that the network traffic mentioned herein includes but is not limited to Hyper Text Transfer Protocol (HTTP), Representational State Transfer (REST), Google Remote Procedure Call (gRPC), Redis, etc.
[0069] In one implementation, the function of extending the data plane layer can be implemented by writing a custom filter for the proxy (Envoy) in the service mesh 300, and the service mesh proxy configuration can be to make the service mesh correctly proxy service traffic, implement service interconnection and service governance. The mesh proxy 303 and the mesh proxy 305 can be configured to perform at least one of the following functions: service discovery, health checking, routing, load balancing, authentication and authorization, and observability.
[0070] As shown in FIG. 3, the service mesh 300 also includes a control plane layer. Among them, the control plane layer can be a group of services running in a dedicated namespace, which are hosted by a hosting control plane component 301 in a machine / Pod 302. As shown in FIG. 3, the hosting control plane component 301 communicates bidirectionally with the mesh agent 303 and the mesh agent 305. The hosting control plane component 301 is configured to perform some control management functions. For example, the hosting control plane component 301 receives telemetry data transmitted by the mesh agent 303 and the mesh agent 305, and can further aggregate the telemetry data. These services, the hosting control plane component 301 can also provide a user-oriented application programming interface (API) to more easily manipulate network behavior, and provide configuration data to the mesh agent 303 and the mesh agent 305, etc.
[0071] In the above running environment, the present disclosure provides a memory data exchange method as shown in FIG. 4. FIG. 4 is a flowchart of a memory data exchange method according to an embodiment of the present disclosure. As shown in FIG. 4, the method can include the following steps:
[0072] Step S401, the control host switches from running a host operating system to running a virtual machine operating system.
[0073] In the technical solution provided in the above step S401 of the present disclosure, the host operating system can be the operating system before switching, and the virtual machine operating system can be the operating system after switching. The above host operating system can be a running operating system. By virtualizing the running host operating system on the host and switching to the virtual machine operating system, a one-layer lightweight virtualization management layer running on the virtual machine operating system (or inserted under the virtual machine operating system) can be used to manage all running memories using an extended page table (EPT), so that the corresponding memory swap function can be developed based on the newly inserted virtualization management layer, and efficient full memory swap can be performed. It should be noted that the virtualization management layer of the embodiment of the present disclosure belongs to the host level, that is, the virtualization management layer of the host, but not an operating system.
[0074] It should be noted that in memory management, task switching (including memory swapping in or out) is a process in which the operating system moves some temporarily unused or inactive memory data from the physical memory of the host to the backend storage medium, or reads the memory data from the backend storage medium back to the physical memory of the host when the memory data is needed, in order to effectively utilize limited physical memory resources. This memory management mechanism is crucial for maintaining system performance and response time. The backend storage medium can be a backend storage space, which is a substantial storage space.
[0075] In this embodiment, in order to realize that the running host operating system starts to perform the memory swapping function, the host can be controlled to switch from running the host operating system to running the virtual machine operating system. That is, the running operating system on the host is switched to the virtualization mode through virtualization switching, and then the memory swapping function is performed in the corresponding virtualization management layer of the switched virtual machine operating system.
[0076] In step S402, a memory swapping request is obtained during the process in which the host runs the virtual machine operating system.
[0077] In the technical solution provided by step S402 of the present disclosure, the memory swapping request is used to request to exchange memory data between the physical memory of the host and the corresponding backend storage medium of the host, for example, to exchange the memory blocks that are not frequently used in the physical memory address of the host to the backend storage medium. The physical memory of the host, i.e. the memory bar in the hardware device, is used to store the data and program code required for the operation of the operating system and the application program. The virtual machine operating system can also be referred to as the guest operating system. The backend storage medium is used to indicate the backend storage space, wherein the backend storage space can be compressed memory, disk, file, remote memory, etc., which is not limited here.
[0078] In this embodiment, the memory swapping request is used to request to exchange the memory data from the physical memory of the host to the backend storage medium, or to request to exchange the memory data from the backend storage medium to the physical memory of the host, wherein the memory data can be a memory block or a memory page, which is not limited here. When the memory swapping task is to be performed, the memory swapping request can be used as a carrier to perform the memory swapping operation.
[0079] Optionally, the memory exchange request is stored in a request queue corresponding to the task exchange category according to the requested task. For example, the memory exchange request corresponding to the active swap-out task category is stored in an active swap-out task queue; the memory exchange request corresponding to the active swap-in task category is stored in an active swap-in task queue; and the memory exchange request corresponding to the passive swap-in task category is stored in a passive swap-in task queue. The active swap-out task category is used to indicate a task category in which the virtualization management layer actively triggers the task of swapping memory data from the physical memory of the host to the backend storage medium; the active swap-in task category is used to indicate a task category in which the virtualization management layer actively triggers the task of swapping memory data from the backend storage medium to the physical memory of the host; and the passive swap-in task category is used to indicate a task category in which the virtual machine operating system passively triggers the task of swapping memory data from the backend storage medium to the physical memory of the host.
[0080] Optionally, the host can obtain the memory exchange request from different request queues during the running of the virtual machine operating system, and the priority of the memory exchange request in the passive swap-in task queue > the priority of the memory exchange request in the active swap-in task queue > the priority of the memory exchange request in the active swap-out task queue. That is, when there is a memory exchange request in the passive swap-in task queue, the memory exchange request in the passive swap-in task queue is obtained first, then the memory exchange request in the active swap-in task queue is obtained, and finally the memory exchange request in the active swap-out task queue is obtained.
[0081] Optionally, the object granularity of the memory exchange request can be a memory page (mp) in a memory segment (ms). That is, the memory exchange operation is performed in units of memory pages in a memory segment during the memory exchange.
[0082] In this step, by storing different types of memory exchange requests in different queues, the system can clearly determine the priority of each task, which helps to improve the efficiency of resource allocation and the response speed of the system.
[0083] In step S403, the task exchange category corresponding to the memory data is determined in response to the memory exchange request.
[0084] In the technical solution provided in the foregoing step S403 of the present disclosure, the memory data can be used to indicate a memory block or a memory page, and the task exchange category can be used to indicate a category of the exchange task. The task exchange category includes an active task exchange category and a passive task exchange category, the active task exchange category includes an active swap-out task category and an active swap-in task category, and the passive task exchange category mainly refers to a passive fault-in task category. The specific meanings of the active swap-out task category, the active swap-in task category, and the passive fault-in task category are described above, and will not be described here again.
[0085] In this embodiment, if the memory exchange request is triggered by the virtualization management layer and is used to request to exchange the memory data from the physical memory of the host computer to the backend storage medium, it can be determined that the task exchange category corresponding to the memory data is the active swap-out task category; if the memory exchange request is triggered by the virtualization management layer and is used to request to exchange the memory data from the backend storage medium to the physical memory of the host computer, it can be determined that the task exchange category corresponding to the memory data is the active swap-in task category; if the memory exchange request is triggered by the virtual machine operating system and is used to request to exchange the memory data from the backend storage medium to the physical memory of the host computer, it can be determined that the task exchange category corresponding to the memory data is the passive fault-in task category.
[0086] For example, when the switched virtual machine operating system accesses the memory, the EPT page table is used to determine the physical address of the memory to be accessed in the host computer. The mapping relationship between the backend storage medium and the physical memory of the host computer is recorded in the extended page table, based on which the virtual machine operating system can use the EPT page table to determine the physical address of the memory to be accessed in the physical memory of the host computer. Alternatively, if the mapping relationship corresponding to the physical address of the memory to be accessed does not exist in the EPT page table, or the mapping relationship is recycled or not established, the virtual machine operating system accessing the physical address corresponding to the memory data will trigger an EPT violation (EPT Violation). In this case, the virtual machine operating system cannot normally access the memory, and a passive fault-in is triggered. In the passive fault-in process, the virtualization management layer allocates a real physical page (Host Physical Address, referred to as HPA) and establishes the mapping relationship between the GPA and the HPA, so that the virtual machine operating system can normally access the memory.
[0087] In this step, the task exchange category corresponding to the memory data can be determined according to the memory exchange request, which helps to distinguish different types of memory exchange tasks and can more intelligently allocate system resources, for example, different priorities or resource quotas are allocated to different types of tasks.
[0088] After the task exchange category corresponding to the memory data is determined, the exchange task corresponding to the task exchange category can be performed between the physical memory of the host and the backend storage medium for the memory data through the following step S404.
[0089] Step S404, performing the exchange task corresponding to the task exchange category between the physical memory of the host and the backend storage medium for the memory data.
[0090] In the technical solution provided by the above step S404 of the present disclosure, after the task exchange category corresponding to the memory data is determined, the exchange task corresponding to the task exchange category can be performed between the physical memory of the host and the backend storage medium for the memory data to be exchanged.
[0091] In this embodiment, if the task exchange category is the active swap-out task category, in this case, the infrequently used memory data stored in the physical memory of the host can be migrated to the backend storage medium; if the task exchange category is the active swap-in task category, in this case, the memory data in the backend storage medium can be swapped back to the physical memory of the host; if the task exchange category is the passive swap-in task category, in this case, the memory data in the backend storage medium can also be swapped back to the physical memory of the host.
[0092] Optionally, the execution priority of the exchange task corresponding to the passive swap-in task category is higher than that of the exchange task corresponding to the active swap-in task category, and the execution priority of the exchange task corresponding to the active swap-in task category is higher than that of the exchange task corresponding to the active swap-out task category.
[0093] It should be noted that in the above steps S401 to S404, when the host switches from running the host operating system to running the virtual machine operating system, there is only one operating system in the lightweight virtualization management layer of the present disclosure, that is, the virtual machine operating system (also referred to as the guest operating system), and the memory management is performed in the lightweight virtualization management layer, and the memory exchange function is enabled.
[0094] Based on the above embodiment steps S401 to S404, the host machine is switched from the running host operating system to the virtual machine operating system, and the memory exchange function is started on this basis. In the process of running the virtual machine operating system on the host machine, the memory exchange request is obtained, which helps to efficiently manage the physical memory of the host machine and the memory resources between the corresponding backend storage medium of the host machine. By determining the task exchange category corresponding to the memory data, the exchange process of the memory data between the physical memory of the host machine and the backend storage medium can be more accurately controlled, the utilization efficiency of the memory resources and the performance of the system are improved, and the memory exchange function can be performed on the virtualization management layer running the virtual machine operating system, and it is not limited whether the exchange object is a user state page or a kernel state page, which realizes the technical effect of reducing the limitation of memory exchange, avoids that the memory exchange function can only be applied to the pages of the user state process and does not support the exchange of kernel state pages, and further solves the technical problems of large memory exchange limitation in related technologies and the technical problem that the memory exchange cannot be started in the running operating system.
[0095] The above method of the embodiment will be further introduced below.
[0096] As an optional implementation, in step S403, in response to the memory exchange request, the task exchange category corresponding to the memory data is determined, including: in response to the memory exchange request, a task list is obtained, wherein the task list includes different task exchange categories; and from the task list, the task exchange category corresponding to the memory data is determined.
[0097] In this embodiment, the task list includes different task categories, wherein the different task categories can include swap-in tasks and swap-out tasks, wherein the swap-in tasks can include a swap-in task category and a fault-in task category, and the swap-out tasks can include a swap-out task category. The swap-in task category is used to indicate that the virtualization management layer actively triggers to load the memory data from the backend storage medium into the physical memory of the host machine, the swap-out task category is used to indicate that the virtualization management layer actively triggers to exchange the memory data from the physical memory of the host machine to the backend storage medium, and the fault-in task category is used to indicate that the virtual machine operating system passively triggers to swap the memory data from the backend storage medium into the physical memory of the host machine. It should be noted that the priorities of the exchange tasks corresponding to different task exchange categories are different, wherein the priority of the fault-in task is greater than that of the swap-in task, and the priority of the swap-in task is greater than that of the swap-out task, that is, fault_in>swap_in>swap_out.
[0098] Optionally, after determining the memory exchange request, the memory data corresponding task exchange category can be determined from the task list according to the memory exchange request. Since different exchange tasks have different priorities, when there is a passive exchange-in task in the task list, the memory data corresponding task exchange category is determined as the passive exchange-in category according to the memory exchange request. After the exchange task corresponding to the passive exchange-in category is executed, the exchange tasks are executed according to the active exchange-in task category and the active exchange-out task category in turn.
[0099] Through the above steps, when determining the memory data corresponding task exchange category in the memory list according to the memory exchange request, the memory data corresponding task exchange category can be determined according to the priority of the task exchange category stored in the task list, which helps to reasonably allocate memory resources and ensure that important tasks can obtain sufficient resources to execute smoothly. Moreover, by processing high-priority tasks first, it can ensure that critical tasks are responded in time, thereby improving the efficiency and response speed of the entire system.
[0100] As an optional implementation, for the memory data, the exchange task corresponding to the task exchange category is executed between the physical memory of the host and the backend storage medium, including: obtaining a read-write lock corresponding to the memory exchange request, wherein the read-write lock is used to allow multiple tasks to read the memory data concurrently and / or allow one task to write the memory data in the process of executing the exchange task on the memory data corresponding to the memory exchange request; and using the read-write lock to execute the exchange task corresponding to the task exchange category between the physical memory of the host and the backend storage medium.
[0101] In this embodiment, the read-write lock is used to indicate a mechanism for locking control of read and write operations at the request level, which guarantees data consistency and concurrency. The read-write lock can include a read lock and a write lock. The read lock is used to lock control the passive triggered exchange task, and the write lock is used to lock control the actively executed exchange task.
[0102] Optionally, the granularity of the read-write lock is at the memory block level, that is, the read-write lock operates in a basic unit of a memory block when controlling access to the memory resource. The read-write lock at the memory block level can reduce lock contention and improve concurrency performance. For example, if multiple tasks concurrently read different memory pages in the same memory block, they can execute concurrently without waiting for other tasks to release the lock. The previous memory swap architecture usually uses a global lock or a fixed number of address locks, where the global lock means that there is only one lock in the entire system, and all tasks must wait for this lock to access the memory page. The fixed number of address locks means that there are a fixed number of locks in the system, and each lock corresponds to one or more memory addresses. That is, compared to the global lock, the read-write lock can more finely control memory access. The global lock usually causes only one task to access the memory at any time, while the read-write lock allows multiple tasks (execution tasks) to concurrently access under certain conditions to achieve concurrent swap-in (concurrent swap-in), which is used to indicate that multiple virtual machines running on the host machine may simultaneously request memory swap-in operations. At this time, the virtualization manager needs to coordinate these concurrent requests to ensure reasonable allocation of memory resources. The read-write lock described above can make the overall speed of executing the swap-in task faster, which avoids resource contention and mutual waiting caused by a single global lock (also known as a large lock), thereby reducing the swap-in delay of executing the swap-in task and achieving efficient and low-latency concurrent swap-in. Compared to the fixed number of address locks, the number of read-write locks is not limited and can be dynamically adjusted according to the actual concurrency requirements, avoiding the problem that the number of locks is insufficient to meet the concurrency requirements.
[0103] Optionally, after obtaining the task swap category according to the memory swap request, the read lock or the write lock for locking control of the swap task corresponding to the task swap category can be determined according to the task swap category, and then the determined read lock or write lock is used to lock control the swap task corresponding to the task swap category when performing memory data between the physical memory of the host and the back-end storage medium.
[0104] In this step, the read-write lock is obtained through the swap task request, and then the read-write lock is used to lock control the swap task corresponding to the task swap category to avoid confusion and conflict when multiple swap tasks are executed.
[0105] As an optional implementation, the memory data is exchanged between the physical memory of the host and the backend storage medium according to the exchange task corresponding to the task exchange category by using the read-write lock, including: in response to the task exchange category being an active task exchange category of a virtualization management layer operated by the virtual machine operating system, performing an active exchange task corresponding to the active task exchange category on the memory data by using the write lock in the read-write lock, wherein the active task exchange category is used to represent a task category in which the virtualization management layer actively triggers the exchange of the memory data between the physical memory of the host and the backend storage medium; and in response to the task exchange category being a passive task exchange category of the host, performing a passive exchange task corresponding to the passive task exchange category on the memory data by using the read lock in the read-write lock, wherein the passive task exchange category is used to represent a task category in which the virtual machine operating system passively triggers the exchange of the memory data between the physical memory of the host and the backend storage medium.
[0106] In this embodiment, as can be known from the foregoing, the task exchange category can include an active swap-in category, an active swap-out category, and a passive swap-in category, wherein the active swap-in category and the active swap-out category can be attributed to the active task exchange category, and the passive swap-in category can be attributed to the passive task exchange category. Based on this, when the memory data is exchanged between the physical memory of the host and the backend storage medium according to the exchange task corresponding to the task exchange category by using the read-write lock, it can be determined whether the read lock or the write lock in the read-write lock is used according to the task exchange category, and then the corresponding lock is used to perform the exchange task corresponding to the task exchange category on the memory data according to the type of the determined lock.
[0107] Optionally, in the execution of the memory exchange task, the active exchange task usually involves changing the state of the memory data, such as writing the memory data from the physical memory of the host to the backend storage medium, or writing the memory data from the backend storage medium back to the physical memory of the host. The backend storage medium can be a storage address in a storage space such as a backend medium, a compressed memory, a file, a remote memory, etc. In this process, the write lock is used to ensure that no other process modifies the data when these operations are performed, thereby avoiding data inconsistency or damage. The passive exchange task is triggered by the virtual machine operating system, but the entire exchange process is transparent to the upper virtual machine operating system. Optionally, the passive exchange task of this embodiment usually involves checking the data state of the metadata in the storage space corresponding to the host operating system to determine whether the metadata in the storage space has not been accessed for a long time, that is, whether the metadata is a cold page, or whether the metadata is marked as unswappable, etc. Moreover, before swapping out, the cyclic redundancy check (CRC) value of the metadata is calculated to perform a check when the data is swapped in, thereby ensuring the integrity and correctness of the data.
[0108] Optionally, in response to the task exchange category being the active task exchange category of the virtualization management layer operated by the virtual machine operating system, the write lock in the read-write lock is used to serially execute the active exchange task corresponding to the active task exchange category on the memory data. Since the memory data is actively exchanged, there is no delay guarantee problem. In response to the task exchange category being the passive task exchange category of the host, the read lock in the read-write lock is used to concurrently execute the passive exchange task corresponding to the passive task exchange category on the memory data. This can ensure that multiple tasks concurrently read different memory pages in the same memory block, thereby reducing the delay and improving the real-time performance of reading, so that the virtual machine process triggering the page fault can resume running as soon as possible, but the logic is relatively complex. Optionally, the reason why the logic is relatively complex here is mainly because when the passive exchange task is concurrently executed, it is necessary to consider that multiple tasks concurrently read different memory pages in the same memory block. Since the same memory block is shared metadata, it may cause data consistency problems and race condition problems. Although the read lock in the read-write lock can allow multiple tasks to concurrently read memory data, it is necessary to ensure that the read memory data is up-to-date when the memory data is updated, and it is also necessary to avoid race condition problems caused by multiple tasks concurrently modifying memory data. Therefore, when the logic of concurrently executing the passive exchange task is executed, it is necessary to consider how to reasonably ensure the consistency and correctness of the data. At the same time, it is necessary to consider how to handle the conflicts and race conditions that may occur when multiple tasks concurrently read data, and a suitable synchronization mechanism and data structure need to be designed to avoid the above problems.
[0109] Optionally, if the task exchange category is the active task exchange category of the virtualization management layer operated by the virtual machine operating system, it can be determined that the lock to be used is the write lock. In this case, the write lock can be used to execute the active exchange task corresponding to the active task exchange category on the memory data. The active exchange task is a memory exchange task actively triggered by the virtualization management layer, and the active exchange task can be an active swap-out task or an active swap-in task.
[0110] Optionally, if the task exchange category is the passive task exchange category of the host, it can be determined that the lock to be used is the read lock. In this case, the read lock can be used to execute the passive exchange task corresponding to the passive task exchange category on the memory data.
[0111] In this step, by using an appropriate lock type (write lock or read lock), the corresponding memory exchange task is executed, which can ensure that the access to the memory data by the task during execution is safe, thereby improving the efficiency and accuracy of task execution.
[0112] As an optional implementation, in response to the task switching category being an active task switching category of a virtualization management layer operated by a virtual machine operating system, the memory data is executed with the write lock in the read-write lock and the active switching task corresponding to the active task switching category, including: in the case of the active task switching category being an active swap-out task category, the write lock is used to serially execute the active swap-out task corresponding to the active swap-out task category on different memory pages of the same memory block, wherein the active swap-out task category is used to represent a task category of the virtualization management layer actively triggering the memory data to be swapped out from the physical memory of the host to the back-end storage medium, and the memory data includes different memory pages of the same memory block; in the case of the active task switching category being an active swap-in task category, the write lock is used to serially execute the active swap-in task corresponding to the active swap-in task category on different memory pages of the same memory block.
[0113] In this embodiment, the object of the memory switching task can be a memory page mp in a memory block ms, and different memory pages can be included in the same memory block. For the active switching task (active swap-in task and active swap-out task), since there is no delay requirement, when the write lock is used to execute the switching task on different memory pages in the same memory block, the active switching task corresponding to the active task switching category can be serially executed. It should be noted that the granularity of the read-write lock is at the memory block (ms) level, and the active switching task for the memory pages (mp) in the same memory block (ms) can be serially executed. Since there is no competition relationship between the active switching tasks of different memory blocks, based on this, the active switching tasks for different memory blocks can also be executed concurrently. In the process of executing the active switching task, each switching task will obtain a time slice, allowing the memory page level switching task to be completed within the time slice. If the time slice expires, the ongoing task will be returned to the queue, waiting for other switching tasks to execute or the next execution.
[0114] In this step, for the active memory swap-in and swap-out tasks, since there is no strict delay requirement, a serial manner can be used to reduce the complexity of the operating system. Moreover, a time slice is designed for each switching task, which can ensure that even under high load conditions, a long-running task will not permanently occupy resources, and all tasks have the opportunity to obtain processing time, which helps to avoid that some tasks cannot be processed for a long time, and improves the fairness of the system.
[0115] As an optional implementation, the read lock is used to ensure that different passive swap-in tasks are allowed to perform concurrent swap-in when the same memory switching request occurs, and in the process of performing concurrent swap-in on different passive swap-in tasks through the read lock, the same memory page of the same memory block is controlled through a bitmap and cannot be concurrently swapped in.
[0116] In the embodiment, the read lock is used to ensure that different passive swap-in tasks are allowed to perform concurrent swap-in when the same memory swap request occurs, that is, under the read lock, memory pages can perform concurrent swap-in regardless of whether the memory pages are the same memory pages in the memory block.
[0117] However, in the process of performing concurrent swap-in of different passive swap-in tasks through the read lock, the embodiment can control the same memory pages in the same memory block from performing concurrent swap-in through the bitmap, that is, the embodiment controls the same memory pages in the same memory block from performing concurrent swap-in through the bitmap.
[0118] The embodiment can control the same memory pages in the same memory block from performing concurrent swap-in through the bitmap, where the bitmap can be understood as controlling different memory pages of the same memory from performing concurrent swap-in in combination with the read lock, that is, the bitmap limits the same memory pages in the same memory block from performing concurrent swap-in.
[0119] It should be noted that the read lock of the embodiment has allowed different memory pages in the memory block to perform concurrent swap-in, but the granularity of limiting concurrent swap-in is the bitmap, and the same memory pages in the memory block are limited from performing concurrent swap-in through the combination of the read lock and the bitmap.
[0120] As an optional implementation, after controlling the same memory pages in the same memory block from performing concurrent swap-in through the bitmap, the method further includes: in response to successfully obtaining the read lock corresponding to the plurality of memory swap requests, determining that the memory data has been successfully swapped from the backend storage medium to the physical memory of the host in the case where it is checked that the page table entry corresponding to the address of the memory data allows access, wherein the memory block level state information of the memory data at least includes to-be-updated state information, the to-be-updated state information is atomically updated based on an unsigned integer type structure, and the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the storage information is atomically updated based on a character type structure in the case where the same memory pages in the same memory block are controlled from performing concurrent swap-in through the bitmap.
[0121] In this embodiment, in response to obtaining the success of the read lock corresponding to the plurality of memory swap requests, in the case of checking that the page table entry corresponding to the address of the memory data allows access, it is determined that the memory data has been successfully swapped in from the backend storage medium to the physical memory of the host computer. For example, the embodiment checks whether the page table entry corresponding to the address of the memory data allows access. In the case of checking that the page table entry corresponding to the address of the memory data allows access, that is, it is determined that access is allowed, it indicates that the page fault exception state handled by another process is available, and it can be determined that the memory data has been successfully swapped in from the backend storage medium to the physical memory of the host computer. Optionally, the embodiment can directly return a processing success message, which can be used to indicate that the memory data has been successfully swapped in from the backend storage medium to the physical memory of the host computer.
[0122] In this embodiment, the page table entry described above can be a PTE page table of the memory block address, to determine whether the PTE page table currently allows read and write access. If access is allowed, it indicates that the page fault exception information handled by another process is available, and a processing success can be directly returned.
[0123] In this embodiment, the state information of the memory block level of the memory data at least includes to-be-updated state information, and the to-be-updated state information is atomically updated based on an unsigned integer structure, that is, the state information of the memory block level of the embodiment of the present disclosure can be atomically updated based on an unsigned integer structure.
[0124] In this embodiment, the to-be-updated state information included in the state information of the memory block level (ms_entry) can include the swap-in and swap-out state of the ms level, the iommu mapping state, the bit_out and bit_swapping bit of the mp level, and the association of 512 pieces of swap-in and swap-out state information of the mp level. The swap-in and swap-out state of the memory block (ms) level can include four kinds: the swapped_in state, the queue_out state, the swapped_out state, and the queue_in state; the address (iommu) mapping state includes several states such as clean, start, and finish. Since the to-be-updated state information is limited, the embodiment can combine two states by bit operation and share an atomic structure in order to reduce metadata overhead and perform atomic update in subsequent concurrency.
[0125] In this embodiment, the memory page level state information (mp_entry) of the memory data at least includes to-be-updated state information and storage information. In the case that the same memory page of the same memory block cannot be concurrently swapped in through the bitmap control, atomic update can be performed based on the character type structure (char). The memory page level state information itself is specially designed, including to-be-updated storage information, to-be-updated state information, and the like. If atomic update needs to be implemented for each information, an atomic structure body needs to be used, which needs to occupy 4 bytes, and then the memory page level state information needs to occupy at least 8 bytes. Then, the memory block level state information has 512 memory page level state information below, which needs to occupy a page size of 4k. Therefore, the overhead of the metadata is very large.
[0126] In addition, the number of storage types and states in the memory page level state information is very limited, and the above-mentioned 4 bytes do not need to be used for storage, otherwise, the storage space will be wasted. In order to save the storage space, the character type structure (char) can be used for atomic update in this embodiment, that is, the information can be kept in a character char type.
[0127] As an optional implementation, the memory data swapping method further includes: in the case that the active task swapping category is an active swap-out task category, adding the memory swapping request to the tree data structure, wherein the active swap-out task category is used to represent a task category in which the virtualization management layer actively triggers swapping of the memory data from the physical memory of the host computer to the back-end storage medium; the tree data structure is provided with a tree level lock; in the case that the active task swapping category is changed from the active swap-out task category to an active swap-in task category or a passive swap-in task category, and the memory data is successfully swapped from the back-end storage medium to the physical memory of the host computer, deleting the memory swapping request in the tree data structure, wherein the active task swapping category includes the active swap-in task category, the active swap-in task category is used to represent a task category in which the virtualization management layer actively triggers swapping of the memory data from the back-end storage medium to the physical memory of the host computer, and the passive task swapping category includes the passive swap-in task category, the passive swap-in task category is used to represent a task category in which the virtual machine operating system passively triggers swapping of the memory data from the back-end storage medium to the physical memory of the host computer.
[0128] In this embodiment, the tree data structure can be a red-black tree structure, and the tree data structure is provided with a tree level lock (also referred to as a tree lock), and the tree data structure is protected by the tree level lock. This is only an example and does not limit the specific type of tree data structure. As described above, the active task exchange category includes an active swap-in task category and an active swap-out task category. Based on this, if the active task exchange category is the active swap-out task category, the memory swap request can be added to the tree data structure, and the tree data structure is used for data management.
[0129] For example, when the active task exchange category is the active swap-out task category, the memory swap request corresponding to the active swap-out task category can be added to the tree data structure to assist in the swap-out of memory data using the tree data structure. After adding the memory swap data to the tree data structure, the tree data structure can be protected by the tree level lock to ensure that the tree data structure is not damaged in a multi-task concurrent environment, and that there is a memory swap request. Therefore, the tree level lock ensures that each memory block (ms) granularity GPA address (i.e., 2m address alignment) has only a unique memory swap request (req) in the tree data structure, that is, there is no repeated GPA address req, and the req can be placed in the corresponding queue according to the task state or not in the queue. Each ms granularity address swap process is protected by a read-write lock and concurrent operation to ensure that no other task interferes during the swap process, thereby ensuring the atomicity of the task swap process of each ms granularity address, and different ms granularities do not need to wait for each other. In addition, the read-write lock can make the overall speed of executing the swap-in task faster, which avoids resource competition and mutual waiting caused by a single global lock, thereby reducing the swap-in delay of executing the swap-in task, and achieving efficient and low-latency concurrent swap-in effect.
[0130] Optionally, a memory swap request can exist in the tree structure, or in a task queue, or in the case of complete swap-out, the memory swap request does not exist in any task queue.
[0131] Optionally, after the memory exchange request is added to the tree data structure, if the active task exchange category is changed from the active swap-out task category to the active swap-in task category or the passive swap-in task category, and the memory data is completely swapped in from the backend storage medium to the physical memory of the host, the memory exchange request can be deleted from the tree data structure. Optionally, the embodiment deletes the req corresponding to the GPA address from the tree data structure after all the exchange tasks of the req are completed, so as to initiate the exchange task for the GPA address again in the future. That is, the embodiment of the present disclosure can ensure that there is only one req for the same 2m GPA address, so as to ensure the correctness of the task exchange process on a large scale; otherwise, if there are multiple reqs corresponding to the same address, the read-write lock in each req cannot guarantee the atomicity of the task exchange process.
[0132] Optionally, after the memory exchange request is added to the tree data structure, if the memory exchange request has been processed, that is, the memory data requested to be exchanged by the memory exchange request is completely swapped in, the memory exchange request can be deleted from the tree data structure.
[0133] In this step, when the active task exchange category is the active swap-out task category, the memory exchange request is added to the tree data structure. Through the tree data structure, the current memory exchange request state can be conveniently monitored, wherein the memory exchange request state can include already processed, being processed, and needing further operation. After the memory exchange request is processed, that is, the memory data is completely swapped in, the memory exchange request can be deleted from the tree data structure in time, which can improve the efficiency and flexibility of memory management, and reduce unnecessary resource waste.
[0134] As an optional implementation, when the passive task exchange category is the passive swap-in task category, and the memory data of the page level is swapped out in the page fault exception state, the state information of the memory data of the memory page level includes at least the to-be-updated state information and the storage information.
[0135] In this embodiment, when it is checked that the page table entry corresponding to the address of the memory data allows access, that is, it is determined that access is allowed, it means that the page fault exception state processed by another process is already available. It can be determined that the state information of the memory page level of the memory data includes at least the to-be-updated state information and the storage information.
[0136] The to-be-updated state information and the to-be-updated storage information are explained as in the foregoing embodiments, and will not be illustrated one by one here.
[0137] As an optional implementation, in the case that the passive task exchange category is the passive swap-in task category and the memory data in the page fault exception state is swapped out, the secondary storage type recorded in the state information of the memory page level of the memory data is parsed; the corresponding secondary storage location is read by using the secondary storage type, wherein the page table is used to record the secondary storage location.
[0138] In the case that the passive task exchange category is the passive swap-in task category and the memory data in the page fault exception state is swapped out, that is, when the memory page data in the page fault is swapped out, data swap-in needs to be performed at this time, the secondary storage type recorded in the state information of the memory page level of the memory data can be parsed, that is, the secondary storage type recorded in the state information of the corresponding memory page level state information (mp_entry) can be parsed by the embodiment of the disclosure, and then the read function of the secondary storage (which can be reading from the disk, reading from the aep memory, even recovering from the zero page, or recovering from the decompression page, etc.) is called, and then the corresponding secondary storage location is read by using the secondary storage type, wherein the page table can be used to record the secondary storage location.
[0139] As an optional implementation, in the process of running the virtual machine operating system on the host machine, the memory exchange request is obtained, including: in the process of running the virtual machine operating system on the host machine, searching for the memory exchange request in the tree-shaped data structure.
[0140] In this embodiment, when the accessed memory data in the host machine is not in the physical memory, a page fault exception is triggered, and in this case, the accessed memory data can be swapped in from the backend storage medium to the physical memory of the host machine by the passive swap-in task.
[0141] Optionally, as known from the foregoing description, the tree-shaped data structure can be used to store and manage the memory exchange request. Based on this, in the process of running the virtual machine operating system on the host machine, the memory exchange request can be searched in the tree-shaped data structure, and if the task exchange category requested to be executed by the searched memory exchange request is the passive swap-in task, the read lock corresponding to the memory exchange request can be used to concurrently execute the passive swap-in task, so as to achieve swapping the memory data from the backend storage medium to the physical memory of the host machine.
[0142] Optionally, in order to improve the concurrent processing capability, the read lock corresponding to the memory exchange request can be used to concurrently execute the page fault swap-in processing.
[0143] Optionally, in the process of processing the passive swap-in task, the virtual machine operating system is only responsible for swapping the required data from the backend storage medium to the physical memory of the host machine, and updating the page table to record the mapping relationship between the data structure of the backend storage medium and the physical memory of the host machine.
[0144] Optionally, in the memory management, a Page Middle Directory (pmd) is a part of the page table, which is used to find the mapping relationship between the back-end storage medium and the physical memory of the host. When processing the passive swap-in task, since the passive swap-in task is triggered by the page fault exception, it is aimed at the memory pages (mp) in the memory block (ms). It should be noted that the page fault exception may occur in part of the memory pages (mp) in the memory block (ms). In this case, only the part of the memory pages (mp) in the memory block (ms) that has the page fault exception needs to be quickly swapped in, and there is no need to wait for the page fault swap-in processing of the entire memory block (ms). In this way, the delay caused by the passive swap-in task triggered by the page fault exception can be reduced. The memory pages (mp) in the memory block (ms) that do not have the page fault, and the final metadata recovery and update, will be actively completed when the subsequent scheduling execution is performed.
[0145] As an optional implementation, in the process of running the virtual machine operating system on the host, the memory swap request is obtained, including: in the process of running the virtual machine operating system on the host, obtaining the memory swap request from the request queue, wherein each request queue in different request queues is provided with a queue lock.
[0146] In this embodiment, in order to distinguish the memory swap tasks to be executed by the concurrent tasks, the memory swap request can be added to different request queues according to the different types of swap tasks to be requested to execute, and the different request queues can be provided with a queue lock. Among them, one request queue is used to store one type of memory swap request, and the one type of memory swap request is used to implement one type of memory swap task. Among them, the request queue can include an active swap-out request queue, an active swap-in request queue, and a passive swap-in request queue. In order to ensure the operation safety of the task queue, each queue will have a lock (queue lock) to protect the out and in of the memory swap request in the respective queue, so as to avoid data competition and consistency problem.
[0147] Optionally, since the memory swap request is added to different request queues according to the type of the swap task to be requested to execute, based on this, in the process of running the virtual machine operating system on the host, the corresponding memory swap request can be obtained from the request queue.
[0148] As an optional implementation, the method further comprises: in the virtualization management layer in which the virtual machine operating system runs, in response to the request queue being empty, obtaining, from the memory data set of the host computer, memory data whose access frequency is lower than an access frequency threshold; constructing a memory swap request by using the memory data whose access frequency is lower than the access frequency threshold; and storing the memory swap request in the request queue corresponding to the task swap category.
[0149] In this embodiment, the memory data set can be used to indicate a cold data set and a hot data set stored in the physical memory, wherein the cold data set is used to indicate memory data whose usage frequency is lower than an access threshold, and the hot data set is used to indicate memory data whose usage frequency is higher than the access threshold.
[0150] Optionally, since the memory swap request is deleted from the request queue after being processed, based on this, in the virtualization management layer in which the virtual machine operating system runs, if the request queue is empty, it indicates that no memory swap request has been created, or the memory swap request in the request queue has been processed, in both cases, the memory swap request in the request queue is empty. In the case that the request queue is empty, the cold data set whose access frequency is lower than the access frequency threshold can be obtained from the memory data set of the host computer, and then the memory swap request is constructed by using the obtained cold data set, and the memory swap request is stored in the request queue corresponding to the task swap category.
[0151] In this step, the cold data with low usage frequency in the host computer is obtained by using the access frequency threshold, the memory data with low usage frequency in the host computer can be quickly determined, and then the memory swap request is constructed, so as to facilitate the migration of the memory data with low usage frequency from the physical memory of the host computer to the back-end storage medium, so as to save the memory space of the physical memory, and make the allocation of memory resources more reasonable.
[0152] As an optional implementation, the storing of the memory exchange request into the request queue corresponding to the task exchange category comprises: in the case that the task exchange category is the active swap-out task category, storing the memory exchange request into an active swap-out task queue corresponding to the active swap-out task category; wherein the active swap-out task category is used to represent a task category in which the virtualization management layer actively triggers the swapping of the memory data from the physical memory of the host computer to the back-end storage medium; the request queue comprises the active swap-out task queue; in the case that the task exchange category is the active swap-in task category, storing the memory exchange request into an active swap-in task queue corresponding to the active swap-in task category; wherein the active swap-in task category is used to represent a task category in which the virtualization management layer actively triggers the swapping of the memory data from the back-end storage medium to the physical memory of the host computer; the request queue comprises the active swap-in task queue; in the case that the task exchange category is the passive swap-in task category, storing the memory exchange request into a passive swap-in task queue corresponding to the passive swap-in task category; wherein the passive swap-in task category is used to represent a task category in which the virtual machine operating system passively triggers the swapping of the memory data from the back-end storage medium to the physical memory of the host computer; the request queue comprises the passive swap-in task queue.
[0153] In this embodiment, when the memory exchange request is stored into the request queue corresponding to the task exchange category, the memory exchange request can be stored into the request queue corresponding to the task exchange category according to the category of the memory exchange task requested by the memory exchange request.
[0154] Optionally, when a memory exchange request is first created, it can be determined that the task exchange category requested by the memory exchange request is the active swap-out task category (for example, swap_out), and in this case, the memory exchange request can be stored into the active swap-out task queue.
[0155] Optionally, if the active swap-out request in the active swap-out request queue has been processed, the active swap-out request will be dequeued, that is, the active swap-out request will be temporarily removed from the active swap-out request queue. It should be noted that after the active swap-out request is dequeued, the active swap-out request will not be in any queue at any level.
[0156] Optionally, for the memory swap-in operation actively triggered by the virtualization management layer, it can be determined that the task exchange category requested by the memory exchange request is the active swap-in task category (for example, swap-in), and in this case, the memory exchange request can be stored into the active swap-in task queue.
[0157] Optionally, if a response to the triggering of the page fault task, it indicates that the page fault memory needs to be swapped in from the backend storage medium to the physical memory of the host computer, in which case, the memory swap request can be determined to request execution of a task swap category of a passive swap-in task category (for example, fault-in), in which case, the memory swap request can be stored in the passive swap-in task queue.
[0158] In this step, the memory swap request is placed in different request queues according to the task swap category requested by the memory swap request, which can improve the processing efficiency of the memory data.
[0159] As an optional implementation, the memory data swap method further includes: determining a first target physical address of the memory data in the physical memory of the host computer; and determining a virtual address corresponding to the first target physical address, wherein the mapping relationship is used to represent the correspondence between different first target physical addresses and different virtual addresses.
[0160] In this embodiment, for the physical memory of the host computer, a kernel mapping relationship is initially established to pre-store the correspondence between different physical addresses and different virtual addresses in the physical memory of the host computer. Based on this, when performing the memory swap task, after determining the first target physical address of the memory data in the physical memory of the host computer, the virtual address HVA corresponding to the first target physical address can be determined according to the mapping relationship. The virtual address HVA is a virtual address established by the virtualization management layer for the HPA and has a mapping relationship with the HPA. It should be noted that the virtualization management layer of this embodiment runs in the kernel state, and thus the HPA can be accessed through the HVA.
[0161] In this step, by pre-establishing the above mapping relationship, subsequent swap-out and swap-in operations are facilitated, so that when processing the memory data swap task, the virtual address corresponding to the physical memory of the host computer can be determined according to the mapping relationship, thereby improving the efficiency of memory management, reducing the overhead of swap-out and swap-in operations, avoiding the temporary establishment of a mapping relationship by the operating system each time a swap-out and swap-in operation is performed, and reducing the overhead of temporary mapping establishment.
[0162] In the above operating environment, the present disclosure provides a swap-out method of memory data as shown in FIG. 5. FIG. 5 is a flowchart of a swap-out method of memory data according to an embodiment of the present disclosure. As shown in FIG. 5, the method can include the following steps:
[0163] Step S501, control the host computer to switch from running the host operating system to running the virtual machine operating system.
[0164] In the technical solution provided in the foregoing step S501 of the present disclosure, the host machine operating system running on the host machine is switched to the virtual machine operating system, so that a light-weight virtualization management layer running on the virtual machine operating system can use the EPT page table for memory management, and the inserted virtualization management layer can implement the corresponding memory exchange function.
[0165] Optionally, the specific manner of switching the host machine from running the host machine operating system to running the virtual machine operating system can be described in the foregoing step S401, which will not be repeated here.
[0166] In step S502, a memory exchange request is obtained during the process in which the host machine runs the virtual machine operating system.
[0167] In the technical solution provided in the foregoing step S502 of the present disclosure, the memory exchange request is used to request exchange of memory data between the physical memory of the host machine and the back-end storage medium, for example, to exchange the memory blocks that are not frequently used in the physical memory of the host machine to the back-end storage medium, so as to release the physical memory of the host machine.
[0168] In this embodiment, the memory exchange request is used to request exchange of memory data from the physical memory of the host machine to the back-end storage medium, or to request exchange of memory data from the back-end storage medium to the physical memory of the host machine. The memory data can be a memory block or a memory page, which is not limited here. When the memory exchange task is to be executed, the memory exchange request can be used as a carrier to execute the memory exchange operation.
[0169] In this step, by storing different types of memory exchange requests in different queues, the system can explicitly determine the priority of each task, which helps to improve the efficiency of resource allocation and the response speed of the system.
[0170] In step S503, a task exchange category corresponding to the memory data is determined in response to the memory exchange request.
[0171] In the technical solution provided in the foregoing step S503 of the present disclosure, the memory data can be used to indicate a memory block or a memory page, and the task exchange category can be used to indicate the category of the exchange task, wherein the task exchange category includes an active task exchange category and a passive task exchange category, the active task exchange category includes a swap-out task category and a swap-in task category, and the passive task exchange category mainly refers to a fault-in task category. The specific meanings of the swap-out task category, the swap-in task category, and the fault-in task category are described above, which will not be repeated here.
[0172] In this step, the memory data corresponding to the task exchange category can be determined according to the memory exchange request, which helps to distinguish different types of memory exchange tasks, and can more intelligently allocate system resources, for example, different priorities or resource quotas are allocated to different types of tasks.
[0173] After determining the task exchange category corresponding to the memory data, the following step S504 can be performed on the memory data between the physical memory of the host and the backend storage medium to perform the exchange task corresponding to the task exchange category.
[0174] In step S504, in response to the task exchange category being the active swap-out task category, the memory data is executed to perform the active swap-out task corresponding to the active swap-out task category.
[0175] In the technical solution provided by the above step S504 of the present disclosure, if the determined task exchange category is the active swap-out task category, since the active swap-out task category is used to represent the task category of the virtualization management layer actively triggering the memory data to be swapped out from the physical memory of the host to the backend storage medium, in this case, the host operating system can be controlled to actively migrate the infrequently used memory data in the physical memory of the host to the backend storage medium, that is, the memory data is executed to perform the active swap-out task corresponding to the active swap-out task category, to save the physical memory space of the host.
[0176] In the above steps S501 to S504, during the running of the virtual machine operating system, the memory exchange request is obtained, which helps to efficiently manage memory resources. By determining the task exchange category corresponding to the memory data, the exchange process of the memory data between the physical memory of the host and the corresponding backend storage medium of the host can be more accurately controlled. For example, if the task exchange category is the active swap-out task category, the memory data is executed to perform the active swap-out task corresponding to the active swap-out task category, to migrate the infrequently used data in the physical memory of the host to the backend storage medium, to save the physical memory space of the host. Moreover, the memory exchange function can be performed on the virtualization management layer on which the virtual machine operating system runs, and it is not limited to whether the exchange object is a user state page or a kernel state page, which realizes the technical effects of reducing the limitations of memory exchange and enabling the memory exchange of the operating system in the running state, thereby solving the technical problems of large limitations of memory exchange and the operating system in the running state cannot enable memory exchange in the related art.
[0177] The above method of this embodiment will be further introduced as follows.
[0178] As an optional implementation, in step S504, in response to the task exchange category being the active swap-out task category, performing, on the memory data, the active swap-out task corresponding to the active swap-out task category, comprises: in response to the task exchange category being the active swap-out task category, acquiring the write lock corresponding to the memory exchange request; and using the write lock, performing, on the memory data, the active swap-out task corresponding to the active swap-out task category.
[0179] In this embodiment, as introduced above, the memory exchange request corresponds to a read-write lock, wherein the read-write lock comprises a read lock and a write lock. Since the active swap task usually involves changing the state of the memory data when performing the memory exchange task. For example, writing the memory data from the physical memory of the host computer to the backend storage medium, or writing back from the backend storage medium to the physical memory of the host computer. In this process, the use of the write lock can ensure that no other processes can modify these data at the same time when performing these operations, thereby avoiding data inconsistency or damage. The active swap-out task usually involves checking the data state of the metadata in the storage space of the host computer to determine whether the metadata in the storage space is a cold page, or whether the metadata is marked as unswappable, etc., and before swapping out, the CRC value of the metadata is maintained to perform verification when the data is swapped in, to ensure the integrity and correctness of the data.
[0180] Optionally, the active swap-in task or the passive swap-in task does not need to check whether the metadata is a cold page, or whether the metadata is a cold page, but will compare the CRC value of the metadata in the active swap-in task or the passive swap-in task with the previously maintained CRC value to ensure the correctness of the data.
[0181] Optionally, since the active swap task includes the active swap-out task and the active swap-in task (i.e. the CRC value of the metadata needs to be checked), based on this, if the task exchange category is the active swap-out task category, the write lock corresponding to the memory exchange request can be acquired, and then the write lock is used to perform, on the memory data, the active swap-out task corresponding to the active swap-out task category, wherein the memory data can be the memory data in the physical memory of the host computer with an access frequency lower than an access frequency threshold.
[0182] For example, using the write lock to lock control the active swap-out task of the memory data from the physical memory of the host computer to the backend storage medium can be used in the control plane to ensure the accuracy of the operation, and in the data plane, it can assist in CRC verification to ensure the accuracy of the data.
[0183] As an optional implementation, the method for swapping out the memory data further comprises: in response to releasing the write lock corresponding to the memory swap request, performing a passive swap-in task corresponding to a passive swap-in task category on the memory data by using the read lock corresponding to the memory swap request, wherein the passive swap-in task category is used to represent a task category in which the virtual machine operating system passively triggers the memory data to be swapped in from the back-end storage medium to the physical memory of the host.
[0184] In this embodiment, if a page fault exception occurs during the execution of the active swap-out task, it indicates that the memory data is being used in the process of moving the memory data from the physical memory of the host to the back-end storage medium, and thus the page fault exception occurs.
[0185] Optionally, the page fault exception indicates that the user may have used the memory data being swapped out, and in this case, if the memory swap request corresponding to the physical address of the page fault exception is being swapped out, the memory swap request corresponding to the active swap-out task needs to be cancelled in order to avoid further page replacement.
[0186] For example, a cancel flag is used to indicate that the current page replacement operation should be cancelled, and the cancel flag is a notification mechanism. If the cancel flag is identified in the step of the active swap-out task being executed, the current active swap-out task operation is cancelled and the current active swap-out task being executed is quickly ended, so as to quickly release the write lock held by the current active swap-out task and further quickly recover the page where the page fault exception occurs, thereby minimizing the delay and allowing the user to use the page as soon as possible.
[0187] Optionally, after the write lock corresponding to the memory swap request is released, the page fault exception occurs at this time, and in this case, the passive swap-in task corresponding to the passive swap-in task category can be performed on the memory data by using the read lock corresponding to the memory swap request, so as to swap in the memory data from the back-end storage medium to the physical memory of the host, thereby increasing the free memory space in the physical memory.
[0188] In this step, if a page fault exception occurs during the execution of the active swap-out task, that is, the page being swapped out needs to be used, in this case, the active swap-out task can be cancelled, the write lock corresponding to the active swap-out task is released, and the read lock is used to perform the passive swap-in task, which is helpful to swap in the memory data from the back-end storage medium to the physical memory of the host, increase the free space in the physical memory, and thus optimize the memory usage.
[0189] The above memory management mechanism improves the stability of the operating system by quickly identifying and responding to exceptions, optimizing resource usage, quickly releasing lock resources, and triggering passive swap-in tasks.
[0190] As an optional implementation, in step S502, the memory swap request is obtained in the process that the host machine runs the virtual machine operating system, comprising: obtaining the memory swap request in a request queue in the process that the host machine runs the virtual machine operating system, wherein the request queue is provided with a queue lock.
[0191] In this embodiment, the memory swap requests for different task exchange categories are stored in different request queues, wherein the request queues can include an active swap-out task queue, an active swap-in task queue and a passive swap-in task queue. The active swap-out task queue is used to store the memory swap request triggered by the virtualization management layer to swap the memory data from the physical memory of the host machine to the back-end storage medium. The active swap-in task queue is used to store the memory swap request triggered by the virtualization management layer to swap the memory data from the back-end storage medium to the physical memory of the host machine. The passive swap-in task queue is used to store the memory swap request triggered by the virtual machine operating system to swap the memory data from the back-end storage medium to the physical memory of the host machine.
[0192] Optionally, taking the active swap-out task as an example, in the execution of the active swap-out task, the memory swap request can be obtained in the active swap-out task queue corresponding to the active swap-out task category, and then the memory swap request is used as a carrier to execute the active swap-out task to swap the memory page in the memory block from the physical memory of the host machine to the back-end storage medium.
[0193] Optionally, each request queue is provided with a queue lock for protecting the dequeuing and enqueuing of the memory swap request in the respective queue.
[0194] Optionally, the memory swap request corresponds to a counter. For example, after the memory swap request is obtained from the active swap-out task queue, the counter of the memory swap request can be increased by 1, indicating that the active swap-out task has been taken over and started to be processed.
[0195] In this step, since the queue lock is for each queue, only the correctness of the operation of the queue can be guaranteed, and the correctness of the cross-queue operation cannot be guaranteed. The cross-queue operation needs the assistance of the counter. By recording the processing state of the memory swap request through the counter, it can be ensured that a memory swap request can only appear in one queue. For example, when the memory swap request needs to be moved from one queue to another queue, the single queue lock mechanism can not be enough to guarantee the correctness of the operation, therefore, the counting mechanism plays a role here.
[0196] Optionally, before performing the cross-queue move request, the type of the request needs to be changed, after changing the type of the request, a lock mechanism needs to be used to ensure the atomicity of the operation, and then the count of the request is decremented (count-1), which indicates that the memory swap request is removed from one queue and is ready to be added to another queue. Before inserting the memory swap request into the new queue, it needs to be checked again whether the memory swap request is empty or in a valid state to ensure that the memory swap request does not change state during the cross-queue move process.
[0197] Optionally, in a multi-CPU environment, multiple tasks may concurrently operate on the queue. This increases the possibility of changes in the type and count of the request during the operation. Due to the change in the type of the request, the queue lock corresponding to the request may be affected. This means that during the operation, the acquisition and release of the lock need to be considered to ensure the consistency and correctness of the operation. The count mechanism plays an auxiliary role here to ensure the correctness and consistency of the cross-queue operation, especially in a multi-CPU concurrent operation environment.
[0198] As an optional implementation, the method for swapping out memory data further includes: in response to completing the active swap-out task corresponding to the active swap-out task category for performing the active swap-out task on the memory data, determining a time slice of the active swap-out task; and based on the time slice, placing the memory swap request back into the active swap-out task queue corresponding to the active swap-out task category, wherein the request queue includes the active swap-out task queue.
[0199] In this embodiment, since the memory swap task corresponds to a time slice for limiting the execution time of the memory swap task, based on this, taking the active swap-out task as an example, after completing the swap-out operation of one memory page, it is determined whether to continue the swap-out operation of the next memory page or to place the uncompleted memory swap request back into the request queue for subsequent processing according to the time slice corresponding to the active swap-out task. It should be noted that the active swap-out task and the active swap-in task of this embodiment can both be within the time slice constraint, for example, for the active swap-in task, after completing the swap-in operation of one memory page, it is determined whether to continue the swap-in operation of the next memory page according to the time slice corresponding to the active swap-in task. The active swap-out task is further exemplified below.
[0200] For example, if the time slice corresponding to the active swap-out task is not used up after completing the swap-out operation of one memory page, in this case, the swap-out operation of the next memory page can be continued. Conversely, if the time slice corresponding to the active swap-out task is used up after completing the swap-out operation of one memory page, the uncompleted memory swap request is placed back into the request queue for subsequent processing.
[0201] In this step, by setting the time slice limit for the execution time of the swap-out task (or swap-in task), long-term occupation of system resources can be avoided, and the execution progress and priority of the task can be better controlled. By determining whether to continue the swap-out operation of the next memory page according to the remaining time slice after completing the swap-out operation of one memory page, dynamic adjustment and load balancing can be achieved, and system overload can be avoided. By placing the unfinished memory swap request back into the request queue for subsequent processing, system crashes or instability caused by task backlog can be avoided, and the stability and reliability of the system can be improved.
[0202] As an optional implementation, in step S504, in response to the task swap category being the active swap-out task category of the host machine, performing the active swap-out task corresponding to the active swap-out task category on the memory data includes: in response to the task swap category being the active swap-out task category, determining a second target physical address in the back-end storage medium based on the memory data; and controlling the virtualization management layer to actively trigger the swap-out of the memory data from the physical memory of the host machine to the second target physical address.
[0203] In this embodiment, when performing the active swap-out task corresponding to the active swap-out task category on the memory data, the second target physical address in the back-end storage medium where the memory data is located can be determined based on the content attribute of the memory data and the state of the back-end storage medium. The content attribute of the memory data can be used to indicate the type, purpose, etc. of the data stored in the memory page, such as code, data, and operating system kernel code, etc. These are only exemplary examples and do not limit the content attribute of the memory data.
[0204] For example, the second target physical address in the back-end storage medium where the memory data is located can be determined based on the content attribute of the memory data and the state of the back-end storage medium, where the back-end storage medium can be a disk, compressed memory, or a merged page, without specific limitation.
[0205] Optionally, after determining the second target physical address in the back-end storage medium where the memory data is located, the physical address in the back-end storage medium corresponding to the physical address in the physical memory of the host machine stored in the page table entry can be updated to the determined second target physical address. The page table entry is a data structure used to implement the mapping between the physical memory of the host machine and the back-end storage medium, thereby implementing back-end storage medium management.
[0206] Optionally, for the page table entry storing the physical address in the physical memory of the host computer and the physical address in the backend storage medium, the following implementation can be used. In this embodiment, for the storage unit in the physical memory of the host computer or the backend storage medium processing the allocation state, the association information of the storage unit in the allocation state can be determined, the encoding result can be obtained by encoding the association information, and the physical address (i.e., the physical address in the physical memory of the host computer or the physical address in the backend storage medium) of the to-be-allocated memory can be determined from the memory pool by using the encoding result, wherein the association information can be used to represent information associated with the attribute information of the storage unit, the position information of the allocated storage unit and other attributes of the storage unit can be determined according to the position serial number of the storage unit in the allocation state, and the association information can be obtained. The attributes of the storage unit can be the serial number, the number and the size of the storage unit, which are only used as examples and are not limited in particular. Based on the above attributes, the corresponding association information can include ms, mp and chunk serial number corresponding to the small memory chunk, and can also include the difference (difference, referred to as diff) between the number of nr_chk, the size of nr_chk and the allocation size size. It should be noted that the high bits of the encoding of the association information need to be marked as the record compression format. nr_chk refers to the number of small segments converted from the memory size allocated from the zbud pool. The nr_chk size refers to the memory size represented by the number of nr_chk. Specifically, the nr_chk size depends on the required memory size and the granularity of the small segment. By converting the required memory size into the number of small segments nr_chk and determining the size of each small segment according to the granularity of the small segment, the size of nr_chk can be calculated.
[0207] Optionally, in the process of encoding the association information to obtain the encoding result, the association information can be encoded to form an encoding handler, so that the position of the allocated storage unit can be quickly located in the subsequent operation. That is, by using the encoding handler, multiple association information can be combined together to form a flag bit of the storage unit, so that the position information of the allocated storage unit can be quickly located, and then the flag bit of the storage unit and the encoding handler corresponding to the position information of the memory block are stored in the page table. Since the above storage unit can be a storage unit in the physical memory of the host computer or a storage unit in the backend storage medium, the physical address in the physical memory of the host computer and the physical address in the backend storage medium can be stored in the page table.
[0208] Optionally, after the second target physical address is determined from the backend storage medium, the virtualization management layer can be controlled to actively trigger the memory data to be swapped out from the physical memory of the host computer to the second target physical address.
[0209] In this step, when the control virtualization management layer initiatively triggers the swapping of the memory data from the physical memory of the host computer to the backend storage medium, the target physical address in the backend storage medium can be determined first, and then the control virtualization management layer can swap the memory data from the physical memory of the host computer to the target physical address in the backend storage medium, so that the data exchange efficiency can be improved.
[0210] As an optional implementation, in response to the task exchange category being the active swap task category, the second target physical address in the backend storage medium is determined based on the memory data, and the method comprises: in response to the task exchange category being the active swap task category, in a case where the memory exchange request is a first generated memory exchange request, determining the state information of the memory data as a queued swap state; splitting the page table corresponding to the memory data in the queued swap state to obtain the page table entry of the memory page; determining the access state of the page table entry corresponding to the memory page as a read-only state; determining the content attribute and the storage state of the memory page in the read-only state; and determining the second target physical address corresponding to both the content attribute and the storage state in the backend storage medium.
[0211] In this embodiment, the queued swap state is used to indicate that when there is memory data to be swapped out, the memory data will be placed in a swap-out queue first, and the memory data in the swap-out queue has not been actually swapped out, but has been marked as about to be swapped out, that is, the state of the memory data in the swap-out queue is the queued swap state. The purpose of this is to quickly release the memory occupied by the memory data to be swapped out when the memory space is tight.
[0212] Optionally, the page table corresponding to the memory data is used to indicate a memory management page table for mapping the physical memory of the host computer to the backend storage medium, and the page table can be a page middle directory (pmd) of a memory management structure, which is used to map the physical memory of the host computer to the backend storage medium.
[0213] Optionally, if the task exchange category is the active swap task category, and the memory exchange request corresponding to the active swap task category is the first time to perform the swap task, in this case, the state information (ms-entry) of the memory data can be determined as the queued swap state (queue-out). And the page table corresponding to the memory data in the queued swap state is split to obtain the page table entry of the plurality of memory pages.
[0214] For example, a memory block of a larger page is split into 512 smaller pages, each of which can be 4KB in size, to perform more fine-grained memory management. After splitting the page, a new level can be added to the existing page table structure. For example, a Page Table Entry (PTE) is added to the page table entry to store more fine-grained address mapping information to map the split small pages.
[0215] Optionally, after the memory data is split into 4K granularity small pages, the PTE page table corresponding to the small page can be changed to a read-only state, and the Translation Lookaside Buffer (TLB) is synchronized and refreshed to avoid other Central Processing Units (CPUs) using the un-updated page table to continue writing, resulting in subsequent data inconsistency.
[0216] Optionally, after the access state of the page table entry corresponding to the memory page is determined to be a read-only state, the content attribute and storage state of the memory page in the read-only state can be further determined. The content attribute of the memory page can include the type and purpose of the data stored in the memory page, which is only an example and does not limit the content attribute of the memory data. After determining the content attribute and storage state of the memory page, the virtualization management layer can be controlled to actively trigger the memory page to be swapped out from the physical memory of the host to the backend storage medium.
[0217] In this step, in response to the active swap-out task category, when the memory swap request is the first memory swap request, the memory data state is first set to a queued swap-out state, then the memory page is split to ensure that the page table entry access state is read-only, thereby determining the content attribute and storage state of the memory page. Further, the target physical address corresponding to the content attribute and storage state of the memory page is found in the backend storage medium, and the virtualization management layer is controlled to actively swap out the memory data from the physical memory of the host to the corresponding target physical address in the backend storage medium. Optionally, this embodiment uses the last level page table to save the position encoding of the backend storage medium, which can improve the efficiency of system processing.
[0218] As an optional implementation, the memory data swap-out method further includes: in the case where the memory page is completed from the physical memory of the host to the backend storage medium, the state information of the memory data is determined to be a swap-out state, and the memory data in the swap-out state is recovered; and / or in the case where the time slice of the memory swap request corresponding to the active swap-out task has been used up and the state information of the memory data is in the swap-out state, the memory data in the swap-out state is recovered.
[0219] In this embodiment, as can be known from the foregoing, in order to support more fine-grained memory management, the page table corresponding to the memory data in the queued-out state can be split to obtain a plurality of memory pages, and the physical address corresponding to the memory page can be determined in the backend storage medium, and then the virtualization management layer is triggered to actively trigger the memory page to be swapped out from the physical memory of the host to the backend storage medium. Based on this, after the memory page is completed from the physical memory of the host to the backend storage medium, the state information of the memory data can be determined as the swapped-out state.
[0220] For example, assuming that the page table corresponding to the memory data is split to obtain 512 smaller pages, based on this, it can be determined whether the 512 memory pages are all completed swap-out operation, if so, the state information (ms-entry) of the memory data is modified to the swapped-out state.
[0221] Optionally, after the state information of the memory data is modified to the swapped-out state, the idle memory after being swapped out can be recycled, wherein recycling the idle memory after being swapped out refers to recycling the memory block.
[0222] Optionally, after the state information of the memory data is modified to the swapped-out state, it indicates that the memory swap request corresponding to the swap-out task has been processed, in this case, the memory swap request corresponding to the active swap-out task can be dequeued to determine that the memory swap request is removed from the request queue, and then the counter cnt corresponding to the memory swap request is decremented by 1, after the memory swap request is dequeued, the memory swap request will not be put into any queue.
[0223] Optionally, if no page fault exception occurs during the entire active swap-out process, but the time slice of the active swap-out corresponding memory swap request has been used up, that is, there is no time slice corresponding to the active swap-out task, in this case, the state information of the memory data can be directly updated to the swapped-out state, and the idle memory after being swapped out can be recycled.
[0224] In this step, in the case that the memory page is completed from the physical memory of the host to the backend storage medium, the state information of the memory data is updated to the swapped-out state in a timely manner, which is helpful for more efficient management of memory resources. Moreover, in the case that the state information of the memory data is in the swapped-out state, the memory data can be recycled, which can reduce the waste of memory, make the memory resources more reasonably allocated and utilized, and improve the running efficiency of the entire system.
[0225] As an optional implementation, the memory data swap-out method further includes: in response to the memory page being in a page fault exception state, or detecting a cancel identifier of the memory swap request, canceling the memory page to be swapped out from the physical memory of the host to the backend storage medium, wherein the cancel identifier is used to indicate the cancellation of the memory swap request.
[0226] In this embodiment, the page fault exception state of the memory page indicates that the memory page to be used by the user does not exist in the physical memory of the host machine, and the memory page has been swapped out, in which case the page fault exception is triggered. The cancelation of the memory swap request is used to indicate the cancellation of the active swap-out task requested by the memory swap request.
[0227] Optionally, if the page fault exception state is responded to during the process of swapping the memory page from the physical memory of the host machine to the backend storage medium, it indicates that the page being swapped out may be used by the user, that is, the memory page being swapped out is needed, in which case, in order to avoid further swap-out operation, the current active swap-out task can be cancelled, that is, the memory page is cancelled from being swapped out from the physical memory of the host machine to the backend storage medium, and the memory allocation and page swap-out strategy are adjusted to use the available memory more effectively.
[0228] Optionally, if the cancelation of the memory swap request is detected during the execution of the active swap-out task, the current active swap-out task can also be cancelled. For example, whether there is a cancel mark in each step of the active swap-out task process can be detected, if there is, it indicates that the cancelation of the memory swap request is detected, in which case, the memory page can be cancelled from being swapped out from the physical memory of the host machine to the backend storage medium.
[0229] In this step, if the page replacement process is responded to the page fault exception or the cancelation of the memory swap request, the currently executed page replacement operation can be cancelled in time.
[0230] In the above running environment, the disclosure provides a memory data swap-in method as shown in FIG. 6, which is applied to the passive swap-in process, that is, the virtual machine operating system passively triggers the memory data to be swapped in from the corresponding backend storage medium of the host machine to the physical memory of the host machine. FIG. 6 is a flowchart of a memory data swap-in method according to an embodiment of the disclosure. As shown in FIG. 6, the method can include the following steps:
[0231] Step S601, control the host machine to switch from running the host machine operating system to running the virtual machine operating system.
[0232] In the technical solution provided in step S601 of the disclosure, the host machine operating system running on the host machine is switched to the virtual machine operating system through virtualization, so that a light virtualization management layer is formed in the virtual machine operating system, and the EPT page table can be used for memory management in the virtualization management layer, and the corresponding memory swap function is realized through the inserted virtualization management layer.
[0233] In this embodiment, in order to realize that the running host operating system starts the memory swapping function, the host can be controlled to switch from running the host operating system to running the virtual machine operating system. That is, the running operating system on the host is switched to the virtualization mode through the virtualization switching.
[0234] In step S602, a memory swapping request is obtained during the process in which the host runs the virtual machine operating system.
[0235] In the technical solution provided in the foregoing step S602 of the disclosure, the memory swapping request is used to request swapping of memory data between the physical memory of the host and the back-end storage medium. The memory swapping request can be obtained in the manner described in the foregoing step S402, and thus a detailed description is omitted here.
[0236] In this embodiment, by storing different types of memory swapping requests in different queues, the system can explicitly determine the priorities of various tasks, which helps to improve the efficiency of resource allocation and the response speed of the system.
[0237] In step S603, in response to the memory swapping request, a task swapping category corresponding to the memory data is determined.
[0238] In the technical solution provided in the foregoing step S603 of the disclosure, the memory data can be used to indicate a memory block or a memory page, and the task swapping category can be used to indicate a category of swapping tasks. The task swapping category includes an active task swapping category and a passive task swapping category. The active task swapping category includes an active swap-out task category and an active swap-in task category. The passive task swapping category mainly refers to a passive fault-in task category. The specific meanings of the active swap-out task category, the active swap-in task category, and the passive fault-in task category are described in the foregoing description, and thus a detailed description is omitted here.
[0239] In this embodiment, the task swapping category corresponding to the memory data can be determined according to the memory swapping request, which helps to distinguish different types of memory swapping tasks and intelligently allocate system resources, for example, to assign different priorities or resource quotas to different types of tasks.
[0240] After the task swapping category corresponding to the memory data is determined, the memory data can be subjected to a swapping task corresponding to the task swapping category between the physical memory and the back-end storage medium through the following step S604.
[0241] In step S604, in response to the task swapping category being the passive fault-in task category of the host, a passive fault-in task corresponding to the passive fault-in task category is performed on the memory data.
[0242] In the technical solution provided in the step S604 of the present disclosure, after determining the task exchange category corresponding to the memory data, if the task exchange category is the passive exchange-in task category of the host computer, in this case, the passive exchange-in task corresponding to the passive exchange-in task category can be executed on the memory data. The passive exchange-in task is used to indicate that the virtual machine operating system passively triggers the memory data to be exchanged from the back-end storage medium to the physical memory of the host computer.
[0243] Based on the steps S601 to S604 of the above embodiment, in the process of running the virtual machine operating system on the host computer, the memory exchange request is obtained, which helps to efficiently manage the memory resources. By determining the task exchange category corresponding to the memory data, the exchange process of the memory data between the physical memory of the host computer and the back-end storage medium corresponding to the host computer can be more accurately controlled. For example, when the task exchange category is the passive exchange-in category, the virtual machine operating system passively triggers the memory data to be exchanged from the back-end storage medium to the physical memory of the host computer to meet the physical memory demand of the host computer. Moreover, the memory exchange function can be performed on the virtualization management layer inserted under the virtualization operating system, and it is not limited that the exchange object is the user-mode page or the kernel-mode page, which realizes the technical effects of reducing the limitation of memory exchange and enabling the memory exchange of the operating system in the running state, thereby solving the technical problems of large limitation of memory exchange and the operating system in the running state cannot enable the memory exchange in the related art.
[0244] The above method of the embodiment will be further introduced below.
[0245] As an optional implementation, in response to the task exchange category being the passive exchange-in task category of the host computer, the passive exchange-in task corresponding to the passive exchange-in task category is executed on the memory data, including: determining the page table entry corresponding to the address of the memory data; in response to the task exchange category being the passive exchange-in task category, executing the passive exchange-in task on the memory data, and determining that the memory data has been successfully exchanged from the back-end storage medium to the physical memory of the host computer.
[0246] In the embodiment, the page table entry corresponding to the address of the memory data can be a PTE page table, wherein the PTE page table is used to map the physical address of the memory data in the back-end storage medium to the physical memory of the host computer.
[0247] Optionally, when the CPU accesses a memory block which has not been loaded into the physical memory of the host computer, a page fault exception is triggered, and different CPUs can trigger a page fault exception for a memory block address at the same time, in which case, the access permission of the page table entry (PTE page table) corresponding to the memory block address can be checked to determine the access permission of the page table entry corresponding to the memory block address, and the state of the memory block can be determined according to the access permission of the page table entry.
[0248] For example, if the page table entry corresponding to the memory block address does not allow access, it means that the memory data corresponding to the memory block address is being swapped out, in which case, a cancel process can be triggered, that is, the process of swapping the memory data from the physical memory of the host computer to the backend storage medium is cancelled. If the page table entry corresponding to the memory block address does not exist, a swap-in task is directly triggered, that is, the memory data is swapped from the backend storage medium to the physical memory of the host computer.
[0249] Optionally, if the read lock of the memory swap request corresponding to the passive swap-in task is obtained, and it is found that another task has already processed the page fault exception of the memory block address and has already swapped the corresponding memory data from the backend storage medium to the physical memory of the host computer when the page fault swap-in operation is prepared to be executed, in this case, the processing success can be directly returned, and the page fault exception will not be triggered when the subsequent other CPUs access the memory data, and the page fault swap-in operation does not need to be executed again.
[0250] In this step, when processing the page fault exception, it can be determined whether another process has already processed the page fault exception, so as to decide whether the memory swap-in operation needs to be executed again, thereby avoiding unnecessary data loading and memory waste.
[0251] As an optional implementation, in step S602, the memory swap request is obtained during the process that the host computer runs the virtual machine operating system, including: searching for the memory swap request in the tree-shaped data structure during the process that the host computer runs the virtual machine operating system, wherein the tree-shaped data structure is provided with a tree level lock.
[0252] In this embodiment, when a CPU or a process attempts to access an address which has not been allocated memory, the page table entry (PTE) of the address is checked to determine whether it can be read and written. If the PTE has been recovered, it means that another process has already processed the page fault exception, and the processing success can be directly returned. If the PTE has not been recovered, it means that the address has not been allocated memory. At this time, the operating system needs to be processed to allocate memory for the address.
[0253] Optionally, the operating system can allocate memory for the address through a passive swap-in task, and the operating system can search the tree-shaped data structure to determine whether there is a memory swap request corresponding to the address.
[0254] Optionally, after finding the memory swap request in the tree data structure, the operating system increments the usage count (cnt) of the memory swap request, where the usage count is a counter used to manage and track the usage of the memory swap request. By incrementing the count, the operating system can ensure that the memory swap request is not deleted or overwritten until the memory page is fully swapped in.
[0255] Optionally, after the memory page is fully swapped in, the operating system decrements the usage count (cnt) to determine that the memory swap request has been completed. In this way, the correctness of the memory swap request moving across the queue (moving queue) is ensured (the state change of the memory swap request during the moving across the queue needs to be identified in time), and the correctness of the memory swap request req release is ensured (there is no task still using the memory swap request req, and the memory swap request req is released).
[0256] As an optional implementation, in step S604, in response to the task exchange category being the passive swap-in task category of the host, performing the passive swap-in task corresponding to the passive swap-in task category on the memory data, including: in response to the task exchange category being the passive swap-in task category, acquiring read locks corresponding to a plurality of memory swap requests; and in response to the read locks corresponding to the plurality of memory swap requests being in an available state, concurrently performing the passive swap-in task corresponding to the passive swap-in task category on the memory data.
[0257] In this embodiment, as described above, the memory swap request corresponds to a read-write lock, where the read lock is used to control the passive swap-in task. Based on this, if the task exchange category is the passive swap-in task category of the host, in this case, the read locks of the plurality of memory swap requests can be acquired, and then the read locks corresponding to the plurality of memory swap requests are used to lock control the passive swap-in task corresponding to the passive swap-in task category on the memory data. The passive swap-in task is used to indicate that the virtual machine operating system passively triggers the memory swap task of swapping the memory data from the back-end storage medium to the physical memory of the host.
[0258] In this step, the read locks corresponding to the plurality of memory swap requests can be acquired, and in the case that the read locks corresponding to the plurality of memory swap requests are in an available state, the passive swap-in task is locked and controlled, and the passive swap-in task corresponding to the passive swap-in task category is concurrently performed on the memory data, that is, concurrent swap-in is achieved. The read lock can be used to ensure that the same memory swap request req (for the same GPA) concurrently performs the passive swap-in task, so as to achieve the purpose of concurrent swap-in, but any other active task (whether it is an active swap-out task or an active swap-in task) cannot be executed.
[0259] As an optional implementation, the method for swapping in memory data further comprises: in response to failure in acquiring the read lock corresponding to the memory swap request, setting a cancel identifier to the memory swap request, wherein the cancel identifier is used to cancel the memory swap request; and using the cancel identifier to trigger a rollback operation on the active swap-out task corresponding to the active swap-out task category, so that the original data is still stored in the physical memory of the host computer, and the re-swapping-in operation is not needed, and the state recovery of the metadata in the storage space of the host computer can be performed. The active swap-out task category is used to represent a task category of actively triggering the virtualization management layer to swap out the memory data from the physical memory of the host computer to the back-end storage medium.
[0260] In this embodiment, in the process of acquiring the read lock of the memory swap request, if the memory swap request currently does not perform an active swap task (the active swap task includes an active swap-out task and an active swap-in task), in this case, the read lock corresponding to the memory swap request can be successfully acquired. Otherwise, the read lock corresponding to the memory swap request cannot be acquired.
[0261] Optionally, in the case where the read lock corresponding to the memory swap request is not acquired, in order to safely interrupt the current swap-out operation, a cancel identifier can be set to the memory swap request, wherein the cancel identifier can be a cancel mark, to notify that the swap-out operation being performed should be cancelled.
[0262] Optionally, after the cancel identifier is set, the swap-out task being performed should be stopped and a rollback operation is performed, wherein the rollback operation is used to indicate to undo the partial swap-out operation that has been performed, and to recover to the state before the operation.
[0263] Optionally, after the cancel mark is set and the rollback is triggered, it is needed to check whether the corresponding page table entry PTE has been loaded into the memory. If the PTE has been loaded, it indicates that the memory page is already available, and a direct return is needed, without further operation.
[0264] Optionally, if the PTE has not been loaded into the memory, it is needed to wait for the swap-out task being currently executed to complete its operation and release the write lock of req. The write lock is an exclusive lock, and only one task is allowed to perform a write operation. After waiting for the write lock to be released, the current task can safely perform its own operation.
[0265] Optionally, since the page fault exception is in the interrupt context, a long wait can cause the host to be stuck, therefore, the time duration for waiting for the current executing swap-out task to complete its operation and release the write lock of the req cannot exceed a time threshold. If the time threshold is exceeded, a page fault retry identifier is returned, so that the page fault exception can be re-triggered, and the next time the related memory swap task is executed, other memory swap tasks can have already handled the page fault exception. The time threshold can be 1 ms, which is merely an example and does not limit the time threshold.
[0266] In this step, after the read lock corresponding to the memory swap request is acquired, a rollback operation on the active swap-out task corresponding to the active swap-out task category can be triggered by setting a cancellation identifier to the memory swap request, and then the state recovery of the metadata is performed.
[0267] It should be noted that the entire memory data (ms) in this embodiment will not be cleared from the physical memory of the host before being swapped out, because the memory management granularity of the virtualization management layer is ms, and the memory data cannot be recycled without being completely swapped out. It should be noted that in an optional example, the memory management granularity can be a hybrid management of ms and mp, and the non-essential preferred mode can select ms granularity management. Therefore, the memory block with the memory management granularity of ms can be quickly recovered when the cancellation operation is performed, otherwise if the memory has been recycled, the memory needs to be re-swapped in.
[0268] As an optional implementation, the swap-in method of the memory data further includes: in response to that the read lock corresponding to the memory swap request is successfully acquired, in a case where the page table entry corresponding to the address of the memory data allows access, unlocking the read lock corresponding to the memory swap request, and determining that the memory data has been successfully swapped in from the back-end storage medium to the physical memory of the host.
[0269] In this embodiment, since the read lock is non-exclusive and multiple vcpus can concurrently occur page fault exceptions during the process of acquiring the read lock of the memory swap request, the page fault exception can have been handled by other vcpu tasks. In this case, in order to avoid re-executing the swap-in operation of the memory data, after the read lock of the memory swap request is successfully acquired, it can be checked again whether the page table entry corresponding to the address of the memory data allows direct access. If it is allowed, the read lock corresponding to the memory swap request is unlocked, and it is determined that the memory data has been successfully swapped in from the back-end storage medium to the physical memory of the host, and a notification message that the page fault task processing is successful can be returned.
[0270] In this step, when the operating system handles the page fault exception, the synchronization mechanism is used to ensure that the task safely accesses the page and avoid repeated work in the case that the page has been processed by other tasks. Optionally, the above synchronization mechanism can be guaranteed by atomic update of bitmap information and state of the storage block.
[0271] As an optional implementation, the method further includes: in response to releasing the read lock corresponding to the memory swap request, storing the memory swap request into the passive swap-in task queue corresponding to the passive swap-in task category.
[0272] In this embodiment, since the read lock corresponding to the memory swap request is used to control the passive swap-in task, based on this, when the read lock corresponding to the memory swap request is released, it indicates that the passive swap-in task has been processed, that is, the memory swap request has been resolved, in this case, the memory swap request can be stored into the passive swap-in task queue corresponding to the passive swap-in task.
[0273] Optionally, if the page fault task has been resolved, in this case, a full swap-in flag is added to the memory swap request corresponding to the page fault task, and then the memory swap request is put back to the passive swap-in queue (fault-in). When the memory swap request is subsequently scheduled for execution, the remaining tail work is performed.
[0274] In this step, after the read lock corresponding to the memory swap request is released, the memory swap request is stored into the passive swap-in task queue corresponding to the passive swap-in task category, which is helpful for classified management of tasks and improves the processing efficiency of the system for different tasks.
[0275] As an optional implementation, the method further includes: determining state information of the memory data corresponding to the memory swap request; in response to the state information of the memory data being a queue-out state, updating the queue-out state to a queue-in state; and in response to the state information of the memory data being a swap-out state, updating the swap-out state to the queue-in state.
[0276] In this embodiment, the state information of the memory data corresponding to the memory swap request can be a queue-out state, where the queue-out state is used to indicate that the last operation performed on the memory data is active swap-out, in this case, the state information of the memory data can be updated to a queue-in state, so as to re-add the memory data to the swap-in queue. The queue-in state is used to indicate that the memory data is waiting to be swapped in from the back-end storage medium to the physical memory of the host.
[0277] Optionally, the state information of the memory data corresponding to the memory swap request can also be a swap-out state, where the swap-out state is used to indicate that the memory data has been swapped out from the physical memory of the host computer to the backend storage medium. In this case, it is also required to atomically update its state to queue_in so as to re-add the memory page to the queue_in queue.
[0278] Optionally, if the state information of the memory data corresponding to the swap request is queue_in or swap_in, no additional state conversion is required. That is, no update is required to its state. Where the queue_in state is used to indicate that the memory data is waiting to be loaded from the backend storage medium to the physical memory of the host computer, and the swap_in state is used to indicate that the memory data has been loaded from the backend storage medium to the physical memory of the host computer.
[0279] Optionally, the update of the state information of the memory data corresponding to the memory swap request can be achieved by atomic update, which refers to ensuring the integrity and consistency of the state update operation in a multi-task concurrent environment. In this case, the atomic update ensures that there is no race condition in the state conversion process, thereby avoiding data inconsistency.
[0280] In this step, it is determined whether the state of the memory data needs to be updated to queue_in according to the current state of the memory data. Such state management is crucial for ensuring that the memory data is correctly moved between the memory and the disk.
[0281] As an optional embodiment, the swap-in method of the memory data further comprises: in response to the state information of the memory data corresponding to the memory swap request being queue_in, re-establishing the correspondence between the backend storage medium and the physical memory of the host computer in the case where the first execution of the passive swap-in task corresponding to the passive swap-in task category is required for the memory data.
[0282] In this embodiment, the queue_in state is used to indicate that the memory data has been waiting to be swapped in the queue. If the state information of the memory data corresponding to the swap request is queue_in, it means that the memory data has performed the iommu_unmap operation when it was swapped out. In this case, if the first execution of the passive swap-in task corresponding to the passive swap-in task category is required for the memory data, it is necessary to re-establish the iommu_map operation.
[0283] Optionally, after the address mapping relationship is re-established, the address (map) field in the state information of the memory data can be updated to a completion state to mark that the address mapping relationship has been established. In this way, when the next request is again queued for swapping in, the system knows that the mapping has been established, and thus does not need to perform the iommu_map operation again.
[0284] In this step, when the state information of the memory data corresponding to the swapping request is in the queued swapping-in state, the mapping relationship between the physical memory of the host and the back-end storage medium is re-established, so as to ensure that the memory data can be quickly accessed and processed when swapped in, and the correctness of the memory data when swapped in is determined.
[0285] As an optional implementation, the swapping-in method of the memory data further includes: in response to the state information of the memory data corresponding to the memory swapping request, determining a first target physical address in the physical memory of the host for the switched swapping-out state, wherein the memory data is used to be swapped in from the back-end storage medium to the first target physical address; and recording a physical page corresponding to the first target physical address in the memory swapping request.
[0286] In this step, the state information of the memory data corresponding to the memory swapping request is in the switched swapping-out state, which indicates that the state information of the memory data is switched from the swapping-out state, that is, the memory data has been swapped out from the physical memory of the host to the back-end storage medium. In this case, if the memory data is to be swapped in from the back-end storage medium to the physical memory of the host, a corresponding physical address needs to be allocated in the physical memory of the host for the memory data as a target address for swapping in, which can be referred to as a first target physical address.
[0287] Optionally, after the first target physical address for swapping in of the memory data is determined in the physical memory of the host, a physical page corresponding to the first target physical address can be recorded in the memory swapping request, so that when the memory data is swapped in from the back-end storage medium to the physical memory of the host, the memory data can be correctly swapped in to the first target physical address of the host. The physical page corresponding to the physical address can be a page frame number (pfn), which is used to uniquely identify the physical address.
[0288] In this step, when the memory data is swapped back from the back-end storage medium to the physical memory of the host, the first target physical address needs to be allocated again for the memory data in the physical memory of the host, and a physical page corresponding to the first target physical address is recorded, so that the data can be directly written and the swapping-in task can be executed again.
[0289] As an optional implementation, the method further comprises: in response to the page fault exception state triggered by the physical address of the virtual machine, allocating a real physical address by a virtualization management layer running the virtual machine operating system; mapping the virtual address to the real physical address by a page table, wherein the page table is used to represent the mapping relationship between the virtual address and the real physical address; and accessing the memory data by the virtual address.
[0290] In this embodiment, the page fault exception state can be triggered by the physical address GPA of the virtual machine. In response to the page fault exception state triggered by the physical address of the virtual machine, a real physical address HPA is allocated by the virtualization management layer to perform the swap-in task. However, since the real physical address cannot be directly accessed, a mapping relationship between the virtual address HVA and the real physical address needs to be established by a page table. The real physical address is mapped to the virtual address by the page table, and the memory data is accessed by the virtual address HVA. Therefore, the virtual address HVA of this embodiment is the virtual address established by the virtualization management layer for the HPA. Through the above mapping relationship, the subsequent swap-out and swap-in operations are facilitated, thereby improving the efficiency of memory management and reducing the overhead of swap-out and swap-in operations.
[0291] In this embodiment, in the memory management of the back-end storage medium, when a program accesses a memory page that has not been loaded into the physical memory of the host computer, a page fault interrupt occurs, that is, a page fault exception is triggered. In this case, the EPT page table needs to be traversed to determine the memory page to be swapped in the back-end storage medium.
[0292] Optionally, the conversion of the back-end storage medium to the physical memory of the host computer is implemented by a multi-level page table, wherein the pmd is an intermediate layer of the multi-level page table, responsible for mapping a part of the back-end storage medium to the next level page table. In this case, the physical address of the memory page corresponding to the memory block in the memory page corresponding to the physical address of the memory page in the back-end storage medium, and the corresponding virtual address can be determined according to the physical address of the memory page in the back-end storage medium where the page fault exception state occurs and the offset of the physical address in the pmd.
[0293] Optionally, after the virtual address is determined, the secondary storage type recorded in the state information of the memory data can be further determined, and a read function corresponding to the secondary storage type is called. The secondary storage type is used to indicate a data storage type, wherein "secondary" is used to indicate a storage mechanism between the memory and the persistent storage (such as a hard disk), for example, a cache or a back-end storage medium. This storage type is used to improve the data access speed or manage the storage space.
[0294] Optionally, when a page fault occurs, it can be further checked whether there is a record of the secondary storage type in the page table entry of the last level PTE. If yes, the corresponding read function of the secondary storage type is called, and the memory data corresponding to the secondary storage address is written into the virtual address, completing the swap-in of the memory data; if the PTE page table entry does not record the secondary storage type, it needs to be recorded by using other data structures to ensure that the information of the backend storage medium must be recorded somewhere.
[0295] In this step, when a page fault exception occurs, the virtual machine operating system can quickly read the required data from the secondary storage and map it to the kernel mode virtual address, thereby reducing the waiting time of the system.
[0296] In the above running environment, the disclosure provides a memory data swap-in method as shown in FIG. 7, which is applied to the active swap-in process, that is, the virtualization management layer actively triggers the swap-in of the memory data from the backend storage medium to the physical memory of the host. FIG. 7 is a flowchart of a memory data swap-in method according to an embodiment of the disclosure. As shown in FIG. 7, the method can include the following steps:
[0297] Step S701, control the host to switch from running a host operating system to running a virtual machine operating system.
[0298] In the technical solution provided in step S701 of the disclosure, the running host operating system on the host is switched by virtualization to the virtual machine operating system, so that the EPT page table can be used for memory management in a layer of lightweight virtualization management layer running the virtual machine operating system, and the corresponding memory swap function is realized through the inserted virtualization management layer.
[0299] In this embodiment, in order to realize that the running host operating system starts the memory swap function, the host can be controlled to switch from running the host operating system to running the virtual machine operating system. That is, the running operating system on the host is switched by virtualization to the virtualization mode.
[0300] Step S702, in the process of running the virtual machine operating system on the host, a memory swap request is obtained.
[0301] In the technical solution provided in step S702 of the above disclosure, the memory swap request is used to request to swap the memory data between the physical memory of the host and the backend storage medium.
[0302] In this embodiment, the memory swap request is used to request to swap memory data from the physical memory of the host computer to the backend storage medium, or to request to swap memory data from the backend storage medium to the physical memory of the host computer. The memory data can be a memory block or a memory page, which is not specifically limited here. When a memory swap task is to be performed, the memory swap request can be used as a carrier to perform the memory swap operation. The specific operation can refer to the description of the foregoing step S402, which will not be repeated here.
[0303] In this step, by storing different types of memory swap requests in different queues, the system can explicitly determine the priority of each task, which helps to improve the efficiency of resource allocation and the response speed of the system.
[0304] Step S703, in response to the memory swap request, determining the task swap category corresponding to the memory data.
[0305] In the technical solution provided by the foregoing step S703 of the present disclosure, the memory data can be used to indicate a memory block or a memory page, and the task swap category can be used to indicate the category of the swap task, wherein the task swap category includes an active task swap category and a passive task swap category, the active task swap category includes a swap-out task category and a swap-in task category, and the passive task swap category mainly refers to a fault-in task category. The specific meanings of the swap-out task category, the swap-in task category, and the fault-in task category are described above, which will not be repeated here.
[0306] In this embodiment, the task swap category corresponding to the memory data can be determined according to the memory swap request, which helps to distinguish different types of memory swap tasks and can more intelligently allocate system resources, for example, to assign different priorities or resource quotas to different types of tasks.
[0307] After determining the task swap category corresponding to the memory data, the following step S704 can be performed to execute the swap task corresponding to the task swap category between the physical memory and the backend storage medium.
[0308] Step S704, in response to the task swap category being the active swap-in task category of the host computer, executing the active swap-in task corresponding to the active swap-in task category on the memory data.
[0309] In the technical solution provided in the foregoing step S704 of the present disclosure, after determining the task exchange category corresponding to the memory data, if the task exchange category is the active swap-in task category of the host computer, in this case, the active swap-in task corresponding to the active swap-in task category can be executed on the memory data. The active swap-in task is used to indicate that the virtualization management layer actively triggers the memory data to be swapped in from the back-end storage medium to the physical memory of the host computer.
[0310] Based on the foregoing steps S701 to S704 of the embodiment, by controlling the host computer to switch from running the host operating system to running the virtual machine operating system, and on this basis, starting the memory exchange function. When the task exchange category is the active swap-in category, the virtualization management layer actively triggers the memory data to be swapped in from the back-end storage medium to the physical memory of the host computer to meet the physical memory requirement of the host computer. Moreover, the memory exchange function can be performed on the virtualization management layer inserted under the virtualization operating system, and it does not limit whether the exchange object is a user-mode page or a kernel-mode page, thereby achieving the technical effects of reducing the limitation of memory exchange and enabling the memory exchange to be started in the running operating system, thereby solving the technical problems of large memory exchange limitation and the memory exchange being unable to be started in the running operating system in the related art.
[0311] The foregoing method of the embodiment is further described below.
[0312] As an optional implementation, in step S704, in response to the task exchange category being the active swap-in task category of the host computer, the active swap-in task corresponding to the active swap-in task category is executed on the memory data, including: in response to the task exchange category being the active swap-in task category, obtaining the write lock corresponding to the memory exchange request; and using the write lock to execute the active swap-in task corresponding to the active swap-in task category on the memory data.
[0313] In the embodiment, as known from the foregoing description, the memory exchange request corresponds to a read-write lock, where the write lock is used to lock control the active exchange task, and the read lock is used to control the passive exchange task. Based on this, if the task exchange category is the active swap-in category, in this case, the write lock of the memory exchange request can be obtained, and then the write lock is used to lock control the active swap-in task corresponding to the active swap-in task category on the memory data. The active swap-in task is used to indicate that the virtualization management layer actively triggers the memory data to be swapped in from the back-end storage medium to the physical memory of the host computer.
[0314] Optionally, when the write lock of the memory exchange request is acquired, the usage count (cnt) corresponding to the memory exchange request is increased by 1 when the active swap-in task is executed. Moreover, since the active swap-in task corresponds to a time slice, which is used to limit the execution time of the active swap-in task, based on this, each time the swap-in task of a memory page is executed, after execution, whether to continue the active swap-in operation of the next memory page or put the memory exchange request back into the queue for execution later can be determined according to the time slice of the active swap-in task.
[0315] For example, if after the execution of the swap-in task of a memory page, the time slice corresponding to the active swap-in task is not used up, the swap-in operation of the next memory page is continued, but if the time slice corresponding to the active swap-in task has been used up, the memory exchange request is put back into the queue for execution later.
[0316] In this step, the write lock corresponding to the memory exchange request is acquired, and the active swap-in task is locked and controlled, which can ensure that during the memory data exchange process, the problem of data conflict or inconsistency during the memory exchange process can be prevented.
[0317] As an optional implementation, in response to the task exchange category being the active swap-in task category, acquiring the write lock corresponding to the memory exchange request comprises: in response to the task exchange category being the active swap-in task category and the state information of the memory data corresponding to the memory exchange request not being the swap-in state or the running state, acquiring the write lock corresponding to the memory exchange request.
[0318] In this embodiment, when the write lock corresponding to the memory exchange request is acquired, whether the memory data corresponding to the memory exchange request is completed swap-in can be determined according to the state information of the memory data, and then whether to acquire the write lock corresponding to the memory exchange request is determined according to the state information.
[0319] Optionally, if the state information of the memory data corresponding to the memory exchange request is the un-swap-in state, that is, the memory data is not swapped in from the back-end storage medium to the physical memory of the host, in this case, the write lock corresponding to the memory exchange request can be acquired to execute the active swap-in task of swapping the memory data from the back-end storage medium to the physical memory of the host.
[0320] Optionally, if the memory data corresponding to the memory exchange request is not completely swapped in in the last swap-in process, in this case, the write lock corresponding to the memory exchange request can also be acquired to continue to execute the active swap-in task of swapping the memory data from the back-end storage medium to the physical memory of the host.
[0321] In this step, the state information of the memory data requested to be exchanged by the memory exchange request is used to drive the acquisition and release of the lock, so that the memory management is more flexible and intelligent, and it can be determined whether the resource needs to be locked according to the actual situation of the memory data. When the memory data is not swapped into the physical memory of the host, the active swap-in task is executed by acquiring the write lock, so as to ensure the consistency of the memory data. Since the write lock can be serially performed, its logic is simple, and it can be applied to the memory data exchange in non-emergency situations, and can be sequentially executed according to the time slice provided by the scheduler.
[0322] As an optional implementation, the swap-in method of the memory data further includes: in response to the state information of the memory data corresponding to the swap request being in the swap-in state, determining that the memory data has been successfully swapped from the back-end storage medium to the physical memory of the host.
[0323] In this embodiment, if the state information of the memory data corresponding to the memory exchange request is in the swap-in state, it indicates that the memory data has been successfully swapped from the back-end storage medium to the physical memory of the host. In this case, the write lock corresponding to the memory exchange request does not need to be acquired, and only the page table is restored to the pmd level, and the PTE level page table is released.
[0324] In this step, by checking the state information of the memory data, the write lock can be avoided to be acquired in unnecessary cases, and the acquisition and release operations of the lock are reduced, so as to improve the overall efficiency of the system.
[0325] As an optional implementation, in step S702, during the process that the host runs the virtual machine operating system, the memory exchange request is acquired, including: during the process that the host runs the virtual machine operating system, the memory exchange request is acquired in the active swap-in task queue corresponding to the active swap-in task.
[0326] In this embodiment, when an active swap-in task starts to execute, the memory exchange request is acquired from the request queue. As described above, in order to distinguish the memory exchange tasks to be executed by the concurrent tasks, the memory exchange request can be added to different request queues according to the different categories of the exchange tasks to be requested to be executed. Based on this, the request queue of the memory exchange request to be acquired can be determined according to the category of the exchange task to be executed, and then the memory exchange request is acquired in the request queue, and the memory exchange task is executed by using the acquired memory exchange request as a carrier.
[0327] For example, since the active swap-in task is executed here, the memory exchange request can be acquired from the active swap-in task queue, and then the active swap-in task is executed. The active swap-in task is used to indicate that the virtualization management layer actively triggers the memory data to be swapped from the back-end storage medium to the physical memory of the host.
[0328] In this step, by assigning different types of memory exchange tasks to different request queues, the tasks can be effectively classified and managed, improving the flexibility and efficiency of task scheduling, and then determining the request queue of the memory exchange request to be obtained according to the task category, so that the memory exchange request can be correctly obtained, avoiding the time waste caused by searching for the memory exchange request in the wrong queue, thereby improving the efficiency of task execution.
[0329] As an optional implementation, the method for swapping in memory data further includes: determining a memory page of the memory data; in response to the state information of the target memory page being in a swapped-out state, determining a secondary storage type recorded in the state information of the target memory page; and calling a read function corresponding to the secondary storage type to write a secondary storage location corresponding to the memory page to a virtual address, wherein the virtual address is obtained by mapping a real physical address allocated by a virtualization management layer, and is used to represent an address used by the virtualization management layer to access the memory page.
[0330] In this embodiment, the memory page is a page after the memory data is split, and the memory page after the memory data is split can be a 4K granularity small page. The target memory page can be a page in the memory page after the split.
[0331] Optionally, if the state information of the target memory page is in a swapped-out state, the secondary storage type recorded in the state information of the target memory page can be parsed, and then a read function corresponding to the secondary storage type is called, and the secondary storage location (identifiers, referred to as ids) corresponding to the target memory page is written into the virtual address. The read function corresponding to the secondary storage type can be read from the disk, or read from the Application Engine Pool memory (aep), or recovered from the zero page, or recovered from the decompressed page, etc., which is not limited here. The virtual address is obtained by mapping a real physical address allocated by a virtualization management layer, and is used to represent an address used by the virtualization management layer to access the memory page.
[0332] In this step, by monitoring the state information of the memory page, the system can better optimize resources, for example, when the memory is tight, the memory page with the swapped-out state is processed preferentially, thereby improving the resource utilization rate.
[0333] As an optional implementation, the method for swapping in memory data further includes: in a case where the memory page is completed from the backend storage medium to the physical memory of the host, determining the state information of the memory data as a swapped-in state.
[0334] In this embodiment, the memory data is swapped in by memory page units when the active swap-in task is performed, and thus, when determining whether the memory data is successfully swapped in to the physical memory of the host, it can be determined whether each memory page in the memory block is swapped in to the physical memory of the host from the backend storage medium, and if so, the state information of the memory data can be updated to the swap-in state.
[0335] In this step, after the state information of the memory data is updated to the swap-in state, the recovery of the pmd page table can be performed when the next swap-in task is performed next time, so as to avoid holding the lock for a long time and blocking the synchronous page fault swap-in operation.
[0336] As an optional implementation, the swap-in method of the memory data further includes: in response to the number of swap requests being less than the number threshold and the state information of the memory data corresponding to the swap request not being the swap-in state, adding the memory swap request to the active swap-in task queue corresponding to the active swap-in task.
[0337] In this embodiment, the memory swap request is stored in the swap request queue, and thus, by comparing the number of swap requests in the swap request queue with the number threshold, it can be determined whether the swap requests in the swap request queue are processed.
[0338] For example, if the number of memory swap requests in the swap request queue is greater than or equal to the number threshold, it indicates that the memory swap requests in the swap request queue are processed.
[0339] For example, if the state information of the memory data corresponding to the swap request is not the swap-in state, the memory swap request is added to the active swap-in task queue corresponding to the active swap-in task.
[0340] It should be noted that in this embodiment, unless the memory swap request is for complete swap-in of the memory data, the memory swap request will not be deleted from the tree-shaped data structure during the intermediate process of performing the task swap, regardless of which task queue or no task queue the memory swap request is in.
[0341] As an optional implementation, the read lock is used to ensure that different passive swap-in tasks are allowed to perform concurrent swap-in when the same memory swap request occurs, and in the process of performing concurrent swap-in of different passive swap-in tasks by the read lock, the same memory page of the same memory block cannot perform concurrent swap-in by the bitmap. It should be noted that the method of this embodiment can be the method in the foregoing embodiments, which will not be described here.
[0342] As an optional implementation, after the same memory page of the same memory block cannot be concurrently swapped in through the bitmap, the method further includes: in response to success of acquiring the read lock corresponding to the plurality of memory swap requests, in a case where it is checked that the page table entry corresponding to the address of the memory data allows access, determining that the memory data has been successfully swapped in from the backend storage medium to the physical memory of the host, wherein the memory block level state information of the memory data at least includes to-be-updated state information, the to-be-updated state information is atomically updated based on an unsigned integer type structure, and the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the storage information is atomically updated based on a character type structure in a case where the same memory page of the same memory block cannot be concurrently swapped in through the bitmap. It should be noted that the method of this embodiment can be the method in the foregoing embodiments, and details are not repeated here.
[0343] As an optional implementation, in a case where the memory data of the page fault exception state is swapped out, the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the passive swap-in task category corresponds to a passive swap-in task. It should be noted that the method of this embodiment can be the method in the foregoing embodiments, and details are not repeated here.
[0344] As an optional implementation, the method further includes: in a case where the passive task swap-in category in the task swap category is a passive swap-in task category, and the memory data of the page fault exception state is swapped out, analyzing the secondary storage type recorded in the memory page level state information of the memory data, the passive swap-in task category corresponds to a passive swap-in task; and reading the corresponding secondary storage location by using the secondary storage type, wherein the secondary storage location is recorded using a page table. It should be noted that the method of this embodiment can be the method in the foregoing embodiments, and details are not repeated here.
[0345] In the above operating environment, the disclosure provides a memory data swap system as shown in FIG. 8. FIG. 8 is a schematic diagram of a memory data swap system according to an embodiment of the disclosure. As shown in FIG. 8, the memory data swap system 800 can include an operating system running end 801 and a memory swap end 802.
[0346] The operating system running end 801 is configured to control the host to switch from running a host operating system to running a virtual machine operating system.
[0347] In the memory management of an operating system, task switching (also referred to as memory swapping in or out) is a process in which, in order to effectively utilize limited physical memory resources, the operating system moves some temporarily unused or inactive memory data from the physical memory of a host computer to a backend storage medium, or reads the memory data from the backend storage medium back to the physical memory of the host computer when the memory data is in demand. This memory management mechanism is crucial for maintaining system performance and response time.
[0348] The control host is switched from running a host operating system to running a virtual machine operating system for indication, and the operating system running on the host is switched to a virtualization mode.
[0349] The memory exchange end 802 is configured to obtain a memory exchange request during the process in which the host computer runs the virtual machine operating system, wherein the memory exchange request is used to request exchange of memory data between the physical memory of the host computer and the backend storage medium; in response to the memory exchange request, a task switching category corresponding to the memory data is determined; and for the memory data, a switching task corresponding to the task switching category is performed between the physical memory of the host computer and the backend storage medium.
[0350] The task switching category includes an active out task category, an active in task category, and a passive in task category, wherein the switching request corresponding to the active out task category is stored in an active out task queue, the memory exchange request corresponding to the active in task category is stored in an active in task queue, and the memory exchange request corresponding to the passive in task category is stored in a passive in task queue. For the active out task category, the active in task category, and the passive in task category, refer to the foregoing step S402, which will not be described here.
[0351] The technical solutions of the embodiments of the present disclosure will be further introduced with reference to the preferred embodiments.
[0352] Currently, in a traditional operating system, memory exchange relies on the least recently used (LRU) function and the swap function in the page replacement function of the operating system, but the memory pages operated by these functions are 4K granularity, which does not support large page granularity, and in the traditional operating system, the memory exchange function is only for the pages of the user state process, and does not support the exchange of kernel state pages. If the running operating system is not configured with the swap function, online memory exchange can only use the file method, which has the technical problem of great limitation of memory exchange.
[0353] However, the embodiment of the present disclosure provides a memory data exchange method, and on this basis, the memory exchange function is started, a light virtualization management layer is inserted under the operating system of the host computer, and the operating system running on the host computer is switched to the virtualization mode. In the virtualization management layer, EPT pages are used to manage all running memories, so that the corresponding swap function can be developed based on the newly inserted virtualization management layer, efficient full memory exchange is performed, and the memory exchange function is enabled in the running memory operating system, so that the memory exchange is not limited, thereby solving the technical problem that the memory exchange is limited in the related art.
[0354] Next, the memory exchange mechanism in the present disclosure is introduced.
[0355] The swap function in the Linux system is a mechanism for using free hard disk space as memory expansion. When the physical pages in the main memory (RAM) are insufficient, the swap mechanism can move a part of the infrequently used memory pages to the hard disk to free up space for other pages. This process is called page out, also known as swap out. When the process uses this part of memory again, page in is triggered, also known as swap in.
[0356] The swap mechanism of Linux includes two aspects: swap partition and swap file. The swap partition is a hard disk space dedicated for swapping, which is usually allocated when installing the Linux system, or can be created manually through commands such as fdisk, mkswap, etc. After dividing the free disk space into a swap partition, it can be mounted as a swap partition through the swap space command (such as the swapon command). The advantage of the swap partition is fast speed and high stability, but the partition size needs to be planned in advance and cannot be dynamically adjusted.
[0357] The swap file is a file created on a normal file system and used as swap space. The swap file can be created through commands such as dd, fallocate, etc., then formatted into a swap file system using the initial swap space (mkswap) command, and finally mounted as swap space through the swapon command. The advantage of the swap file is high flexibility, which can dynamically adjust the size and is convenient to manage, but the performance is slightly inferior to that of the swap partition.
[0358] In Linux systems, the size of swap space is usually set to twice or three times the physical memory. If the physical memory in the system is sufficient, the usage of swap space will be low and will not have a significant impact on system performance. However, if the physical memory is insufficient, the usage of swap space will be high and will severely affect the performance of the system. Therefore, the performance of swap space is also crucial for the stability of the system.
[0359] In addition, the swap mechanism of the Linux kernel is for user processes and does not directly affect the swapping in and out of kernel pages. If the memory is insufficient, the kernel will attempt to reclaim some unnecessary pages and swap them to the disk through the swap mechanism to release memory space. These unnecessary pages include user process pages, cache pages, anonymous memory pages, etc., but do not include kernel pages, as kernel pages are usually not swappable. Kernel code and data are usually locked in memory and will not be swapped to disk, so they are not affected by the swap mechanism. Moreover, the swap function currently only supports 4k small pages, while large pages are increasingly used in cloud computing scenarios, and swap for large pages is not supported. Furthermore, if it is a running operating system and swap is not originally configured to be enabled, the swap mechanism in the kernel cannot be used, resulting in the technical problem that a running operating system cannot enable memory swapping.
[0360] In order to efficiently implement the swap function for all pages of a running operating system, in this disclosure, the running operating system is switched through hardware virtualization, thereby inserting a lightweight virtualization management layer under the operating system. In the virtualization management layer, EPT pages are used to manage all running memory, so that the corresponding swap function can be developed based on the newly inserted virtualization management layer for efficient full memory swapping, thereby achieving the purpose of also being effective for the running system.
[0361] Next, the data structure of the memory swapping function is introduced.
[0362] The total entry swap structure of the memory swapping architecture saves various structure bodies related to the control plane and data plane of swapping; it is associated with the path, name, type, and other configuration information of the secondary storage devices currently supported by the swap function. For each secondary storage that saves swap data, a series of functions that control the behavior of the secondary storage are abstracted into an sdev structure body; according to the configuration information of the secondary storage associated with the swap, the sdev corresponding to all secondary storages is registered in the devs array field of the swap; these secondary storage devices are automatically registered when the swap function is initialized.
[0363] The most important structure in sdev is a collection of ops for various operations on the secondary storage, such as registering and destroying the secondary storage, registering and reporting the data plane capacity of the secondary storage, and the like, active swapping out, canceling swapping out, swapping in, page fault swapping in, cache operations for asynchronous operations, and the like. This is only an example, and the various operations on the secondary storage are not limited.
[0364] The sdev device structure also has a private field that points to a specific device structure, such as a compression structure zram or a zero page structure Zsm. These structures also record some fields specific to the secondary storage. For example, configuration information (config) can be saved, such as the priority of the secondary storage, the information saving policy, and the like. The total statistics of the secondary storage (stat) are also recorded, such as the total number of swapping out and swapping in, the number of swapping out and swapping in, the number of successes, the average time, the maximum time, and the minimum time of each swapping out and swapping in, and the like. In addition, there are some specific ones, such as a small memory cache pool matched with Zsm and a shared zero page associated with Zsm. Of course, if necessary, the capacity of the secondary storage (info) can also be recorded, such as the granularity, total size, range, remaining capacity, number of bad pages, number of holes, current use location, and the like. There is also a bitmap information (status) corresponding to all storage blocks.
[0365] The swap total structure also records the water level control information of each swap node and the swapping policy information polc, which facilitates the determination of the number of pages to be swapped out and the swapping rate when actively swapping out.
[0366] For each swapped memory, a memory block ms is used as a unit, and a memory swap request (req) structure is established for it, which is the most important structure for memory swapping. The swap has a red-black tree and multiple linked lists to save reqs in different linked lists according to different states. This structure contains information such as the memory swap page fault address gfn, the corresponding ms physical address pfn, the read-write lock for swapping in and out, the type of req, the number of tasks using this req, and special flag bits (such as cancel operation), as well as ms-level state information. It should be noted that the above gfn and pfn correspond to gpa and hpa in the previous embodiments, respectively. The difference is that the former is a page frame number, and the latter is a physical address. The difference is only that page frame number = physical address >> 12.
[0367] The memory block (ms) level state information ms_entry includes the ms level swap-in and swap-out state, the iommu mapping state, the mp level bit_out and bit_swapping bits, and is associated with 512 mp level swap-in and swap-out state information. The memory block (ms) level swap-in and swap-out state includes four states: swapped_in, queue_out, swapped_out, and queue_in. The address (iommu) mapping state includes several states such as clean, start, and finish. Since the states are limited, in order to reduce metadata overhead, two states are combined by bit operation, and an atomic structure is shared, so as to perform atomic update in subsequent concurrency.
[0368] The mp level state information mp_entry includes the swap-in and swap-out state of the mp, and the device type used after swap-out and the like. The swap-in and swap-out state only includes swapped_in and swapped_out. Metadata overhead is reduced by bit operation.
[0369] After the secondary storage sdev and the swap request req, a task structure is needed to represent the swap task. The task is a scheduling body for background execution of the swap function, and includes a scheduling structure se, a corresponding cpu, a running state, running statistics and the like. All task structures are recorded in the swap large structure.
[0370] Optionally, in addition to the above main structure, the swap large structure also records the statistical information and configuration information of the current swap function, and also includes various lock protection fields.
[0371] The following describes the overall execution flow of the background task of the memory swap function.
[0372] FIG. 9 is a flowchart of a memory data swap method according to an embodiment of the present disclosure. As shown in FIG. 9, the memory data swap method includes the following steps.
[0373] In step S901, it is determined that the memory swap request is a carrier of the memory swap task.
[0374] In this embodiment, when the scheduler of the virtualization bottom layer selects the memory swap task for execution, the memory swap task can be executed by taking the memory swap request req as a carrier.
[0375] For example, when performing the swap-out operation of a memory block for the first time, a corresponding memory swap request can be created, and the memory swap request can be added to the red-black tree until the memory block corresponding to the memory swap request is completely swapped out from the physical memory of the host computer to the backend storage medium, and then the memory swap request is deleted from the red-black tree, wherein the red-black tree is protected by a tree level lock.
[0376] Optionally, in order to distinguish the swap-out and swap-in tasks required to be performed by the concurrent tasks, the memory swap request can also be placed in different task queues according to the different categories of the memory swap tasks to be performed.
[0377] For example, according to the memory swap task, after the memory data is completely swapped out from the physical memory of the host computer to the backend storage medium, the type of the memory swap request performing the active swap-out task can be determined as the active swap-out type, i.e., the swap-out type, and the memory swap request can be placed in the swap-out queue. It should be noted that after the memory swap request is completely swapped out, it will not be in any queue.
[0378] Optionally, when the page fault is triggered, the type of the memory swap request can be modified to the passive swap-in type, and the memory swap request can be placed in the fault-in queue. When the memory swap request is in the fault-in queue, its state can be the swap-in state or the queue-in state.
[0379] Optionally, for the active swap-in task, the state of the memory swap request can be modified to the queue-in state, i.e., the queue-in type, and in this case, the memory swap request can be placed in the swap-in queue. All queues correspond to a queue lock, i.e., protected by the queue lock.
[0380] Step S902, according to the memory swap request, obtaining a memory swap task from the task list.
[0381] In this embodiment, since there can be one or more active swap tasks in the memory swap framework, each swap task obtains a swap task from the task list when it is executed, and the order of obtaining the swap task is: passive swap-in task (fault-in) > active swap-in task (swap-in) > active swap-out task (swap-out).
[0382] Optionally, after obtaining the swap task, the lock corresponding to the memory swap request can be used to lock the memory swap task being executed during the execution of the swap task, so as to avoid the conflict between the active swap task being performed and the passive triggered page fault task.
[0383] In step S903, according to the memory exchange task, the type of the lock for processing the memory exchange task is determined from the read-write lock corresponding to the memory exchange request.
[0384] In this embodiment, the memory exchange request corresponds to a read-write lock, wherein the read-write lock includes a read lock and a write lock. In response to the memory exchange task being an active exchange task, the write lock in the memory exchange request is used to lock control the active exchange task.
[0385] Optionally, in response to the memory exchange task being a passive exchange task, the read lock in the memory exchange request is used to lock control the passive exchange task.
[0386] In step S904, according to the type of the lock, the memory data exchange task is executed.
[0387] In this embodiment, taking the passive swap-in task as an example, the passive triggered page fault task searches for the memory exchange request corresponding to the page fault address from the red-black tree, and then performs the page fault swap-in through the read lock of the memory exchange request. The passive page fault task only performs data swap-in and page table update, and other pre- and post- processing such as pmd recovery and req release are left to the active swap task for processing, so as to avoid long execution time of the page fault task.
[0388] Optionally, to ensure low latency, the memory exchange architecture allows different memory pages (mp) of the same memory block (ms) to perform page fault swap-in processing at the same time. For the active swap-in and swap-out tasks, there is no latency requirement and they are executed in series to reduce system complexity. The active swap task is assigned a time slice, and multiple mp-level tasks can be performed within the time slice. If the time slice expires, the req being processed needs to be returned to the queue for execution by other swap tasks or next time.
[0389] Optionally, for all physical addresses, a kernel-level mapping relationship is initially established to facilitate subsequent swap-out and swap-in operations and reduce the overhead of temporarily establishing a mapping each time. It should be noted that because the mapping relationship from HVA to HPA is established in advance, repeated mapping and demapping is avoided, thereby reducing the overhead of the entire memory exchange process.
[0390] In the above steps S901 to S904, the memory exchange function can be performed on the virtualization management layer running the virtual machine operating system, and it is not limited that the swap object is a user-mode page or a kernel-mode page, thereby achieving the technical effects of reducing the limitations of memory exchange and enabling the memory exchange of the operating system running in stock, thereby solving the technical problems of large limitations of memory exchange in related technologies and the technical problem that the memory exchange of the operating system running in stock cannot be started.
[0391] Next, the active swap-out process of the exchange function is introduced.
[0392] Next, the active swap-out process of the exchange function is introduced.
[0393] FIG. 10 is a flowchart of an active swap-out method of memory data according to an embodiment of the present disclosure. As shown in FIG. 10, the method comprises the following steps:
[0394] In step S1001, a write lock corresponding to a memory exchange request is acquired.
[0395] In this embodiment, the active swap-out process of the memory data does not require a high latency requirement, and thus does not need to be performed concurrently. Therefore, for a req corresponding to one ms, a write lock is acquired before performing the swap-out operation, and then the write lock is used to perform the step of swapping out the memory data from the physical memory of the host computer to the back-end storage medium.
[0396] In step S1002, a memory exchange request corresponding to the active swap-out task is acquired.
[0397] In this embodiment, when the active swap-out task is started to be executed, a memory exchange request req can be acquired from an active swap-out task queue corresponding to the active swap-out task, and a usage count cnt corresponding to the memory exchange request req is incremented by 1.
[0398] Optionally, the active swap-out task has a time slice, and the active swap-out task is directed to a memory page. After performing the swap-out task of one memory page each time, whether to continue to perform the swap-out of the next memory page or to put the memory exchange request req back into the queue can be determined according to the time slice of the task.
[0399] Optionally, if the memory page requested to be swapped out by the memory exchange request has been completely swapped out, in this case, the memory exchange request req will not be put back into any queue, but will be in a tree structure to facilitate subsequent swap-in operations.
[0400] In step S1003, the state information of the memory data is set based on the number of times of execution of the memory exchange request, and a page table corresponding to the memory data is split.
[0401] In this embodiment, if this memory exchange request req is the first time to perform swap-out, the state of the memory data (ms_entry) is set to a queue-out state (queue_out), and a pmd page table corresponding to the memory block ms to be swapped out is split into 512 4k-granularity small pages, and a next-level PTE page table mapping is established.
[0402] In step S1004, the state information of the split memory page is adjusted.
[0403] In this embodiment, the PTE page table corresponding to each 4k granularity small page mp of the ms is changed to read-only, and the TLB needs to be synchronized and refreshed to avoid other CPUs using the old page table and continuing to write, which causes subsequent data inconsistency.
[0404] In step S1005, the address mapping page table corresponding to the memory data is removed.
[0405] In this embodiment, the mapping of the iommu page table corresponding to the ms is removed, and the page table state is set to the clean state.
[0406] In step S1006, the state of the split memory page is set to the swapped_in state.
[0407] In this embodiment, each 4k granularity small page mp of the ms after splitting is selected, the mp_entry state corresponding to the mp is initially set to swapped_in, and the bit_swapping position bit corresponding to the mp in the ms_entry is set to 1.
[0408] In step S1007, the target storage location of the swap-out is determined based on the content attribute of the memory page and the secondary storage state.
[0409] In this embodiment, according to the content attribute of the memory page mp and the secondary storage state, a suitable target storage location for swap-out is selected in the back-end storage medium, and the swap-out is performed, wherein the target storage location can be a disk, a compressed memory or a merged page, which is not limited here.
[0410] In step S1008, the target storage location information is recorded in the PTE page table entry.
[0411] In this embodiment, the original PTE page table is emptied, and the target storage location information is recorded in the PTE page table entry.
[0412] In step S1009, the state information of the memory data is set to the swapped_out state.
[0413] In this embodiment, the state of the memory data (mp_entry) at the mp level is set to the swapped_out state (swapped_out), the bit_out position bit corresponding to the mp in the ms_entry is set to 1, and the bit_swapping position bit corresponding to the mp in the ms_entry is set to 0.
[0414] Optionally, if the swap-out operation of the 512 mp small pages is completed respectively, the ms_entry state is changed to the swap_out state.
[0415] In step S1010, it is judged whether a page fault exception occurs in the active swap-out process.
[0416] In this embodiment, if no page fault exception occurs during the swapping out of the whole memory block, and the time slice corresponding to the active swapping out task has not been used up after the swapping out of one memory page is performed, the foregoing steps S1001 to S1009 are repeated. If the time slice corresponding to the active swapping out task has been used up after the swapping out of one memory page is performed, step S1011 is performed.
[0417] In step S1011, the active swapping out operation is cancelled.
[0418] In this embodiment, if a page fault exception occurs during the active swapping out, and it is required to avoid further swapping out, the active swapping out operation is cancelled, and the currently performed swapping out task is quickly ended, so as to quickly release the held req write lock.
[0419] Optionally, setting the cancel flag of req at the same time can be set by other tasks, and it is determined whether there is the cancel flag between the important steps of the active swapping out task. If there is, the active swapping out operation is cancelled, and the currently performed swapping out task is quickly ended, so as to quickly release the held req write lock.
[0420] In step S1012, page fault processing is performed.
[0421] In this embodiment, after the lock of the memory swap request corresponding to the active swapping out task is released, subsequent page fault processing procedures can be entered. The page fault processing procedures can be referred to FIG. 11.
[0422] In step S1013, the use count of the memory swap request is reduced by 1.
[0423] In this embodiment, after the state information of the memory block is in the swapping out state, it is determined that the memory swap request has been performed, and the use count corresponding to the memory swap request is reduced by 1.
[0424] Optionally, if the ms_entry state information of the memory block is in the swapping out state, the memory block is recycled. That is, the memory swap request that has been swapped out is not put back to the request queue, and is acquired from the passive page fault queue or the active swapping in queue when it needs to be swapped in subsequently.
[0425] In step S1014, if the use count is 0 and the memory block is not in the swapping out state, the swap request is put into the corresponding request queue according to the type of the swap request.
[0426] In this embodiment, if the use count cnt corresponding to the memory swap request is 0, and the memory block is not in the complete swap-out state (swap_out), the swap request (req) is put into the corresponding queue according to the type of the swap request, otherwise, for the complete swap-out state, the swap request is not put into the queue, and is directly returned.
[0427] In the steps S1001 to S1014, in the process of running the virtual machine operating system on the host, the memory swap request is obtained, which is helpful for efficient management of memory resources. By determining the task swap category corresponding to the memory data, the swap process of the memory data between the physical memory of the host and the backend storage medium can be more accurately controlled. For example, if the task swap category is the active swap-out task category of the host, the memory data is executed with the active swap-out task corresponding to the active swap-out task category to migrate the data not frequently used in the physical memory of the host to the backend storage medium, so as to save the memory space of the physical memory of the host. Moreover, the memory swap function can be performed on the virtualization management layer on which the virtual machine operating system is run, and it is not limited that the swap object is a user state page or a kernel state page, thereby realizing the technical effects of reducing the limitation of memory swap and enabling the memory swap of the operating system in the running state, and further solving the technical problems of large limitation of memory swap and inability to enable the memory swap of the operating system in the running state in the related art.
[0428] Next, the passive swap-in process of the swap function is introduced.
[0429] FIG. 11 is a flowchart of a passive swap-in method of memory data according to an embodiment of the present disclosure. As shown in FIG. 11, the method comprises the following steps:
[0430] In step S1101, a memory swap request corresponding to a page fault exception of a memory block address is obtained.
[0431] In this embodiment, since different CPUs can trigger a page fault exception of the same memory block address at the same time, before the real processing is performed, the PTE page table of the memory block address needs to be checked to determine whether the PTE page table can be accessed for reading and writing at present. If the PTE page table can be accessed, it indicates that the page fault exception has been processed by another process, and the processing success can be directly returned.
[0432] Optionally, if the PTE page table cannot be accessed, for the page fault of the memory address, there is a previously created req, so the corresponding req is found through the PTE page table query red-black tree, and the use count cnt is increased by 1.
[0433] In step S1102, a read lock corresponding to the swap request is obtained.
[0434] In this embodiment, the read lock of the req is acquired to facilitate the subsequent concurrent operation. If the read lock of the req is acquired, it indicates that the req is not currently performing the swap-out operation, and then the subsequent processing is performed in step S1104.
[0435] Optionally, if the read lock of the req is not acquired, the cancel flag of the req is set to trigger the rollback of the swap-out task being executed, and it is judged whether the corresponding PTE page table has been swapped in. If yes, it is directly returned, otherwise, the req write lock is waited for release by the swap-out task being executed.
[0436] Optionally, if the waiting is timed out, the page fault retry flag can be returned, so that the page fault exception is triggered again, and the next time the process enters, the page fault exception can be possibly handled by another process. Since the page fault exception is in the interrupt context, long waiting can cause the host to be deadlocked.
[0437] In step S1103, it is checked whether the PTE page can be directly accessed.
[0438] In this embodiment, after the read lock of the req is successfully acquired, it is checked again whether the page can be directly accessed, because the above steps are not atomic operations, and the page fault exception can be possibly handled by another task during the lock acquisition. If the page can be accessed, the lock is released, and the processing success is returned.
[0439] Optionally, it is judged whether the bit_swapping corresponding to the virtual machine physical address GPA triggering the page fault is set to 1. If yes, it indicates that the memory page mp granularity has occurred the page fault, and it is polled whether the corresponding PTE page table has been swapped in. If yes, it is returned, otherwise, it is continued to be waited.
[0440] Optionally, if the bit_swapping is not set to 1, the bit_swapping is set to 1, and the mp page fault swap-in task is started. It needs to be noted that the judgment and setting method herein need to be performed by atom, and the cmpxchg atomic method is generally used.
[0441] In the embodiment, the ms_entry is specially designed, and includes storage information, etc. If each information needs to realize atomic update, an atomic structure is needed, which needs to occupy 4 bytes. However, the number of states in the ms_entry is very limited, and the 4 bytes are not needed to store, otherwise, the storage space will be wasted. In order to save the storage space, only 4 bits in the 4-byte atomic structure can be used, and the other bits can be extended to reserve other information, such as flag bits, the number of page faults, etc. which are not limited here. However, the update of the ms_entry also needs to be atomic. The atomic update in the related art is at least the atomic structure of 4 bytes, which is the unsigned int structure. Therefore, the embodiment realizes an atomic update method for multiple information sharing the unsigned int structure by the following steps.
[0442] Firstly, an old unsigned int variable val is read.
[0443] Secondly, each bit of the unsigned int structure is updated according to the respective field information, and a new unsigned int variable new_val is obtained.
[0444] Thirdly, the update is performed by cmpxchag.
[0445] If the val is not changed in the above steps, it is determined that the update is successful. Otherwise, the first step to the third step are re-executed until the update is successful, so that the atomic update for multiple information sharing the unsigned int structure is realized.
[0446] In step S1104, the state information of the memory block corresponding to the memory exchange request is updated based on the state information of the memory block corresponding to the memory exchange request.
[0447] In the embodiment, if the original state of the req corresponding to the ms_entry is queue_out, it indicates that the req has executed the swap out task last time, and the state of the req needs to be atomically updated to queue_in. If the original state of the req corresponding to the ms_entry is swap_out, it indicates that the req has been completely swapped out, and the state of the req needs to be atomically updated to queue_in. For the states of queue_in and swap_in, no additional state transformation is needed.
[0448] In step S1105, for the memory block in the queue-in state, the address mapping is re-established.
[0449] In this embodiment, for the req of queue_in, since it has executed iommu_unmap when swapping out, it needs to re-establish the iommu_map operation and set the map field of the ms_entry state to 1 at the first time of swapping in. Next time when swapping in, no additional iommu mapping operation is needed.
[0450] In step S1106, the state information of the memory block corresponding to the exchange request is switched from the swap-out state to the target address of the memory block for swapping in.
[0451] In this embodiment, if the ms_entry of the req is switched from the swap-out state, it also needs to allocate the target address of the swap-in and record the pfn in the req, and then obtain the corresponding start kernel mode virtual address according to the global kernel mapping.
[0452] Optionally, according to the offset of the pmd granularity of the virtual address of the page fault, the physical address pa1 of the corresponding ms internal page mp and the corresponding kernel mode virtual address are calculated.
[0453] In step S1107, the state information of the memory page level is set to the read-only state.
[0454] In this embodiment, the formal page fault swap-in is started. Since the ms level cuts the page table into the PTE level at the beginning and sets it to read-only, the page fault at this time may be caused by the write permission. In this case, the PTE page table is directly restored. It should be noted that the ms has not been recycled, and its data is still in place, and the write protection is set before swapping out, thereby ensuring the correctness of the data.
[0455] Optionally, when the memory page data of the page fault is swapped out, data swap-in is needed, the secondary storage type recorded in the state information of the corresponding mp_entry is parsed, and then the read function of the secondary storage (which can be reading from the disk, reading from the aep memory, even restoring from the zero page, or restoring from the decompressed page, etc.) is called to read the secondary storage id position. This embodiment can wait for the reading to be completed or an error; if the swap-in is successful, the page table corresponding to the process needs to be updated.
[0456] The design method of the above mp_entry of this embodiment will be further introduced below.
[0457] In this embodiment, the mp_entry itself is specially designed, including storage information to be updated, state information to be updated, etc. If each information needs to implement atomic update, an atomic structure is needed, which needs to occupy 4 bytes, so the single mp_entry needs to occupy at least 8 bytes; then there are 512 mp_entries under one ms_entry, which needs to occupy a page size of 4k, so the overhead of metadata is very large.
[0458] In addition, the number of storage types and states in the mp_entry is very limited, and it is not necessary to store them by using the above 4 bytes, otherwise, the storage space will be wasted; in order to save the storage space, this embodiment can use a character char type to keep these information, in which the state state occupies 2 bits, the device dev occupies 3 bits, and 2 bits are left for extension.
[0459] However, if the mp_entry uses char to save, the update cannot guarantee atomicity, which needs to design bit_swappin and bit_out (the bitmap update itself can guarantee atomicity), through which it can be guaranteed that only one mp granularity of page fault will go to the real swap-in process, and the information in the mp_entry can be directly updated without lock.
[0460] In step S1108, the state information of the memory block is set to the swap-in state, and the read lock corresponding to the memory swap request is released.
[0461] In this embodiment, the state of the mp_entry is set to swapped_in, and it is checked whether the mp_entry is set. If it is set, it means that the mp_entry has been swapped in, and the bit_out bit in the ms_entry corresponding to it is set to 0, and the bit_swapping bit in the ms_entry corresponding to it is set to 0. The read lock req of the concurrent swap-in is released, and the count cnt is reduced by 1. If the cnt is 0, it is put into the corresponding task queue, for example, the fault-in queue. The remaining pages that have not been triggered can be processed by the active swap-in task. In addition, if the cnt is not 0, it means that there are other swap-in tasks running, and it cannot be put into the queue.
[0462] Optionally, concurrent swap-in is used to indicate that multiple virtual machines running on the host machine can simultaneously request memory swap-in operations. At this time, the virtualization manager needs to coordinate these concurrent requests to ensure the reasonable allocation of memory resources.
[0463] In the steps S1101 to S1108, the memory swap request is obtained in the process that the host runs the virtual machine operating system, which helps to efficiently manage the memory resources, and the memory data is exchanged between the physical memory of the host and the back-end storage medium more accurately by determining the task swap category corresponding to the memory data. For example, when the task swap category is the passive swap-in category, the operating system of the host passively triggers the memory data to be swapped from the back-end storage medium to the physical memory of the host to meet the physical memory requirement of the host. The memory swap function can be performed on the virtualization management layer running under the virtual machine operating system, and the object of the swap is not limited to the user-mode page or the kernel-mode page, which realizes the technical effect of reducing the limitation of memory swap, the technical effect that the memory swap can be started in the running operating system, and further solves the technical problems that the memory swap is limited in the related art and the memory swap cannot be started in the running operating system.
[0464] Next, the active swap-in process of the swap function is introduced.
[0465] FIG. 12 is a flowchart of an active swap-in method of memory data according to an embodiment of the present disclosure. As shown in FIG. 12, the method includes the following steps:
[0466] In step S1201, a memory swap request is obtained from the active swap-in task queue in response to the start of the active swap-in task.
[0467] In this embodiment, when an active swap-in task starts to work, a memory swap request req is obtained from the active swap-in task queue. The write lock of the req is obtained, the count cnt of the req is increased by 1, and the swap-in task of each memory page mp is executed. After the execution, it is determined whether to continue to execute the next mp swap-in or return to the queue according to the time slice of the active swap-in task.
[0468] In step S1202, it is determined whether the memory block completes the swap-in operation according to the state information of the memory block.
[0469] In this embodiment, it is determined whether the memory block completes the swap-in operation by judging whether the state of the ms_entry is swap_in. If yes, it indicates that the swap-in operation is completed, and only post-processing is needed, that is, the page table is restored to the pmd level, the PTE level page table is released, and step S1011 is executed.
[0470] Optionally, if no, it indicates that there is a page that has not been swapped in, and step S1203 is executed.
[0471] In step S1203, the write lock corresponding to the swap request is obtained.
[0472] In this embodiment, the active swap-in process does not require too high latency requirement, thus does not need to be concurrent, and for this, the write lock is acquired first when the swap-in operation is performed for a req corresponding to an ms.
[0473] In step S1204, the memory block is split into a plurality of memory pages.
[0474] If the state information of each 4K granularity page mp after the split of the memory block ms is swapped_out, the bit_swapping bit in the ms_entry of the memory block ms is set to 1.
[0475] In step S1205, the state information of the memory page is analyzed to obtain the secondary storage type.
[0476] In this embodiment, the formal page fault swap-in is started, the secondary storage type recorded in the state information of the mp_entry is analyzed, and the read function of the secondary storage (which can be reading from the disk, reading from the aep memory, even recovering from the zero page, or recovering from the decompressed page, etc.) is called to write the secondary storage ids into the kernel virtual machine address; the read is waited to be completed or an error is waited to be generated; if the swap-in is successful, the page table corresponding to the process needs to be updated.
[0477] In step S1206, the state information of the memory block is updated based on the swap-out state of the memory page after the split of the memory block.
[0478] In this embodiment, the mp_entry state is initially set to swapped_in, the bit_out bit in the ms_entry is set to 0, and the bit_swapping bit in the ms_entry is set to 0.
[0479] Optionally, it is judged whether the swap-in operation of the 512 mp pages is completed, and if yes, the ms_entry state is changed to swap_in, wherein the pmd page table recovery can be delayed to the next time, that is, the memory swap request can be re-queued first, so as to avoid the problem of too long lock or too long running time, which affects the scheduling accuracy; in the next swap task, the request is taken from the queue, and the finishing work is completed, so as to avoid the problem of long-time holding of the lock and blocking of the synchronous page fault swap-in operation.
[0480] In step S1207, the write lock of the memory swap request is released, and the use count is reduced by 1.
[0481] In this embodiment, the write lock of the memory swap request req is released. If the active swap-in task does not have a time slice, the usage count cnt is reduced by 1; if cnt is not 0, it is directly returned, where not 0 indicates that a page fault task has occurred, and it is avoided to be put into the queue and taken away by other active swap tasks. If taken away by the active swap task, the write lock is taken, thereby blocking the read lock of the passive page fault task.
[0482] Optionally, if cnt is 0 at this time and the state of ms_entry is not swap_in, the req is added to the corresponding list; if it is swap_in, the req cleaning process is started.
[0483] In step S1208, the memory swap request is deleted from the red-black tree.
[0484] In this embodiment, if the memory data requested to be swapped by the memory swap request req has been completely swapped in, the req is removed from the red-black tree in this case. Then it is continued to judge whether the cnt of req is 0, if yes, the req is released.
[0485] Optionally, if cnt is not 0 at this time, it indicates that a page fault occurs before the swap_in state is updated (i.e., completely swapped in) when the red-black tree is removed above, in which case it can be judged whether cnt is 0 after the page fault process is processed.
[0486] In the above steps S1201 to S1208, when the task swap category is the active swap-in category, the virtualization management layer actively triggers the memory data to be swapped from the back-end storage medium to the physical memory of the host to meet the physical memory demand of the host, and the memory swap function can be performed on the virtualization management layer running the virtual machine operating system, and it is not limited that the swap object is a user state page or a kernel state page, thereby realizing the technical effect of reducing the limitation of memory swap, and further solving the technical problem of large limitation of memory swap in the related art.
[0487] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present disclosure are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.
[0488] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all described as a combination of a series of actions, but those skilled in the art should know that the present disclosure is not limited to the action sequence described, because according to the present disclosure, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present disclosure.
[0489] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, and of course it can also be realized by hardware. Based on such understanding, the technical solutions of the present disclosure can be embodied in the form of a software product in essence or in the form of a part of the prior art. The computer software product is stored in a storage medium (such as a ROM / RAM, a magnetic disk, or an optical disk), and includes a plurality of instructions for causing an end device (which can be a mobile phone, a computer, a server, or a network device) to execute the method described in each embodiment of the present disclosure.
[0490] According to the embodiments of the present disclosure, a memory data exchange device for implementing the above memory data exchange method is also provided, as shown in FIG. 13, the device comprises: a first control component 1301, a first acquisition component 1302, a first determination component 1303, and a first execution component 1304.
[0491] The first control component 1301 is configured to control the host computer to switch from running a host operating system to running a virtual machine operating system.
[0492] The first acquisition component 1302 is configured to acquire a memory exchange request in the process that the host computer runs the virtual machine operating system, wherein the memory exchange request is used to request to exchange memory data between the physical memory of the host computer and the corresponding back-end storage medium of the host computer.
[0493] The first determination component 1303 is configured to determine a task exchange category corresponding to the memory data in response to the memory exchange request.
[0494] The first execution component 1304 is configured to perform an exchange task corresponding to the task exchange category between the physical memory of the host computer and the back-end storage medium for the memory data.
[0495] It should be noted that the first control component 1301 to the first execution component 1304 correspond to steps S401 to S404 in the embodiments of the present disclosure, and the four components have the same instances and application scenarios as the corresponding steps, but are not limited to the content disclosed in Embodiment I. It should be noted that the above modules or components can be hardware components or software components stored in the memory (for example, the memory 104) and processed by one or more processors (for example, the processors 102a, 102b, …, 102n), and the above modules can also be run in the computer terminal 10 provided in Embodiment I as part of the device.
[0496] According to the embodiments of the present disclosure, a memory data swapping-out device for implementing the above memory data swapping-out method is also provided, as shown in FIG. 14, the device comprises a second control component 1401, a second acquisition component 1402, a second determination component 1403, and a second execution component 1404.
[0497] The second control component 1401 is configured to control the host computer to switch from running a host operating system to running a virtual machine operating system.
[0498] The second acquisition component 1402 is configured to acquire a memory swapping request during the process that the host computer runs the virtual machine operating system, wherein the memory swapping request is used to request to swap memory data between the physical memory of the host computer and the corresponding back-end storage medium of the host computer.
[0499] The second determination component 1403 is configured to determine a task swapping category corresponding to the memory data in response to the memory swapping request.
[0500] The second execution component 1404 is configured to perform an active swapping-out task corresponding to the active swapping-out task category on the memory data in response to the task swapping category being the active swapping-out task category of the host computer, wherein the active swapping-out task category is used to represent a task category that a virtualization management layer running the virtual machine operating system actively triggers to swap the memory data from the physical memory of the host computer to the back-end storage medium.
[0501] It should be noted that the second control component 1401 to the second execution component 1404 correspond to steps S501 to S504 in the embodiments of the present disclosure, and the four components have the same instances and application scenarios as the corresponding steps, but are not limited to the content disclosed in Embodiment I. It should be noted that the above modules or components can be hardware components or software components stored in the memory (for example, the memory 104) and processed by one or more processors (for example, the processors 102a, 102b, …, 102n), and the above modules can also be run in the computer terminal 10 provided in Embodiment I as part of the device.
[0502] According to the embodiments of the present disclosure, a memory data swap-in apparatus for implementing the memory data swap-in method is also provided, as shown in FIG. 15, the apparatus comprises a third control component 1501, a third acquisition component 1502, a third determination component 1503 and a third execution component 1504.
[0503] The third control component 1501 is configured to control the host machine to switch from running the host operating system to running the virtual machine operating system.
[0504] The third acquisition component 1502 is configured to acquire a memory swap request during the process that the host machine runs the virtual machine operating system, wherein the memory swap request is used to request to swap the memory data between the physical memory of the host machine and the corresponding back-end storage medium of the host machine.
[0505] The third determination component 1503 is configured to determine the task swap category corresponding to the memory data in response to the memory swap request.
[0506] The third execution component 1504 is configured to perform the passive swap-in task corresponding to the memory data in response to the task swap category being the passive swap-in task category of the host machine, wherein the passive swap-in task category is used to represent the task category that the virtual machine operating system passively triggers to swap the memory data from the back-end storage medium to the physical memory of the host machine.
[0507] It should be noted that the third control component 1501 to the third execution component 1504 correspond to the steps S601 to S604 in the embodiments of the present disclosure, and the four components have the same instances and application scenarios as the corresponding steps, but are not limited to the content disclosed in the above embodiment one. It should be noted that the above modules or components can be hardware components or software components stored in the memory (for example, the memory 104) and processed by one or more processors (for example, the processors 102a, 102b, …, 102n), and the above modules can also be run in the computer terminal 10 provided in the embodiment one as a part of the apparatus.
[0508] According to the embodiments of the present disclosure, a memory data swap-in apparatus for implementing the memory data swap-in method is also provided, as shown in FIG. 16, the apparatus comprises a fourth control component 1601, a fourth acquisition component 1602, a fourth determination component 1603 and a fourth execution component 1604.
[0509] The fourth control component 1601 is configured to control the host machine to switch from running the host operating system to running the virtual machine operating system.
[0510] The fourth obtaining component 1602 is configured to obtain a memory swap request in a process in which the host computer runs the virtual machine operating system, wherein the memory swap request is used to request to swap memory data between the physical memory of the host computer and the corresponding back-end storage medium of the host computer.
[0511] The fourth determining component 1603 is configured to determine a task swap category corresponding to the memory data in response to the memory swap request.
[0512] The fourth executing component 1604 is configured to execute, for the memory data, an active swap-in task corresponding to an active swap-in task category in response to the task swap category being the active swap-in task category, wherein the active swap-in task category is used to represent a task category in which the virtualization management layer running the virtual machine operating system actively triggers to swap the memory data from the back-end storage medium to the physical memory of the host computer.
[0513] It should be noted that the fourth control component 1601 to the fourth executing component 1604 correspond to steps S701 to S704 in the embodiments of the present disclosure, and the four components have the same instances and application scenarios as the corresponding steps, but are not limited to the content disclosed in the above embodiment one. It should be noted that the above modules or components can be hardware components or software components stored in the memory (for example, the memory 104) and processed by one or more processors (for example, the processors 102a, 102b, …, 102n), and the above modules can also be run in the computer terminal 10 provided in the embodiment one as a part of the device.
[0514] It should be noted that the preferred embodiments involved in the above embodiments of the present disclosure have the same scheme, application scenario and implementation process as the schemes provided by the embodiments of the present disclosure, but are not limited to the schemes provided by the embodiments of the present disclosure.
[0515] The embodiments of the present disclosure can provide an electronic device, which can be any one of the electronic devices in the electronic device group. Alternatively, in the present embodiment, the above electronic device can also be replaced by a terminal device such as a mobile terminal.
[0516] Alternatively, in the present embodiment, the above electronic device can be located in at least one network device of a plurality of network devices of a computer network.
[0517] In the present embodiment, the above computer terminal can execute program codes in the method.
[0518] Optionally, FIG. 17 is a structural block diagram of an electronic device according to an embodiment of the present disclosure. As shown in FIG. 17, the electronic device A can include one or more (only one is shown in the figure) processors 1702, a memory 1704, a storage controller, and a peripheral interface, wherein the peripheral interface is connected with a radio frequency module, an audio module, and a display.
[0519] The memory is configured to store software programs and modules, such as program instructions / modules corresponding to the method and device in the embodiments of the present disclosure. The processor executes various function applications and data processing by running the software programs and modules stored in the memory, that is, implements the method in the above embodiments. The memory can include a high-speed random access memory, and can further include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory can further include a memory remotely arranged with respect to the processor, which can be connected to the electronic device A through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0520] The processor can call information and application programs stored in the memory through the transmission device to perform the following steps: controlling the host machine to switch from running the host machine operating system to running the virtual machine operating system; obtaining a memory exchange request during the process that the host machine runs the virtual machine operating system, wherein the memory exchange request is used to request to exchange memory data between the physical memory of the host machine and the corresponding backend storage medium of the host machine; in response to the memory exchange request, determining a task exchange category corresponding to the memory data; and performing an exchange task corresponding to the task exchange category between the physical memory of the host machine and the backend storage medium on the memory data.
[0521] By using the embodiments of the present disclosure, a memory data exchange method is provided. By controlling the host machine to switch from running the host machine operating system to running the virtual machine operating system, and on this basis, starting the memory exchange function, and the memory exchange function can be performed on the virtualization management layer running the virtual machine operating system, and without limiting whether the exchange object is a user state page or a kernel state page, the technical effect of reducing the limitation of memory exchange is achieved, thereby solving the technical problem of large limitation of memory exchange in the related art.
[0522] Those skilled in the art can understand that the structure as shown in the figure is only schematic, and the electronic device can also be a terminal device such as a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, a Mobile Internet Device (MID), a Personal Access Device (PAD), etc. The figure does not limit the structure of the electronic device. For example, the electronic device A can further include more or less components (such as a network interface, a display device, etc.) than those shown in the figure, or have a different configuration from that shown in the figure.
[0523] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device by a program, and the program can be stored in a computer readable storage medium, which can include a flash disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, etc.
[0524] The embodiments of the present disclosure further provide a computer readable storage medium. Optionally, in the present embodiment, the above computer readable storage medium can be used to save the program code executed by the method provided by the above embodiments.
[0525] Optionally, in the present embodiment, the above storage medium can be located in any one of the electronic devices in the group of electronic devices in the computer network, or in any one of the mobile terminals in the group of mobile terminals.
[0526] Optionally, in the present embodiment, the computer readable storage medium is configured to store program code for performing the following steps: controlling the host machine to switch from running a host machine operating system to running a virtual machine operating system; obtaining a memory swap request during the process that the host machine runs the virtual machine operating system, wherein the memory swap request is used to request to exchange memory data between the physical memory of the host machine and the corresponding back-end storage medium of the host machine; in response to the memory swap request, determining a task exchange category corresponding to the memory data; and performing an exchange task corresponding to the task exchange category between the physical memory of the host machine and the back-end storage medium on the memory data.
[0527] The embodiment of the present disclosure provides a memory data exchange method. By controlling the host computer to switch from running a host operating system to running a virtual machine operating system, and on this basis, starting a memory exchange function. The memory exchange function can be performed on a virtualization management layer running the virtual machine operating system, and does not limit whether the exchange object is a user state page or a kernel state page, thereby achieving the technical effects of reducing the limitations of memory exchange, and enabling the memory exchange of the running operating system, thereby solving the technical problems of the related art that the memory exchange has great limitations, and the memory exchange cannot be started in the running operating system.
[0528] The embodiment of the present disclosure further provides a computer program product. Optionally, the computer program product can include a computer program, and the computer program can implement the method provided by the above embodiment when executed by a processor.
[0529] The embodiment of the present disclosure further provides a computer program product. Optionally, the computer program product can include a nonvolatile computer readable storage medium, and the nonvolatile computer readable storage medium can be used to store a computer program, and the computer program can implement the method provided by the above embodiment when executed by a processor.
[0530] The embodiment of the present disclosure further provides a computer program. Optionally, the computer program can implement the method provided by the above embodiment when executed by a processor.
[0531] The above embodiment numbers of the present disclosure are only for description, and do not represent the advantages or disadvantages of the embodiments.
[0532] In the above embodiments of the present disclosure, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0533] In the several embodiments provided by the present disclosure, it should be understood that the disclosed technology can be implemented in other ways. Of course, the embodiment described above is only a schematic, for example, the division of units is only a logical function division, and there can be another division manner in actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection between units can be indirect coupling or communication connection through some interface, unit or module, and can be electrical or other forms.
[0534] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e. may be located in one place, or may be distributed on multiple network units. Part or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
[0535] In addition, each functional unit in various embodiments of the present disclosure can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0536] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present disclosure, essentially or the part that contributes to the prior art, or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The foregoing storage medium includes: a U disk, a read-only memory, a random access memory, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0537] The above is only the preferred embodiment of the present disclosure, and it should be pointed out that for those skilled in the art, without departing from the principles of the present disclosure, a number of improvements and refinements can be made, which should also be considered as the protection scope of the present disclosure. Industrial applicability
[0538] The scheme provided by the embodiment of the present disclosure can be applied in the memory exchange process, by controlling the host computer to switch from the running host operating system to the virtual machine operating system, and on this basis, the memory exchange function is started. In the process of running the virtual machine operating system in the host computer, the memory exchange request is obtained, which helps to efficiently manage the memory resources. By determining the task exchange category corresponding to the memory data, the exchange process of the memory data between the physical memory of the host computer and the back-end storage medium can be more accurately controlled, and the memory exchange function can be performed on the virtualization management layer running the virtual machine operating system, and it is not limited whether the exchange object is a user state page or a kernel state page, which realizes the technical effect of reducing the limitation of memory exchange, avoids that the memory exchange function can only be applied to the pages of the user state process and does not support the exchange of the kernel state page, and further solves the technical problem of large limitation of memory exchange in the related art.
Claims
A memory data swapping method comprises: controlling a host computer to switch from running a host operating system to running a virtual machine operating system; acquiring a memory swapping request during running of the virtual machine operating system on the host computer, wherein the memory swapping request is used to request swapping of memory data between a physical memory of the host computer and a corresponding backend storage medium of the host computer; in response to the memory swapping request, determining a task swapping category corresponding to the memory data; for the memory data, performing a swapping task corresponding to the task swapping category between the physical memory of the host computer and the backend storage medium. The method of claim 1, wherein, in response to the memory swapping request, determining a task swapping category corresponding to the memory data, comprises: in response to the memory swapping request, acquiring a task list, wherein the task list comprises different task swapping categories; from the task list, determining the task swapping category corresponding to the memory data. The method of claim 1, wherein, for the memory data, performing a swapping task corresponding to the task swapping category between the physical memory of the host computer and the backend storage medium, comprises: acquiring a read-write lock corresponding to the memory swapping request, wherein the read-write lock is used to allow multiple tasks to concurrently read the memory data and / or allow one task to write the memory data during performance of the swapping task on the memory data corresponding to the memory swapping request; using the read-write lock, performing the swapping task corresponding to the task swapping category on the memory data between the physical memory of the host computer and the backend storage medium. The method of claim 3, wherein, using the read-write lock, performing the swapping task corresponding to the task swapping category on the memory data between the physical memory of the host computer and the backend storage medium, comprises: in response to the task swapping category being an active task swapping category of a virtualization management layer run by the virtual machine operating system, using a write lock in the read-write lock to perform an active swapping task corresponding to the active task swapping category on the memory data, wherein the active task swapping category is used to represent a task category in which the virtualization management layer actively triggers swapping of the memory data between the physical memory of the host computer and the backend storage medium; in response to the task swapping category being a passive task swapping category of the virtualization management layer, using a read lock in the read-write lock to perform a passive swapping task corresponding to the passive task swapping category on the memory data, wherein the passive task swapping category is used to represent a task category in which the virtual machine operating system passively triggers swapping of the memory data between the physical memory of the host computer and the backend storage medium. The method of claim 4, wherein, in response to the task swapping category being an active task swapping category of a virtualization management layer run by the virtual machine operating system, using a write lock in the read-write lock to perform an active swapping task corresponding to the active task swapping category on the memory data, comprises: In a case where the active task exchange category is an active swap-out task category, the write lock is used to serially execute an active swap-out task corresponding to the active swap-out task category for different memory pages of the same memory block, where the active swap-out task category is used to represent a task category in which the virtualization management layer actively triggers swap-out of the memory data from the physical memory of the host computer to the backend storage medium; and the memory data includes different memory pages of the same memory block. In a case where the active task exchange category is an active swap-in task category, the write lock is used to serially execute an active swap-in task corresponding to the active swap-in task category for different memory pages of the same memory block, where the active swap-in task category is used to represent a task category in which the virtualization management layer actively triggers swap-in of the memory data from the backend storage medium to the physical memory of the host computer. The method of claim 4, wherein, The read lock is used to ensure that different passive swap-in tasks are allowed to perform concurrent swap-in when the same memory exchange request occurs, and in the process of performing concurrent swap-in on different passive swap-in tasks through the read lock, the same memory pages of the same memory block are controlled by the bitmap to prevent concurrent swap-in. The method of claim 6, wherein, After the same memory pages of the same memory block are controlled by the bitmap to prevent concurrent swap-in, the method further includes: In response to successfully obtaining the read lock corresponding to the plurality of memory exchange requests, in a case where it is checked that the page table entry corresponding to the address of the memory data allows access, it is determined that the memory data has been successfully swapped in from the backend storage medium to the physical memory of the host computer, where the memory block level state information of the memory data at least includes to-be-updated state information, the to-be-updated state information is atomically updated based on an unsigned integer structure, and the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the storage information is atomically updated based on a character type structure in a case where the same memory pages of the same memory block are controlled by the bitmap to prevent concurrent swap-in. The method of claim 4, wherein, The method further includes: In a case where the active task exchange category is an active swap-out task category, the memory exchange request is added to a tree data structure, where the active swap-out task category is used to represent a task category in which the virtualization management layer actively triggered by the virtual machine operating system swaps out the memory data from the physical memory of the host computer to the backend storage medium; and the tree data structure is provided with a tree level lock. In response to the active task exchange category being changed from the active swap-out task category to the active swap-in task category or the passive swap-in task category, and the memory data being successfully swapped in from the back-end storage medium to the physical memory of the host computer, the memory swap request is deleted from the tree data structure; the active task exchange category includes the active swap-in task category, which is used to represent a task category in which the virtualization management layer actively triggers the memory data to be swapped in from the back-end storage medium to the physical memory of the host computer; the passive task exchange category includes the passive swap-in task category, which is used to represent a task category in which the virtual machine operating system passively triggers the memory data to be swapped in from the back-end storage medium to the physical memory of the host computer. The method of claim 8, wherein, In the case where the passive task exchange category is the passive swap-in task and the memory data that triggers a page fault exception is swapped out, the state information of the memory page level of the memory data includes at least to-be-updated state information and storage information. The method of claim 8, wherein, The method further includes: In the case where the passive task exchange category is the passive swap-in task category and the memory data that triggers a page fault exception is swapped out, the secondary storage type recorded in the state information of the memory page level of the memory data is parsed; The corresponding secondary storage location is read by using the secondary storage type, and the secondary storage location is recorded by using a page table. The method of claim 8, wherein, In the process in which the host computer runs the virtual machine operating system, a memory swap request is obtained, including: In the process in which the host computer runs the virtual machine operating system, the memory swap request is searched for in the tree data structure. The method of claim 1, wherein, In the process in which the host computer runs the virtual machine operating system, a memory swap request is obtained, including: In the process in which the host computer runs the virtual machine operating system, the memory swap request is obtained from a request queue, and each of the request queues is provided with a queue lock. The method of claim 12, wherein, The method further includes: In the virtualization management layer in which the virtual machine operating system runs, in response to the request queue being empty, the memory data with an access frequency lower than an access frequency threshold is obtained from a memory data set of the host computer; The memory swap request is constructed by using the memory data with the access frequency lower than the access frequency threshold; The memory swap request is stored in the request queue corresponding to the task exchange category. The method of claim 13, wherein, The memory swap request is stored in the request queue corresponding to the task exchange category, including: In the case where the task exchange category is the active swap-out task category, the memory swap request is stored in an active swap-out task queue corresponding to the active swap-out task category; the active swap-out task category is used to represent a task category in which the virtualization management layer actively triggers the memory data to be swapped out from the physical memory of the host computer to the back-end storage medium; and the request queue includes the active swap-out task queue. In a case where the task exchange category is an active swap-in task category, the memory swap request is stored in an active swap-in task queue corresponding to the active swap-in task category; the active swap-in task category is used to represent a task category in which the virtualization management layer actively triggers swap-in of the memory data from the back-end storage medium to the physical memory of the host computer; and the request queue includes the active swap-in task queue. In a case where the task exchange category is a passive swap-in task category, the memory swap request is stored in a passive swap-in task queue corresponding to the passive swap-in task category; the passive swap-in task category is used to represent a task category in which the virtual machine operating system passively triggers swap-in of the memory data from the back-end storage medium to the physical memory of the host computer; and the request queue includes the passive swap-in task queue. The method according to any one of claims 1 to 14, wherein The method further includes: determining a first target physical address of the memory data in the physical memory of the host computer; determining a virtual address that satisfies a mapping relationship with the first target physical address, wherein the mapping relationship is used to represent a correspondence between different first target physical addresses and different virtual addresses. A method for swap-in of memory data, including: controlling a host computer to switch from running a host computer operating system to running a virtual machine operating system; acquiring a memory swap request during running of the virtual machine operating system by the host computer, wherein the memory swap request is used to request exchange of memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; determining a task exchange category corresponding to the memory data in response to the memory swap request; in response to the task exchange category being an active swap-in task category of the host computer, performing an active swap-in task corresponding to the active swap-in task category on the memory data; the active swap-in task category is used to represent a task category in which a virtualization management layer running the virtual machine operating system actively triggers swap-in of the memory data from the back-end storage medium to the physical memory of the host computer. The method of claim 16, wherein, in response to the task exchange category being an active swap-in task category of the host computer, performing an active swap-in task corresponding to the active swap-in task category on the memory data, including: in response to the task exchange category being the active swap-in task category, acquiring a write lock corresponding to the memory swap request; performing the active swap-in task corresponding to the active swap-in task category on the memory data by using the write lock. The method of claim 17, wherein, in response to the task exchange category being the active swap-in task category, acquiring a write lock corresponding to the memory swap request, including: in response to the task exchange category being the active swap-in task category and state information of the memory data corresponding to the swap request not being in a swap-in state or in a running state, acquiring a write lock corresponding to the memory swap request. The method of claim 16, wherein, The method further includes: determining a memory page of the memory data; in response to state information of the memory page being in a swap-out state, determining a second storage type recorded in the state information of the memory page; calling a read function corresponding to the secondary storage type, and writing the secondary storage location corresponding to the memory page to a virtual address, wherein the virtual address is mapped from a real physical address allocated by the virtualization management layer and is used as an address used by the virtualization management layer to access the memory page. The method of claim 19, wherein, The method further includes: In a case where the memory page is completed to be swapped in from the back-end storage medium to the physical memory of the host, the state information of the memory data is determined as a swap-in state. The method according to any one of claims 16 to 20, wherein The method further includes: In response to the number of the swap requests being less than a number threshold and the state information of the memory data corresponding to the swap request not being the swap-in state, the memory swap request is added to an active swap-in task queue corresponding to the active swap-in task. The method according to any one of claims 16 to 20, wherein The read lock is used to ensure that different passive swap-in tasks are allowed to perform concurrent swapping in the same memory swap request, and in the process of performing concurrent swapping of different passive swap-in tasks through the read lock, the same memory page of the same memory block is controlled by the bitmap to prevent concurrent swapping. The method of claim 22, wherein, After the same memory page of the same memory block is controlled by the bitmap to prevent concurrent swapping, the method further includes: In response to successfully obtaining the read lock corresponding to a plurality of memory swap requests, in a case where it is checked that the page table entry corresponding to the address of the memory data allows access, it is determined that the memory data has been successfully swapped in from the back-end storage medium to the physical memory of the host, wherein the memory block level state information of the memory data at least includes to-be-updated state information, the to-be-updated state information is atomically updated based on an unsigned integer type structure, and the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the storage information is atomically updated based on a character type structure in a case where the same memory page of the same memory block is controlled by the bitmap to prevent concurrent swapping. The method according to any one of claims 16 to 20, wherein In a case where the memory data in the page fault exception state is swapped out, the passive task exchange category in the task exchange category is a passive swap-in task category, and the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the passive swap-in task category corresponds to the passive swap-in task. The method according to any one of claims 16 to 20, wherein The method further includes: In a case where the memory data in the page fault exception state is swapped out, the passive task exchange category in the task exchange category is a passive swap-in task category, and the memory page level state information of the memory data at least includes to-be-updated state information and storage information, the passive swap-in task category corresponds to the passive swap-in task; Using the secondary storage type, a corresponding secondary storage location is read, wherein the secondary storage location is recorded using a page table. A memory data swap-out method, comprising: controlling the host to switch from running a host operating system to running a virtual machine operating system; In a process that the host computer runs the virtual machine operating system, a memory swap request is acquired, wherein the memory swap request is used to request to swap memory data between a physical memory of the host computer and a corresponding back-end storage medium of the host computer; In response to the memory swap request, a task swap category corresponding to the memory data is determined; In response to the task swap category being an active swap-out task category of the host computer, an active swap-out task corresponding to the active swap-out task category is executed on the memory data, wherein the active swap-out task category is used to represent a task category that a virtualization management layer running the virtual machine operating system actively triggers to swap the memory data from the physical memory of the host computer to the back-end storage medium. The method of claim 26, wherein, In response to the task swap category being the active swap-out task category, the write lock corresponding to the memory swap request is acquired; The write lock is used to execute the active swap-out task corresponding to the active swap-out task category on the memory data. The method further comprises: The method of claim 26, wherein, In response to releasing the write lock corresponding to the memory swap request, a read lock corresponding to the memory swap request is used to execute a passive swap-in task corresponding to a passive swap-in task category on the memory data, wherein the passive swap-in task category is used to represent a task category that the virtual machine operating system passively triggers to swap the memory data from the back-end storage medium to the physical memory of the host computer. In a process that the host computer runs the virtual machine operating system, a memory swap request is acquired, comprising: The method of any one of claims 26 to 28, wherein, In a process that the host computer runs the virtual machine operating system, the memory swap request is acquired in a request queue, wherein the request queue is provided with a queue lock. The method further comprises: The method of claim 29, wherein, In response to completing the execution of the active swap-out task corresponding to the active swap-out task category on the memory data, a time slice of the active swap-out task is determined; Based on the time slice, the memory swap request is put back into an active swap-out task queue corresponding to the active swap-out task category, wherein the request queue comprises the active swap-out task queue. In response to the task swap category being the active swap-out task category of the host computer, the active swap-out task corresponding to the active swap-out task category is executed on the memory data, comprising: The method of any one of claims 26 to 28, wherein, In response to the task swap category being the active swap-out task category, a second target physical address in the back-end storage medium based on the memory data is determined; The virtualization management layer is controlled to actively trigger to swap the memory data from the physical memory of the host computer to the second target physical address. In response to the task swap category being the active swap-out task category, a second target physical address in the back-end storage medium based on the memory data is determined, comprising: The method of claim 31, wherein, In response to the task exchange category being the active swap-out task category, in a case that the memory exchange request is a first generated memory exchange request, determining state information of the memory data as a queued swap-out state; Splitting a page table corresponding to the memory data in the queued swap-out state to obtain a page table entry of a memory page; Determining an access state of the page table entry corresponding to the memory page as a read-only state; Determining a content attribute and a storage state of the memory page in the read-only state; In the back-end storage medium, determining the second target physical address corresponding to both the content attribute and the storage state. The method of claim 32, wherein, The method further comprises: In a case that the memory page is completed to be swapped out from the physical memory of the host computer to the second target physical address of the back-end storage medium, determining the state information of the memory data as a swap-out state, and recycling the memory data in the swap-out state; and / or, In a case that the time slice of the active swap-out task is not present, and the state information of the memory data is the swap-out state, recycling the memory data in the swap-out state. The method of claim 32, wherein, The method further comprises: In response to the memory page being in a page fault exception state, or detecting a cancellation identifier of the memory exchange request, canceling the memory page to be swapped out from the physical memory of the host computer to the back-end storage medium, wherein the cancellation identifier is used to indicate canceling the memory exchange request. A memory data swap-in method, comprising: Controlling a host computer to switch from running a host computer operating system to running a virtual machine operating system; In a process that the host computer runs the virtual machine operating system, obtaining a memory exchange request, wherein the memory exchange request is used to request to exchange memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; In response to the memory exchange request, determining a task exchange category corresponding to the memory data; In response to the task exchange category being a passive swap-in task category of the host computer, performing a passive swap-in task corresponding to the passive swap-in task category on the memory data, wherein the passive swap-in task category is used to represent a task category that the virtual machine operating system passively triggers to swap the memory data from the back-end storage medium to the physical memory of the host computer. The method of claim 35, wherein, In response to the task exchange category being the passive swap-in task category of the host computer, performing the passive swap-in task corresponding to the passive swap-in task category on the memory data, comprising: Determining a page table entry corresponding to an address of the memory data; In response to the task exchange category being the passive swap-in task category, performing the passive swap-in task on the memory data, and determining that the memory data has been successfully swapped in from the back-end storage medium to the physical memory of the host computer. The method of claim 35, wherein, In a process that the host computer runs the virtual machine operating system, obtaining a memory exchange request, comprising: In the process that the host computer runs the virtual machine operating system, searching for the memory exchange request in a tree-shaped data structure, wherein the tree-shaped data structure is provided with a tree level lock. The method of claim 35, wherein, In response to the task exchange category being a passive swap-in task category of the host machine, performing, on the memory data, a passive swap-in task corresponding to the passive swap-in task category, including: In response to the task exchange category being the passive swap-in task category, obtaining read locks corresponding to a plurality of the memory exchange requests, wherein the read locks are used to ensure that, when the same memory exchange request occurs, different passive swap-in tasks are allowed to perform concurrent swap-in, and any other active swap-out or swap-in task is prohibited from being executed; In response to the read locks corresponding to a plurality of the memory exchange requests being in an available state, controlling the memory data to concurrently execute the passive swap-in tasks corresponding to the passive swap-in task category. The method of claim 35, wherein, The method further includes: In response to failing to obtain the read lock corresponding to the memory exchange request, setting a cancellation identifier to the memory exchange request, wherein the cancellation identifier is used to indicate cancellation of the memory exchange request; Using the cancellation identifier, triggering a rollback operation on an active swap-out task corresponding to an active swap-out task category, wherein the active swap-out task category is used to represent a task category in which a virtualization management layer operated by the virtual machine operating system actively triggers swap-out of the memory data from the physical memory of the host machine to the backend storage medium. The method of claim 38, wherein, The method further includes: In response to successfully obtaining the read lock corresponding to the memory exchange request, in a case where a page table entry corresponding to an address of the memory data allows access, unlocking the read lock corresponding to the memory exchange request, and determining that the memory data has been successfully swapped in from the backend storage medium to the physical memory of the host machine. The method of claim 38, wherein, The method further includes: In response to releasing the read lock corresponding to the memory exchange request, storing the memory exchange request to a passive swap-in task queue corresponding to the passive swap-in task category. The method of claim 35, wherein, The method further includes: Determining state information of the memory data corresponding to the memory exchange request; In response to the state information of the memory data being a queued swap-out state, updating the queued swap-out state to a queued swap-in state; In response to the state information of the memory data being a swap-out state, updating the swap-out state to the queued swap-in state. The method of claim 42, wherein, The method further includes: In response to the state information of the memory data corresponding to the memory exchange request being the queued swap-in state, in a case where it is necessary to first execute a passive swap-in task corresponding to the passive swap-in task category on the memory data, re-establishing a correspondence between the backend storage medium and the physical memory of the host machine. The method of claim 42, wherein, The method further includes: In response to the state information of the memory data corresponding to the memory exchange request being the swap-out state after switching, determining a first target physical address of the memory data in the physical memory of the host machine, wherein the memory data is used to be swapped in from the backend storage medium to the first target physical address; Recording a physical page corresponding to the first target physical address to the memory exchange request. The method of any one of claims 35 to 44, wherein The method further includes: In response to triggering a page fault exception state in response to a physical address of the virtual machine, a virtualization management layer running the virtual machine operating system is utilized to allocate a real physical address; A page table is utilized to map the virtual address to the real physical address, wherein the page table is used to represent a mapping relationship between the virtual address and the real physical address; The memory data is accessed by using the virtual address. An exchange system of memory data, comprising: An operating system running end configured to control a host computer to switch from running a host operating system to running a virtual machine operating system; An exchange end of memory configured to, during a process in which the host computer runs the virtual machine operating system, acquire a memory exchange request, wherein the memory exchange request is used to request exchange of memory data between a physical memory of the host computer and a back-end storage medium corresponding to the host computer; in response to the memory exchange request, determine a task exchange category corresponding to the memory data; and for the memory data, perform an exchange task corresponding to the task exchange category between the physical memory of the host computer and the back-end storage medium. An electronic device, comprising: A memory storing an executable program; A processor configured to run the program, wherein the program, when running, performs the method of any one of claims 1 to 45. A computer-readable storage medium comprising a stored executable program, wherein, Controlling a device in which the storage medium is located to perform the method of any one of claims 1 to 45 when the executable program is running. A computer program product, comprising a computer program which, when executed by a processor, implements the method of any one of claims 1 to 45. A computer program product, comprising a non-volatile computer readable storage medium storing a computer program which, when executed by a processor, implements the method of any one of claims 1 to 45. A computer program product, comprising a non-volatile computer readable storage medium storing a computer program which, when executed by a processor, implements the method of any one of claims 1 to 45.
Citation Information
Patent Citations
Virtual machine memory management method and system based on remote memory, terminal and medium
CN112748989A
Memory cache pool maintenance method, device and system and storage medium
CN116303128A
Page swap-out method, page swap-out device, page swap-out equipment and data processing system
CN117785370A
Data exchange-based platform
US20210216983A1
Cited By
An application-insensitive memory management method and memory management system
CN122132327A
A memory management method and a memory management system without inductance
CN122132327B