WO2021057489A1 - 虚拟机内存管理的方法及设备 - Google Patents

虚拟机内存管理的方法及设备 Download PDF

Info

Publication number
WO2021057489A1
WO2021057489A1 PCT/CN2020/114446 CN2020114446W WO2021057489A1 WO 2021057489 A1 WO2021057489 A1 WO 2021057489A1 CN 2020114446 W CN2020114446 W CN 2020114446W WO 2021057489 A1 WO2021057489 A1 WO 2021057489A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
virtual machine
operating system
swappable
physical
Prior art date
Application number
PCT/CN2020/114446
Other languages
English (en)
French (fr)
Inventor
王志钢
蒋毅飞
马剑
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP20870358.7A priority Critical patent/EP4030289A4/en
Publication of WO2021057489A1 publication Critical patent/WO2021057489A1/zh
Priority to US17/656,699 priority patent/US20220214907A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/0706Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment
    • G06F11/073Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation the processing taking place on a specific hardware platform or in a specific software environment in a memory management context, e.g. virtual memory or cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/0284Multiple user address space allocation, e.g. using different base addresses
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1016Performance improvement
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1032Reliability improvement, data loss prevention, degraded operation etc
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1041Resource optimization
    • G06F2212/1044Space efficiency improvement
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/15Use in a specific computing environment
    • G06F2212/152Virtualized environment, e.g. logically partitioned system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/20Employing a main memory using a specific memory technology
    • G06F2212/205Hybrid memory, e.g. using both volatile and non-volatile memory

Definitions

  • This application relates to the technical field of virtual machines, and in particular to methods and devices for virtual machine memory management.
  • Virtualization technology is the core technology of cloud scenarios.
  • multiple virtual machines Virtual Machine, VM
  • multiple virtual machines share the physical resources of the same physical host (Physical Machine, PM), such as processors, Memory, disk and network equipment, etc.
  • PM Physical Machine
  • the physical resources of a physical host can be shared to multiple users with VM as the granularity, so that multiple users can conveniently and flexibly use physical resources under the premise of safe isolation, and greatly improve the utilization of physical resources.
  • the memory allocated to each virtual machine is fixed.
  • the memory usage rate is relatively low in terms of virtual machines and physical hosts.
  • the memory usage rate of a single physical host is only 40% on average.
  • the virtual machine monitor dynamically allocates memory resources for each virtual machine according to the changing external load of the virtual machine. Since the peak load time of different virtual machines may be different, the physical memory is sufficient for most of the time. However, in some cases, it may also happen that the actual memory demand is greater than the physical memory.
  • part of the hard disk storage space can be used as memory, and the operating system selects part of the content from the total memory allocated to the virtual machine and stores it on the disk. Since the access speed of the disk is usually several orders of magnitude slower than the access speed of the memory, when this part of the content needs to be used, the performance of the computer is significantly reduced, which greatly affects the user experience.
  • the embodiments of the present application provide a method and device for virtual machine memory management, which are beneficial to avoid the problem of a significant drop in computer performance in a virtual machine oversubmission scenario, improve the stability of virtual machine operation, and improve user experience.
  • an embodiment of the present application provides a method for virtual machine memory management.
  • the method includes: identifying the non-operating system memory of the virtual machine from the total memory allocated to the virtual machine (VM); the total memory includes The memory of the virtual machine and the memory of the virtual machine monitor (Hypervisor); the memory of the virtual machine is used to store the code of the virtual machine and the data generated during the operation of the virtual machine, and the management memory of the virtual machine monitor is used to store the virtual machine.
  • the machine monitor manages the data required for the operation of the virtual machine;
  • the memory of the virtual machine includes the memory of the operating system of the virtual machine and the memory of the virtual machine's non-operating system;
  • the memory of the operating system of the virtual machine is used to store the operation of the virtual machine
  • the code and data of the system, the non-operating system memory of the virtual machine represents the remaining memory in the memory of the virtual machine except for the memory of the operating system of the virtual machine; the virtual machine is identified from the total memory
  • the non-operating system memory of the virtual machine is used as the swappable memory;
  • the swappable memory represents the memory that allows memory swapping;
  • the data in the swappable memory is stored in the non-easy Lost memory.
  • the operating system (Host OS) of the physical host will allocate the virtual machine's memory specification (that is, total memory) to the virtual machine.
  • the memory specification indicates the total memory size that the virtual machine is allowed to apply for. .
  • the memory specification covers the memory of the virtual machine and the managed memory of the hypervisor.
  • the memory of the virtual machine is the size of the memory provided for the virtual machine to apply for use
  • the management memory of the hypervisor is the size of the memory provided for the hypervisor to apply for use.
  • the allocated memory specification is 4G, of which the size of the virtual machine's memory occupies 3.5G, and the hypervisor's management memory occupies 0.5G.
  • the examples here are only for explaining the application and not for limitation.
  • the physical memory does not actually allocate storage space such as the memory specification size (for example, the memory specification is 3G) for the virtual machine, but when the memory of the virtual machine and the management memory of the hypervisor actually apply for memory, it will be based on Apply to establish the virtual machine's memory or the mapping relationship between the hypervisor's management memory and the memory pages in the physical memory.
  • the memory specification size for example, the memory specification is 3G
  • the memory of the virtual machine covers the operating system memory of the virtual machine and the non-operating system memory of the virtual machine.
  • the operating system of the virtual machine may also be referred to as a guest operating system (Guest operating system, Guest OS), and the memory of the Guest OS is the amount of memory provided to the guest OS itself for application.
  • the non-operating system of the virtual machine in this article can be referred to as non-Guest OS, and the memory of the non-Guest OS is the remaining memory of the virtual machine except the memory of the Guest OS.
  • the memory size of the virtual machine is 3.5G, of which the memory size of GuestOS occupies 1G, and the memory size of non-GuestOS occupies 2.5G.
  • Non-GuestOS memory for example, can be provided to applications in GuestOS to apply for use, that is to say, non-GuestOS memory can be used to store application code and data.
  • the data stored in the management memory of the hypervisor may include, for example, the data structure describing various hardware devices (such as CPU, memory, network card, disk, graphics card, etc.), and the respective management information of each hardware device. Taking CPU (that is, central processing unit, central processing unit) as an example, its management information will record information including the number of CPUs and the description of the simulated CPU hardware architecture.
  • Data stored in the management memory of the Hypervisor may also include, for example, cache data for display, and cache data for input/output (Input/Output, IO). Hypervisor can be used to coordinate the shared access of virtual machines to hardware devices such as memory, CPU, network card, disk, etc. When the virtual machine starts, each virtual machine has corresponding data structure, cache and other data to be stored, so when creating a virtual machine , It is necessary to cover the virtual machine memory and the hypervisor's management memory in the allocated memory specifications.
  • the memory of the operating system of the virtual machine is used to store the code and data of the operating system of the virtual machine.
  • the data stored in the memory of the operating system of the virtual machine may be, for example, a compiled library, stack data required for application running, and a guest OS kernel. Data needed when the module is running, etc.
  • the non-operating system memory of the virtual machine can be used to store related codes and data of various application programs running on the Guest OS.
  • the specific data of the application program may include, for example, the data loaded into the memory of the database program, the file data opened by the word processing program, and so on.
  • the total memory allocated to the VM is referred to as “virtual machine process memory”
  • the hypervisor management memory is referred to as “hypervisor management memory”
  • the VM memory is referred to as “virtual machine memory”.
  • the operating system memory of the VM is referred to as “Guest OS memory”
  • the non-operating system memory of the VM is referred to as “Non-Guest OS memory” or as virtual machine normal (VM-Normal) memory.
  • non-Guest OS memory is limited to exchangeable memory.
  • the physical memory is insufficient, only exchangeable memory is allowed for memory exchange, that is, part or all of the data in the exchangeable memory is stored in non-volatile memory (such as disk ) Exchange space, and does not allow other memory (such as Hypervisor management memory and Guest OS memory) to exchange memory.
  • swap does not refer to exchange in the usual sense, and swap in this application refers to the field of memory management.
  • Memory swapping is to transfer the data in the memory to the disk, or it can be understood as changing the data stored in the memory to be stored on the disk.
  • identifying the non-operating system memory of the virtual machine from the total memory includes: identifying from the total memory allocated to the virtual machine The memory of the virtual machine; from the memory of the virtual machine, the non-operating system memory of the virtual machine is identified as the exchangeable memory.
  • management memory such as Hypervisor and Guest OS memory can also be collectively referred to as critical memory
  • non-Guest OS memory can also be referred to as non-critical memory.
  • the identification of the memory, the non-critical memory as the memory that allows memory swapping.
  • the efficiency of identifying non-critical memory is improved.
  • the physical memory is tight, the memory can be exchanged according to the non-critical memory , To ensure the reliability of virtual machine operation and improve user experience.
  • the method further includes: The memory of the virtual machine and the non-operating system memory of the virtual machine are all added with marking information; the marking information indicates that the data in the marked memory is allowed to be exchanged for the memory; in this way, the memory of the virtual machine can be further added, Identify the non-operating system memory of the virtual machine; delete the mark information of the virtual machine's operating system memory, while retaining the mark information of the virtual machine's non-operating system memory; change the mark with the mark Part or all of the data in the information memory is stored in the non-volatile memory.
  • non-critical memory non-Guest OS memory
  • critical memory Hossion management memory and Guest OS memory
  • the tag information is used as the tag of the exchangeable memory.
  • the physical memory of the physical host is insufficient, only the data in the memory with the tag information may be stored on the disk; the data in the memory without the tag information is not allowed to be stored on the disk, so Ensuring that key memory is not swapped by memory and ensuring the performance of virtual machines is conducive to increasing the memory reuse rate in the virtual machine system by further increasing the number of virtual machines, thereby greatly improving the user experience.
  • the identifying the memory of the virtual machine from the total memory allocated to the virtual machine includes: determining the amount of memory allocated to the virtual machine The memory usage of different memory segments in the total memory; the memory usage includes the use of the virtual machine and the use of the virtual machine monitor; all the memory segments used by the virtual machine are used as the memory of the virtual machine .
  • the memory segment represents a whole composed of some memory pages with consecutive memory addresses
  • the physical memory usually includes multiple memory segments.
  • QEMU is an analog processor that distributes source code under General Public License (GPL).
  • GPL General Public License
  • QEMU simulates a variety of memory devices: device memory module (pc.ram), memory in-line storage Module (memdimm), memory node (ram-node).
  • pc.ram device memory module
  • memdimm memory in-line storage Module
  • ram-node memory node
  • These types of memory devices may be configured with actual memory segments and provided to the virtual machine itself, so the memory segments configured by these types of memory devices can be identified as virtual machines RAM.
  • the memory of the virtual machine can be marked with the exchangeable memory, that is, the marking information. Then the remaining unmarked memory is the critical memory, which belongs to the hypervisor managed memory, and subsequent memory swaps cannot occur.
  • This realizes the distinction between hypervisor management memory and virtual machine memory. Therefore, the implementation of the embodiments of the present application can improve the identification efficiency of the virtual machine memory.
  • the hypervisor management memory can be indirectly determined, thus avoiding the problem of low identification efficiency that may be caused by directly identifying the hypervisor management memory. Guarantee the performance of the virtual machine and improve the stability of the virtual machine operation.
  • the identifying non-operating system memory of the virtual machine from the memory of the virtual machine as the swappable memory includes: applying for the virtual machine The free memory in the memory, obtain the memory addresses of all free memory; use the memory corresponding to the memory addresses of all free memory as the non-operating system memory (non-GuestOS memory) of the virtual machine, and use it as the swappable RAM.
  • the free memory refers to the memory in the virtual machine memory that has not yet established a mapping relationship with the memory pages in the physical memory (that is, the memory pages have not been actually allocated).
  • the implementation of the embodiments of the present application can improve the identification efficiency of non-critical memory (non-GuestOS memory), ensure the performance of the virtual machine, and improve the stability of the operation of the virtual machine.
  • the identifying the memory of the virtual machine from the total memory allocated to the virtual machine includes: during the startup phase of the virtual machine, In the total memory allocated to the virtual machine, the memory of the virtual machine is identified; from the memory of the virtual machine, the non-operating system memory of the virtual machine is identified as the swappable
  • the memory includes: in a running phase after the virtual machine is started, identifying the non-operating system memory of the virtual machine from the memory of the virtual machine as the exchangeable memory.
  • an initialization virtual machine process is created, and the total memory required by the virtual machine process is allocated, that is, the virtual machine process memory.
  • the related data of the virtual machine and the hypervisor will be loaded into the memory, and then the virtual machine memory can be identified in the virtual machine process memory.
  • the relevant code data of the virtual machine's operating system (GuestOS) will be loaded into the memory, and then the non-GuestOS can be further identified in the virtual machine's memory, for example, by
  • the method of applying for free memory identifies non-GuestOS memory, and uses non-GuestOS memory as swappable memory. Due to the identification work done in advance, once there is a scene of physical memory shortage (physical memory shortage), it can respond quickly, execute memory swap according to the exchangeable memory, quickly optimize the memory usage, and ensure the stable operation of the entire system And reliability.
  • memory swap means that when the remaining available memory pages of the physical memory reach the water level specified by the physical memory (that is, the physical memory is used tightly, or the physical memory is insufficient), the data of some memory pages of the physical memory can be stored in Swap space on non-volatile memory (such as a disk), so that these memory pages free up memory space to meet new memory application requirements. Later, when the data needs to be used, the data is transferred from the swap space on the non-volatile memory (such as a disk) back to the physical memory.
  • the water level specified by the physical memory represents the ratio between the remaining free memory pages set by the physical memory and the total memory pages of the physical memory.
  • the data in the swappable memory is stored in Non-volatile memory.
  • the prescribed water level of the physical memory may be set to be close to 0%, and the physical memory is in a fully loaded state at this time. That is, when the physical memory of the physical host where the virtual machine is located is in a full load state, the data in the swappable memory is stored in the non-volatile memory; the full load state indicates that the physical memory is not free Space to store new memory pages.
  • the method further includes: if physical memory usage is tight or insufficient, when the virtual machine applies for memory allocation, determining the memory type of the memory allocated for the application; When the memory type belongs to the managed memory of the virtual machine monitor or the memory of the operating system of the virtual machine, memory recovery is not triggered; when the memory type belongs to the memory of the virtual machine non-operating system, memory recovery is triggered.
  • the implementation process of memory reclamation includes: acquiring a plurality of memory pages in physical memory; filtering the plurality of memory pages, and the filtering rules include eliminating memory pages without marking information, and retaining the marking information The memory page; the data in the memory page with the tag information is stored in the swap space on the non-volatile memory, so that the physical memory releases storage space to facilitate new memory allocation.
  • critical memory and non-critical memory can be processed differently in memory recycling.
  • the memory recycling operation can be triggered for non-critical memory to optimize memory usage and improve the operating performance of the virtual machine system.
  • critical memory the memory recovery operation is not triggered when physical memory is allocated (that is, the key memory is allowed to delay trigger memory recovery), thereby improving the memory allocation speed, avoiding the key memory being exchanged and causing performance fluctuations when the memory is tight, and improving the system Reliability and stability ensure user experience.
  • the solution of this application can be implemented in the scenario of virtual machine oversubmission, that is, before allocating total memory for the virtual machine process, the virtual machine oversubmission function can be configured through the function switch .
  • Virtual machine overcommitment means that the sum of the total memory of all virtual machines started on the physical host exceeds the size of the actual physical memory. Create more virtual machines through the virtualization platform on each physical host, improve the utilization of physical host memory resources, and reduce memory costs.
  • the solution of the application can ensure the performance and reliability of the virtual machine when memory swap occurs in the memory of the virtual machine.
  • an embodiment of the present application provides yet another method for managing memory of a virtual machine, the method comprising: identifying the memory of the virtual machine from the total memory allocated to the virtual machine; and the total memory includes the The memory of the virtual machine and the management memory of the virtual machine monitor; the memory of the virtual machine is used to store the code of the virtual machine and the data generated during the operation of the virtual machine, and the management memory of the virtual machine monitor is used for To store the data required by the virtual machine monitor to manage the virtual machine; use the memory of the virtual machine as a swappable memory; the swappable memory represents a memory that allows memory swapping; put the swappable memory in The data is stored in non-volatile memory.
  • the memory of the virtual machine is limited to exchangeable memory.
  • the physical memory is insufficient, only exchangeable memory is allowed for memory exchange, that is, part or all of the data in the exchangeable memory is stored in non-volatile memory (such as disk ) Swap space without allowing the Hypervisor to manage memory for memory swapping.
  • an embodiment of the present application provides a device for virtual machine memory management.
  • the device includes: a swappable memory determining module for identifying the virtual machine's memory from the total memory allocated to the virtual machine.
  • Non-operating system memory includes the memory of the virtual machine and the management memory of the virtual machine monitor; the memory of the virtual machine is used to store the code of the virtual machine and the information generated during the running of the virtual machine
  • the management memory of the virtual machine monitor is used to store the data required by the virtual machine monitor to manage the virtual machine;
  • the memory of the virtual machine includes the memory of the operating system of the virtual machine and the virtual machine Non-operating system memory of the virtual machine;
  • the operating system memory of the virtual machine is used to store the code and data of the operating system of the virtual machine, and the non-operating system memory of the virtual machine represents the memory of the virtual machine ,
  • the swappable memory determining module is also configured to use the non-operating system memory of the virtual
  • the device can implement the method described in any embodiment of the first aspect through various functional modules.
  • an embodiment of the present application provides yet another device for managing memory of a virtual machine.
  • the device includes: a swappable memory determining module for identifying the memory of the virtual machine from the total memory allocated to the virtual machine.
  • the total memory includes the memory of the virtual machine and the management memory of the virtual machine monitor; the memory of the virtual machine is used to store the code of the virtual machine and the data generated during the operation of the virtual machine, the The management memory of the virtual machine monitor is used to store the data required by the virtual machine monitor to manage the virtual machine;
  • the exchangeable memory determining module is also used to identify the virtual machine's memory from the total memory Memory;
  • a memory swap module used to use the memory of the virtual machine as swappable memory; the swappable memory represents memory that allows memory swapping.
  • the device can implement the method described in the second aspect through various functional modules.
  • an embodiment of the present application provides a computer device, including: at least one processor and a memory; the processor and the memory are connected or coupled together by a bus; the memory is used to store one or more A computer program, the one or more computer programs including instructions; the processor is configured to execute the one or more computer programs to implement the method as described in any embodiment of the first aspect.
  • the embodiments of the present application provide yet another computer device, including: at least one processor and a memory; the processor and the memory are connected or coupled together by a bus; the memory is used to store one or more A computer program, the one or more computer programs includes instructions; the processor is configured to execute the one or more computer programs to implement the method as described in the second aspect.
  • the embodiments of the present application provide a computer-readable storage medium on which instructions are stored.
  • one or more processors of the computer device can execute any possible embodiment of the first aspect or the second aspect. Methods.
  • an embodiment of the present application provides a computer program including program code, which executes the method of any possible embodiment of the first aspect or the second aspect when the program code runs on a computer device.
  • non-critical memory such as non-Guest OS memory
  • critical memory such as Hypervisor management memory or Guest OS memory
  • the embodiment of the present application does not need to directly identify key memory (such as Hypervisor management memory, Guest OS memory, etc.), so it can avoid identification problems caused by the diversification and uncertainty of key memory types. .
  • the implementation of the embodiments of the present application is beneficial to increase the memory usage efficiency by increasing the number of virtual machines, thereby greatly improving the user experience.
  • FIG. 1 is a schematic diagram of a system architecture of a physical host using virtualization technology provided by an embodiment of the present application.
  • FIG. 2 is a schematic diagram of memory swap occurring in a scenario where a virtual machine is oversubmitted according to an embodiment of the present application
  • FIG. 3 is a schematic structural diagram of a device for implementing a method for virtual machine memory management provided by an embodiment of the present application
  • FIG. 4 is a schematic flowchart of a method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 5 is a schematic structural diagram of a device for implementing yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 6 is a schematic diagram of a logic flow diagram for determining swappable memory provided by an embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a device for implementing yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 8 is a schematic flowchart of yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 9 is a schematic structural diagram of a device for implementing yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 10 is a schematic flowchart of yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 11 is a schematic structural diagram of a device for implementing yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 12 is a schematic flowchart of yet another method for virtual machine memory management provided by an embodiment of the present application.
  • FIG. 13 is a schematic structural diagram of a system provided by an embodiment of the present application.
  • the method for virtual machine memory management provided in this application can be applied to a physical host (or called a physical host).
  • FIG. 1 exemplarily describes a schematic diagram of the system architecture of a physical host 100 applying virtualization technology in an embodiment of the present application.
  • the physical host 100 includes the hardware of the server and runs in a virtual environment.
  • Virtual Machine is a complete computer system with complete hardware system functions simulated by software and running in an isolated environment.
  • VM also includes guest operating system (Guest operating system, Guest OS) and guest OS-based applications.
  • Guest OS is an operating system running in a VM.
  • Guest OS may be a kernel-mode OS or a user-mode OS.
  • VM1 and VM2 are taken as examples. VM1 and VM2 can run their own Guest OS and guest OS-based applications independently.
  • Hypervisor also known as a hypervisor, is an intermediate software layer that runs between the server hardware and the virtual machine operating system. It can be used to manage one or more VMs, allowing multiple VMs to share server hardware, such as accessing the server All physical devices, including memory, CPU, network card, disk, etc., realize the abstraction of physical hardware. Hypervisor not only coordinates the virtual machine's shared access to these hardware resources, but also can impose protection between each virtual machine.
  • the server hardware includes the storage resources of the server, and the storage resources further include volatile memory and non-volatile memory.
  • Volatile memory is used to provide physical memory (physical memory) of the server. Physical memory usually refers to a memory space that provides temporary storage for hypervisors, operating systems, and various applications through volatile memory (such as physical memory sticks).
  • the physical memory is used to store multiple memory segments, and each memory segment includes multiple memory pages. In the embodiment of the present application, the memory pages of the physical memory can be used to store codes and data corresponding to the Hypervisor, Guest OS, and application programs.
  • Non-volatile memory can be used to provide swap space.
  • the swap space is a section of storage space (or address space) in non-volatile memory.
  • the swap space is used to store data exchanged from physical memory. . That is to say, when the available memory of the physical memory is insufficient, part of the stored data in the physical memory can be stored, such as data in a memory page (page) or data in a block (block) or other types of storage unit granularity data , Stored in the swap space of the non-volatile memory, so that this part of the memory page or block or other type of storage unit in the physical memory releases this part of the memory due to the emptying of data.
  • the swap space provided by the non-volatile memory may be, for example, a swap partition or a page swap file.
  • the volatile memory may be Double Data Rate Synchronous Dynamic Random Access Memory (DDR SDRAM) or Static Random-Access Memory (SRAM) or random access memory ( Random Access Memory, RAM) and other memory; non-volatile memory can be flash memory or disk and other memory.
  • DDR SDRAM Double Data Rate Synchronous Dynamic Random Access Memory
  • SRAM Static Random-Access Memory
  • RAM random access memory
  • non-volatile memory can be flash memory or disk and other memory.
  • Virtual machine overcommitment means that the total amount of memory allocated by each virtual machine in all virtual machines started on the physical host exceeds the size of actual physical memory.
  • the size of the physical memory is 100G, and 10 VMs are started on the physical host, and the memory allocated by each VM is 20G, then 10 virtual machines are allocated at this time
  • the total amount of memory is 200G, which exceeds the size of actual physical memory.
  • the size of the physical memory is 100G
  • a VM is started on the physical host
  • the memory allocated by the VM is 150G, that is, the total amount of virtual machine specifications at this time is 150G, exceeding the actual physical memory size.
  • the number of virtual machines on a single physical host can be increased, the memory usage rate can be increased, and the memory cost can be reduced.
  • the memory of a single VM can be allocated on demand, and the peak load time of different VMs may be different. In most of the time, the physical memory is sufficient. In some cases, the total memory requirements of virtual machines running on the physical host may exceed the physical memory, which triggers memory swap.
  • Memory swap means that when the remaining available memory pages in the physical memory reach the threshold specified by the physical memory, the data of some memory pages of the physical memory can be stored on the disk, thereby freeing memory space for new application requirements. When the data of the memory page needs to be used, the data is transferred back to the physical memory.
  • the threshold specified by the physical memory can set the threshold of the ratio between the remaining available memory pages and the total memory pages of the physical memory for the physical memory.
  • the threshold specified by the physical memory can set the threshold of the ratio between the remaining available memory pages and the total memory pages of the physical memory for the physical memory.
  • the threshold specified by the physical memory can be set to 10%, and when the ratio of the remaining available memory pages in the physical memory is as low as 10%, a part of the memory pages in the physical memory can be put into the disk.
  • the specified threshold of physical memory can be set close to 0% (that is, the physical memory is in a fully loaded state).
  • a part of the memory pages in the physical memory can be placed on the disk, as shown in Figure 2 for memory swapping for VM2, thereby placing a part of the memory pages of VM2 Into the paging file on the disk.
  • the threshold specified by the physical memory can be set according to actual conditions, and this application does not make specific limitations.
  • the access speed to the memory pages in the disk is much slower than the access speed to the memory pages in the physical memory.
  • some inactive memory of the physical memory is usually swapped to the disk.
  • the memory page needs to be used the memory is swapped back to the physical memory. .
  • some memory pages that require high access speed such as Hypervisor management memory pages and Guest OS memory pages, are swapped to disk due to temporary inactivity and other reasons.
  • a memory lock (Memory Lock, mlock) technology is used, and the mlock interface is directly called in the program code to remove a certain part of the memory in the memory.
  • Mlock is a mechanism used by the kernel to lock memory. It is used to lock part or all of the memory used by the process to physical memory. The locked memory page will not be swapped to disk until it is unlocked or the process exits.
  • the technical shortcomings of this solution include the following: (1) When using this technology, it is necessary to explicitly call the mlock interface, but many key memories are dynamically requested and cannot be locked by identifying one by one and then explicitly calling mlock; (2) ) The diversification and uncertainty of the types of key memory make it impossible to completely identify it at one time. Some key memory may even take a long period of time to be identified, which is inefficient in recognition. (3) The mlock method will cause all the memory to be allocated in advance without distinction, which will destroy the on-demand allocation of memory in the overcommit scenario. Even if the munlock operation is executed, the allocated memory cannot be reclaimed, resulting in the memory reuse rate in the system. reduce.
  • embodiments of the present application provide a method for virtual machine memory management and related equipment.
  • FIG. 3 shows a schematic structural diagram of a device 200 for implementing a method for virtual machine memory management provided by an embodiment of the present application.
  • the device 200 includes a processor 201, a volatile memory 202, and a non-volatile memory 203.
  • the device 200 may be the physical host 100 described in the embodiment of FIG. 1.
  • the processor 201 includes one or more general-purpose processors, where the general-purpose processor may be any type of device capable of processing electronic instructions, including a central processing unit (CPU), a microprocessor, a microcontroller, and a main Processor, controller and ASIC (Application Specific Integrated Circuit, application specific integrated circuit) and so on.
  • the processor 201 executes various types of digital storage instructions.
  • the processor 201 can run software or firmware programs stored in the volatile memory 202.
  • the processor 201 can execute programs or process data to perform at least a part of the methods discussed herein.
  • the volatile memory 202 is used to provide physical memory, and the physical memory is used to store multiple memory pages.
  • the memory pages of the physical memory can be used to store codes and data corresponding to the Hypervisor, Guest OS, and application programs.
  • the volatile memory 202 is also used to store logic codes or instructions corresponding to various requirements that the processor 201 runs in the volatile memory 202.
  • the non-volatile memory can be used to provide swap space, which is used to implement the memory swap function with the physical memory and store multiple memory pages swapped from the physical memory.
  • the volatile memory 202 may be a volatile memory such as DDR, SDRAM, or SRAM; the non-volatile memory 203 may be a non-volatile memory such as flash memory or a magnetic disk.
  • the processor 201 when memory exchange is required between the physical memory of the volatile memory 202 and the exchange space of the non-volatile memory, the processor 201 implements the page in the physical memory and the exchange space of the selected memory page. exchange. Specifically, the processor (CPU) 201 can execute the virtual machine memory management method shown in FIG. 4, including but not limited to the following steps:
  • the non-operating system memory of the virtual machine is identified from the total memory allocated to the virtual machine.
  • the total memory allocated to the VM includes the memory of the VM and the memory of a virtual machine monitor (Hypervisor). Since the Hypervisor is used to coordinate the virtual machine's shared access to hardware resources such as memory, CPU, network card, and disk, and each virtual machine has a corresponding data structure, cache and other data that needs to be stored when the virtual machine is started, it is necessary to create a virtual machine At this time, the memory of the VM and the management memory of the hypervisor need to be allocated. The memory of the virtual machine is used to store the code and data of the virtual machine, and the management memory of the hypervisor is used to store the data that the hypervisor manages the operation of the virtual machine.
  • the hypervisor is used to coordinate the virtual machine's shared access to hardware resources such as memory, CPU, network card, and disk, and each virtual machine has a corresponding data structure, cache and other data that needs to be stored when the virtual machine is started, it is necessary to create a virtual machine At this time, the memory of the VM and the management memory of the hypervisor need to
  • the data stored in the management memory of the hypervisor may be, for example, a data structure describing various hardware devices (such as a CPU, a memory, a network card, a disk, a graphics card, etc.), and respective management information of each hardware device. Taking CPU (that is, central processing unit, central processing unit) as an example, its management information will record information including the number of CPUs and the description of the simulated CPU hardware architecture.
  • the data stored in the management memory of the hypervisor may also be, for example, cache data for display, and cache data for input/output (Input/Output, IO).
  • the memory of the VM further includes the memory of the operating system of the VM and the memory of the non-operating system of the VM; the memory of the operating system of the virtual machine is used to store the code and data of the operating system of the virtual machine; the memory of the non-operating system of the VM represents the memory of the VM. In the memory, the remaining memory except for the memory of the operating system of the VM.
  • the memory of the operating system of the virtual machine is used to store the code and data of the operating system of the virtual machine.
  • the data stored in the memory of the operating system of the virtual machine may be, for example, a compiled library, stack data required for application running, and a guest OS kernel. Data needed when the module is running, etc.
  • the non-operating system memory of the virtual machine can be used to store related codes and data of various application programs running on the Guest OS.
  • the specific data of the application program may include, for example, the data loaded into the memory of the database program, the file data opened by the word processing program, and so on.
  • the operating system (Host OS) of the physical host will allocate the virtual machine's memory specification (that is, total memory) to the virtual machine.
  • the memory specification indicates the total memory size that the virtual machine is allowed to apply for. .
  • the memory specification covers the memory of the virtual machine and the management memory of the hypervisor.
  • the memory of the virtual machine is the size of the memory provided for the virtual machine to apply for use
  • the management memory of the hypervisor is the size of the memory provided for the hypervisor to apply for use.
  • the memory of the virtual machine covers the operating system memory of the virtual machine and the non-operating system memory of the virtual machine.
  • the operating system of the virtual machine may also be referred to as a guest operating system (Guest operating system, Guest OS), and the memory of the Guest OS is the amount of memory provided to the guest OS itself for application.
  • the non-operating system of the virtual machine in this article can be referred to as non-Guest OS, and the memory of the non-Guest OS is the remaining memory of the virtual machine except the memory of the Guest OS.
  • the total memory allocated to the VM is also referred to as “virtual machine process memory”
  • the management memory of the hypervisor is referred to as “hypervisor management memory”
  • the memory of the virtual machine is referred to as “virtual machine memory”.
  • the operating system memory of the virtual machine is referred to as “Guest OS memory” for short, and the non-operating system memory of the virtual machine is referred to as “Non-Guest OS memory” or virtual machine normal (VM-Normal) memory.
  • the virtual machine process memory covers the hypervisor management memory and the virtual machine memory
  • the virtual machine memory covers the virtual machine's operating system memory and the virtual machine's non-operating system memory.
  • non-Guest OS memory can be identified from the total memory (virtual machine process memory), that is, non-Guest OS memory can be distinguished from other memory (such as Hypervisor management memory, Guest OS memory).
  • the non-operating system memory of the VM is used as exchangeable memory.
  • the VM-Normal memory can be determined as the swappable memory. Swappable memory means the memory that allows memory swapping.
  • the memory is exchanged according to the exchangeable memory, that is, part or all of the data in the exchangeable memory is stored in the non-exchangeable memory. Swap space for volatile memory.
  • the water level specified by the physical memory represents the ratio between the remaining free memory pages set by the physical memory and the total memory pages of the physical memory.
  • VM-Normal As swappable memory in the virtual machine process memory in advance.
  • memory exchange is required between the physical memory and the swap space, only VM-Normal is required.
  • Some memory pages in the normal memory are exchanged for memory, instead of using Hypervisor to manage memory or Guest OS memory for memory exchange, which greatly reduces the impact on the entire virtual machine process and the performance of the virtual machine system, and ensures that the memory pressure is high. Time to avoid large fluctuations in performance and stability issues.
  • the embodiment of the present application does not need to directly identify key memory (Hypervisor management memory, Guest OS memory, etc.), so it can avoid identification difficulties caused by the diversification and uncertainty of the types of key memory.
  • the recognition efficiency can be improved by recognizing VM-Normal memory.
  • the implementation of the method of this application will not affect the characteristics of memory on-demand allocation in the oversubmission scenario, which is beneficial to increase the memory reuse rate in the virtual machine system by further increasing the number of virtual machines, thereby greatly improving users Experience.
  • the solution of the present application can be implemented by adding a new software code module to the Hypervisor kernel of the physical host and adding a new software code module to the VM operating system (Guest OS) .
  • the virtual machine process memory allocation module 101, the exchangeable memory determination module 102, and the hypervisor can be set in the hypervisor.
  • the memory exchange module 103 the virtual machine process memory allocation module 101 is used to determine the memory allocated to the VM, and the exchangeable memory determination module 102 is used to identify the non-operating system memory of the VM in the memory allocated to the VM and use it as exchangeable memory ;
  • the memory swap module 103 is used to perform memory swap according to the swappable memory when the memory page corresponding to the memory allocated to the VM needs to be swapped, that is, to store part or all of the data in the swappable memory in the nonvolatile sexual memory.
  • the swappable memory determining module 102 in the hypervisor may further include a virtual machine memory identifying module 1021 and a non-operating system memory identifying module 1022 (or called a non-GuestOS memory identifying module 1022).
  • a GuestOS memory identification module 104 is also provided in the GuestOS of each VM.
  • the virtual machine memory identification module 1021 is used to identify the virtual machine memory from the virtual machine process memory allocated to the VM.
  • the virtual machine memory identification module 1021 will identify the allocated virtual machine process memory, distinguish the virtual machine's own memory, that is, the virtual machine memory, and add tag information to the memory page corresponding to the virtual machine memory, that is, at this time, GuestOS Both the memory and VM-Normal memory are marked with marking information, and the marking information is used as the mark of the exchangeable memory; then the remaining unmarked memory, that is, the hypervisor management memory is a critical memory, and memory exchange cannot occur, thereby protecting the hypervisor memory.
  • the marking information in the embodiments of the present application may be, for example, markings such as identification positions, labels, identification codes, etc., which are not limited in this application.
  • the non-GuestOS memory identification module 1022 is used to further identify the VM-Normal memory as a swappable memory from the memory of the virtual machine, and memory swap can occur, but the GuestOS memory cannot be swapped.
  • the GuestOS memory identification module 104 in the GuestOS will identify the free memory currently available for use in the GuestOS, and notify the non-GuestOS memory identification module 1022 in the Hypervisor.
  • the non-GuestOS memory identification module 1022 further determines the free memory as VM-Normal memory, and the remaining memory in the virtual machine memory that cannot be applied for is the GuestOS memory.
  • the non-GuestOS memory identification module 1022 further deletes the marking information of the GuestOS memory, and retains the marking information of the VM-Normal memory, that is, only the VM-Normal memory is used as the exchangeable memory, and memory exchange can occur; at this time, the GuestOS memory belongs to Critical memory, memory swap cannot occur, thereby protecting GuestOS memory.
  • the memory exchange module 103 can perform memory exchange operations according to the memory pages of the VM-Normal memory marked with the marking information.
  • the swappable memory determining module 102 can identify the memory that can be finally used for page swapping (ie VM-Normal memory) and add mark information, and the virtual machine system selects according to the mark information. Swap, that is, when the system's physical memory is insufficient, only memory segments with marked information can be swapped to disk; memory segments without marked information are not allowed to be swapped to disk, so as to ensure that critical memory (Hypervisor memory and GuestOS memory) will not be swapped Exchange, to ensure the performance of virtual machines, is conducive to increasing the memory reuse rate in the virtual machine system by further increasing the number of virtual machines, thereby greatly improving the user experience.
  • VM-Normal memory ie VM-Normal memory
  • a virtual machine initialization module 110 may be further provided in the hypervisor of the physical host 100.
  • the processor CPU
  • the virtual machine initialization module 110 the virtual machine process memory allocation module 101, the virtual machine memory identification module 1021, the non-GuestOS memory identification module 1022, and the guest OS of the VM in the Hypervisor.
  • the GuestOS memory identification module is used to execute the virtual machine memory management method as shown in FIG. 8. The method occurs during the startup phase of the virtual machine, including but not limited to the following steps:
  • an initialization virtual machine process is created through the virtual machine initialization module 110.
  • the initialization module calls the virtual machine process memory allocation module 101, and the virtual machine process memory allocation module 101 allocates required memory for the virtual machine process, that is, the virtual machine process memory described in the embodiment of the present application.
  • the Hypervisor is used to coordinate the virtual machine's shared access to hardware resources such as memory, CPU, network card, and disk, and each virtual machine has a corresponding data structure, cache and other data that needs to be stored when the virtual machine is started, it is necessary to create a virtual machine When, you need to allocate virtual machine memory and Hypervisor management memory. That is, the virtual machine process memory includes Hypervisor management memory and virtual machine memory.
  • the allocated virtual machine process memory is identified by the virtual machine memory identification module 1021, thereby distinguishing the virtual machine memory, and adding marking information to the virtual machine memory, where the marking information is temporarily used as a mark of the exchangeable memory.
  • the initialization module 110 will call the virtual machine process memory allocation module 101 to allocate the required memory for the virtual machine process.
  • the virtual machine memory identification module 1021 adds a memory filter to the memory allocation process, and the memory filter may specifically be a memory filtering algorithm.
  • the memory filter determines the memory usage of different memory segments in the memory allocated to the VM; the types of memory usage include the usage for the VM and the usage for the hypervisor; the memory filter determines the memory usage of these memory segments according to the memory usage.
  • the classification is performed, and all memory segments whose memory usage is the usage for the VM are identified as the virtual machine memory. Take QEMU as an example.
  • QEMU is a set of analog processors written by Fabrice Bellard that distributes source code under a General Public License (GPL).
  • QEMU simulates a variety of memory devices: Device memory module (pc.ram), memory in-line storage module (memdimm), memory node (ram-node). These types of memory devices may be configured with actual memory segments and provided to the virtual machine itself, so memory filtering The memory segment configured by these types of memory devices is recognized as virtual machine memory.
  • the virtual machine memory identification module 1021 uses madvise (madvise stands for a system call interface) to mark the identified virtual machine memory as exchangeable. , That is, labeled information. Then the remaining unlabeled memory is critical memory, which belongs to hypervisor management memory and cannot be exchanged. This realizes the distinction between hypervisor management memory and virtual machine memory.
  • the guestOS memory in the memory of the virtual machine and the memory page corresponding to the VM-Normal memory are marked with marking information.
  • the marking information can be, for example, markings such as marking positions, labels, and marking codes, which are not limited in this application.
  • the remaining memory except the virtual machine memory is the hypervisor management memory, and the hypervisor management memory has no marking information, that is, the hypervisor management memory is non-swappable memory. Therefore, the S403 can quickly realize the difference between the hypervisor management memory and the virtual machine memory, improve the identification efficiency, and also realize the protection of the hypervisor management memory to prevent the hypervisor management memory from being subsequently swapped out.
  • the GuestOS memory identification module 104 in the GuestOS can be used to query the memory usage in the GuestOS, try to apply for free memory, and identify the currently available applications in the GuestOS Free memory, get the memory addresses of all free memory.
  • Free memory refers to the memory in the virtual machine memory that has not yet established a mapping relationship with the memory pages in the physical memory (that is, the memory pages have not been actually allocated).
  • the GuestOS memory identification module 104 notifies the memory address of the free memory to the non-GuestOS memory identification module 1022 in the hypervisor.
  • the non-GuestOS memory identification module 1022 determines the free memory as VM-Normal memory, and retains the mark information of the VM-Normal memory, and the VM-Normal memory is used as the exchangeable memory. Then, in the virtual machine memory, the remaining memory except for the VM-Normal memory is the GuestOS memory, that is, the remaining memory in the virtual machine memory that cannot be applied for is the GuestOS memory, which realizes the GuestOS memory and VM-Normal in the virtual machine memory Classification of memory. The non-GuestOS memory identification module 1022 removes the marking information of the GuestOS memory, so that the GuestOS memory becomes non-swappable memory.
  • the S404 can quickly realize the difference between GuestOS memory and VM-Normal memory, improve the recognition efficiency, and also realize the protection of GuestOS memory to avoid the subsequent exchange of GuestOS memory.
  • the implementation of the embodiments of this application can identify the memory that can be finally used for page swapping (ie VM-Normal memory) during the startup phase of the virtual machine and reserve the mark information as the exchangeable mark, thereby distinguishing the exchangeable Memory and non-swappable memory.
  • VM-Normal memory ie VM-Normal memory
  • the system is insufficient in physical memory, only swappable memory with marked information can be swapped to disk; non-swappable memory without marked information will not be swapped to disk, thus ensuring that critical memory (Hypervisor memory and GuestOS memory) is not available. It is swapped, thus ensuring that the virtual machine is prevented from waiting for a long time when the memory pressure is high, thereby avoiding large fluctuations in performance and stability problems, and ensuring the performance of the virtual machine. It is also beneficial to increase the memory reuse rate in the virtual machine system by further increasing the number of virtual machines, which greatly improves the user experience.
  • a memory management module 106 and a key memory delay recovery module 107 may be further provided in the hypervisor of the physical host 100.
  • the memory recovery module 108 where the memory recovery module 108 may specifically include a key memory filtering module 109 and a memory swap module 103.
  • the processor CPU
  • the processor can run the above-mentioned memory management module 106, critical memory delay recovery module 107, and memory recovery module 108 in the Hypervisor to execute the virtual machine memory management method shown in FIG. 10, which occurs During the operation phase of the virtual machine, it includes but not limited to the following steps:
  • the memory management module 106 detects that the virtual machine currently needs to apply for actual allocation of physical memory.
  • the operating system of the physical host usually allocates actual physical memory to the virtual machine by dynamically allocating physical memory.
  • the operating system of the physical host allocates virtual machine process memory to the virtual machine.
  • the virtual machine process memory can be considered a virtual machine memory specification or virtual memory, that is, the operating system does not There is no real mapping relationship between all virtual machine process memory and pages in physical memory.
  • the virtual machine's process memory is 4G, which does not mean that 4G is actually allocated to the virtual machine in the physical memory after the virtual machine is started.
  • the operating system then actually allocates real physical memory pages for the virtual machine according to the virtual machine's application.
  • the memory management module 106 may determine that the virtual machine currently needs to apply for new memory allocation based on at least one of the following events: the hypervisor management module in the virtual machine process will apply for new management memory; or, the VM The kernel of the GuestOS needs to access the memory of the virtual machine that has not actually allocated physical memory; or, the application in the GuestOS of the VM needs to access the memory of the virtual machine that has not actually allocated the physical memory, and so on.
  • S502 is triggered to perform virtual machine memory allocation.
  • the memory management module 106 executes a process of allocating a new physical memory page to the virtual machine.
  • the memory management module 106 determines whether the memory type of the new physical memory currently allocated is critical memory. For example, if the new physical memory currently allocated belongs to Hypervisor memory or GuestOS memory, the new physical memory currently allocated is critical memory. The execution of step S505 will be triggered; if the new physical memory currently allocated belongs to VM-Normal memory, the new physical memory currently allocated is not critical memory, and step S504 will be triggered subsequently.
  • the memory recycling module 108 triggers a memory recycling operation for this physical memory allocation, so that free physical pages are released from the physical memory to facilitate actual memory allocation.
  • the memory recycling methods include memory swapping, memory page discarding, and so on.
  • the memory recycling module 108 will filter out some memory pages, and put the data of these memory pages into the swap space of the disk, so as to free up storage space for these memory pages for reallocation.
  • the key memory filtering module 109 in the memory recycling module 108 filters the memory pages obtained in the memory recycling process, and only allows memory pages with tag information (swappable memory tags) to be exchanged. Then, through the memory swap module 103, the selected memory is swapped to the swap space of the disk, thereby freeing up physical memory space. Based on the previous description, it can be seen that only some memory pages corresponding to VM-Normal memory can be exchanged.
  • the memory recycling method can optimize the memory usage and improve the operating performance of the virtual machine system.
  • the memory reclamation operation takes a long time, it will cause the memory application operation time to be too long, that is, the allocation of new content is slow, and it is easy to cause stability and performance problems in the system. For example, for the new management memory requested by the Hypervisor management module, if you wait for the memory recovery to complete, it will have a greater impact on the global performance, and even cause serious stability problems.
  • the key memory delayed recovery module 107 can allow the virtual machine to temporarily break through the memory specification constraints to obtain a small amount of memory to complete the allocation of new physical memory, and this physical memory allocation does not trigger memory recovery. Thereby, it is helpful to speed up the allocation of new memory pages of critical memory, and ensure the stability and performance of the system.
  • a small amount of available memory space (100M) can be additionally set as a cache.
  • the virtual machine can be allowed to temporarily break the memory specification constraints , Get an appropriate amount of memory space in the 100M cache for physical memory allocation.
  • critical memory such as Hypervisor memory or GuestOS memory
  • non-critical memory such as VM-Normal memory
  • the memory recycling operation can be triggered for non-critical memory to optimize memory usage and improve the operating performance of the virtual machine system.
  • critical memory the memory recovery operation is not triggered when physical memory is allocated (that is, the key memory is allowed to delay trigger memory recovery), thereby improving the memory allocation speed, avoiding the performance fluctuation problem caused by the exchange of management memory when the memory is tight, and improving the system Reliability and stability ensure user experience.
  • the following takes a cloud computing scenario in which virtual machines are oversubmitted (or referred to as memory oversubmission) as an example to illustrate the solution.
  • memory oversubmission the virtualization platform on each physical host can create more VMs, improve the utilization of physical host memory resources, and reduce memory costs.
  • the solution of the application can ensure the performance and reliability of the virtual machine when memory swap occurs in the memory of the virtual machine.
  • the solution of the embodiment of the present application can be implemented on the basis of the system architecture described in FIG. 5 or FIG. 7 or FIG. 9.
  • the memory delay recovery module 107 and the memory recovery module 108, the memory recovery module 108 may specifically include a key memory filtering module 109 and a memory swap module 103.
  • a GuestOS memory identification module is set in the GuestOS of each VM.
  • virtual machine oversubmission can be dynamically configured through the software interface, and performance and reliability can be guaranteed in the virtual machine oversubmission scenario.
  • the processor CPU
  • the oversubmission function of the virtual machine is configured through the function switch.
  • the function switch only after the function switch can be turned on can the sum of the memory specifications of all virtual machines be allowed to exceed the size of the physical memory of the physical host, thereby realizing over-commitment of memory.
  • the size of the physical memory is 100G.
  • 10 VMs can be started on the physical host, and the memory allocated by each VM is 20G, then at this time The total amount of virtual machine specifications is 200G, which exceeds the size of actual physical memory.
  • the virtual machine initialization module 110 will call the virtual machine process memory allocation module 101, and the virtual machine process memory allocation module 101 allocates the required memory for the virtual machine process, that is, the virtual machine Process memory.
  • the virtual machine process memory can be identified into two types: virtual machine memory and hypervisor management memory.
  • the marking information can be, for example, markings such as marking positions, labels, and marking codes, which are not limited in this application.
  • the hypervisor management memory is non-swappable memory, which realizes the protection of the hypervisor management memory and prevents the hypervisor management memory from being subsequently swapped out.
  • the virtual machine memory identification module 1021 will identify the allocated virtual machine memory. For details, please refer to the description of step S403, which will not be repeated here.
  • the VM-Normal memory is identified, the marking information of the VM-Normal memory is retained, and the marking information of the GuestOS memory is deleted.
  • the non-GuestOS memory identification module 1022 in the Hypervisor and the GuestOS memory identification module in the GuestOS can cooperate with each other to further divide the virtual machine memory into two types: VM-Normal memory and GuestOS memory. Remove the tag information of the GuestOS memory, so that the GuestOS memory cannot be page swapped. The mark information of VM-Normal memory continues to be retained, which means that VM-Normal memory is used as exchangeable memory. For details, please refer to the description of step S404, which will not be repeated here.
  • physical memory stress means that the ratio of the remaining free memory pages in the physical memory to the total memory pages of the physical memory reaches or exceeds a preset threshold.
  • the preset threshold can be set to 5%, 10%, 20 % Etc. This application is not limited.
  • physical memory stress means that the physical memory is under full load, and at this time, there are no or nearly no free memory pages in the physical memory to store information.
  • the memory triggered by the key memory without tag information (such as Hypervisor memory or GuestOS memory) can be realized when the physical memory is tight.
  • the allocation will be executed immediately without triggering memory reclamation; while memory allocation triggered by non-critical memory with tag information (such as VM-Normal memory) will also trigger memory reclamation. Memory allocation is completed after memory reclamation is performed. .
  • non-critical memory ie, VM-Normal memory
  • VM-Normal memory can be identified during the startup phase of the virtual machine and retained as the exchangeable mark. Information, the remaining memory is the critical memory, and the critical memory does not carry tag information.
  • FIG. 13 is a schematic structural diagram of a system provided by an embodiment of the present application.
  • the system includes one or more computing devices 70, each computing device 70 includes a processor 701, a first memory 702, a second memory 703, and a communication interface 503, the processor 701, a first memory 702, a second memory 703, and a communication interface 503 is connected by bus 504. among them:
  • the number of the first memory 702 is one or more.
  • the first memory 702 is used to provide physical memory.
  • the first memory 702 may be a volatile memory (Volatile Memory) such as DDR SDRAM or SRAM or RAM.
  • the number of the second storage 703 is one or more, and the second storage 703 is used to provide a swap space, so as to realize the memory swap between the physical memory of the first storage 702 and the swap space.
  • the second memory 703 can be a read-only memory (Read-Only Memory, ROM), a flash memory (Flash Memory), a hard disk (Hard Disk Drive, HDD) or a solid-state drive (Solid-State Drive, SSD), a magnetic disk, etc. Lost memory.
  • the first memory 702 and/or the second memory 703 may also be used to store a set of program codes, so that the processor 701 can call the program codes to implement the virtual machine memory management method described in the above embodiments.
  • code instructions and related data of each functional module described in FIG. 5 or FIG. 7 or FIG. 9 or FIG. 11 may be stored in the memory of different computing devices 70, or may be stored in the same computing device 70. On the same memory, it may also be stored on different memories (for example, the first memory 702 and the second memory 703) of the same computing device.
  • the processor 701 may be composed of one or more general-purpose processors, such as a central processing unit (CPU).
  • the processor 701 may be used to run the code instructions and related data of each functional module described in FIG. 5 or FIG. 7 or FIG. 9 or FIG. 11. That is to say, the program code executed by the processor 701 can realize the specific functions of each functional module described in FIG. 5 or FIG. 7 or FIG. 9 or FIG. 11, and realize the virtual machine memory management method of the embodiment of the present application.
  • the system further includes a communication interface 503.
  • the communication interface 503 may be a wired interface (for example, an Ethernet interface) or a wireless interface (for example, a cellular network interface or a wireless LAN interface), which is used to communicate with a terminal or a server so as to To provide users with related virtual machine services.
  • system may also include more or fewer components, which is not limited here.
  • the specific functions and implementation processes of the different components of the system can be referred to the foregoing description, which will not be repeated here.
  • the computer may be implemented in whole or in part by software, hardware, firmware or any combination.
  • software it can be implemented in the form of a computer program product in whole or in part.
  • the computer program product includes one or more computer instructions, and when the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a network site, computer, server, or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer, and may also be a data storage device such as a server or a data center integrated with one or more available media.
  • the usable medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape, etc.), an optical medium (such as a DVD, etc.), or a semiconductor medium (such as a solid-state hard disk), and so on.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

一种虚拟机内存管理的方法及设备,方法包括:从分配给虚拟机的总内存中识别出虚拟机的非操作系统内存;总内存包括虚拟机的内存和虚拟机监控器的管理内存;虚拟机的内存包括虚拟机的操作系统的内存和虚拟机的非操作系统的内存;将虚拟机的非操作系统的内存作为可交换内存;将可交换内存中的数据存放到非易失性存储器。所述方法有利于避免在虚拟机超量提交场景下计算机的性能的明显下降的问题,提升虚拟机运行的稳定性,提升用户使用体验。

Description

虚拟机内存管理的方法及设备
本申请要求于2019年09月29日提交到中国专利局、申请号为201910953083.9、申请名称为“虚拟机内存管理的方法及设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及虚拟机技术领域,尤其涉及虚拟机内存管理的方法及设备。
背景技术
虚拟化技术为云场景的核心技术,在部署有多个虚拟机(Virtual Machine,VM)的系统中,多个虚拟机共享同一个物理主机(Physical Machine,PM)的物理资源,如处理器、内存、磁盘和网络设备等。从而可实现以VM为粒度将一台物理主机的物理资源共享给多个用户使用,使多个用户能在安全隔离的前提下方便灵活地使用物理资源,极大提升物理资源的利用率。
在虚拟化技术中,分配给每台虚拟机的内存都是固定的。在云计算平台中,不管是从虚拟机还是从物理主机的维度来看,内存使用率相对都比较低,例如单台物理主机的内存使用率平均只有40%。通过增加同一个物理主机的虚拟机数量,能有效提升单台物理主机上的虚拟机密度和物理内存地使用率。在虚拟机超量提交(oversummit)场景下,为了保证各个虚拟机的性能和服务质量,虚拟机监控器会根据虚拟机不断变化的外部负载为各个虚拟机动态地分配内存资源。由于不同虚拟机的负载高峰时间可能不同,在绝大多数时间内,物理内存都是充裕的。但是在某些情况下,也可能会发生实际的内存需求大于物理内存的场景。
当物理内存不足时,可利用一部分硬盘存储空间作为内存来使用,操作系统在给虚拟机分配的全部内存中选择部分内容存放到磁盘上。由于磁盘的访问速度通常比内存的访问速度慢几个数量级,当需要使用这部分内容时,计算机的性能明显下降,极大影响用户的使用体验。
发明内容
本申请实施例提供了虚拟机内存管理的方法及设备,有利于避免在虚拟机超量提交场景下计算机的性能的明显下降的问题,提升虚拟机运行的稳定性,提升用户使用体验。
第一方面,本申请实施例提供了一种虚拟机内存管理的方法,方法包括:从分配给虚拟机(VM)的总内存中识别出所述虚拟机的非操作系统内存;该总内存包括虚拟机的内存和虚拟机监控器(Hypervisor)的内存;虚拟机的内存用于存放虚拟机的代码和和所述虚拟机运行过程中产生的数据,虚拟机监控器的管理内存用于存放虚拟机监控器管理虚拟机运行所需的数据;虚拟机的内存包括虚拟机的操作系统的内存和虚拟机的非操作系统的内存;虚拟机的操作系统的内存用于存放所述虚拟机的操作系统的代码和数据,虚拟机的非操作系统的内存表示所述虚拟机的内存中,除所述虚拟机的操作系统的内存之外剩余的内存;从所述总内存中识别出所述虚拟机的非操作系统的内存;将所述虚拟机的非操作系统的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存;将所述可交换内存中的数据存放到非易失性存储器。
也就是说,在虚拟机启动时,物理主机的操作系统(Host OS)会给该虚拟机分配虚拟机的内存规格(即总内存),该内存规格表示允许该虚拟机申请使用的总内存大小。该内存规格 涵盖了虚拟机的内存和Hypervisor的管理内存,虚拟机的内存为提供给虚拟机申请使用的内存大小,Hypervisor的管理内存为提供给Hypervisor申请使用的内存大小。例如,分配的内存规格为4G,其中虚拟机的内存的大小占了3.5G,Hypervisor的管理内存的大占了0.5G。当然,这里的示例仅用于解释本申请而非限定。此时,物理内存中并没有真正为该虚拟机实际分配如内存规格大小(例如,内存规格为3G)的存储空间,而是待虚拟机的内存和Hypervisor的管理内存实际申请内存时,再根据申请建立虚拟机的内存或和Hypervisor的管理内存与物理内存中的内存页的映射关系。
其中,虚拟机的内存涵盖了虚拟机的操作系统的内存和虚拟机的非操作系统的内存。本文中,虚拟机的操作系统又可称为客户机操作系统(Guest operating system,Guest OS),Guest OS的内存为提供给Guest OS自身申请使用的内存大小。相应的,本文中虚拟机的非操作系统可相应称为非Guest OS,非Guest OS的内存为虚拟机的内存除Guest OS的内存之外剩余的内存。例如,虚拟机的内存大小为3.5G,其中GuestOS的内存大小占了1G,非GuestOS的内存大小占了2.5G。当然,这里的示例仅用于解释本申请而非限定。非GuestOS的内存例如可以提供给GuestOS中的应用程序申请使用,也就是说非GuestOS的内存可用于存放应用程序的代码和数据。
Hypervisor的管理内存中存放的数据例如可以包括描述各种硬件设备(比如CPU、内存、网卡、磁盘、显卡等设备)的数据结构、每个硬件设备各自的管理信息等。以CPU(即central processing unit,中央处理器)为例,其管理信息里面会记录包括CPU的数量、模拟的CPU硬件架构描述等信息。Hypervisor的管理内存中存放的数据Hypervisor的管理内存例如还可以包括显示用缓存、输入输出(Input/Output,IO)用缓存等缓存数据。Hypervisor可用于协调虚拟机对内存、CPU、网卡、磁盘等这些硬件设备的共享访问,而虚拟机启动时每个虚拟机都有对应的数据结构、缓存等数据需要存储,所以要创建虚拟机时,需要在分配的内存规格中涵盖虚拟机内存和Hypervisor的管理内存。
虚拟机的操作系统的内存用于存放所述虚拟机的操作系统的代码和数据,其中,虚拟机操作系统的内存存放的数据例如可以是编译库、应用程序运行需要的堆栈数据、Guest OS内核模块运行时需要的数据,等等。
虚拟机的非操作系统的内存例如可用于存放运行在Guest OS上的各种应用程序的相关代码和数据。应用程序的具体数据例如可以包括数据库程序的加载到内存中的数据、文字处理程序打开的文件数据,等等。
本文中,为了描述方便,有时也将分配给VM的总内存简称为“虚拟机进程内存”,将Hypervisor的管理内存简称为“Hypervisor管理内存”,将VM的内存简称为“虚拟机内存”,将VM的操作系统的内存简称为“Guest OS内存”,将VM的非操作系统的内存称为“非Guest OS内存”或者称为虚拟机常规(Virtual Machine Normal,VM-Normal)内存。
本申请方案中,限定非Guest OS内存为可交换内存,当物理内存不足时,仅允许可交换内存进行内存交换,即将可交换内存中的部分或全部数据存放到非易失性存储器(例如磁盘)的交换空间,而不允许其他的内存(例如Hypervisor管理内存以及Guest OS内存)进行内存交换。这样,一方面,通过基于一部分内存而不是全局的内存进行内存交换,从而能释放出一定的内存空间,优化系统内存占用;另一方面,诸如Hypervisor管理内存或Guest OS内存中的数据如果被交换到磁盘,当需要重新访问这部分的内存页时,从磁盘对这部分的数据进行访问会导致整个虚拟机进程长时间地等待数据访问,进而导致出现用户业务进程大幅 波动的严重性能问题甚至稳定性问题,而本申请由于只允许诸如应用程序的内存等非Guest OS内存被交换到磁盘,而非Guest OS内存对系统性能的影响相对较小,业务迟滞时用户可接受性高,所以能够避免在虚拟机超量提交场景下计算机的性能的明显下降的问题,提高虚拟机运行的稳定性,提升用户使用体验。
需要注意的是,在本申请各个方面及各个可能的实施例中,交换(swap)并非指的是通常意义中的交换(exchange),本申请中的交换(swap)指的是内存管理领域中的内存交换(memory swapping),即将内存中的数据转移至磁盘上,或者可以理解为将存储在内存中的数据变更为存储在磁盘上。
基于第一方面,在一些可能的实施例中,从所述总内存中识别出所述虚拟机的非操作系统的内存,包括:从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存;从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存。
本申请实施例中,诸如Hypervisor的管理内存以及Guest OS内存也可统称为关键内存,诸如非Guest OS内存也可称为非关键内存,可以看到,本申请技术方案的落脚点在于对非关键内存的识别,将非关键内存作为允许进行内存交换的内存。通过在虚拟机进程内存中识别出虚拟机内存,以及通过在虚拟机内存中识别出非操作系统内存,提高了非关键内存的识别效率,当物理内存紧张时将可根据非关键内存进行内存交换,保证虚拟机运行的可靠性,提升用户使用体验。
基于第一方面,在一些可能的实施例中,所述从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存之后,还包括:对所述虚拟机的操作系统的内存和所述虚拟机的非操作系统的内存均增加标记信息;所述标记信息表示允许被标记的内存中的数据进行所述内存交换;这样,可进一步从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存;删除所述虚拟机的操作系统的内存的标记信息,同时保留所述虚拟机的非操作系统的内存的标记信息;将所述具有所述标记信息的内存中的部分或全部数据存放到非易失性存储器。
可以看到,本申请实施例中,识别出非关键内存(非Guest OS内存)后,可以确保只有非关键内存带有标记信息,而关键内存(Hypervisor管理内存以及Guest OS内存)将不会带走标记信息。标记信息作为可交换内存的标记,在物理主机的物理内存不足时,只有带标记信息的内存中的数据才有可能被存放到磁盘;没有标记信息的内存中的数据不允许存放到磁盘,从而保证关键内存不被内存交换,保障虚拟机的性能,有利于通过进一步增加虚拟机数量来提高了虚拟机系统中的内存复用率,从而大大提升了用户的使用体验。
基于第一方面,在一些可能的实施例中,所述从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存,包括:确定所述分配给所述虚拟机的总内存中的不同内存段的内存用途;所述内存用途包括供所述虚拟机使用和供所述虚拟机监控器使用;将供所述虚拟机使用的所有内存段作为所述虚拟机的内存。
其中,内存段表示由一些内存地址连续的内存页组成的整体,物理内存中通常包括多个内存段。
以QEMU为例,QEMU是一种以通用性公开许可证(General Public License,GPL分发源码的模拟处理器,QEMU模拟了多种内存设备:设备内存模块(pc.ram)、内存直插式存储模块(memdimm)、内存节点(ram-node)。这几种内存设备都可能配置实际的内存段并提供给虚拟机自身使用,因此可以把这几种内存设备配置的内存段都识别为虚拟机内存。
这样,后续可为虚拟机内存打上可交换内存的标记,即标记信息。那么剩下的没有标记 的内存则为关键内存,即属于hypervisor管理内存,后续不可发生内存交换。这样就实现了hypervisor管理内存和虚拟机内存的区分。所以实施本申请实施例能够提高虚拟机内存的识别效率,识别出虚拟机内存就可间接地确定了hypervisor管理内存,所以避免了直接对hypervisor管理内存进行识别而可能导致的识别效率低下的问题,保障虚拟机的性能,提高虚拟机运行的稳定性。
基于第一方面,在一些可能的实施例中,所述从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存,包括:申请所述虚拟机的内存中的空闲内存,获得所有空闲内存的内存地址;将所述所有空闲内存的内存地址对应的内存作为所述虚拟机的非操作系统的内存(非GuestOS内存),并用作所述可交换内存。
其中,空闲内存表示虚拟机内存中,尚未与物理内存中的内存页建立起映射关系(即尚未实际分配内存页)的内存。
那么,虚拟机内存中,除非GuestOS内存外剩下的内存则为GuestOS内存,即虚拟机内存中剩下的无法被申请的内存为GuestOS内存,从而实现虚拟机内存中GuestOS内存和非GuestOS内存的区分。由于在虚拟机内存识别过程中,GuestOS内存和非GuestOS内存都带上了标记信息,那么在本申请实施例完成对GuestOS内存和非GuestOS内存的区分后,可将GuestOS内存的标记信息去除,从而使GuestOS内存变成不可交换内存。保留非GuestOS内存的标记信息,从而使非GuestOS内存作为可交换内存。所以实施本申请实施例能够提高非关键内存(非GuestOS内存)的识别效率,保障虚拟机的性能,提高虚拟机运行的稳定性。
基于第一方面,在一些可能的实施例中,所述从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存,包括:在所述虚拟机的启动阶段,从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存;所述从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存,包括:在所述虚拟机启动后的运行阶段,从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存。
也就是说,实施本申请实施例,在虚拟机初始化启动阶段,创建初始化虚拟机进程,为虚拟机进程分配所需的总内存,即虚拟机进程内存。这样,虚拟机和Hypervisor的相关数据就会被载入到内存中,进而可以在虚拟机进程内存中识别出虚拟机内存。在虚拟机启动完成后,在虚拟机运行中,虚拟机的操作系统(GuestOS)的相关代码数据会被载入到内存中,进而就可以在虚拟机内存中,进一步识别出非GuestOS,例如通过申请空闲内存的方式识别出非GuestOS内存,将非GuestOS内存作为可交换内存。由于提前做了这些识别工作,所以一旦出现物理内存紧张(物理内存不足)的场景时,就能够做出快速响应,根据可交换内存执行内存交换,快速优化内存占用,同时保证整个系统的稳定运行和可靠性。
本申请实施例中,内存交换是指在物理内存剩余可用内存页达到物理内存规定的水位(即物理内存使用紧张,或称物理内存不足)时,可把物理内存的一些内存页的数据存放到非易失性存储器(例如磁盘)上的交换空间,从而使这些内存页腾出内存空间,以满足新的内存申请使用需求。后续在需要使用这些数据的时候,再把这些数据从非易失性存储器(例如磁盘)上的交换空间调回到物理内存。
其中,物理内存规定的水位表示物理内存设定剩余的可用内存页与物理内存总内存页之间的比率。当物理内存规定的水位达到预设阈值时,需要进行内存交换。
也就是说,当所述虚拟机所在物理主机的物理内存中剩余可用的内存页与所述物理内存总内存页之间的比率达到预设阈值时,将所述可交换内存中的数据存放到非易失性存储器。
在一种实施例中,可将物理内存规定水位设为接近0%,此时物理内存处于满负载状态。也就是说,当所述虚拟机所在物理主机的物理内存处于满负载状态时,将所述可交换内存中的数据存放到非易失性存储器;所述满负载状态表示所述物理内存无空闲空间存储新的内存页。
可以看到,在物理内存满负载或者物理内存占用达到一定比例的情况下,均可以采用本申请的方案进行内存交换,有助于根据实际情况进行内存优化设计,提升用户使用体验。
基于第一方面,在一些可能的实施例中,所述方法还包括:如果物理内存使用紧张或不足,在所述虚拟机申请分配内存时,可确定所述申请分配的内存的内存类型;当内存类型属于所述虚拟机监控器的管理内存或所述虚拟机的操作系统的内存时,不触发内存回收;当内存类型属于所述虚拟机的非操作系统的内存时,触发内存回收。
一种实施例中,内存回收的实施过程包括:在物理内存中获取多个内存页;对所述多个些内存页进行过滤,过滤规则包括淘汰不具有标记信息的内存页,保留具有标记信息的内存页;将所述具有标记信息的内存页中的数据存放到非易失性存储器上的交换空间,从而使物理内存释放出存储空间以便于进行新的内存分配。
可以看到,本申请实施例中,在虚拟机运行阶段,当需要在物理内存紧张的时候申请物理内存分配时,可让关键内存和非关键内存在内存回收上进行区别处理。针对非关键内存可触发内存回收操作,以优化内存占用,提高虚拟机系统的运行性能。针对关键内存,在分配物理内存时不触发内存回收操作(即允许关键内存延迟触发内存回收),从而提升内存分配速度,在内存紧张的时候避免了关键内存被交换而导致性能波动问题,提高系统可靠性和稳定性,保障用户使用体验。
基于第一方面,在一些可能的实施例中,可以在虚拟机超量提交的场景下实施本申请方案,即在为虚拟机进程分配总内存之前,可通过功能开关配置虚拟机超量提交功能。虚拟机超量提交是指在物理主机上启动的所有虚拟机的总内存之和超过实际物理内存的大小。通过每台物理主机上的虚拟化平台创建更多的虚拟机,提升物理主机内存资源利用率,降低内存成本。本申请方案可以保证虚拟机的内存在发生内存交换时的虚拟机性能和可靠性。
第二方面,本申请实施例提供了又一种虚拟机内存管理的方法,所述方法包括:从分配给虚拟机的总内存中识别出所述虚拟机的内存;所述总内存包括所述虚拟机的内存和虚拟机监控器的管理内存;所述虚拟机的内存用于存放所述虚拟机的代码和所述虚拟机运行过程中产生的数据,所述虚拟机监控器的管理内存用于存放所述虚拟机监控器管理所述虚拟机所需的数据;将所述虚拟机的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存;将所述可交换内存中的数据存放到非易失性存储器。
本申请方案中,限定虚拟机的内存为可交换内存,当物理内存不足时,仅允许可交换内存进行内存交换,即将可交换内存中的部分或全部数据存放到非易失性存储器(例如磁盘)的交换空间,而不允许Hypervisor管理内存进行内存交换。这样,一方面,通过基于一部分内存而不是全局的内存进行内存交换,从而能释放出一定的内存空间,优化系统内存占用;另一方面,诸如Hypervisor管理内存如果被交换到磁盘,当需要重新访问这部分的内存页时,从磁盘对这部分的数据进行访问会导致整个虚拟机进程长时间地等待数据访问,进而导致出现用户业务进程大幅波动的严重性能问题甚至稳定性问题,而本申请由于只允许诸如应用程序的内存等非Guest OS内存以及Guest OS内存被交换到磁盘,在一定程度上也能保证虚拟机运行的稳定性,提升用户使用体验。
第三方面,本申请实施例提供了一种用于虚拟机内存管理的设备,所述设备包括:可交换内存确定模块,用于从分配给虚拟机的总内存中识别出所述虚拟机的非操作系统内存;所述总内存包括所述虚拟机的内存和虚拟机监控器的管理内存;所述虚拟机的内存用于存放所述虚拟机的代码和所述虚拟机运行过程中产生的数据,所述虚拟机监控器的管理内存用于存放所述虚拟机监控器管理所述虚拟机所需的数据;所述虚拟机的内存包括所述虚拟机的操作系统的内存和所述虚拟机的非操作系统的内存;所述虚拟机的操作系统的内存用于存放所述虚拟机的操作系统的代码和数据,所述虚拟机的非操作系统的内存表示所述虚拟机的内存中,除所述虚拟机的操作系统的内存之外剩余的内存;所述可交换内存确定模块还用于,将所述虚拟机的非操作系统的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存;内存交换模块,用于将所述可交换内存中的数据存放到非易失性存储器。
该设备可通过各功能模块实现如第一方面任意实施例所描述的方法。
第四方面,本申请实施例提供了又一种虚拟机内存管理的设备,所述设备包括:可交换内存确定模块,用于从分配给虚拟机的总内存中识别出所述虚拟机的内存;所述总内存包括所述虚拟机的内存和虚拟机监控器的管理内存;所述虚拟机的内存用于存放所述虚拟机的代码和所述虚拟机运行过程中产生的数据,所述虚拟机监控器的管理内存用于存放所述虚拟机监控器管理所述虚拟机所需的数据;所述可交换内存确定模块还用于,从所述总内存中识别出所述虚拟机的内存;内存交换模块,用于将所述虚拟机的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存。
该设备可通过各功能模块实现如第二方面所描述的方法。
第五方面,本申请实施例提供了一种计算机设备,包括:至少一个处理器和存储器;所述处理器和所述存储器通过总线连接或者耦合在一起;所述存储器用于存储一个或多个计算机程序,所述一个或多个计算机程序包括指令;所述处理器用于执行所述一个或多个计算机程序以实现如第一方面任意实施例所描述的方法。
第六方面,本申请实施例提供了又一种计算机设备,包括:至少一个处理器和存储器;所述处理器和所述存储器通过总线连接或者耦合在一起;所述存储器用于存储一个或多个计算机程序,所述一个或多个计算机程序包括指令;所述处理器用于执行所述一个或多个计算机程序以实现如第二方面所描述的方法。
第七方面,本申请实施例提供了计算机可读存储介质,其上储存有指令,所述指令执行时,使得计算机设备的一个或多个处理器执行第一方面或第二方面任何可能实施例的方法。
第八方面,本申请实施例提供了包括程序代码的计算机程序,所述程序代码在计算机设备上运行时执行第一方面或第二方面任何可能实施例的方法。
可以看到,实施本申请实施例,可预先在虚拟机进程内存中识别非关键内存(如非Guest OS内存)作为可交换内存,当物理内存和交换空间中之间需要进行内存交换时,只需要采用非关键内存中的一些内存页的数据进行内存交换,而不需要采用关键内存(例如Hypervisor管理内存或Guest OS内存)进行内存交换,从而大大降低对整个虚拟机进程和虚拟机系统性能造成的影响,保证了在内存压力大的时候规避性能大幅波动和稳定性问题。还可以看到,本申请实施例由于不需要直接对关键内存(例如Hypervisor管理内存、Guest OS内存等)进行识别,所以能够避免由于关键内存的种类类型的多样化、不确定性导致的识别难题。此外,实施本申请实施例有利于通过增加虚拟机数量来提高了内存使用效率,从而大大提升了用户的使用体验。
附图说明
图1是本申请实施例提供的一种应用虚拟化技术的物理主机的系统架构示意图。
图2是本申请实施例提供的一种虚拟机超量提交的场景下发生内存交换的示意图;
图3是本申请实施例提供的一种实现虚拟机内存管理的方法的设备的结构示意图;
图4是本申请实施例提供的一种虚拟机内存管理的方法的流程示意图;
图5是本申请实施例提供的又一种实现虚拟机内存管理的方法的设备的架构示意图;
图6是本申请实施例提供的一种确定可交换内存的逻辑流程示意图;
图7是本申请实施例提供的又一种实现虚拟机内存管理的方法的设备的架构示意图;
图8是本申请实施例提供的又一种虚拟机内存管理的方法的流程示意图;
图9是本申请实施例提供的又一种实现虚拟机内存管理的方法的设备的架构示意图;
图10是本申请实施例提供的又一种虚拟机内存管理的方法的流程示意图;
图11是本申请实施例提供的又一种实现虚拟机内存管理的方法的设备的架构示意图;
图12是本申请实施例提供的又一种虚拟机内存管理的方法的流程示意图;
图13是本申请实施例提供的一种系统的结构示意图。
具体实施方式
下面将基于附图详细描述本申请的各种实施方案。应理解的是,本说明书并非旨在将本申请限制于那些示例性实施方案。相反,本申请旨在不但覆盖这些示例性实施方案,而且覆盖可以包括在由所附权利要求所限定的本申请的精神和范围之内的各种替选方式、修改方式、等同方式以及其它的实施方案。
本申请提供的虚拟机内存管理的方法可应用于物理主机(或称物理主机)。
参见图1,图1示例性地描述本申请实施例中的一种应用虚拟化技术的物理主机100的系统架构示意图,如图1所示,物理主机100包括服务器的硬件、运行于虚拟环境中的一个或多个虚拟机,以及运行在服务器硬件和虚拟机之间的虚拟机监控器(Hypervisor)。其中:
虚拟机(Virtual Machine,VM)是通过软件模拟的具有完整硬件系统功能的、运行在隔离环境中的完整计算机系统。VM又包括客户机操作系统(Guest operating system,Guest OS)和基于Guest OS的应用程序。Guest OS为在VM中运行的操作系统,例如Guest OS可以具体为内核态OS或者用户态OS。如图示中以VM1和VM2为例,VM1和VM2中可分别独立运行各自的Guest OS以及基于Guest OS的应用程序。
Hypervisor又可称为虚拟机管理程序,是一种运行在服务器硬件和虚拟机操作系统之间的中间软件层,可用于管理一个或多个VM,允许多个VM共享服务器硬件,如访问服务器上包括内存、CPU、网卡、磁盘等等在内的所有物理设备,实现对物理硬件的抽象。Hypervisor不但协调着虚拟机对这些硬件资源的共享访问,同时也可在各个虚拟机之间施加防护。
服务器硬件包括服务器的存储资源,存储资源进一步包括易失性存储器和非易失性存储器。易失性存储器用于提供服务器的物理内存(Physical memory),物理内存通常指通过易失性存储器(例如物理内存条)中为Hypervisor、操作系统和各种应用程序提供临时储存的内存空间。物理内存用于存储多个内存段,每个内存段包括多个内存页,本申请实施例中,物理内存的内存页可用于保存Hypervisor、Guest OS以及应用程序对应的代码和数据。
非易失性存储器可用于提供交换空间(Swap space),该交换空间为非易失性存储器中的 一段存储空间(或称为地址空间),交换空间用于存放从物理内存中交换来的数据。也就是说,当物理内存的可用内存不足时,可将物理内存中的部分的存储数据,例如内存页(page)中的数据或者块(block)中的数据或者其他类型的存储单元粒度的数据,存放到非易失性存储器的交换空间上,从而使得物理内存中的这部分内存页或者块(block)或者其他类型的存储单元由于数据的清空而释放出这部分的内存。非易失性存储器提供的交换空间在具体实现场景中例如可以是Swap分区或者页交换文件。
在一些实现中,易失性存储器可以是双倍速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory,DDR SDRAM)或静态随机存储器(Static Random-Access Memory,SRAM)或随机存取存储器(Random Access Memory,RAM)等存储器;非易失性存储器可以是闪存或磁盘等存储器。
下面描述本申请实施例所涉及的虚拟机超量提交和内存交换的概念。
虚拟机超量提交是指在物理主机上启动的所有虚拟机中每个虚拟机被分配的内存的总量之和超过实际物理内存的大小。
举例来说,在一种虚拟机超量提交中,物理内存的大小为100G,在物理主机上启动10个VM,每个VM分配的内存均为20G,那么此时10个虚拟机被分配的内存的总量为200G,超过实际物理内存的大小。
又举例来说,在又一种虚拟机超量提交中,物理内存的大小为100G,在物理主机上启动1个VM,该VM分配的内存为150G,即此时虚拟机规格的总量为150G,超过实际物理内存的大小。
需要说明的是,上述示例仅用于解释概念而非限定。
通过采用虚拟机超量提交技术,可以提高单台物理主机上的虚拟机数量,提高内存使用率,降低内存成本。单台VM的内存可按需分配,不同VM的负载高峰时间可能不同,在绝大多数时间内,物理内存都是充裕的。个别情况下,物理主机上运行的虚拟机的内存需求总量可能超过物理内存,则会触发内存交换。
内存交换是指在物理内存中剩余的可用的内存页达到物理内存规定的阈值时,可把物理内存的一些内存页的数据存放到磁盘上,从而为新的应用需求腾出内存空间。在需要使用该内存页的数据的时候再把该数据调回到物理内存。
其中,物理内存规定的阈值可为物理内存设定剩余的可用内存页与物理内存总内存页之间的比率的阈值。当物理内存规定的水位达到预设阈值时,需要进行内存交换。
例如可将物理内存规定的阈值设为10%,当物理内存剩余可用内存页的比率低至10%时,可将物理内存中的一部分内存页放入磁盘中。
又例如可将物理内存规定阈值设为接近0%(即物理内存处于满负载状态),如图2所示,在一种虚拟机超量提交的场景中,当物理主机上的不同虚拟机(VM1-VMn)实际使用内存量之和达到物理内存的满负载时,可将物理内存中的一部分内存页放入磁盘中,如图2中对VM2进行内存交换,从而将VM2的一部分内存页放入到磁盘的页交换文件中。
需要说明的是,在具体实现中,可根据实际情况进行物理内存规定的阈值的设定,本申请不做具体限定。
由于介质的访问速度差异,对磁盘中的内存页的访问速度要远远慢于对物理内存中的内 存页的访问速度。而现有常规的内存交换方案中,当物理内存不足的时候,通常是把物理内存的一些不活跃的内存交换到磁盘上,在需要使用该内存页的时候,再把该内存交换回物理内存。这样,导致一些对访问速度要求较高的内存页,比如Hypervisor管理内存页、Guest OS的内存页,由于暂时性不活跃等原因而被交换到磁盘上。需要重新访问这部分的内存页时,从磁盘对这部分的内存页进行访问会导致整个虚拟机进程长时间地等待数据访问,导致出现用户业务进程大幅波动的严重性能问题甚至稳定性问题,使得用户体验严重下降。
在一种现有解决方案中,为了避免内存交换导致的对重要进程的内存的影响,采用内存锁定(Memory Lock,mlock)技术,直接在程序代码中调用mlock接口来将内存中的某部分内存(例如Hypervisor管理内存、Guest OS占用的内存、应用程序占用的内存等等)锁定,而不交换到物理磁盘上。mlock是内核实现锁定内存的一种机制,用来将进程使用的部分或全部内存锁定到物理内存。被锁定的内存页被解锁或进程退出前,不会被交换到磁盘。
然而,该方案存在的技术缺陷包括如下:(1)使用该技术时,需要显式的调用mlock接口,但是很多关键内存是动态申请的,无法通过挨个识别再显式调用mlock来锁定;(2)关键内存的类型种类的多样化和不确定性导致其无法一次完全识别清楚,有的关键内存甚至会要运行较长一段时间后才能识别出来,识别效率低下。(3)mlock方式会导致内存无差别的提前全部分配,会破坏超量提交场景下内存按需分配的特性,即使执行munlock操作也无法回收已经分配的内存,从而导致系统中的内存复用率降低。
为了解决现有技术的至少一种技术缺陷,本申请实施例提供了虚拟机内存管理的方法以及相关设备。
参见图3,图3示出了本申请实施例提供的一种实现虚拟机内存管理的方法的设备200的结构示意图。该设备200包括:处理器201、易失性存储器202和非易失性存储器203。在一些实现中,该设备200可以是图1实施例所描述的物理主机100。
处理器201包括一个或者多个通用处理器,其中,通用处理器可以是能够处理电子指令的任何类型的设备,包括中央处理器(Central Processing Unit,CPU)、微处理器、微控制器、主处理器、控制器以及ASIC(Application Specific Integrated Circuit,专用集成电路)等等。处理器201执行各种类型的数字存储指令,例如,处理器201可运行存储在易失性存储器202中的软件或者固件程序。又例如,处理器201能够执行程序或者处理数据,以执行本文讨论的方法的至少一部分。
易失性存储器202用于提供物理内存,物理内存用于存储多个内存页,本申请实施例中,物理内存的内存页可用于保存Hypervisor、Guest OS以及应用程序对应的代码和数据。易失性存储器202还用于存储处理器201在该易失性存储器202中运行各种需求所对应的逻辑代码或指令。
非易失性存储器可用于提供交换空间,该交换空间用于实现与物理内存的内存交换功能,并存储由物理内存交换过来的多个内存页。
在一些可能的实现中,易失性存储器202可以是DDR、SDRAM或SRAM等易失性存储器;非易失性存储器203可以是闪存或磁盘等非易失性存储器。
本申请实施例中,当易失性存储器202的物理内存和非易失性存储器的交换空间之间需要进行内存交换时,处理器201将选定的内存页在物理内存和交换空间中实现页交换。具体 的,处理器(CPU)201可执行如图4所示的虚拟机内存管理方法,包括但不限于以下步骤:
通过S301,从分配给虚拟机的总内存中识别出虚拟机的非操作系统内存。
具体的,分配给VM的总内存包括VM的内存和虚拟机监控器(Hypervisor)的内存。由于Hypervisor用于协调虚拟机对内存、CPU、网卡、磁盘等这些硬件资源的共享访问,而虚拟机启动时每个虚拟机都有对应的数据结构、缓存等数据需要存储,所以要创建虚拟机时,需分配VM的内存和Hypervisor的管理内存。虚拟机的内存用于存放虚拟机的代码和数据,Hypervisor的管理内存用于存放Hypervisor管理虚拟机运行的数据。Hypervisor的管理内存中存放的数据例如可以是描述各种硬件设备(比如CPU、内存、网卡、磁盘、显卡等设备)的数据结构、每个硬件设备各自的管理信息。以CPU(即central processing unit,中央处理器)为例,其管理信息里面会记录包括CPU的数量、模拟的CPU硬件架构描述等信息。Hypervisor的管理内存中存放的数据例如还可以是显示用缓存,输入输出(Input/Output,IO)用缓存等缓存数据。
VM的内存进一步包括VM的操作系统的内存和VM的非操作系统的内存;虚拟机的操作系统的内存用于存放虚拟机的操作系统的代码和数据;VM的非操作系统的内存表示VM的内存中,除VM的操作系统的内存之外剩余的内存。
虚拟机的操作系统的内存用于存放所述虚拟机的操作系统的代码和数据,其中,虚拟机操作系统的内存存放的数据例如可以是编译库、应用程序运行需要的堆栈数据、Guest OS内核模块运行时需要的数据,等等。
虚拟机的非操作系统的内存例如可用于存放运行在Guest OS上的各种应用程序的相关代码和数据。应用程序的具体数据例如可以包括数据库程序的加载到内存中的数据、文字处理程序打开的文件数据,等等。
也就是说,在虚拟机启动时,物理主机的操作系统(Host OS)会给该虚拟机分配虚拟机的内存规格(即总内存),该内存规格表示允许该虚拟机申请使用的总内存大小。该内存规格涵盖了虚拟机的内存和Hypervisor的管理内存,虚拟机的内存为提供给虚拟机申请使用的内存大小,Hypervisor的管理内存为提供给Hypervisor申请使用的内存大小。虚拟机的内存涵盖了虚拟机的操作系统的内存和虚拟机的非操作系统的内存。本文中,虚拟机的操作系统又可称为客户机操作系统(Guest operating system,Guest OS),Guest OS的内存为提供给Guest OS自身申请使用的内存大小。相应的,本文中虚拟机的非操作系统可相应称为非Guest OS,非Guest OS的内存为虚拟机的内存除Guest OS的内存之外剩余的内存。
为了便于描述,本文中也将分配给VM的总内存简称为“虚拟机进程内存”,将Hypervisor的管理内存简称为“Hypervisor管理内存”,将虚拟机的内存简称为“虚拟机内存”,将虚拟机的操作系统的内存简称为“Guest OS内存”,将虚拟机的非操作系统的内存称为“非Guest OS内存”或者称为虚拟机常规(Virtual Machine Normal,VM-Normal)内存。
也就是说,虚拟机进程内存涵盖了Hypervisor管理内存和虚拟机内存,虚拟机的内存涵盖了虚拟机的操作系统的内存和虚拟机的非操作系统的内存。通过步骤S301,可实现从总内存(虚拟机进程内存)中识别出非Guest OS内存,也就是将非Guest OS内存与其他内存(如例如Hypervisor管理内存、Guest OS内存)区分出来。
通过S302,将VM的非操作系统的内存作为可交换内存。
由于Hypervisor管理内存和GUEST OS内存对访问速度要求较高,容易对整个虚拟机进程和虚拟机系统性能造成显著影响,而VM-Normal内存对虚拟机进程和虚拟机系统性能的影 响相对较小,所以本申请实施例中,可将VM-Normal内存确定为可交换内存。可交换内存表示允许进行内存交换的内存。
通过S303,将所述可交换内存中的数据存放到非易失性存储器。
在物理内存剩余可用内存页达到物理内存规定的水位(即物理内存使用紧张,或称物理内存不足)时,根据该可交换内存进行内存交换,即将可交换内存中的部分或全部数据存放到非易失性存储器的交换空间。其中,物理内存规定的水位表示物理内存设定剩余的可用内存页与物理内存总内存页之间的比率。当物理内存规定的水位达到预设阈值时,需要进行内存交换。
也就是说,实施本申请实施例的方法,只需要预先在虚拟机进程内存中识别VM-Normal作为可交换内存,当物理内存和交换空间中之间需要进行内存交换时,只需要采用VM-Normal内存中的一些内存页进行内存交换,而不需要采用Hypervisor管理内存或Guest OS内存进行内存交换,从而大大降低对整个虚拟机进程和虚拟机系统性能造成的影响,保证了在内存压力大的时候规避性能大幅波动和稳定性问题。还可以看到,本申请实施例由于不需要直接对关键内存(Hypervisor管理内存、Guest OS内存等)进行识别,所以能够避免由于关键内存的种类类型的多样化、不确定性导致的识别难题,而通过对VM-Normal内存进行识别能够提高识别效率。此外,实施本申请的方法不会对超量提交场景下内存按需分配的特性造成影响,有利于通过进一步增加虚拟机数量来提高了虚拟机系统中的内存复用率,从而大大提升了用户的使用体验。
在本申请实施例的一种实施方式中,可以通过在物理主机的Hypervisor内核中增加新的软件代码模块以及在VM的操作系统(Guest OS)上增加新的软件代码模块来实现本申请的方案。
请综合参见图5和图6,在一种实现方案中,可在图1描述的物理主机100的系统架构基础上,在Hypervisor中设置虚拟机进程内存分配模块101、可交换内存确定模块102和内存交换模块103,虚拟机进程内存分配模块101用于确定分配给VM的内存,可交换内存确定模块102用于将分配给VM的内存中VM的非操作系统的内存识别出来并作为可交换内存;内存交换模块103用于,在分配给VM的内存对应的内存页需要进行内存交换的情况下,根据该可交换内存进行内存交换,即将可交换内存中的部分或全部数据存放到非易失性存储器。
具体的,Hypervisor中的可交换内存确定模块102可进一步包括虚拟机内存识别模块1021和非操作系统内存识别模块1022(或称非GuestOS内存识别模块1022)。在各个VM的GuestOS中还分别设置有GuestOS内存识别模块104。
虚拟机内存识别模块1021用于从分配给VM的虚拟机进程内存中识别出虚拟机内存。
具体的,虚拟机内存识别模块1021会对分配的虚拟机进程内存进行识别,区分出虚拟机自身的内存,即虚拟机内存,并为虚拟机内存对应的内存页增加标记信息,即此时GuestOS内存和VM-Normal内存均标记有标记信息,标记信息作为可交换内存的标记;那么剩下的没有标记的内存,即Hypervisor管理内存属于为关键内存,不可发生内存交换,从而保护Hypervisor内存。
本申请实施例中的标记信息例如可以是标识位、标签、标识码等标记,本申请不做限定。
非GuestOS内存识别模块1022用于从虚拟机内存中,进一步识别出VM-Normal内存作为可交换内存,可发生内存交换,而GuestOS内存不可发生内存交换。
具体的,GuestOS中的GuestOS内存识别模块104会识别出GuestOS内部当前可申请使用的空闲内存,并通知给Hypervisor中的非GuestOS内存识别模块1022。非GuestOS内存识别模块1022将这些空闲内存进一步确定为VM-Normal内存,那么虚拟机内存中剩下的无法被申请的内存即为GuestOS内存。非GuestOS内存识别模块1022进一步删除GuestOS内存的标记信息,而保留VM-Normal内存的标记信息,也就是只将VM-Normal内存作为可交换内存,可发生内存交换;而此时GuestOS内存则属于为关键内存,不可发生内存交换,从而保护GuestOS内存。
这样,后续当物理内存不足,需要进行内存交换时,内存交换模块103即可根据标记有标记信息的VM-Normal内存的内存页进行内存交换的操作。
可以看到,实施本申请实施例,可通过可交换内存确定模块102来识别出最终可用于页交换的内存(即VM-Normal内存)并增加标记信息,虚拟机系统根据该标记信息进行选择性交换,即在系统物理内存不足时,只有带标记信息的内存段才有可能被交换到磁盘;没有标记信息的内存段不允许交换到磁盘,从而保证关键内存(Hypervisor内存和GuestOS内存)不被交换,保障虚拟机的性能,有利于通过进一步增加虚拟机数量来提高了虚拟机系统中的内存复用率,从而大大提升了用户的使用体验。
下面以虚拟机启动阶段和虚拟机运行时内存分配交换阶段为例,对本申请方案的具体实现过程进行进一步详述。
参见图7,在一种更具体的实施例中,在图5所描述的系统架构基础上,在物理主机100的Hypervisor中还可进一步设置虚拟机初始化模块110。在一些实施例中,处理器(CPU)可运行Hypervisor中上述虚拟机初始化模块110、虚拟机进程内存分配模块101、虚拟机内存识别模块1021、非GuestOS内存识别模块1022,以及VM的GuestOS中的GuestOS内存识别模块,以执行如图8所示的虚拟机内存管理方法,该方法发生在虚拟机的启动阶段,包括但不限于以下步骤:
在S401,通过虚拟机初始化模块110创建初始化虚拟机进程。
在S402,初始化模块会调用虚拟机进程内存分配模块101,通过该虚拟机进程内存分配模块101为虚拟机进程分配所需内存,即本申请实施例描述的虚拟机进程内存。由于Hypervisor用于协调虚拟机对内存、CPU、网卡、磁盘等这些硬件资源的共享访问,而虚拟机启动时每个虚拟机都有对应的数据结构、缓存等数据需要存储,所以要创建虚拟机时,需分配虚拟机内存和Hypervisor管理内存。即虚拟机进程内存包括Hypervisor管理内存和虚拟机内存。
在S403,通过虚拟机内存识别模块1021对所分配的虚拟机进程内存进行识别,从而区分出虚拟机内存,并为虚拟机内存增加标记信息,这里的标记信息暂时作为可交换内存的标记。
例如,虚拟机启动时初始化模块110会调用虚拟机进程内存分配模块101为虚拟机进程分配所需内存。虚拟机初始化时,所有内存都不带可交换内存标记。虚拟机内存识别模块1021会在内存分配流程中增加了一个内存过滤器,内存过滤器具体可以是一种内存过滤算法。内存过滤器确定分配给VM的内存中的不同内存段的内存用途;内存用途的种类包括供所述VM使用的用途和供所述hypervisor使用的用途;内存过滤器会根据内存用途对这些内存段进行分类,将内存用途为供VM使用的用途的所有内存段识别为所述虚拟机内存。以QEMU为例, QEMU是一套由法布里斯·贝拉(Fabrice Bellard)所编写的以通用性公开许可证(General Public License,GPL分发源码的模拟处理器,QEMU模拟了多种内存设备:设备内存模块(pc.ram)、内存直插式存储模块(memdimm)、内存节点(ram-node)。这几种内存设备都可能配置实际的内存段并提供给虚拟机自身使用,因此内存过滤器把这几种内存设备配置的内存段都识别为虚拟机内存。进一步的,虚拟机内存识别模块1021通过madvise(madvise表示一种系统调用接口)为识别出的虚拟机内存打上可交换的标记,即标记信息。那么剩下的没有标记的内存则为关键内存,即属于hypervisor管理内存,不可发生交换。这样就实现了hypervisor管理内存和虚拟机内存的区分。
这样,虚拟机内存中的GuestOS内存和VM-Normal内存对应的内存页均被标记了标记信息。标记信息例如可以是标识位、标签、标识码等标记,本申请不做限定。
虚拟机进程内存中,除虚拟机内存外剩下的内存则为Hypervisor管理内存,该Hypervisor管理内存没有标记信息,即该Hypervisor管理内存属于不可交换内存。所以,通过S403既可快捷实现对Hypervisor管理内存和虚拟机内存的区别,提高识别效率,又可实现对Hypervisor管理内存的保护,避免Hypervisor管理内存后续被交换出去。
在S404,虚拟机初始化完成,并且VM的GuestOS完成启动后,可通过GuestOS中的GuestOS内存识别模块104,在GuestOS内部查询内存使用情况,尝试进行空闲内存申请,识别出GuestOS内部当前可申请使用的空闲内存,获得所有空闲内存的内存地址。空闲内存表示虚拟机内存中,尚未与物理内存中的内存页建立起映射关系(即尚未实际分配内存页)的内存。GuestOS内存识别模块104将空闲内存的内存地址通知给Hypervisor中的非GuestOS内存识别模块1022。通过非GuestOS内存识别模块1022将这些空闲内存确定为VM-Normal内存,并保留VM-Normal内存的标记信息,则VM-Normal内存作为可交换内存。那么,虚拟机内存中,除VM-Normal内存外剩下的内存则为GuestOS内存,即虚拟机内存中剩下的无法被申请的内存为GuestOS内存,实现虚拟机内存中GuestOS内存和VM-Normal内存的分类。通过非GuestOS内存识别模块1022将GuestOS内存的标记信息去除,从而使GuestOS内存变成不可交换内存。
所以,通过S404既可快捷实现对GuestOS内存和VM-Normal内存的区别,提高识别效率,又可实现对GuestOS内存的保护,避免GuestOS内存后续被交换出去。
可以看到,实施本申请实施例,可以在虚拟机的启动阶段,识别出最终可用于页交换的内存(即VM-Normal内存)并保留作为可交换标记的标记信息,从而区分出了可交换内存和不可交换内存。系统在物理内存不足时,只有带标记信息的可交换内存才有可能被交换到磁盘;没有标记信息的不可交换内存将不会被交换到磁盘,从而保证关键内存(Hypervisor内存和GuestOS内存)不被交换,从而保证了在内存压力大的时候规避虚拟机长时间的数据等待,从而规避性能大幅波动和稳定性问题,保障了虚拟机的性能。还有利于通过进一步增加虚拟机数量来提高了虚拟机系统中的内存复用率,大大提升了用户的使用体验。
参见图9,在一种更具体的实施例中,在图5或图7所描述的系统架构基础上,在物理主机100的Hypervisor中还可进一步设置内存管理模块106、关键内存延迟回收模块107和内存回收模块108,其中,内存回收模块108具体可包括关键内存过滤模块109和内存交换模块103。在一些实施例中,处理器(CPU)可运行Hypervisor中上述内存管理模块106、关键内存延迟回收模块107和内存回收模块108,以执行如图10所示的虚拟机内存管理方法, 该方法发生在虚拟机的运行阶段,包括但不限于以下步骤:
在S501,内存管理模块106检测到虚拟机当前需要申请实际分配物理内存。
物理主机的操作系统通常通过动态分配物理内存的方式为虚拟机分配实际的物理内存。也就是说,在虚拟机启动阶段,物理主机的操作系统为虚拟机分配了虚拟机进程内存,虚拟机进程内存可以认为是一种虚拟机内存规格或者虚拟的内存,也就是说,操作系统并没有真正在所有的虚拟机进程内存和物理内存中的页面之间建立映射关系。例如虚拟机进程内存为4G,并不意味着虚拟机启动后就在物理内存中实际划分了4G容量给该虚拟机。当虚拟机运行中实际需要使内存时,操作系统再根据虚拟机的申请实际去为虚拟机分配真正的物理内存页。
例如,在一些场景中,内存管理模块106可基于以下事件中的至少一种来确定虚拟机当前需要申请分配新的内存:虚拟机进程中的Hypervisor管理模块会申请新的管理内存;或者,VM的GuestOS的内核需要访问未实际分配物理内存的虚拟机内存;或者,VM的GuestOS中的应用程序需要访问未实际分配物理内存的虚拟机内存,等等。从而,触发S502执行虚拟机内存分配。
在S502,内存管理模块106执行给虚拟机分配新的物理内存页的过程。
在S503,内存管理模块106判断当前分配新的物理内存的内存类型是否为关键内存,例如,若当前分配新的物理内存属于Hypervisor内存或者GuestOS内存,则当前分配新的物理内存是关键内存,后续将触发执行步骤S505;若当前分配新的物理内存属于VM-Normal内存,则当前分配新的物理内存不是关键内存,后续将触发执行步骤S504。
在S504,在内存不足或内存紧张时,通过内存回收模块108,对本次物理内存分配触发内存回收操作,以使物理内存中释放出空闲的物理页以便于内存实际分配。
通常来说,当物理内存紧张时,为了给新的物理内存申请提供足够的内存,虚拟机系统会触发内存回收操作。内存回收的方式有内存交换、内存页丢弃等方式。
对于内存交换,内存回收模块108会筛选出一些内存页,将这些内存页的数据放入到磁盘的交换空间中,从而使这些内存页腾出存储空间以便于重新分配。
具体的,内存回收模块108中的关键内存过滤模块109会对内存回收流程中获取的内存页进行过滤,只允许有标记信息(可交换内存标记)的内存页进行内存交换。然后,通过内存交换模块103,将筛选出来的内存交换到磁盘的交换空间,从而释放出物理内存空间。基于前文的描述可知,发生内存交换的只能是VM-Normal内存对应的一些内存页。通过内存回收的方法可以优化内存占用,提高虚拟机系统的运行性能。
在S505,通过关键内存延迟回收模块107,对本次物理内存分配不触发内存回收。
由于内存回收操作耗时很长,会导致内存申请操作时间过长,即新的内容分配缓慢,容易导致系统出现稳定性问题和性能问题。例如,对于Hypervisor管理模块申请的新的管理内存,如果等待内存回收完成,则会对全局性能造成较大影响,甚至会导致严重的稳定性问题。
本申请实施例中,通过关键内存延迟回收模块107,可允许虚拟机能临时突破内存规格约束获取少量内存,以完成新的物理内存的分配,且本次物理内存分配不触发内存回收。从而,有利于加快对关键内存的新内存页的分配速度,保障系统的稳定性和性能。
举例来说,在物理内存(例如100G)中,可额外设置小量的可用内存空间(100M)作为缓存,当遇到需要对关键内存延迟回收的情况时,可允许虚拟机临时突破内存规格约束,在100M的缓存中获取适量的内存空间进行物理内存分配。
需要说明的是,上述示例仅用于解释本申请而非限定。
可以看到,实施本申请实施例,对于虚拟机运行阶段,在申请新的物理内存分配时,可让关键内存(例如Hypervisor内存或者GuestOS内存)和非关键内存(例如VM-Normal内存)在内存回收上进行区别处理。针对非关键内存可触发内存回收操作,以优化内存占用,提高虚拟机系统的运行性能。针对关键内存,在分配物理内存时不触发内存回收操作(即允许关键内存延迟触发内存回收),从而提升内存分配速度,在内存紧张的时候避免了管理内存被交换而导致性能波动问题,提高系统可靠性和稳定性,保障用户使用体验。
为了更好理解本申请方案,下面以虚拟机超量提交(或称为内存超量提交)的云计算场景为例进行方案的说明。通过内存超量提交,每台物理主机上的虚拟化平台可创建更多的VM,提升物理主机内存资源利用率,降低内存成本。本申请方案可以保证虚拟机的内存在发生内存交换时的虚拟机性能和可靠性。
参见图11,本申请实施例的方案可以在图5或图7或图9所描述的系统架构基础上实现。如图11所示,在物理主机的Hypervisor中可同时设置虚拟机初始化模块110、虚拟机进程内存分配模块101、虚拟机内存识别模块1021、非GuestOS内存识别模块1022,以及内存管理模块106、关键内存延迟回收模块107和内存回收模块108,内存回收模块108具体可包括关键内存过滤模块109和内存交换模块103。此外,在各个VM的GuestOS中设置GuestOS内存识别模块。在云计算场景下,可以通过软件接口动态配置虚拟机超量提交,并在虚拟机超量提交场景下实现性能和可靠性保障。在一些实施例中,处理器(CPU)可运行Hypervisor和VM中的上述各个功能模块,以执行如图12所示的虚拟机内存管理方法,包括但不限于以下步骤:
在S601,通过功能开关配置虚拟机的超量提交功能。
在一具体实现中,只有可打开该功能开关后,才能允许所有虚拟机的内存规格之和超过物理主机的物理内存的大小,从而实现内存的超量提交。举例来说,在一种虚拟机超量提交中,物理内存的大小为100G,打开该功能开关后,可在物理主机上启动10个VM,每个VM分配的内存均为20G,那么此时虚拟机规格的总量为200G,超过实际物理内存的大小。
需要说明的是,上述示例仅用于解释概念而非限定。
在S602、内存超量提交打开后,虚拟机启动时,虚拟机初始化模块110会调用虚拟机进程内存分配模块101,通过虚拟机进程内存分配模块101为虚拟机进程分配所需内存,即虚拟机进程内存。
在S603、通过虚拟机内存识别模块1021,可把虚拟机进程内存识别成两类:虚拟机内存和Hypervisor管理内存。
对虚拟机内存增加标记信息,标记信息作为可交换内存的标记。这样,虚拟机内存中的GuestOS内存和VM-Normal内存对应的内存页均被标记了标记信息。标记信息例如可以是标识位、标签、标识码等标记,本申请不做限定。
而对Hypervisor管理内存则没有标记信息,即该Hypervisor管理内存属于不可交换内存,实现对Hypervisor管理内存的保护,避免Hypervisor管理内存后续被交换出去。
在一种实现中,虚拟机初始化时,可设置所有内存页都不带标记信息。虚拟机内存识别模块1021会对分配的虚拟机内存进行识别。具体可参考前述步骤S403的描述,这里不再赘述。
在S604,识别VM-Normal内存,保留VM-Normal内存的标记信息,删除GuestOS内存的 标记信息。
具体的,可通过Hypervisor中的非GuestOS内存识别模块1022和GuestOS中的GuestOS内存识别模块相互配合,可把虚拟机内存进一步区分成两类:VM-Normal内存和GuestOS内存。将GuestOS内存的标记信息去除,从而使得GuestOS内存不可发生页交换。而VM-Normal内存的标记信息继续保留,也就是说将VM-Normal内存作为可交换内存。具体可参考前述步骤S404的描述,这里不再赘述。
在S605,在虚拟机的运行阶段,当物理内存不足,需要进行内存交换的情况下,根据可交换内存进行内存交换。
具体的,在物理内存紧张需要发生交换时,需要将具有标记信息的VM-Normal内存的一些内存页与交换空间进行内存交换,例如将这一些内存交换到磁盘。而不带有标记信息的关键内存则不会发生内存交换。
在一种示例中,物理内存紧张指物理内存中剩余的可用内存页与物理内存总内存页之间的比率达到或超过预设阈值,例如可将预设阈值设为5%,10%,20%等等,本申请不做限定。
在又一种示例中,物理内存紧张指物理内存处于满负载状态,此时物理内存中已没有或者接近于没有空闲的内存页来存储信息。
在S606,在虚拟机的运行阶段,根据所设置的标记信息执行内存分配和内存回收策略。
具体的,通过内存管理模块106、关键内存延迟回收模块107和内存回收模块108的互相配合,可实现在物理内存紧张时,不带标记信息的关键内存(例如Hypervisor内存或者GuestOS内存)触发的内存分配会被立刻执行,而不会触发内存回收;而带有标记信息的非关键内存(例如VM-Normal内存)触发的内存分配的同时也会触发内存回收,待执行内存回收后才完成内存分配。具体实现过程可参考前述步骤S502-S505的相关描述,这里不再赘述。
可以看到,实施本申请实施例,在虚拟机超量提交的云计算场景中,可以在虚拟机的启动阶段,识别出非关键内存(即VM-Normal内存)并保留作为可交换标记的标记信息,剩下的内存则为关键内存,关键内存不带有标记信息。后续只允许非关键内存发生内存交换,即系统在物理内存不足时,只有带标记信息的非关键内存才有可能被交换到磁盘;没有标记信息的关键内存将不会被交换到磁盘,从而保证关键内存(Hypervisor内存和GuestOS内存)不被交换,从而保证了在内存压力大的时候规避虚拟机长时间的数据等待,从而规避性能大幅波动和稳定性问题,保障了虚拟机的性能。通过修改内存回收流程,允许关键内存延迟触发内存回收,可以加快关键内存分配速度,保证系统的稳定性和可靠性。此外,实施本申请能够实现通过增加虚拟机数量以及虚拟机规格来显著提高虚拟机系统中的内存复用率,降低内存成本,大大提升了用户的使用体验,具有较大的商业价值。
需要说明的是,对于上文描述的各方法实施例,为了方便起见,将其都表述为一系列的动作步骤的组合,但是本领域技术人员应该知悉,本申请技术方案的具体实现并不受所描述的一系列的动作步骤的顺序的限制。
请参见图13,图13是本申请实施例提供的一种系统的结构示意图。系统包括一个或者多个计算设备70,每个计算设备70包括处理器701、第一存储器702、第二存储器703和通信接口503,处理器701、第一存储器702、第二存储器703和通信接口503通过总线504连接。其中:
第一存储器702的数量为一个或多个,第一存储器702用于提供物理内存,第一存储器702可以是DDR SDRAM或SRAM或RAM等易失性存储器(Volatile Memory)。
第二存储器703的数量为一个或多个,第二存储器703用于提供交换空间,以实现第一存储器702的物理内存和该交换空间之间的内存交换。第二存储器703可以是只读存储器(Read-Only Memory,ROM)、快闪存储器(Flash Memory)、硬盘(Hard Disk Drive,HDD)或固态硬盘(Solid-State Drive,SSD)、磁盘等非易失性存储器。
第一存储器702和/或第二存储器703还可用于存储一组程序代码,以便于处理器701调用该程序代码以实现上文实施例描述的虚拟机内存管理方法。
具体实现中,前述图5或图7或图9或图11中所描述的各个功能模块的代码指令和相关数据可能保存在不同的计算设备70的存储器上,也可能保存在同一计算设备70的相同存储器上,也可能保存在相同计算设备的不同存储器(例如第一存储器702和第二存储器703)上。
处理器701可以由一个或者多个通用处理器构成,例如中央处理器(Central Processing Unit,CPU)。处理器701可用于运行前述图5或图7或图9或图11中所描述的各个功能模块的代码指令和相关数据。也就是说,处理器701执行程序代码可以实现前述图5或图7或图9或图11中所描述的各个功能模块的具体功能,实现本申请实施例的虚拟机内存管理方法。
可选的,该系统还包括通信接口503,通信接口503可以为有线接口(例如以太网接口)或无线接口(例如蜂窝网络接口或使用无线局域网接口),用于与终端或服务器进行通信,以便于为用户提供相关的虚拟机服务。
实际应用中,该系统还可以包括更多或更少的部件,这里不作限制。该系统的不同器件的具体功能以及实现过程可参考前文的描述,这里不再赘述。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者任意组合来实现。当使用软件实现时,可以全部或者部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令,在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络或其他可编程装置。所述计算机指令可存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网络站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线)或无线(例如红外、微波等)方式向另一个网络站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质,也可以是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如软盘、硬盘、磁带等)、光介质(例如DVD等)、或者半导体介质(例如固态硬盘)等等。
在上述实施例中,对各个实施例的描述各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。

Claims (21)

  1. 一种虚拟机内存管理的方法,其特征在于,所述方法包括:
    从分配给虚拟机的总内存中识别出所述虚拟机的非操作系统内存;所述总内存包括所述虚拟机的内存和虚拟机监控器的管理内存;所述虚拟机的内存包括所述虚拟机的操作系统的内存和所述虚拟机的非操作系统的内存;
    将所述虚拟机的非操作系统的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存;
    将所述可交换内存中的数据存放到非易失性存储器。
  2. 根据权利要求1所述的方法,其特征在于,所述从分配给虚拟机的总内存中识别出所述虚拟机的非操作系统的内存,包括:
    从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存;
    从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存。
  3. 根据权利要求2所述的方法,其特征在于,所述从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存之后,还包括:
    对所述虚拟机的操作系统的内存和所述虚拟机的非操作系统的内存均增加标记信息;所述标记信息表示允许被标记的内存中的数据进行所述内存交换;
    相应的,所述从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存,包括:
    从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存;删除所述虚拟机的操作系统的内存的标记信息,同时保留所述虚拟机的非操作系统的内存的标记信息;
    相应的,所述将所述可交换内存中的数据存放到非易失性存储器,包括:
    将所述具有所述标记信息的内存中的数据存放到非易失性存储器。
  4. 根据权利要求2或3所述的方法,其特征在于,所述从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存,包括:
    确定所述分配给所述虚拟机的总内存中的不同内存段的内存用途;所述内存用途包括供所述虚拟机使用和供所述虚拟机监控器使用;
    将供所述虚拟机使用的所有内存段作为所述虚拟机的内存。
  5. 根据权利要求2-4任一项所述的方法,其特征在于,所述从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存,包括:
    申请所述虚拟机的内存中的空闲内存,获得所有空闲内存的内存地址;
    将所述所有空闲内存的内存地址对应的内存作为所述虚拟机的非操作系统的内存,并用作所述可交换内存。
  6. 根据权利要求2-5任一项所述的方法,其特征在于,
    所述从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存,包括:
    在所述虚拟机的启动阶段,从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的 内存;
    所述从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存,包括:
    在所述虚拟机启动后的运行阶段,从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存。
  7. 根据权利要求1-6任一项所述的方法,其特征在于,所述将所述可交换内存中的数据存放到非易失性存储器,包括:
    当所述虚拟机所在物理主机的物理内存处于满负载状态时,将所述可交换内存中的数据存放到非易失性存储器;所述满负载状态表示所述物理内存无空闲空间存储新的内存页。
  8. 根据权利要求1-6任一项所述的方法,其特征在于,所述将所述可交换内存中的数据存放到非易失性存储器,包括:
    当所述虚拟机所在物理主机的物理内存中剩余可用的内存页与所述物理内存总内存页之间的比率达到预设阈值时,将所述可交换内存中的数据存放到非易失性存储器。
  9. 根据权利要求1-8任一项所述的方法,其特征在于,所述方法还包括:
    在所述虚拟机申请分配内存时,确定所述申请分配的内存的内存类型;
    当内存类型属于所述虚拟机监控器的管理内存或所述虚拟机的操作系统的内存时,不触发内存回收;
    当内存类型属于所述虚拟机的非操作系统的内存时,触发内存回收。
  10. 一种虚拟机内存管理的方法,其特征在于,所述方法包括:
    从分配给虚拟机的总内存中识别出所述虚拟机的内存;所述虚拟机的内存用于存放所述虚拟机的代码和所述虚拟机运行过程中产生的数据;
    将所述虚拟机的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存;
    将所述可交换内存中的数据存放到非易失性存储器。
  11. 一种用于虚拟机内存管理的设备,其特征在于,所述设备包括:
    可交换内存确定模块,用于从分配给虚拟机的总内存中识别出所述虚拟机的非操作系统内存;所述总内存包括所述虚拟机的内存和虚拟机监控器的管理内存;所述虚拟机的内存包括所述虚拟机的操作系统的内存和所述虚拟机的非操作系统的内存;
    所述可交换内存确定模块还用于,将所述虚拟机的非操作系统的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存;
    内存交换模块,用于将所述可交换内存中的数据存放到非易失性存储器。
  12. 根据权利要求11所述的设备,其特征在于,所述可交换内存确定模块包括虚拟机内存识别模块和非操作系统内存识别模块;
    所述虚拟机内存识别模块用于,从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存;
    所述非操作系统内存识别模块用于,从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存。
  13. 根据权利要求12所述的设备,其特征在于,
    所述虚拟机内存识别模块还用于,对所述虚拟机的操作系统的内存和所述虚拟机的非操作系统的内存均增加标记信息;所述标记信息表示允许被标记的内存中的数据进行所述内存交换;
    所述非操作系统内存识别模块具体用于,从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存;删除所述虚拟机的操作系统的内存的标记信息,同时保留所述虚拟机的非操作系统的内存的标记信息;
    所述内存交换模块具体用于,将所述具有所述标记信息的内存中的数据存放到非易失性存储器。
  14. 根据权利要求12或13所述的设备,其特征在于,所述虚拟机内存识别模块具体用于:
    确定所述分配给所述虚拟机的总内存中的不同内存段的内存用途;所述内存用途包括供所述虚拟机使用和供所述虚拟机监控器使用;
    将供所述虚拟机使用的所有内存段作为所述虚拟机的内存。
  15. 根据权利要求12-14任一项所述的设备,其特征在于,所述非操作系统内存识别模块具体用于:
    申请所述虚拟机的内存中的空闲内存,获得所有空闲内存的内存地址;
    将所述所有空闲内存的内存地址对应的内存作为所述虚拟机的非操作系统的内存,并用作所述可交换内存。
  16. 根据权利要求12-15任一项所述的设备,其特征在于,
    所述虚拟机内存识别模块具体用于,在所述虚拟机的启动阶段,从所述分配给所述虚拟机的总内存中,识别出所述虚拟机的内存;
    所述非操作系统内存识别模块具体用于,在所述虚拟机启动后的运行阶段,从所述虚拟机的内存中,识别出所述虚拟机的非操作系统的内存作为所述可交换内存。
  17. 根据权利要求11-16任一项所述的设备,其特征在于,
    所述内存交换模块具体用于,当所述虚拟机所在物理主机的物理内存处于满负载状态时,将所述可交换内存中的数据存放到非易失性存储器;所述满负载状态表示所述物理内存无空闲空间存储新的内存页。
  18. 根据权利要求11-16任一项所述的设备,其特征在于,
    所述内存交换模块具体用于,当所述虚拟机所在物理主机的物理内存中剩余可用的内存页与所述物理内存总内存页之间的比率达到预设阈值时,将所述可交换内存中的数据存放到非易失性存储器。
  19. 根据权利要求11-18任一项所述的设备,其特征在于,所述设备还包括内存管理模块、关键内存延迟回收模块和内存回收模块:
    所述内存管理模块用于,在所述虚拟机申请分配内存时,确定所述申请分配的内存的内存类型;
    所述关键内存延迟回收模块用于,当内存类型属于所述虚拟机监控器的管理内存或所述虚拟机的操作系统的内存时,不触发内存回收;
    所述内存回收模块用于,当内存类型属于所述虚拟机的非操作系统的内存时,触发内存回收。
  20. 一种虚拟机内存管理的设备,其特征在于,所述设备包括:
    可交换内存确定模块,用于从分配给虚拟机的总内存中识别出所述虚拟机的内存;所述虚拟机的内存用于存放所述虚拟机的代码和所述虚拟机运行过程中产生的数据;
    所述可交换内存确定模块还用于,从所述总内存中识别出所述虚拟机的内存;
    内存交换模块,用于将所述虚拟机的内存作为可交换内存;所述可交换内存表示允许进行内存交换的内存。
  21. 一种计算机设备,其特征在于,包括:至少一个处理器和存储器;所述处理器和所述存储器通过总线连接或者耦合在一起;所述存储器用于存储一个或多个计算机程序,所述一个或多个计算机程序包括指令;所述处理器用于执行所述一个或多个计算机程序以实现如权利要求1-9的任一项所描述的方法或者如权利要求10所描述的方法。
PCT/CN2020/114446 2019-09-29 2020-09-10 虚拟机内存管理的方法及设备 WO2021057489A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP20870358.7A EP4030289A4 (en) 2019-09-29 2020-09-10 VIRTUAL MACHINE MEMORY MANAGEMENT METHOD AND DEVICE
US17/656,699 US20220214907A1 (en) 2019-09-29 2022-03-28 Virtual machine memory management method and device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910953083.9 2019-09-29
CN201910953083.9A CN112579251B (zh) 2019-09-29 2019-09-29 虚拟机内存管理的方法及设备

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/656,699 Continuation US20220214907A1 (en) 2019-09-29 2022-03-28 Virtual machine memory management method and device

Publications (1)

Publication Number Publication Date
WO2021057489A1 true WO2021057489A1 (zh) 2021-04-01

Family

ID=75116961

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/114446 WO2021057489A1 (zh) 2019-09-29 2020-09-10 虚拟机内存管理的方法及设备

Country Status (4)

Country Link
US (1) US20220214907A1 (zh)
EP (1) EP4030289A4 (zh)
CN (1) CN112579251B (zh)
WO (1) WO2021057489A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023152284A1 (de) * 2022-02-11 2023-08-17 Robert Bosch Gmbh Verfahren zur bereitstellung eines zugangspunkts zur messung und kalibrierung einer oder mehrerer funktionen einer recheneinheit
WO2023172319A1 (en) * 2022-03-11 2023-09-14 Microsoft Technology Licensing, Llc Direct swap caching with noisy neighbor mitigation and dynamic address range assignment
US11860783B2 (en) 2022-03-11 2024-01-02 Microsoft Technology Licensing, Llc Direct swap caching with noisy neighbor mitigation and dynamic address range assignment

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113485791B (zh) * 2021-07-07 2022-06-03 上海壁仞智能科技有限公司 配置方法和访问方法、装置、虚拟化系统和存储介质
CN115344226B (zh) * 2022-10-20 2023-03-24 亿咖通(北京)科技有限公司 一种虚拟化管理下的投屏方法、装置、设备及介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040054994A1 (en) * 2002-09-17 2004-03-18 Microsoft Corporation System and method for persisting dynamically generated code in a directly addressable and executable storage medium
US20090172639A1 (en) * 2007-12-27 2009-07-02 Mahesh Natu Firmware integrity verification
CN104216837A (zh) * 2013-05-31 2014-12-17 华为技术有限公司 一种内存系统、内存访问请求的处理方法和计算机系统
CN104571955A (zh) * 2014-12-27 2015-04-29 华为技术有限公司 提高存储容量的方法和装置
CN107273212A (zh) * 2017-06-23 2017-10-20 郑州云海信息技术有限公司 一种动态分配内存的方法及系统

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7757034B1 (en) * 2006-06-29 2010-07-13 Parallels Software International, Inc. Expansion of virtualized physical memory of virtual machine
US8156492B2 (en) * 2007-09-07 2012-04-10 Oracle International Corporation System and method to improve memory usage in virtual machines running as hypervisor guests
US9390028B2 (en) * 2014-10-19 2016-07-12 Strato Scale Ltd. Coordination between memory-saving mechanisms in computers that run virtual machines
US10534720B2 (en) * 2016-05-26 2020-01-14 Vmware, Inc. Application aware memory resource management

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040054994A1 (en) * 2002-09-17 2004-03-18 Microsoft Corporation System and method for persisting dynamically generated code in a directly addressable and executable storage medium
US20090172639A1 (en) * 2007-12-27 2009-07-02 Mahesh Natu Firmware integrity verification
CN104216837A (zh) * 2013-05-31 2014-12-17 华为技术有限公司 一种内存系统、内存访问请求的处理方法和计算机系统
CN104571955A (zh) * 2014-12-27 2015-04-29 华为技术有限公司 提高存储容量的方法和装置
CN107273212A (zh) * 2017-06-23 2017-10-20 郑州云海信息技术有限公司 一种动态分配内存的方法及系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4030289A4

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023152284A1 (de) * 2022-02-11 2023-08-17 Robert Bosch Gmbh Verfahren zur bereitstellung eines zugangspunkts zur messung und kalibrierung einer oder mehrerer funktionen einer recheneinheit
WO2023172319A1 (en) * 2022-03-11 2023-09-14 Microsoft Technology Licensing, Llc Direct swap caching with noisy neighbor mitigation and dynamic address range assignment
US11860783B2 (en) 2022-03-11 2024-01-02 Microsoft Technology Licensing, Llc Direct swap caching with noisy neighbor mitigation and dynamic address range assignment

Also Published As

Publication number Publication date
CN112579251B (zh) 2024-04-23
CN112579251A (zh) 2021-03-30
EP4030289A4 (en) 2022-10-12
US20220214907A1 (en) 2022-07-07
EP4030289A1 (en) 2022-07-20

Similar Documents

Publication Publication Date Title
WO2021057489A1 (zh) 虚拟机内存管理的方法及设备
US11531625B2 (en) Memory management method and apparatus
JP5510556B2 (ja) 仮想マシンのストレージスペースおよび物理ホストを管理するための方法およびシステム
US9317320B2 (en) Hypervisor-based server duplication system and method and storage medium storing server duplication computer program
US8312201B2 (en) Managing memory allocations loans
US8601201B2 (en) Managing memory across a network of cloned virtual machines
US20240054006A1 (en) Virtualization processing system, method and apparatus, and device
US20160378399A1 (en) Affinity-aware parallel zeroing of memory in non-uniform memory access (numa) servers
CN113204407B (zh) 一种内存超配管理方法及装置
US20230168953A1 (en) Inter-process communication method and apparatus
US20220253252A1 (en) Data processing method and apparatus
US9886387B2 (en) Method and system for performing on-demand data write through based on virtual machine types
CN112384893A (zh) 多个热补丁的资源上高效的部署
CN111679914B (zh) 一种内存管理方法、系统、计算机设备及存储介质
US20130173880A1 (en) Dedicated large page memory pools
US20070033371A1 (en) Method and apparatus for establishing a cache footprint for shared processor logical partitions
US20200201691A1 (en) Enhanced message control banks
EP2642387B1 (en) Method, memory management unit and computer system for managing memory of computer system
CN110447019B (zh) 存储器分配管理器及由其执行的用于管理存储器分配的方法
CN110750221A (zh) 卷克隆方法、装置、电子设备及机器可读存储介质
US20220114086A1 (en) Techniques to expand system memory via use of available device memory
CN113268356A (zh) 基于LINUX系统的多GPU板卡bounding的系统、方法及介质
WO2022222977A1 (zh) 用于运行云业务实例的物理服务器的内存管理方法和装置
US20230342458A1 (en) Techniques to mitigate cache-based side-channel attacks
US20230027307A1 (en) Hypervisor-assisted transient cache for virtual machines

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20870358

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2020870358

Country of ref document: EP

Effective date: 20220411