WO2025181598A1 - 内存扩展 - Google Patents
内存扩展Info
- Publication number
- WO2025181598A1 WO2025181598A1 PCT/IB2025/051388 IB2025051388W WO2025181598A1 WO 2025181598 A1 WO2025181598 A1 WO 2025181598A1 IB 2025051388 W IB2025051388 W IB 2025051388W WO 2025181598 A1 WO2025181598 A1 WO 2025181598A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- memory
- target
- operating system
- target operating
- extended
- Prior art date
- Legal status (The legal status 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 status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/06—Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation 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/5016—Allocation 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
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
- G06F2009/45583—Memory management, e.g. access or allocation
Definitions
- the embodiments of the present disclosure relate to the field of computer technology, and more particularly to a memory expansion method, a memory expansion device, a computing device, a computer-readable storage medium, and a computer program product.
- memory expansion can only be performed online when physical memory is confirmed to exist.
- the memory hot-swap function can be used to dynamically add virtual machine memory to the virtual machine.
- the virtual memory expanded by the memory hot-swap function is virtual memory, which is subject to the limitations and support level of the virtualization platform and cannot be used in the host operating system.
- embodiments of the present disclosure provide a memory expansion method.
- One or more embodiments of the present disclosure also relate to a memory expansion device, a computing device, a computer-readable storage medium, and a computer program product to address technical deficiencies in the prior art.
- a memory expansion method comprising: receiving a memory expansion instruction, wherein the memory expansion instruction is associated with a target operating system, and the target operating system is obtained by converting an operating system running in a physical mode to running in a virtual mode; determining memory expansion parameters according to the memory expansion instruction, and calling a memory management interface of the target operating system to add extended memory corresponding to the memory expansion parameters to the target operating system; allocating the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by a memory management function, wherein the memory contained in the target memory pool is used by the target operating system.
- a memory expansion device comprising: a receiving module configured to receive a memory expansion instruction, wherein the memory expansion instruction is associated with a target operating system, and the target operating system is obtained by converting an operating system running in a physical mode to running in a virtual mode; a determining module configured to determine a memory expansion parameter according to the memory expansion instruction, and call a memory management interface of the target operating system to add an extended memory corresponding to the memory expansion parameter to the target operating system; an allocating module configured to allocate the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by a memory management function, wherein the target memory contained in the target memory pool is used by the target operating system.
- another memory expansion method comprising: receiving a configuration change instruction submitted by an operating system running in a physical mode; converting the operating system to a physical mode according to the configuration change instruction; Switching a target operating system to a virtual mode, wherein the target operating system is configured with a memory management function; upon receiving a memory expansion instruction submitted by the memory management function, determining memory expansion parameters according to the memory expansion instruction, and calling a memory management interface of the target operating system to add extended memory corresponding to the memory expansion parameters to the target operating system; and allocating the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by the memory management function, wherein the target memory contained in the target memory pool is used by the target operating system.
- another memory expansion device comprising: a receiving module configured to receive a configuration change instruction submitted for an operating system running in a physical mode; a conversion module configured to convert the operating system into a target operating system running in a virtual mode according to the configuration change instruction, wherein the target operating system is configured with a memory management function; a determining module configured to, upon receiving a memory expansion instruction submitted through the memory management function, determine a memory expansion parameter according to the memory expansion instruction, and call a memory management interface of the target operating system to add an extended memory corresponding to the memory expansion parameter to the target operating system; an allocating module configured to allocate the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by the memory management function, wherein the target memory contained in the target memory pool is used by the target operating system.
- a computing device comprising a memory and a processor; the memory is used to store computer programs/instructions, and the processor is used to execute the computer programs/instructions, and when the computer programs/instructions are executed by the processor, the steps of the above-mentioned memory expansion method are implemented.
- a computer-readable storage medium which stores a computer program/instruction, and when the computer program/instruction is executed by a processor, the steps of the above-mentioned memory expansion method are implemented.
- a computer program product including a computer program/instruction, which implements the steps of the above-mentioned memory expansion method when executed by a processor.
- An embodiment of the present disclosure provides a memory expansion method, which comprises receiving a memory expansion instruction, wherein the memory expansion instruction is associated with a target operating system, and the target operating system is obtained by converting an operating system running in a physical mode to running in a virtual mode; determining a memory expansion parameter according to the memory expansion instruction, and calling a memory management interface of the target operating system to add an extended memory corresponding to the memory expansion parameter to the target operating system; and allocating the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by a memory management function, wherein the memory contained in the target memory pool is used by the target operating system.
- An embodiment of the present disclosure provides a memory expansion method, which switches an operating system running in physical mode to a target operating system running in virtual mode, receives memory expansion instructions for the target operating system, adds corresponding extended memory to the target operating system, and performs smooth and flexible memory expansion without stopping the target operating system, ensuring that services in the operating system are not interrupted, achieving user-friendly operation, reducing various unstable factors caused by restarting the operating system, and enhancing the stability and reliability of the operating system.
- the extended memory can be allocated to the target memory pool on demand, so that the extended memory in the target memory pool can be used by the target process corresponding to the target memory pool, significantly improving the operating performance of the target process.
- Figure 1 is a scenario diagram of a memory expansion method provided by an embodiment of the present disclosure.
- Figure 2 is a flowchart of a memory expansion method provided by an embodiment of the present disclosure.
- FIG. 17 is a flowchart of the processing process of a memory expansion method provided by an embodiment of the present disclosure.
- FIG. 4 is a flowchart of another memory expansion method provided by an embodiment of the present disclosure.
- Figure 5 is a schematic diagram of the structure of a memory expansion device provided in one embodiment of the present disclosure.
- Figure 6 is a schematic diagram of the structure of another memory expansion device provided by an embodiment of the present disclosure.
- Figure 7 is a block diagram of a computing device provided by an embodiment of the present disclosure.
- first, second, etc. may be used to describe various information in one or more embodiments of the present disclosure, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, first may also be referred to as second, and similarly, second may also be referred to as first without departing from the scope of one or more embodiments of the present disclosure. Depending on the context, the word “if” as used herein may be interpreted as "at the time of" or "when” or "in response to determining”.
- the user information including but not limited to user device information, user personal information, etc.
- data including but not limited to data used for analysis, stored data, displayed data, etc.
- the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
- EPT Extended Page Table, a hardware-assisted virtual memory management technology. In a virtualized environment, EPT is used to solve the memory address translation problem between the guest operating system (Guest OS) and the host operating system (Host OS).
- Guest OS guest operating system
- Host OS host operating system
- the page table is a concept of virtual memory technology.
- the operating system To allow programs to obtain more available memory and expand physical memory into a larger logical memory, the operating system also uses virtual memory technology. It abstracts physical memory into an address space. The operating system allocates an independent set of virtual addresses to each process. The virtual addresses of different processes are mapped to the physical addresses of different memories. When a program wants to access a virtual address, the operating system converts it into a different physical address. There are two concepts of addresses involved here: the memory address used by the program is called the virtual address; the space address actually existing in the hardware is called the physical address.
- Virtual addresses and physical addresses are mapped through page tables, which are stored in memory.
- the system will generate a page fault exception, enter the system kernel space to allocate physical memory, update the process page table, and finally return to the user space to resume the process.
- VMCS Virtual Machine Control Structure
- VMCS contains a large number of fields and information related to the virtual machine execution environment, such as: virtual machine processor status, including general registers, instruction pointer, flag register and other CPU (central processing unit) internal status; memory management information, such as EPT page table base address, address translation control field, etc., used to support memory virtualization and address translation; execution control information, such as entry points for entering and exiting the virtual machine, event injection, exception and interrupt handling mechanisms, etc.; virtual machine operation mode settings, such as operating permissions and behavior rules in non-root (virtual) mode and root (physical) mode; and virtual machine execution control fields, such as whether to enable specific functions, virtualization extensions, etc.
- virtual machine processor status including general registers, instruction pointer, flag register and other CPU (central processing unit) internal status
- memory management information such as EPT page table base address, address translation control field, etc., used to support memory virtualization and address translation
- execution control information such as entry points for entering and exiting the virtual machine, event injection, exception and interrupt handling mechanisms, etc.
- VMCS when converting an operating system running in physical mode to a target operating system running in virtual mode, is a data structure used to manage the state of the target operating system running in virtual mode.
- Memory hot-swap is a technology that allows memory modules to be added or removed while the computer is running without shutting down. It is commonly used in servers and high-end computer systems to improve system availability and resource flexibility. The key to achieving this function is that the motherboard design includes pluggable memory slots and is equipped with a dedicated hot-swap controller to monitor memory insertion and removal and communicate with the motherboard firmware.
- the virtualization platform usually allows virtual machines to perform hot-swap memory operations while running, thereby adding or removing memory without stopping the virtual machine.
- Virtualization platforms (such as VMware ESXi, KVM, Hyper-V, etc.) provide relevant functions and interfaces to enable virtual machines to dynamically increase or decrease memory resources. The specific steps are as follows.
- the hot-plug operation of virtual machine memory in virtual environment is actually the hot-plug operation of virtual memory.
- the expanded virtual memory is affected by the limitations and support level of the virtualization platform and cannot be used by the host machine's operating system.
- a memory expansion method is provided.
- the present disclosure also relates to a memory expansion device, a computing device, a computer-readable storage medium, and a computer program product, which are described in detail one by one in the following embodiments.
- the memory expansion method is implemented by using an end-side device 102 and a server 104, wherein the end-side device 102 is used to send a memory expansion instruction to the server 104, that is, to expand the memory in the server 104; the server 104 receives the memory expansion instruction, wherein the memory expansion instruction is associated with a target operating system, and the target operating system is obtained by converting an operating system running in a physical mode to a virtual mode; the memory expansion parameter is determined according to the memory expansion instruction, and the memory management interface of the target operating system is called to add the extended memory corresponding to the memory expansion parameter to the target operating system; based on the memory management function preset by the memory management function, the extended memory is allocated to the target memory pool corresponding to the target operating system, wherein the memory contained in the target memory pool is used by the target operating system, and the extension result, such as the message of successful extension and available memory after extension, is returned to the end-side device 102.
- the end-side device 102 is used to send a memory expansion instruction to the server
- the end-side device 102 may include a browser, an APP (Application), or a web application such as an H5 (Hyper Text Markup Languages, version 5) application, or a light application (also known as a mini-program, a lightweight application) or a cloud application.
- the end-side device may be developed based on a software development kit (SDK) of a corresponding service provided by the server, such as a real-time communication (RTC) SDK.
- SDK software development kit
- RTC real-time communication
- the end-side device may be deployed in an electronic device and may rely on the device to run or certain APPs in the device to run.
- the electronic device may have a display screen and support information browsing, such as a personal mobile terminal such as a mobile phone, a tablet computer, or a personal computer.
- a personal mobile terminal such as a mobile phone, a tablet computer, or a personal computer.
- applications may also be configured in the electronic device, such as human-computer dialogue applications, model training applications, text processing applications, web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
- Server 104 can be understood as a server that provides various services, including physical servers and cloud servers, such as servers that provide communication services for multiple clients, servers that provide background training to support models used on clients, and servers that process data sent by clients. It should be noted that server 104 can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. Server 104 can also be a server for a distributed system, or a server that is integrated with a blockchain.
- Server 104 can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
- basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
- An embodiment of the present disclosure provides a memory expansion method, which switches a running host operating system to a target operating system running in virtual mode, receives a memory expansion instruction for the target operating system, adds corresponding extended memory to the target operating system, and performs smooth and flexible memory expansion without stopping the target operating system.
- Memory expansion ensures uninterrupted operating system services, achieving seamless user experience and reducing instability caused by restarting the operating system. This enhances operating system stability and reliability.
- the extended memory can be allocated to the target memory pool on demand, allowing the extended memory in the target memory pool to be used by the target process, significantly improving the target process's performance.
- FIG2 shows a flow chart of a memory expansion method provided by an embodiment of the present disclosure, which specifically includes the following steps.
- Step 202 Receive a memory expansion instruction, wherein the memory expansion instruction is associated with a target operating system, and the target operating system is obtained by converting an operating system running in a physical mode to running in a virtual mode.
- the memory expansion instruction may be understood as an instruction for causing the target operating system to perform memory expansion; the memory expansion instruction may carry memory expansion parameters, and the memory expansion parameters may include the starting address of the memory to be expanded and the size of the memory to be expanded.
- the operating system is equipped with memory management functions, which can realize memory allocation, memory recycling, address translation, etc.; memory allocation, such as when a process requests memory, the operating system divides a suitable area from the available memory and allocates it to the process; memory recycling, such as when a process ends or releases an unused memory area, the operating system promptly reclaims this memory space for use by other processes; address translation, such as the operating system provides virtual address space for each process, and performs address translation between virtual addresses and physical addresses through data structures such as page tables.
- Physical mode can be understood as root mode or kernel mode; virtual mode can be understood as non-root mode or user mode; target operating system can be understood as an operating system running in non-root mode.
- the method further includes: receiving a configuration change instruction submitted by the operating system running in the physical mode; and converting the operating system into a target operating system running in the virtual mode according to the configuration change instruction.
- the configuration change instruction can be understood as a change instruction used to cause the operating system to perform mode conversion.
- the memory expansion method provided in the embodiment of the present disclosure can dynamically convert an operating system running in physical mode to running in virtual mode according to actual needs by receiving configuration change instructions, thereby achieving flexible scheduling and efficient utilization of resources.
- the method of converting the operating system into a target operating system running in virtual mode according to the configuration change instruction includes: establishing an address mapping page table for the operating system according to the configuration change instruction, and saving the initial data of the register corresponding to the operating system running in physical mode; establishing a target data structure according to the address mapping page table and the initial data; configuring the target data in the target data structure, and loading the configured target data structure into a central processing unit, triggering the operating system to be converted into a target operating system running in virtual mode, wherein the target data is control information corresponding to the target operating system.
- the address mapping page table can be understood as the EPT page table.
- the EPT page table contains page table entries for recording the mapping of virtual addresses to physical addresses. Since the operating system running in root mode has not yet been converted to the target operating system running in non-root mode, the GPA in the EPT page table is equal to the HPA.
- the initial data can be understood as the data in the register;
- the target data structure can be understood as VMCS, a data structure used to manage and control the target operating system execution environment;
- the target data can be understood as the fields and information related to controlling the virtual execution environment.
- VMCS contains a large number of fields and information related to the virtual execution environment.
- the control of the VCPU central processing unit running in virtual mode is achieved by configuring the fields in VMCS, such as setting the VM-entry/VM-exit (virtual machine entry/virtual machine exit) control bits in VMCS to specify which instructions should be intercepted, such as setting the exit processing function during the virtualization mode operation.
- VM-entry/VM-exit virtual machine entry/virtual machine exit
- EPT Violation When an EPT Violation (EPT violation, when the CPU tries to access an address, if the EPT mapping of the address is not set correctly or the permissions do not match, an EPT Violation exception will occur) exception causes VM Exit, the exit processing function is used as the EPT page fault processing function corresponding to the EPT Violation to handle the VM Exit caused by the EPT Violation exception.
- the running central processing unit is switched to the VCPU running in non-root mode, so that the running host machine (physical machine running in root mode) enters the virtual mode, which is equivalent to triggering the switching of the operating system mode, that is, converting the operating system to the target operating system running in virtual mode.
- the memory expansion method provided in the embodiment of the present disclosure establishes an address mapping page table and saves the initial data of the register to establish a target data structure, and can accurately and effectively complete the conversion of the operating system mode by configuring the target data of the target data structure.
- the memory is divided into blocks of fixed granularity, and the memory state of the memory blocks is set to be in use.
- the specific implementation method is as follows.
- the method further includes: dividing the physical memory corresponding to the target operating system into memory blocks of a preset granularity through the memory management function; and setting the memory state of the memory block to a used state.
- the preset granularity can be set according to actual needs and is not limited here.
- the preset granularity is 2MB (megabytes).
- all the real physical memory of the host machine can be divided into memory blocks with a granularity of 2M. Since all the physical memory is managed by the host machine, when the host machine runs in virtual mode, the initial memory state of all the physical memory is in the used state.
- the memory expansion method provided by the embodiment of the present disclosure is conducive to managing and organizing memory space and reducing the generation of memory fragmentation by dividing the physical memory into blocks of fixed granularity; it can efficiently manage each memory block and thus more efficiently allocate physical memory resources.
- the page table entries in the address mapping page table corresponding to the idle pages are deleted, and the memory state is updated to facilitate subsequent allocation of idle pages.
- the method further includes: determining the current idle page corresponding to the target operating system through the memory management function, wherein the idle page is a physical memory page that is not currently occupied by any process and can be allocated to the process by the target operating system, and the physical memory pages constitute the physical memory; deleting the page table entry in the address mapping page table corresponding to the idle page, and updating the memory state corresponding to the idle page to the idle state, wherein the address mapping page table is composed of the page table entries, and the page table entries record the mapping of virtual addresses to physical addresses.
- physical memory pages are the allocation units of physical memory, that is, when allocating physical memory to a process, it is allocated page by page.
- the memory management function is used to traverse the currently idle pages in the host machine.
- a physical page becomes idle it means that the page is referenced by any virtual address. Therefore, the corresponding page table entry can be deleted from the address mapping page table, and the memory state is updated to the idle state.
- the idle page By adding the idle page to the global free list, it is convenient to quickly find the allocatable physical memory page during subsequent memory allocation operations.
- the memory expansion method provided by the embodiment of the present disclosure ensures the effective management and rational use of physical memory, and provides the necessary basis for memory scheduling in a multi-tasking environment. By adding free pages to the global free list, it is convenient to quickly find the allocatable physical memory pages during subsequent memory allocation operations.
- Step 204 Determine memory extension parameters according to the memory extension instruction, and call the memory management interface of the target operating system to add extended memory corresponding to the memory extension parameters to the target operating system.
- the memory expansion parameters include the address space of the extended memory and the size of the extended memory;
- the memory management interface can be understood as an extension interface, and the addition of extended memory is achieved by calling the extension interface.
- extended memory is added to the virtual memory address range corresponding to the target operating system, ensuring that the target operating system can provide a larger available memory space for the application.
- the specific implementation method is as follows.
- the step of determining memory extension parameters according to the memory extension instruction and calling the memory management interface of the target operating system to add extended memory corresponding to the memory extension parameters to the target operating system includes: determining memory extension parameters according to the memory extension instruction, wherein the memory extension parameters include the virtual memory corresponding to the extended memory. Virtual memory address range; calling the memory management interface of the target operating system to add the extended memory to the virtual memory address range corresponding to the target operating system.
- the virtual memory address range can be understood as the address space range determined by the address space of the extended memory and the size of the extended memory.
- the GPA address space of the extended memory to be added and the size of the extended memory i.e., memory extension parameters
- the maximum physical page frame number (PFN) currently used by the target operating system must be determined.
- PFN physical page frame number
- an address range higher than the existing maximum PFN is selected as the new memory mapping area. For example, if the current maximum PFN of the target operating system corresponds to the end of the 40GB (gigabyte) memory space, the newly added extended memory can be allocated starting from 40GB and allocated according to the memory size of the extended memory.
- the memory expansion method provided in the embodiment of the present disclosure can meet the needs of application products in the host machine by expanding the memory, and can also avoid the problem of being unable to allocate the required memory to the process due to insufficient available memory, thereby triggering the abnormal termination of the system or forcibly killing some processes, or being unable to upgrade to the latest product.
- Step 206 Based on a memory management function preset by a memory management function, the extended memory is allocated to a target memory pool corresponding to the target operating system, wherein the memory contained in the target memory pool is used by the target operating system.
- the memory management function can be understood as a processing function for extended memory, which is used to process and manage the extended memory.
- the memory management function can be used to allow the extended memory to enter a specific memory pool, such as hugetlb (Huge Translation Lookaside Buffer, a memory management mechanism used to support large page memory) or a dedicated pool.
- the target memory pool can be understood as the specific memory pool mentioned above, which can be used to meet the memory requirements of specific programs (such as programs for high-performance computing resources).
- the processing function of the extended memory will be preset through the memory management function, so that the processing of the extended memory can be realized when the extended memory is added.
- the extended memory can be dynamically allocated by setting a target memory pool mechanism to achieve the processing allocation of the extended memory.
- the specific implementation method is as follows.
- the allocating the extended memory to the target memory pool corresponding to the target operating system includes: allocating the extended memory to the target memory pool corresponding to the target operating system according to a target memory pool mechanism.
- the method of allocating the extended memory to the target memory pool corresponding to the target operating system according to the target memory pool mechanism includes: setting the target memory pool for use by the target process, allocating the extended memory to the target memory pool corresponding to the target operating system, so that the target process uses the extended memory in the target memory pool; or setting the target memory pool for use by the code segment and/or data segment in the target process, allocating the extended memory to the target memory pool corresponding to the target operating system, so that the code segment and/or data segment in the target process uses the extended memory in the target memory pool.
- the target process can be understood as a process that is set to allow the use of the target memory pool.
- the process that is allowed to use the specific memory pool can be dynamically set, so that the target process uses the memory in the target memory pool; the code segment or data segment of the corresponding process can also be set to use a specific memory pool.
- the memory in the memory pool is used to allow the target process to use the memory in the target memory pool.
- the extended memory can also be allocated to the general memory corresponding to the target operating system, which is not limited here.
- the memory expansion method provided by the embodiment of the present disclosure provides a dedicated memory space for the target process by setting the target memory pool to be used by a specific target process or the code segment and/or data segment in the target process, thereby reducing memory contention between different processes and helping to improve the data reading and writing speed and execution efficiency of the target process.
- the size of a specific memory pool can be dynamically adjusted to ensure that the capacity of the specific memory pool can meet the size of the extended memory.
- the specific implementation method is as follows.
- the allocating the extended memory to the target memory pool corresponding to the target operating system according to the target memory pool mechanism includes: adjusting the capacity configuration of the target memory pool according to the memory expansion parameters of the extended memory so that the capacity of the target memory pool matches the size of the extended memory; and allocating the extended memory to the adjusted target memory pool corresponding to the target operating system.
- the size of a specific memory pool can also be adjusted dynamically. For example, if the newly added extended memory is smaller than the current size of the specific memory pool, part of the memory in the specific memory pool is released to the general memory; otherwise, memory is obtained from the general hugetlb and the extended memory is allocated to the target memory pool after the capacity adjustment. It should be noted that if there is a memory allocation request for a specific memory pool, and the request cannot be satisfied if the specific memory pool does not have enough memory, the target operating system will not immediately report a memory allocation failure, but will choose to fall back to the regular memory allocation path and find a suitable memory area from the overall available memory to complete the allocation.
- the memory expansion method provided in the embodiment of the present disclosure can effectively utilize the newly added memory resources by adjusting the capacity of the target memory pool to match the expanded memory, thereby avoiding memory waste and improving the overall performance of the system.
- an exception handling function is set to handle the problem.
- the specific implementation method is as follows.
- the method further includes: when a target process running in the target operating system uses the extended memory in the target memory pool and triggers a page fault exception, calling an exception handling function corresponding to the page fault exception according to the page fault exception; based on the exception handling function, determining a target memory block through the memory management function, and establishing a page table entry corresponding to the extended memory and the target memory block, wherein the target memory block is a memory block whose memory status is idle; mapping the extended memory to the target memory block through the page table entry corresponding to the extended memory and the target memory block.
- the memory expansion method provided by the embodiment of the present disclosure effectively solves the page fault exception problem by calling the exception handling function corresponding to the page fault exception, and realizes the dynamic mapping of the virtual memory address to the physical memory address, so that the process can smoothly use the newly added extended memory resources.
- the memory expansion method further includes: setting memory free space in the physical memory corresponding to the target operating system through the memory management function; triggering a memory recycling operation to release the physical memory in the idle state when the memory free space is lower than a first threshold and higher than a second threshold; and sending a processing notification to an operation and maintenance program when the memory free space is lower than the second threshold, so that the operation and maintenance program performs process migration and data protection operations according to the processing notification.
- the first threshold and the second threshold can be set according to actual conditions, and the first threshold and the second threshold can also be expressed as a ratio in actual applications; for example, the first threshold is 30% and the second threshold is 10%; the operation and maintenance program can be understood as a program for operating and maintaining the system to ensure the safe operation of the system.
- the free space of memory can be visually represented by the memory water level.
- the memory water level is higher than the first threshold, it is considered that the memory water level is at a high water level, that is, there is a lot of free memory. At this time, the status quo can be maintained without any processing.
- the memory water level is lower than the first threshold but higher than the second threshold, it is considered that the memory water level is between the high water level and the low water level, then the memory recycling operation is triggered, that is, recycling the free memory, or compressing the memory, etc., to make room for the bottom-level free memory.
- priority is given to recycling cold pages (cold pages refer to free pages that are no longer in the cache) or free memory.
- the memory expansion method monitors and adjusts the usage of physical memory in real time by setting memory free space, ensuring that the system can dynamically allocate and reclaim memory resources according to actual needs, thereby improving memory utilization; and by sending processing notifications, it can greatly enhance the stability and availability of the system and reduce operation and maintenance costs.
- An embodiment of the present disclosure provides a memory expansion method, which switches an operating system running in physical mode to a target operating system running in virtual mode, receives memory expansion instructions for the target operating system, adds corresponding extended memory to the target operating system, and performs smooth and flexible memory expansion without stopping the operation of the target operating system, thereby ensuring that services in the operating system are not interrupted, achieving user-friendly operation, reducing various unstable factors caused by restarting the operating system, and enhancing the stability and reliability of the operating system.
- the extended memory in the target memory pool is made available to the target process by setting the usage permissions of the memory in the target memory pool, thereby significantly improving the operating performance of the target process.
- FIG3 shows a flow chart of a processing process of a memory expansion method provided by an embodiment of the present disclosure, which specifically includes the following steps.
- Step 302 Create an address mapping table.
- Step 304 Save the register value and create the target data structure.
- a VMCS running in virtual mode is established based on the data of these registers and EPT.
- the correctness of the memory access of the target operating system after switching needs to be ensured according to the EPT configuration.
- the register value of the VCPU (virtual central processing unit) corresponding to the target operating system is loaded according to the information in the VMCS, thereby restoring the execution environment of the target operating system. In this way, when the target operating system is rescheduled back, it can continue to execute from the previously saved state, ensuring the continuity and independence of the target operating system execution.
- Step 306 Configure the target data structure and set the exit function.
- the exit function can be understood as an exit processing function during the virtual mode operation, which is used to switch from non-root mode back to root mode when a specific event is triggered during the execution of the target operating system.
- VMCS contains a large number of fields and information related to the virtual execution environment.
- the control of the VCPU is achieved by configuring the fields in VMCS, such as setting the VM-entry/VM-exit control bits in VMCS to specify which instructions should be intercepted; for example, in the process of setting and initializing VMCS, it is necessary to correctly configure the relevant VM Exit information.
- EPT Violation EPT violation, when the CPU tries to access an address, if the EPT mapping of the address is not set correctly or the permissions do not match, an EPT Violation exception will occur)
- the exit processing function is the EPT page fault processing function corresponding to the EPT Violation, which is used to handle the VM Exit caused by the EPT Violation exception.
- Step 308 Switch operating mode.
- Step 310 Divide the memory block and set the memory state of the memory block.
- a memory block management function is established for all real physical memories of the physical machine. That is, in order to efficiently manage and allocate physical memory resources, continuous physical memory will be divided into memory blocks of equal or unequal sizes. For example, the physical memory can be divided into multiple memory blocks with a granularity of 2MB (megabytes). Since all physical memories are managed by the physical machine, when the physical machine runs in virtual mode, the initial memory state of all physical memories is used.
- Step 312 Determine the free pages and update the memory status of the memory block.
- Step 314 Set the memory management function and determine the memory extension parameters of the extended memory.
- the memory management function can be understood as an extended memory processing function, which is used to make the extended memory enter the dedicated memory pool. Specifically, the dedicated memory pool is first created and initialized, and the dedicated memory pool is used to meet the memory requirements of specific programs (such as programs with high-performance computing resources). The general hugetlb is used to dynamically allocate to any required large page requests.
- the newly added extended memory can be managed by setting the extended memory processing function, so that the newly added extended memory can enter the dedicated memory pool, and the dedicated memory pool will be configured with the required memory capacity.
- the extended memory will be given priority to enter the dedicated pool. If there is still some extended memory left, it will be placed in the general hugetlb to ensure that the added extended memory has priority to enter the dedicated memory pool.
- Step 316 Add virtual memory to the specified memory pool.
- the memory management interface (extension interface) of the target operating system can be directly called to add the extended memory corresponding to the memory expansion parameters to the target operating system, thereby avoiding the problem of large-scale OOM on the online host machine due to insufficient memory (due to insufficient available memory, the required memory cannot be allocated to the process, thereby triggering the abnormal termination of the system or forcibly killing some processes).
- the extended memory can be allocated to the specific memory pool corresponding to the target operating system (i.e., the dedicated memory pool in the above embodiment) for use by a specific process.
- Step 318 Configure a specific memory pool.
- a specific memory pool can be set according to actual needs.
- the processes that are allowed to use the specific memory pool can be dynamically set; the code segment or data segment of the corresponding process can also be set to use the memory in the specific memory pool.
- the newly added extended memory is added to the specific memory pool; when the newly added extended memory is larger than the specific memory pool, the excess extended memory is placed in the general memory; and the size of the specific memory pool can also be adjusted dynamically.
- Step 320 Use extended memory to trigger a page fault exception.
- Step 322 Determine unused memory blocks based on the page fault handling function.
- the EPT page fault handling function is used to find an unused (currently idle) memory block from the memory block to establish the EPT page table corresponding to the extended memory and the memory block, so that the application can use the newly extended virtual memory.
- Step 324 Set the memory water level.
- a memory water level can be set for the physical memory to ensure that there is a reasonable amount of free memory in the memory block management function, wherein the memory water level represents the free space of the current free memory; if the memory water level is at a high water level, it means that the current amount of free memory is large and the status quo is temporarily maintained; if the memory water level is lower than the high water level and higher than the low water level, the free memory will be recycled, or the memory will be compressed, etc., to obtain more free memory; if the memory water level is lower than the low water level and higher than the emergency water level, memory recycling will be accelerated; specifically, when recycling memory, cold pages (cold pages represent free pages that are no longer in the cache) or free memory will be recycled first to ensure that the memory water level is at a reasonable position; if the memory water level is lower than the emergency water level, then when the EPT page fault exception is triggered, no memory block will be allocated for the extended memory, and a failure will be returned to
- An embodiment of the present disclosure provides a memory expansion method, which switches the operating mode of the operating system. Without stopping the target operating system, the method adds corresponding extended memory to the target operating system according to the memory expansion instruction by calling the interface. Compared with the method in which the virtual machine notifies the operating system of the extended memory through a complex hardware interrupt mechanism, the method not only greatly improves the expansion efficiency but also realizes the user-friendly operation, reduces various unstable factors caused by restarting the operating system, and enhances the stability and reliability of the operating system.
- FIG4 shows a flowchart of another memory expansion method provided by an embodiment of the present disclosure, which specifically includes the following steps 402 to 408.
- Step 402 Receive configuration change instructions submitted by the operating system running in physical mode.
- Step 404 Convert the operating system to a target operating system running in virtual mode according to the configuration change instruction, wherein the target operating system is configured with a memory management function.
- Step 406 Upon receiving the memory extension instruction submitted through the memory management function, determine the memory extension parameters according to the memory extension instruction, and call the memory management interface of the target operating system to add extended memory corresponding to the memory extension parameters to the target operating system.
- Step 408 Based on the memory management function preset by the memory management function, the extended memory is allocated to the target memory pool corresponding to the target operating system, wherein the target memory contained in the target memory pool is used by the target operating system.
- the memory expansion method provided in one embodiment of the present disclosure can realize the conversion of the operating system from the physical mode to the virtual mode.
- the target operating system can increase the memory resources according to the actual demand during the operation, thereby improving the resource utilization efficiency and response speed of the system; and the preset memory management function can effectively manage and allocate the extended memory to the target memory, thereby ensuring that the newly added memory resources can be used reasonably and efficiently by the target operating system, avoiding the waste of memory resources, and also improving the overall performance and stability of the system.
- FIG5 shows a schematic structural diagram of a memory expansion device provided by an embodiment of the present disclosure.
- the device includes: a receiving module 502, configured to receive a memory expansion instruction, wherein the memory expansion instruction is associated with a target operating system, and the target operating system is obtained by converting an operating system running in a physical mode to a virtual mode; a determining module 504, configured to determine a memory expansion parameter according to the memory expansion instruction, and call the memory management interface of the target operating system to add extended memory corresponding to the memory expansion parameter to the target operating system; an allocating module 506, configured to allocate the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by the memory management function, wherein the target memory contained in the target memory pool is used by the target operating system.
- the device further includes a conversion module, which is configured to: receive a configuration change instruction submitted for an operating system running in a physical mode; and convert the operating system into a target operating system running in a virtual mode according to the configuration change instruction, wherein the target operating system is configured with a memory management function.
- a conversion module which is configured to: receive a configuration change instruction submitted for an operating system running in a physical mode; and convert the operating system into a target operating system running in a virtual mode according to the configuration change instruction, wherein the target operating system is configured with a memory management function.
- the conversion module is further configured to: establish an address mapping page table for the operating system according to the configuration change instruction, and save the initial data of the register, wherein the address mapping page table is composed of page table entries, and the page table entries record the mapping of virtual addresses to physical addresses; establish a target data structure according to the address mapping page table and the initial data; configure the target data in the target data structure, and load the configured target data structure into the target processor, triggering the operating system to convert to the target operating system running in virtual mode.
- the device further includes a management module, which is configured to: divide the physical memory of the target operating system into memory blocks of preset granularity through the memory management function, wherein the physical memory is the hardware resource corresponding to the physical address; and set the memory state of the memory block to an initial use state.
- a management module which is configured to: divide the physical memory of the target operating system into memory blocks of preset granularity through the memory management function, wherein the physical memory is the hardware resource corresponding to the physical address; and set the memory state of the memory block to an initial use state.
- the management module is further configured to: determine the current free page of the target operating system through the memory management function, wherein the free page is a physical memory page that is not currently occupied by any process and can be allocated for use by the target operating system, and the physical memory page is obtained by dividing the physical memory into blocks of a fixed size; delete the page table entry in the address mapping page table corresponding to the free page, and update the memory state of the memory block corresponding to the free page to an idle state.
- the determination module 504 is further configured to: determine memory extension parameters according to the memory extension instruction, wherein the memory extension parameters include a virtual memory address range corresponding to the extended memory; call the The memory management interface of the target operating system adds the extended memory to the virtual memory address range corresponding to the target operating system.
- the allocation module 506 is further configured to: allocate the extended memory to the target memory pool corresponding to the target operating system according to the target memory pool mechanism.
- the allocation module 506 is further configured to: set the target memory pool for use by the target process, or the code segment and/or data segment in the target process, and allocate the extended memory to the target memory pool corresponding to the target operating system, so that the target process, or the code segment and/or data segment in the target process uses the extended memory in the target memory pool.
- the allocation module 506 is further configured to: adjust the capacity configuration of the target memory pool according to the memory extension parameters of the extended memory so that the capacity of the target memory pool matches the size of the extended memory; and allocate the extended memory to the target memory pool corresponding to the target operating system.
- the device further includes a processing module, which is configured to trigger a page fault exception when the target process running in the target operating system uses the extended memory in the target memory pool, and call an exception handling function corresponding to the page fault exception based on the page fault exception; based on the exception handling function, determine the target memory block through the memory management function, and establish a page table entry corresponding to the extended memory and the target memory block, and map the virtual memory to the target memory block.
- a processing module which is configured to trigger a page fault exception when the target process running in the target operating system uses the extended memory in the target memory pool, and call an exception handling function corresponding to the page fault exception based on the page fault exception; based on the exception handling function, determine the target memory block through the memory management function, and establish a page table entry corresponding to the extended memory and the target memory block, and map the virtual memory to the target memory block.
- the device further includes a setting module, which is configured to set a memory water level in the physical memory of the target operating system through the memory management function, wherein the memory water level represents the water level of the idle physical memory; when the memory water level is lower than the first threshold and higher than the second threshold, a memory recycling operation is triggered to release the physical memory in the idle state; when the memory water level is lower than the second threshold, a processing notification is sent to the operation and maintenance program, and process migration and data protection operations are performed according to the processing notification.
- a setting module which is configured to set a memory water level in the physical memory of the target operating system through the memory management function, wherein the memory water level represents the water level of the idle physical memory; when the memory water level is lower than the first threshold and higher than the second threshold, a memory recycling operation is triggered to release the physical memory in the idle state; when the memory water level is lower than the second threshold, a processing notification is sent to the operation and maintenance program, and process migration and data protection operations are performed according to the processing notification.
- a memory expansion device switches an operating system running in physical mode to a target operating system running in virtual mode, receives memory expansion instructions for the target operating system, adds corresponding extended memory to the target operating system, and performs smooth and flexible memory expansion without stopping the operation of the target operating system, thereby ensuring that services in the operating system are not interrupted, achieving user-friendly operation, reducing various unstable factors caused by restarting the operating system, and enhancing the stability and reliability of the operating system.
- the extended memory can be allocated to the target memory pool on demand, so that the extended memory in the target memory pool can be used by the target process corresponding to the target memory pool, thereby significantly improving the operating performance of the target process.
- FIG. 16 The above is a schematic diagram of a memory expansion device according to this embodiment. It should be noted that the technical solution of the memory expansion device and the technical solution of the above-mentioned memory expansion method are based on the same concept. For details not described in detail in the technical solution of the memory expansion device, please refer to the description of the technical solution of the above-mentioned memory expansion method.
- FIG6 shows a schematic structural diagram of another memory expansion device provided by one embodiment of the present disclosure.
- the device includes: a receiving module 602 configured to receive a configuration change instruction submitted by an operating system running in a physical mode; a conversion module 604 configured to convert the operating system into a target operating system running in a virtual mode according to the configuration change instruction, wherein the target operating system is configured with a memory management function;
- the determination module 606 is configured to, upon receiving a memory extension instruction submitted through the memory management function, determine memory extension parameters according to the memory extension instruction, and call the memory management interface of the target operating system to add extended memory corresponding to the memory extension parameters for the target operating system.
- the allocation module 608 is configured to allocate the extended memory to a target memory pool corresponding to the target operating system based on a memory management function preset by the memory management function, wherein the target memory included in the target memory pool is for use by the
- FIG7 shows a block diagram of a computing device 700 according to an embodiment of the present disclosure.
- the components of the computing device 700 include, but are not limited to, a memory 710 and a processor 720.
- the processor 720 is connected to the memory 710 via a bus 730, and the database 750 is used to store data.
- the computing device 700 also includes an access device 740 that enables the computing device 700 to communicate via one or more networks 760.
- networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet.
- PSTN public switched telephone network
- LAN local area network
- WAN wide area network
- PAN personal area network
- Internet a combination of communication networks such as the Internet.
- the access device 740 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, or a near field communication (NFC) interface.
- a network interface card e.g., a network interface card (NIC)
- WLAN wireless local area network
- Wi-MAX Worldwide Interoperability for Microwave Access
- Ethernet a USB interface
- USB universal serial bus
- NFC near field communication
- the aforementioned components of the computing device 700 and other components not shown in FIG. 7 may also be connected to each other, for example, via a bus. It should be understood that the block diagram of the computing device structure shown in FIG. 7 is for illustrative purposes only and does not limit the scope of the present disclosure. Those skilled in the art may add or replace other components as needed.
- Computing device 700 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook computer, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC).
- Computing device 700 may also be a mobile or stationary server.
- the processor 720 is configured to execute the following computer program/instructions, which, when executed by the processor, implement the steps of the above-mentioned memory expansion method.
- the various embodiments of this disclosure are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences from other embodiments.
- the computing device embodiment is generally similar to the memory expansion method embodiment, so the description is relatively simple. For relevant parts, refer to the partial description of the memory expansion method embodiment.
- An embodiment of the present disclosure also provides a computer program product, including a computer program/instruction, which implements the steps of the above-mentioned memory expansion method when executed by a processor.
- the computer instructions include computer program codes, which may be in source code form, object code form, executable files, or some intermediate form.
- the computer-readable medium may include any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. It should be noted that the content of the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
本公开实施例提供内存扩展方法及装置、计算设备、计算机可读存储介质、计算机程序产品。其中内存扩展方法包括:接收内存扩展指令,其中,内存扩展指令关联目标操作系统,且目标操作系统为由物理模式运行的操作系统转换为虚拟模式运行获得;根据内存扩展指令确定内存扩展参数,并调用目标操作系统的内存管理接口,为目标操作系统添加所述内存扩展参数对应的扩展内存;基于内存管理功能预设的内存管理函数,将扩展内存分配至所述目标操作系统对应的目标内存池,其中,目标内存池中包含的内存供所述目标操作系统使用。
Description
内存扩展 相关申请的交又引用
[01]本申请要求于 2024年 02月 28 日提交的、 申请号为 202410225776.7的中国专利申 请的优先权, 该申请的全文以引用的方式并入本文中。 技术领域
[02]本公开实施例涉及计算机技术领域, 特别涉及内存扩展方法、 内存扩展装置、 计算 设备、 计算机可读存储介质以及计算机程序产品。 背景技术
[03]在传统操作系统中, 内存扩展只能针对确定存在物理内存的情况, 才能在线添加内 存; 对于虚拟化场景, 可以利用内存热插拔功能方便的给虚拟机动态添加虚拟机内存, 但是虚拟机的利用内存热插拔功能扩展出来的是虚拟内存,其功能受到虚拟化平台的限 制和支持程度的影响, 而且也不能用于宿主机操作系统。
[04]对于已经运行中的宿主机操作系统, 除非硬件存在备用冗余内存, 否则无法给它动 态添加内存。 发明内客
[05]有鉴于此, 本公开实施例提供了内存扩展方法。 本公开一个或者多个实施例同时涉 及内存扩展装置, 一种计算设备, 一种计算机可读存储介质以及一种计算机程序产品, 以解决现有技术中存在的技术缺陷。
[06]根据本公开实施例的第一方面, 提供了一种内存扩展方法, 包括: 接收内存扩展指 令, 其中, 所述内存扩展指令关联目标操作系统, 且所述目标操作系统为由物理模式运 行的操作系统转换为虚拟模式运行获得; 根据所述内存扩展指令确定内存扩展参数, 并 调用所述目标操作系统的内存管理接口,为所述目标操作系统添加所述内存扩展参数对 应的扩展内存; 基于内存管理功能预设的内存管理函数, 将所述扩展内存分配至所述目 标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的内存供所述目标操作系 统使用。
[07]根据本公开实施例的第二方面, 提供了一种内存扩展装置, 包括: 接收模块, 被配 置为接收内存扩展指令, 其中, 所述内存扩展指令关联目标操作系统, 且所述目标操作 系统为由物理模式运行的操作系统转换为虚拟模式运行获得; 确定模块, 被配置为根据 所述内存扩展指令确定内存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所 述目标操作系统添加所述内存扩展参数对应的扩展内存; 分配模块, 被配置为基于内存 管理功能预设的内存管理函数,将所述扩展内存分配至所述目标操作系统对应的目标内 存池, 其中, 所述目标内存池中包含的目标内存供所述目标操作系统使用。
[08]根据本公开实施例的第三方面, 提供了另一种内存扩展方法, 包括: 接收针对物理 模式运行的操作系统、 提交的配置变更指令; 根据所述配置变更指令将所述操作系统转
换为虚拟模式运行的目标操作系统, 其中, 所述目标操作系统配置有内存管理功能; 在 接收到通过所述内存管理功能提交的内存扩展指令的情况下,根据所述内存扩展指令确 定内存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所述目标操作系统添加 所述内存扩展参数对应的扩展内存; 基于所述内存管理功能预设的内存管理函数, 将所 述扩展内存分配至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含 的目标内存供所述目标操作系统使用。
[09]根据本公开实施例的第四方面, 提供了另一种内存扩展装置, 包括: 接收模块, 被 配置为接收针对物理模式运行的操作系统、 提交的配置变更指令; 转换模块, 被配置为 根据所述配置变更指令将所述操作系统转换为虚拟模式运行的目标操作系统, 其中, 所 述目标操作系统配置有内存管理功能; 确定模块, 被配置为在接收到通过所述内存管理 功能提交的内存扩展指令的情况下, 根据所述内存扩展指令确定内存扩展参数, 并调用 所述目标操作系统的内存管理接口,为所述目标操作系统添加所述内存扩展参数对应的 扩展内存; 分配模块, 被配置为基于所述内存管理功能预设的内存管理函数, 将所述扩 展内存分配至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的目 标内存供所述目标操作系统使用。
[10]根据本公开实施例的第五方面, 提供了一种计算设备, 包括存储器和处理器; 所述 存储器用于存储计算机程序 /指令, 所述处理器用于执行所述计算机程序 /指令, 该计算 机程序 /指令被处理器执行时实现上述内存扩展方法的步骤。
[11]根据本公开实施例的第六方面, 提供了一种计算机可读存储介质, 其存储有计算机 程序 /指令, 该计算机程序 /指令被处理器执行时实现上述内存扩展方法的步骤。
[12]根据本公开实施例的第七方面,提供了一种计算机程序产品,包括计算机程序/指令, 该计算机程序 /指令被处理器执行时实现上述内存扩展方法的步骤。
[13]本公开一个实施例提供一种内存扩展方法, 通过接收内存扩展指令, 其中, 所述内 存扩展指令关联目标操作系统,且所述目标操作系统为由物理模式运行的操作系统转换 为虚拟模式运行获得; 根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操作 系统的内存管理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存; 基 于内存管理功能预设的内存管理函数,将所述扩展内存分配至所述目标操作系统对应的 目标内存池, 其中, 所述目标内存池中包含的内存供所述目标操作系统使用。
[14]本公开一个实施例提供的内存扩展方法,通过将正在以物理模式运行中的操作系统, 切换成虚拟模式运行的目标操作系统, 接收针对目标操作系统的内存扩展指令, 为目标 操作系统添加对应的扩展内存, 在不停止目标操作系统运行的情况下进行平滑、 灵活的 内存扩展, 确保操作系统中的服务不会中断, 实现了对用户的无感操作, 降低了由重启 操作系统引发的各种不稳定因素, 增强了操作系统的稳定性和可靠性, 且可以按需将扩 展内存分配至目标内存池,使目标内存池中的扩展内存给目标内存池对应的目标进程使 用, 显著提升目标进程的运行性能。 附图说明
[15]图 1是本公开一个实施例提供的一种内存扩展方法的场景示意图。
[16]图 2是本公开一个实施例提供的一种内存扩展方法的流程图。
[17]图 3是本公开一个实施例提供的一种内存扩展方法的处理过程流程图。
[18]图 4是本公开一个实施例提供的另一种内存扩展方法的流程图。
[19]图 5是本公开一个实施例提供的一种内存扩展装置的结构示意图。
[20]图 6是本公开一个实施例提供的另一种内存扩展装置的结构示意图。
[21]图 7是本公开一个实施例提供的一种计算设备的结构框图。 具体实施方式
[22]在下面的描述中阐述了很多具体细节以便于充分理解本公开。 但是本公开能够以很 多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本公开内涵的情况 下做类似推广, 因此本公开不受下面公开的具体实施的限制。
[23]在本公开一个或多个实施例中使用的术语是仅仅出于描述特定实施例的目的, 而非 旨在限制本公开一个或多个实施例。在本公开一个或多个实施例和所附权利要求书中所 使用的单数形式的 “一种” 、 “所述” 和 “该” 也旨在包括多数形式, 除非上下文清楚 地表示其他含义。 还应当理解, 本公开一个或多个实施例中使用的术语 "和 /或”是指并 包含一个或多个相关联的列出项目的任何或所有可能组合。
[24]应当理解, 尽管在本公开一个或多个实施例中可能采用术语第一、 第二等来描述各 种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。 例如, 在不脱离本公开一个或多个实施例范围的情况下, 第一也可以被称为第二, 类似 地, 第二也可以被称为第一。 取决于语境, 如在此所使用的词语 “如果” 可以被解释成 为 “在 .. ...时” 或 “当 .. ...时” 或 “响应于确定” 。
[25]此外, 需要说明的是, 本公开一个或多个实施例所涉及的用户信息(包括但不限于 用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、 展示的数据等), 均为经用户授权或者经过各方充分授权的信息和数据, 并且相关数据 的收集、 使用和处理需要遵守相关国家和地区的相关法律法规和标准, 并提供有相应的 操作入口, 供用户选择授权或者拒绝。
[26]首先, 对本公开一个或多个实施例涉及的名词术语进行解释。
[27]GPA: Guest Physical Address, 客户机物理地址。
[28]HPA: Host Physical Address, 宿主机物理地址。
[29]EPT页表: Extend Page Table, 扩展页表, 一种硬件辅助的虚拟内存管理技术, 在虚 拟化环境中, EPT用于解决客户操作系统( Guest OS)与宿主机操作系统( Host OS) 之间的内存地址转换问题。
[30]页表是虚拟内存技术的概念, 为了让程序获得更多的可用内存、 将物理内存扩充成 更大的逻辑内存, 操作系统还使用了虚拟内存的技术, 它将物理内存抽象为地址空间, 操作系统为每个进程分配独立的一套虚拟地址,不同进程的虚拟地址和不同内存的物理 地址映射起来。 如果程序要访问虚拟地址的时候, 由操作系统转换成不同的物理地址。
此处涉及两个地址的概念: 程序所使用的内存地址叫做虚拟地址; 实际存在硬件里面的 空间地址叫做物理地址。
[31]虚拟地址与物理地址之间通过页表来映射, 页表存储在内存中, 当进程要访问的虚 拟地址在页表中查不到对应的物理地址时, 系统会产生一个缺页(pagefault)异常, 进入 系统内核态空间分配物理内存、 更新进程页表, 最后再返回用户态空间, 恢复进程的运 行。
[32]VMCS ( Virtual Machine Control Structure) : 虚拟机控制结构, 用于管理虚拟机状 态的数据结构; 在硬件虚拟化环境中, 每个虚拟机实例都有一个与其关联的 VMCS。
[33]VMCS包含了大量与虚拟机执行环境相关的字段和信息, 如: 虚拟机处理器状态, 包括通用寄存器、 指令指针、 标志寄存器等 CPU(中央处理器)内 部状态; 内存管理信息, 如 EPT页表基址、地址转换控制字段等, 用于支持内存虚拟化和地址转 换; 执行控制信息, 如进入和退出虚拟机的入口点、 事件注入、 异常和中断处理机制等; 虚拟机运行模式设置,如非根(虚拟)模式和根(物理)模式下的操作权限和行为规则; 以及 虚拟机执行控制字段, 如是否启用特定功能、 虚拟化扩展等。
[34]本公开实施例中, 在将物理模式运行的操作系统转换为虚拟模式运行的目标操作系 统的情况下, VMCS为用于管理虚拟模式运行的目标操作系统状态的数据结构。
[35]内存热插拔是一种允许在计算机运行状态下无需关机即可添加或移除内存模块的技 术, 常见于服务器和高端计算机系统中以提高系统的可用性和资源灵活性。 实现这一功 能的关键在于主板设计时包含了可插拔的内存槽位,并配置有专门的热插拔控制器来监 控内存插拔动作并与主板固件进行通信。
[36]在实际操作中, 只需将新的内存模块插入空闲的内存槽内, 热插拔控制器便会检测 到插入事件并通知主板固件。 随后, 固件会自动识别检测到新插入的内存模块, 并完成 初始化和物理地址空间分配等必要设置。
[37]在虚拟化环境中, 虚拟化平台通常允许虚拟机在运行时进行内存热插拔操作, 从而 实现在不停止虚拟机的情况下添加或移除内存。虚拟化平台(如 VMware ESXi、 KVM、 Hyper-V等)提供了相关的功能和接口, 使得虚拟机可以动态增加或减少内存资源。 具 体步骤如下。
[38]首先, 确保虚拟机的配置允许内存热插拔操作, 这通常需要设置虚拟机的内存热插 拔参数, 并确保虚拟机的操作系统和应用程序支持内存热插拔; 接着, 在虚拟化管理工 具或控制台中, 选择要调整内存的虚拟机, 按照虚拟化平台指引执行增加或减少内存的 操作; 虚拟机内部操作系统在接收到内存变更后, 会自动响应并重新分配与配置内存资 源, 使得新增加的内存能够被操作系统及应用程序有效利用。
[39]需要注意的是, 虚拟环境下针对虚拟机的内存热插拔操作, 实际上是针对虚拟内存
而非宿主机物理内存的操作, 扩展出来的是虚拟内存, 其功能受到虚拟化平台的限制和 支持程度的影响, 不能用于宿主机操作系统。
[40]因此, 亟需一种内存扩展方法, 让正在运行的宿主机操作系统具备热升级能力, 且 可以将热插内存(新添加的扩展内存)用于特定程序。
[41]在本公开中,提供了内存扩展方法,本公开同时涉及内存扩展装置,一种计算设备, 一种计算机可读存储介质以及一种计算机程序产品,在下面的实施例中逐一进行详细说 明。
[42]参见图 1 , 图 1示出了根据本公开一个实施例提供的一种内存扩展方法的场景示意 图。
[43]具体的, 该内存扩展方法应用端例设备 102以及服务器 104实现, 端例设备 102用 于向服务器 104发送内存扩展指令,即针对服务器 104中的内存进行扩展;服务器 104, 接收内存扩展指令, 其中, 所述内存扩展指令关联目标操作系统, 且所述目标操作系统 为由物理模式运行的操作系统转换为虚拟模式运行获得;根据所述内存扩展指令确定内 存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所述目标操作系统添加所述 内存扩展参数对应的扩展内存; 基于内存管理功能预设的内存管理函数, 将所述扩展内 存分配至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的内存供 所述目标操作系统使用, 并将该扩展结果, 比如是扩展成功, 扩展后的可用内存的消息 返回至端侧设备 102。
[44]端侧设备 102可以包括浏览器、 APP( Application, 应用程序) 、 或网页应用如 H5 ( Hyper Text Markup Languages , 超文本标记语言第 5版)应用、 或轻应用 (也被称为 小程序, 一种轻量级应用程序)或云应用等, 端侧设备可以基于服务端提供的相应服务 的软件开发工具包( SDK, Software Development Kit) ,如基于实时通信( RTC, Real Time Communication) SDK开发获得等。 端侦 J设备可以部署在电子设备中, 需要依赖设备运 行或者设备中的某些 APP 而运行等。 电子设备可以具有显示屏并支持信息浏览等, 如 可以是个人移动终端如手机、 平板电脑、 个人计算机等。 在电子设备中通常还可以配置 各种其它类应用, 例如人机对话类应用、 模型训练类应用、 文本处理类应用、 网页浏览 器应用、 购物类应用、 搜索类应用、 即时通信工具、 邮箱客户端、 社交平台软件等。
[45]服务器 104可以理解为提供各种服务的服务器, 包括物理服务器、 云服务器, 例如 为多个客户端提供通信服务的服务器,又如为客户端上使用的模型提供支持的用于后台 训练的服务器, 又如对客户端发送的数据进行处理的服务器等。 需要说明的是, 服务器 104可以实现成多个服务器组成的分布式服务器集群, 也可以实现成单个服务器。 服务 器 104也可以为分布式系统的服务器, 或者是结合了区块链的服务器。 服务器 104也可 以是云服务、 云数据库、 云计算、 云函数、 云存储、 网络服务、 云通信、 中间件服务、 域名服务、 安全服务、 内容分发网络( CDN, Content Delivery Network) > 以及大数据 和人工智能平台等基础云计算服务的云服务器,或者是带人工智能技术的智能云计算服 务器或智能云主机。
[46]本公开一个实施例提供的内存扩展方法, 通过将正在运行中的宿主机操作系统, 切 换成虚拟模式运行的目标操作系统, 接收针对目标操作系统的内存扩展指令, 为目标操 作系统添加对应的扩展内存, 在不停止目标操作系统运行的情况下进行平滑、 灵活的内
存扩展, 确保操作系统中的服务不会中断, 实现了对用户的无感操作, 降低了由重启操 作系统引发的各种不稳定因素, 增强了操作系统的稳定性和可靠性, 且在可以按需将扩 展内存分配至目标内存池,使目标内存池中的扩展内存给目标内存池对应的目标进程使 用, 显著提升目标进程的运行性能。
[47]参见图 2, 图 2示出了本公开一个实施例提供的一种内存扩展方法的流程图, 具体 包括以下步骤。
[48]步骤 202: 接收内存扩展指令, 其中, 所述内存扩展指令关联目标操作系统, 且所 述目标操作系统为由物理模式运行的操作系统转换为虚拟模式运行获得。
[49]其中,内存扩展指令可以理解为,用于使目标操作系统进行内存扩展的指令;其中, 内存扩展指令中可以携带有内存扩展参数, 内存扩展参数可以包括要扩展的内存的起始 地址、 以及要扩展的内存大小。
[50]操作系统配置内存管理功能, 通过内存管理功能能够实现内存分配、 内存回收、 地 址转换等; 内存分配, 如当进程请求内存时, 操作系统从可用内存中划分出合适的区域 分配给进程; 内存回收, 如进程结束或释放不再使用的内存区域时, 操作系统及时回收 这些内存空间, 以供其他进程使用; 地址转换, 如操作系统为每个进程提供虚拟地址空 间, 通过页表等数据结构进行虚拟地址与物理地址之间的地址转换。
[51]物理模式可以理解为, root(根)模式或者内核模式;虚拟模式可以理解为, non-root (非根)模式或者用户模式; 目标操作系统可以理解为, 以非根模式运行的操作系统。
[52]具体的, 接收通过内存管理功能提交的、 针对以非根模式运行的目标操作系统的内 存扩展指令, 使目标操作系统进行内存扩展。
[53]在本公开一个或多个实施例中, 在接收内存扩展指令之前, 还需要先根据接收到的 配置变更指令将以根模式运行的操作系统转换为以非根模式运行的目标操作系统。具体 实现方式如下所述。
[54]所述接收内存扩展指令之前, 还包括: 接收针对所述物理模式运行的操作系统、 提 交的配置变更指令; 根据所述配置变更指令将所述操作系统, 转换为虚拟模式运行的目 标操作系统。
[55]其中, 配置变更指令可以理解为, 用于使操作系统进行模式转换的变更指令。
[56]具体的, 在需要扩展内存的情况下, 由于以根模式运行的操作系统在存在物理内存 的情况下, 才能在线添加内存, 因此, 需要先转换操作系统的运行模式, 在以非根模式 运行的目标操作系统中扩展内存。
[57]实际应用中, 在需要为正在运行中的操作系统扩展内存的情况下, 首先向操作系统 发送配置变更指令, 从而根据配置变更指令切换操作系统的运行模式。
[58]本公开实施例提供的内存扩展方法, 通过接收配置变更指令, 能够根据实际需求动 态地将物理模式运行的操作系统转换为虚拟模式运行,从而实现资源的灵活调度和高效 利用。
[59]在本公开一个或多个实施例中, 在需要根据配置变更指令将所述操作系统, 转换为 非根模式运行的目标操作系统的情况下, 需要首先进行一系列的配置操作, 由此才能完
成模式切换。 具体实现方式如下所述。
[60]所述根据所述配置变更指令将所述操作系统,转换为虚拟模式运行的目标操作系统, 包括: 根据所述配置变更指令为所述操作系统建立地址映射页表, 并保存所述物理模式 运行的操作系统对应的寄存器的初始数据; 根据所述地址映射页表以及所述初始数据, 建立目标数据结构; 对所述目标数据结构中的目标数据进行配置, 并将配置完成的目标 数据结构加载到中央处理器, 触发所述操作系统转换为虚拟模式运行的目标操作系统, 其中, 所述目标数据为与所述目标操作系统对应的控制信息。
[61]其中, 地址映射页表可以理解为 EPT页表, EPT页表中存在页表项, 用于记录虚拟 地址到物理地址的映射; 而由于此时还未将以根模式运行的操作系统, 转换为以非根模 式运行的目标操作系统, 因此, 此时 EPT页表中的 GPA等于 HPA.
[62]初始数据可以理解为, 寄存器中的数据; 目标数据结构可以理解为 VMCS , 用于管 理和控制目标操作系统执行环境的数据结构; 目标数据可以理解为, 与控制虚拟执行环 境相关的字段和信息。
[63]具体的, 在接收到配置变更指令的情况下, 建立从 GPA到 HPA —映射的 EPT页 表, 并将当前运行的 CPU的所有状态信息保存下来, 包括但不限于各个通用寄存器、 控制寄存器、 标志寄存器等所有影响 CPU执行状态的数据; 根据这些寄存器的值以及 EPT页表建立运行虚拟模式的 VMCS。
[64]在 VMCS中, 包含了大量与虚拟执行环境相关的字段和信息, 通过配置 VMCS中 的字段实现对 VCPU(虚拟模式运行的中央处理器) 的控制, 比如设置 VMCS 中的 VM-entry/VM-exit(虚拟机进入 /虚拟机退出)控制位, 以指定哪些指令应该被截获, 如 设置虚拟化模式运行过程中的退出处理函数, 当 EPT Violation(EPT违规, 当 CPU尝 试访问一个地址时, 如果该地址的 EPT映射未正确设置或者权限不符, 则会发生 EPT Violation异常)异常导致 VM Exit时, 利用退出处理函数为 EPT Violation对应的 EPT 缺页处理函数, 处理因 EPT Violation异常而引发的 VM Exit。
[65]通过将配置好的 VMCS加载到 CPU,将正在运行的中央处理器切换成非根模式运行 的 VCPU, 使得正在运行的宿主机(以根模式运行的物理机)进入虚拟模式运行, 也就 相当于触发了操作系统模式的切换, 即将操作系统转换为虚拟模式运行的目标操作系统 0
[66]本公开实施例提供的内存扩展方法, 通过建立地址映射页表以及保存寄存器的初始 数据, 建立目标数据结构, 并通过配置目标数据结构的目标数据能够准确、 有效的完成 操作系统模式的转换。
[67]在本公开一个或多个实施例中, 为更有效的管理以及整理内存空间, 将内存划分为 固定粒度的块, 并将内存块的内存状态设置为使用状态。 具体实现方式如下所述。
[68]所述根据所述配置变更指令将所述操作系统转换为虚拟模式运行的目标操作系统之 后, 还包括: 通过所述内存管理功能, 将所述目标操作系统对应的物理内存划分为预设 粒度的内存块; 将所述内存块的内存状态设置为使用状态。
[69]其中,预设粒度可以根据实际需求进行设置,在此不做限定,如预设粒度为 2MB(兆 字节) 。
[70]具体的, 可以以 2 M粒度将宿主机所有真实的物理内存划分为内存块, 且由于所有 的物理内存均由宿主机进行管理, 因此, 此时在宿主机以虚拟模式运行的情况下, 所有 的物理内存的初始内存状态均为已使用状态。
[71]本公开实施例提供的内存扩展方法, 通过将物理内存划分为固定粒度的块, 有利于 管理和整理内存空间, 降低内存碎片的产生; 可以针对各内存块进行高效管理从而更高 效的分配物理内存资源。
[72]在本公开一个或多个实施例中, 通过查找当前空闲的空闲页面, 将空闲页面对应的 地址映射页表中的页表项删除, 并更新内存状态, 方便后续针对空闲页面进行分配。 具 体实现方式如下所述。
[73]所述将所述内存块的内存状态设置为使用状态之后, 还包括: 通过所述内存管理功 能, 确定所述目标操作系统对应的、 当前空闲页面, 其中, 所述空闲页面为当前未被任 何进程占用、 可供所述目标操作系统分配给进程使用的物理内存页面, 所述物理内存页 面组成所述物理内存; 将所述空闲页面对应的所述地址映射页表中的页表项删除, 并将 所述空闲页面对应的内存状态更新为空闲状态, 其中, 所述地址映射页表由所述页表项 组成, 所述页表项记录虚拟地址到物理地址的映射。
[74]实际应用中, 物理内存页面为物理内存的分配单位, 即在为进程分配物理内存, 一 页一页的为其进行分配。
[75]具体的, 通过内存管理功能遍历宿主机中的当前空闲的空闲页面, 而在某个物理内 页面变为空闲状态的情况下, 意味着该页面为被任何虚拟地址所引用, 因此可以将其对 应的页表项从地址映射页表中删除, 并更新内存状态为空闲状态, 通过将空闲页面添加 至全局空闲列表中, 便于后续内存分配操作时能够快速找到可分配的物理内存页面。
[76]本公开实施例提供的内存扩展方法, 确保了物理内存的有效管理和合理利用, 并且 为多任务环境下的内存调度提供了必要的基础,通过将空闲页面添加至全局空闲列表中, 便于后续内存分配操作时能够快速找到可分配的物理内存页面。
[77]步骤 204: 根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操作系统的 内存管理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存。
[78]其中, 内存扩展参数包括扩展内存的地址空间以及扩展内存的大小; 内存管理接口 可以理解为扩展接口, 通过调用扩展接口实现添加扩展内存。
[79]实际应用中, 为虚拟机扩展内存时, 需要通过复杂的硬件中断机制的通知机制来通 知操作系统扩展内存, 而在内存扩展方法以模块形式提供各种功能的情况下, 可直接通 过调用目标操作系统的扩展接口, 为目标操作系统添加内存扩展参数对应的扩展内存。
[80]在本公开一个或多个实施例中, 为准确的添加扩展内存, 在目标操作系统对应的虚 拟内存地址范围添加扩展内存,保证目标操作系统能够为应用程序提供更大的可用内存 空间。 具体实现方式如下所述。
[81]所述根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操作系统的内存管 理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存, 包括: 根据所述 内存扩展指令确定内存扩展参数, 其中, 所述内存扩展参数包括所述扩展内存对应的虚
拟内存地址范围; 调用所述目标操作系统的内存管理接口, 在所述目标操作系统对应的 所述虚拟内存地址范围添加所述扩展内存。
[82]其中, 虚拟内存地址范围可以理解为, 依据扩展内存的地址空间以及扩展内存的大 小确定的地址空间范围。
[83]在需要添加扩展内存的情况下,确定要添加的扩展内存的 GPA地址空间和扩展内存 的大小(即内存扩展参数), 那就首先需要确定目标操作系统当前使用的最大物理页面 帧号( Physical Frame Number, PFN) ,在获取到最大 PFN之后,选择高于现有最大 PFN 的地址区间作为新的内存映射区域, 例如, 如果当前目标操作系统最大的 PFN对应的 是 40GB(吉字节) 内存空间的末端, 则可以将新添加的扩展内存从 40GB之后开始分 配, 并依据扩展内存的内存大小进行分配。
[84]本公开实施例提供的内存扩展方法, 通过扩展内存满足宿主机中应用产品的需求, 也可以避免由于可用内存不足, 导致无法为进程分配所需的内存, 进而触发系统的异常 终止或强制杀死部分进程的问题, 或者不能升级到最新产品的问题 °
[85]步骤 206: 基于内存管理功能预设的内存管理函数, 将所述扩展内存分配至所述目 标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的内存供所述目标操作系 统使用。
[86]其中, 内存管理函数可以理解为, 针对扩展内存的处理函数, 用于对扩展内存进行 处理以及管理, 例如利用内存管理函数可以让扩展内存进入特定内存池, 比如进入 hugetlb ( Huge Translation Lookaside Buffer, 一种内存管理机制, 用于支持大页内存) 、 或者专用池子等。
[87]目标内存池即可以理解为上述的特定内存池, 可用于满足特定程序 (如高性能运算 资源的程序)的内存需求。
[88]实际应用中, 为让扩展内存进入特定的内存池, 会通过内存管理功能预设扩展内存 的处理函数, 以便在增加扩展内存的情况下, 实现对扩展内存的处理。
[89]在本公开一个或多个实施例中, 可通过设置目标内存池机制, 动态分配扩展内存, 实现对扩展内存的处理分配。 具体实现方式如下所述。
[90]所述将所述扩展内存分配至所述目标操作系统对应的目标内存池, 包括: 根据目标 内存池机制, 将所述扩展内存分配至所述目标操作系统对应的目标内存池。
[91]所述根据目标内存池机制, 将所述扩展内存分配至所述目标操作系统对应的目标内 存池, 包括: 将所述目标内存池设置为目标进程使用, 将所述扩展内存分配至所述目标 操作系统对应的目标内存池, 以使所述目标进程使用所述目标内存池中的所述扩展内存, 或者,将所述目标内存池设置为所述目标进程中的代码段和 /或数据段使用,将所述扩展 内存分配至所述目标操作系统对应的目标内存池,以使所述目标进程中的代码段和 /或数 据段使用所述目标内存池中的所述扩展内存。
[92]其中, 目标进程可以理解为, 设置为允许使用目标内存池的进程。
[93]具体的, 针对特定内存池, 可以动态设置允许使用该特定内存池的进程, 从而使得 目标进程使用目标内存池中的内存;还可以设置对应进程的代码段或者数据段使用特定
内存池中的内存, 从而使得目标进程使用目标内存池中内存。
[94]当然, 实际应用中, 也可以将扩展内存分配至目标操作系统对应的通用内存中, 在 此不做限定。
[95]本公开实施例提供的内存扩展方法, 通过将目标内存池设置为特定的目标进程或者 是, 目标进程中的代码段和 /或数据段使用, 为目标进程提供专用的内存空间, 减少了不 同进程间的内存争抢, 有助于提升目标进程的数据读写速度和执行效率。
[96]在本公开一个或多个实施例中, 可以动态调整特定内存池的大小, 实现特定内存池 的容量能够满足扩展内存的大小。 具体实现方式如下所述。
[97]所述根据目标内存池机制, 将所述扩展内存分配至所述目标操作系统对应的目标内 存池, 包括: 根据所述扩展内存的内存扩展参数, 调整所述目标内存池的容量配置, 使 得所述目标内存池的容量与所述扩展内存的大小相匹配;将所述扩展内存分配至所述目 标操作系统对应的、 调整后的目标内存池。
[98]具体的, 在新添加的扩展内存小于特定内存池容量的情况下, 将新添加的扩展内存 加入到特定内存池; 在新添加的扩展内存大于特定内存池的情况下, 将多余的扩展内存 放到通用内存。
[99]实际应用中, 特定内存池中的大小也可以动态调整, 比如新添加的扩展内存如果小 于当前特定内存池的大小, 则释放部分特定内存池中的内存给通用内存; 否则, 从通用 hugetlb中获取内存, 将扩展内存分配至调整容量后的目标内存池。 需要说明的是, 如果 有针对特定内存池的内存分配请求, 而在特定内存池内存不够的情况下就不能满足该请 求, 此时, 目标操作系统并不会立即报告内存分配失败, 而是会选择回退到常规的内存 分配路径, 从整体可用内存中寻找合适的内存区域来完成分配。
[ 100]本公开实施例提供的内存扩展方法, 通过调整目标内存池的容量以匹配扩展内存, 能够有效利用新增加的内存资源, 避免了内存浪费, 使得系统整体性能得到提升。
[101]在本公开一个或多个实施例中, 为使得在添加扩展内存的情况下,应用程序能够使 用新添加的扩展内存, 通过设置异常处理函数进行处理。 具体实现方式如下所述。
[102]所述将所述扩展内存分配至所述目标操作系统对应的目标内存池之后,还包括: 在 所述目标操作系统中运行的目标进程、使用所述目标内存池中的所述扩展内存, 触发缺 页异常的情况下, 根据所述缺页异常, 调用与所述缺页异常对应的异常处理函数; 基于 所述异常处理函数, 通过所述内存管理功能确定目标内存块, 并建立所述扩展内存与所 述目标内存块对应的页表项, 其中, 目标内存块为内存状态为空闲状态的内存块; 通过 所述扩展内存与所述目标内存块对应的页表项,将所述扩展内存映射到所述目标内存块。
[103]具体的,后续在进程使用到新添加的扩展内存的情况下, 由于底层还未建立其和真 实物理内存的映射, 会自动触发缺页异常走 EPT violation的处理路径, 此时根据触发的 缺页异常,调用上述设置的 EPT缺页处理函数,将从内存块中找到一块未使用(当前处 于空闲状态)的内存块作为目标内存块, 用于建立扩展内存与该目标内存块对应的 EPT 页表项, 记录虚拟地址到新分配的物理地址(目标内存块地址)的映射关系, 操作系统 重新启动因缺页异常而暂停的进程, 使其能够继续执行, 并成功访问到之前无法访问的 扩展内存区域。
[104]本公开实施例提供的内存扩展方法,通过调用与缺页异常对应的异常处理函数,有 效地解决了缺页异常问题, 实现了虚拟内存地址到物理内存地址的动态映射, 从而使得 进程可以顺利地使用新增加的扩展内存资源。
[105]在本公开一个或多个实施例中,为保证底层内存管理功能能够实现对内存块的分配, 需要底层物理内存中存在合理数量的空闲内存, 因此可通过设置内存空闲空间, 通过内 存空闲空间的大小来判断当前是否存在合理数量的空闲内存, 以进行对应的处理操作。 具体实现方式如下所述。
[106]所述内存扩展方法,还包括: 通过所述内存管理功能在所述目标操作系统对应的物 理内存中设置内存空闲空间;在所述内存空闲空间低于第一阈值高于第二阈值的情况下, 触发内存回收操作, 释放所述内存状态处于空闲状态的物理内存; 在所述内存空闲空间 低于所述第二阈值的情况下, 向运维程序发送处理通知, 以使所述运维程序根据所述处 理通知进行进程迁移以及数据保护操作 „
[107]其中, 第一阈值、 第二阈值可根据实际情况进行设置, 且第一阈值、 第二阈值在实 际应用中也可应用比例进行表示; 如第一阈值为 30%, 第二阈值为 10%; 运维程序可以 理解为, 对系统进行运维的程序, 保证系统的安全运行。
[108]实际应用中, 内存空闲空间可形象化的用内存水位进行表示,在内存水位高于第一 阈值的情况下, 认为内存水位处于高水位, 即存在较多空闲内存, 此时可保持现状不做 任何处理; 在内存水位低于第一阈值高于第二阈值的情况下, 认为内存水位处于高水位 与低水位之间, 则触发内存回收操作, 即回收空闲内存, 或者压缩内存等, 来腾挪出底 层的空闲内存, 具体的在回收内存时, 优先回收冷页(冷页表示已不在高速缓存中的空 闲页面)或空闲内存。
[109]而在内存水位低于第二阈值的情况下, 认为内存水位低于紧急水位, 则 EPT缺页 会返回失败, 以便预留保底内存保证系统还能运行一段时间, 同时需要向上层运维程序 发送处理通知, 以便运维程序根据处理通知进行系统崩溃前的紧急迁移等处理。
[110]本公开一个实施例提供的内存扩展方法,通过设置内存空闲空间, 实时监控和调整 物理内存的使用情况, 确保系统能根据实际需求动态分配和回收内存资源, 提高内存利 用率; 且通过发送处理通知, 能够极大地增强系统的稳定性和可用性, 降低运维成本。
[111]本公开一个实施例提供的内存扩展方法,通过将正在以物理模式运行中的操作系统 , 切换成虚拟模式运行的目标操作系统, 接收针对目标操作系统的内存扩展指令, 为目标 操作系统添加对应的扩展内存, 在不停止目标操作系统运行的情况下进行平滑、 灵活的 内存扩展, 确保操作系统中的服务不会中断, 实现了对用户的无感操作, 降低了由重启 操作系统引发的各种不稳定因素, 增强了操作系统的稳定性和可靠性, 且在可以按需将 扩展内存分配至目标内存池的情况下, 通过设定目标内存池中内存的使用权限, 使目标 内存池中的扩展内存给目标进程使用, 显著提升目标进程的运行性能。
[112]参见图 3 , 图 3示出了本公开一个实施例提供的一种内存扩展方法的处理过程流程 图, 具体包括以下步骤。
[113]步骤 302: 建立地址映射表。
[114]具体的, 在接收到变更配置指令的情况下, 建立从 GPA到 HPA —映射的 EPT
页表, 由于此时还未将以根模式运行的操作系统, 转换为以非根模式运行的目标操作系 统, 因此, 此时的 GPA等于 HPA。
[115]步骤 304: 保存寄存器的值, 建立目标数据结构。
[116]当需要对当前操作系统的运行模式进行切换的情况下,首先需要将当前运行的 CPU 的所有状态信息保存下来, 包括但不限于各个通用寄存器、 控制寄存器、 标志寄存器等 所有影响 CPU执行状态的数据。
[117]根据这些寄存器的数据和 EPT建立运行虚拟模式的 VMCS , 在建立 VMCS的过程 中, 需要才艮据 EPT 配置来确保切换后的目标操作系统内存访问的正确性; 在建立完成 VMCS 后, 通过根据 VMCS中的信息加载目标操作系统对应的 VCPU(虚拟中央处理 器)的寄存器值, 从而恢复目标操作系统的执行环境; 这样, 当重新调度回该目标操作 系统时,能够从之前保存的状态继续执行,保证了目标操作系统执行的连续性和独立性。
[118]步骤 306: 配置目标数据结构, 设置退出函数。
[119]其中, 退出函数可以理解为, 虚拟模式运行过程中的退出处理函数, 用于当目标操 系统执行过程中触发特定事件时从非根模式切换回根模式。
[120] VMCS中包含了大量与虚拟执行环境相关的字段和信息, 通过配置 VMCS中的字 段实现对 VCPU的控制, 比如设置 VMCS中的 VM-entry/VM-exit(虚拟机进入 /虚拟机 退出)控制位, 以指定哪些指令应该被截获; 如在设置和初始化 VMCS 的过程中, 需 要正确配置相关的 VM Exit信息, 对于 EPT Violation(EPT违规, 当 CPU尝试访问一 个地址时, 如果该地址的 EPT映射未正确设置或者权限不符, 则会发生 EPT Violation 异常), 需要启用相应的 VM Exit控制位, 并配置好退出相应的字段以捕获不同类型的 EPT违规行为, 例如读取、 写入或执行权限等。
[121]当 EPT Violation异常导致 VM Exit时, 退出处理函数为 EPT Violation对应的 EPT 缺页处理函数, 用于处理因 EPT Violation异常而引发的 VM Exit。
[122]步骤 308: 转换运行模式。
[123]在 VMCS配置完毕的情况下, 通过向正在运行的物理机的 CPU发送指令, 加载配 置好的 VMCS到 CPU中, 这一步骤使得 CPU开始依据 VMCS中的配置进入虚拟模式 运行; 即实现了将正在运行的 CPU切换成虚拟模式运行的 VCPU, 使得正在运行的物 理机进入虚拟模式运行。
[124]步骤 310: 划分内存块、 设置内存块的内存状态。
[125]为物理机所有真实的物理内存建立内存块管理功能,即为了高效管理和分配物理内 存资源, 会将连续的物理内存划分为大小相等或不等的内存块, 如可以以 2MB(兆字 节)粒度将物理内存划分为多个内存块, 由于所有的物理内存均由物理机管理, 因此, 此时在物理机以虚拟模式运行的情况下,所有的物理内存的初始内存状态均为已使用状 态。
[126]步骤 312: 确定空闲页面, 更新内存块的内存状态。
[127]遍历物理机中的所有内存块, 查找内存状态为 “已使用”但实际上当前正处于空闲 状态的物理内存页面, 对于找到的每个空闲页面, 获取其在 EPT 中的页表项, 并通过
EPT操作指令将对应的页表项清除或置零, 从而撤销对虚拟内存的映射, 将这些空闲页 面的内存状态更新为空闲状态, 以便后续的分配。
[128]步骤 314: 设置内存管理函数、 确定扩展内存的内存扩展参数。
[129]其中, 内存管理函数可以理解为, 扩展内存的处理函数, 用于使扩展内存进入专用 内存池; 具体的, 首先创建并初始化专用内存池, 专用内存池用于满足特定程序(如高 性能运算资源的程序)的内存需求; 而通用 hugetlb, 则用于动态分配给任何需要的大页 面请求。
[130]实际应用中,可以通过设置扩展内存的处理函数来管理新添加的扩展内存,让新添 加的扩展内存进入专用内存池, 且专用内存池会配置需要的内存容量, 扩展内存会优先 进入专用池, 如果扩展内存还有余量则会放入通用 hugetlb中, 确保添加的扩展内存优 先进入专用内存池。
[131]而在需要添加扩展内存的情况下, 需要确定要添加的扩展内存的 GPA地址空间和 扩展内存的大小(即内存扩展参数), 那就首先需要确定目标操作系统当前使用的最大 物理页面帧号( Physical Frame Number, PFN) , 在获取到最大 PFN之后, 选择高于现 有最大 PFN 的地址区间作为新的内存映射区域, 例如, 如果当前目标操作系统最大的 PFN 对应的是 40GB (吉字节) 内存空间的末端, 则可以将新添加的扩展内存从 40GB 之后开始分配。
[132]步骤 316: 添加虚拟内存至特定内存池。
[133]实际应用中, 为虚拟机扩展内存时, 需要通过复杂的硬件中断机制的通知机制来通 知操作系统扩展内存, 而在内存扩展方法以模块形式提供各种功能的情况下, 可直接通 过调用目标操作系统的内存管理接口 (扩展接口), 为目标操作系统添加内存扩展参数 对应的扩展内存,从而避免由于内存不足,导致线上宿主机出现大规模 OOM的问题(因 可用内存不足而导致无法为进程分配所需的内存,进而触发系统的异常终止或强制杀死 部分进程) 。
[134]且基于上述设置的扩展内存的处理函数,可以将所述扩展内存分配至所述目标操作 系统对应的特定内存池(即上述实施例中的专用内存池) , 用于特定进程使用。
[135]步骤 318: 配置特定内存池。
[136]具体的, 特定内存池可以尤 I据实际需求进行设置, 例如针对特定内存池, 可以动态 设置允许使用该特定内存池的进程;还可以设置对应进程的代码段或者数据段使用特定 内存池中的内存。
[137]在新添加的扩展内存小于特定内存池的情况下,将新添加的扩展内存加入到特定内 存池;在新添加的扩展内存大于特定内存池的情况下,将多余的扩展内存放到通用内存; 并且特定内存池中的大小也可以动态调整, 比如新添加的扩展内存如果小于当前特定内 存池的大小, 则释放部分特定内存池中的内存给通用内存; 否则, 从通用 hugetlb中获 取内存; 如果有针对特定内存池的内存分配请求, 而在特定内存池内存不够的情况下就 不能满足该请求, 此时, 目标操作系统并不会立即报告内存分配失败, 而是会选择回退 到常规的内存分配路径, 从整体可用内存中寻找合适的内存区域来完成分配。
[138]步骤 320: 使用扩展内存, 触发缺页异常。
[139]后续在应用程序使用到扩展内存的情况下,由于底层还未建立其和真实物理内存的 映射, 会自动触发缺页异常走上述 EPT violation的处理路径。
[140]步骤 322: 根据缺页处理函数, 确定未使用的内存块。
[141]根据 EPT violation异常利用 EPT缺页处理函数, 从内存块中找到一块未使用 (当 前处于空闲状态)的内存块, 用于建立扩展内存与该内存块对应的 EPT页表,这样应用 程序就可以使用新扩展的虚拟内存。
[142]步骤 324: 设定内存水位。
[143]具体的通过内存块管理功能,可以针对物理内存设定内存水位, 以便保证内存块管 理功能中存在合理数量的空闲内存,其中,内存水位表示的是当前空闲内存的空闲空间; 如果内存水位处于高水位, 说明当前空闲内存数量较多则暂时保持现状; 如果内存水位 低于高水位, 高于低水位, 则会回收空闲内存, 或者压缩内存等, 来获得更多的空闲内 存; 如果内存水位低于低水位, 高于紧急水位, 则会加速内存回收; 具体的在回收内存 时, 优先回收冷页(冷页表示已不在高速缓存中的空闲页面)或空闲内存, 以保证内存 水位处于合理位置; 如果内存水位低于紧急水位, 则在触发 EPT缺页异常的情况下, 不 会为扩展内存分配内存块, 会返回失败, 以便预留预设的内存保证系统能够运行一段时 间, 同时需要通知上层运维程序, 将严重内存不足的状态告知上层运维程序, 以便上层 运维程序进行系统崩溃前的紧急迁移等处理。
[144]当然, 实际应用中, 当系统资源处于较为空闲的状态时, 可以回收掉扩展内存, 这 样一来, 系统能够更加集中地利用原本的物理内存资源; 且在通过预定策略识别冷页的 情况下, 在识别的准确率越高时, 越能减少缺页异常发生的概率, 进而减少系统的运行 开销和性能损失, 即在系统资源充足且利用率不高的情况下, 合理调整内存分配策略, 将更多的操作限制在真实物理内存范围内进行, 有助于提升整体系统性能和响应速度。
[145]本公开一个实施例提供的内存扩展方法,通过切换操作系统的运行模式,针对切换 后的目标操作系统, 在不停止目标操作系统运行的情况下, 根据内存扩展指令, 通过调 用接口的方式为目标操作系统添加对应的扩展内存,相比较虚拟机通过复杂的硬件中断 机制的通知机制来通知操作系统扩展内存的方式, 不仅大大提高了扩展效率还实现了对 用户的无感操作, 降低了由重启操作系统引发的各种不稳定因素, 增强了操作系统的稳 定性和可靠性。
[146]参见图 4, 图 4示出了本公开一个实施例提供的另一种内存扩展方法的流程图, 具 体包括以下步骤 402至 408。
[147]步骤 402: 接收针对物理模式运行的操作系统、 提交的配置变更指令。
[148]步骤 404: 根据所述配置变更指令将所述操作系统转换为虚拟模式运行的目标操作 系统, 其中, 所述目标操作系统配置有内存管理功能。
[149]步骤 406: 在接收到通过所述内存管理功能提交的内存扩展指令的情况下, 根据所 述内存扩展指令确定内存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所述 目标操作系统添加所述内存扩展参数对应的扩展内存。
[150]步骤 408: 基于所述内存管理功能预设的内存管理函数, 将所述扩展内存分配至所 述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的目标内存供所述目 标操作系统使用。
[151]具体可参见上述实施例, 在此不再赘述。
[152]本公开一个实施例提供的内存扩展方法,能够实现操作系统从物理模式到虚拟模式 的转换, 通过接收内存扩展指令并根据该指令动态添加扩展内存, 使得目标操作系统能 够在运行时根据实际需求增加内存资源, 提高了系统对资源的利用效率和响应速度; 且 预设内存管理函数可以有效地管理和分配扩展内存至目标内存也中,保证了新增内存资 源能被目标操作系统合理、 高效地使用, 避免了内存资源浪费, 同时也提升了系统的整 体性能和稳定性。
[153]与上述方法实施例相对应,本公开还提供了内存扩展装置实施例, 图 5示出了本公 开一个实施例提供的一种内存扩展装置的结构示意图。 如图 5所示, 该装置包括: 接收模块 502, 被配置为接收内存扩展指令, 其中, 所述内存扩展指令关联目标操作系 统, 且所述目标操作系统为由物理模式运行的操作系统转换为虚拟模式运行获得; 确定模块 504, 被配置为根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操 作系统的内存管理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存; 分配模块 506, 被配置为基于内存管理功能预设的内存管理函数, 将所述扩展内存分配 至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的目标内存供所 述目标操作系统使用。
[154]所述装置, 还包括转换模块, 其被配置为: 接收针对物理模式运行的操作系统、 提 交的配置变更指令;根据所述配置变更指令将所述操作系统转换为虚拟模式运行的目标 操作系统, 其中, 所述目标操作系统配置有内存管理功能 „
[155]可选地, 所述转换模块, 进一步被配置为: 根据所述配置变更指令为所述操作系统 建立地址映射页表,并保存寄存器的初始数据,其中,所述地址映射页表由页表项组成, 所述页表项记录虚拟地址到物理地址的映射;根据所述地址映射页表以及所述初始数据, 建立目标数据结构; 对所述目标数据结构中的目标数据进行配置, 并将配置完成的目标 数据结构加载到目标处理器, 触发所述操作系统转换为虚拟模式运行的目标操作系统。
[156]所述装置, 还包括管理模块, 其被配置为: 通过所述内存管理功能, 将所述目标操 作系统的物理内存划分为预设粒度的内存块, 其中, 物理内存为所述物理地址对应的硬 件资源; 将所述内存块的内存状态设置为初始使用状态。
[157]可选地, 所述管理模块, 进一步被配置为: 通过所述内存管理功能, 确定所述目标 操作系统当前的空闲页面, 其中, 所述空闲页面为当前未被任何进程占用、 可供所述目 标操作系统分配使用的物理内存页面,所述物理内存页面通过将所述物理内存划分为固 定大小的块得到; 将所述空闲页面对应的所述地址映射页表中的页表项删除, 并将所述 空闲页面对应的内存块的内存状态更新为空闲状态。
[158]可选地, 所述确定模块 504, 进一步被配置为: 根据所述内存扩展指令确定内存扩 展参数, 其中, 所述内存扩展参数包括所述扩展内存对应的虚拟内存地址范围; 调用所
述目标操作系统的内存管理接口,在所述目标操作系统对应的所述虚拟内存地址范围添 加所述扩展内存。
[159]可选地, 所述分配模块 506, 进一步被配置为: 根据目标内存池机制, 将所述扩展 内存分配至所述目标操作系统对应的目标内存池。
[160]可选地,所述分配模块 506,进一步被配置为:将所述目标内存池设置为目标进程、 或者所述目标进程中的代码段和 /或数据段使用,并将所述扩展内存分配至所述目标操作 系统对应的目标内存池,以使所述目标进程、或者所述目标进程中的代码段和 /或数据段 使用所述目标内存池中的所述扩展内存。
[161]可选地,所述分配模块 506,进一步被配置为:根据所述扩展内存的内存扩展参数, 调整所述目标内存池的容量配置,使得所述目标内存池的容量与所述扩展内存的大小相 匹配; 将所述扩展内存分配至所述目标操作系统对应的目标内存池。
[162]所述装置, 还包括处理模块, 其被配置为在所述目标操作系统中运行的目标进程、 使用所述目标内存池中的所述扩展内存的情况下,触发缺页异常,并根据所述缺页异常, 调用与所述缺页异常对应的异常处理函数; 基于所述异常处理函数, 通过所述内存管理 功能确定目标内存块, 并建立所述扩展内存与所述目标内存块对应的页表项, 将所述虚 拟内存映射到所述目标内存块。
[163]所述装置,还包括设置模块,其被配置为通过所述内存管理功能在所述目标操作系 统的物理内存中设置内存水位, 其中, 所述内存水位表示空闲物理内存的水位; 在所述 内存水位低于第一阈值高于第二阈值的情况下, 触发内存回收操作, 释放所述内存状态 处于空闲状态的物理内存; 在所述内存水位低于第二阈值的情况下, 向运维程序发送处 理通知, 根据所述处理通知进行进程迁移以及数据保护操作。
[164]本公开一个实施例提供的内存扩展装置,通过将正在以物理模式运行中的操作系统, 切换成虚拟模式运行的目标操作系统, 接收针对目标操作系统的内存扩展指令, 为目标 操作系统添加对应的扩展内存, 在不停止目标操作系统运行的情况下进行平滑、 灵活的 内存扩展, 确保操作系统中的服务不会中断, 实现了对用户的无感操作, 降低了由重启 操作系统引发的各种不稳定因素, 增强了操作系统的稳定性和可靠性, 且可以按需将扩 展内存分配至目标内存池,使目标内存池中的扩展内存给目标内存池对应的目标进程使 用, 显著提升目标进程的运行性能。
[165]上述为本实施例的一种内存扩展装置的示意性方案。需要说明的是,该内存扩展装 置的技术方案与上述的内存扩展方法的技术方案属于同一构思, 内存扩展装置的技术方 案未详细描述的细节内容, 均可以参见上述内存扩展方法的技术方案的描述。
[166]与上述方法实施例相对应,本公开还提供了另一种内存扩展装置实施例, 图 6示出 了本公开一个实施例提供的另一种内存扩展装置的结构示意图。 如图 6所示, 该装置包 括: 接收模块 602, 被配置为接收针对物理模式运行的操:作系统、 提交的配置变更指令; 转换模块 604, 被配置为根据所述配置变更指令将所述操作系统转换为虚拟模式运行的 目标操作系统, 其中, 所述目标操作系统配置有内存管理功能;
确定模块 606,被配置为在接收到通过所述内存管理功能提交的内存扩展指令的情况下, 根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存; 分配模块 608, 被配置为基于所述内存管理功能预设的内存管理函数, 将所述扩展内存 分配至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的目标内存 供所述目标操作系统使用。
[167]本公开一个实施例提供的内存扩展装置,能够实现操作系统从物理模式到虚拟模式 的转换, 通过接收内存扩展指令并根据该指令动态添加扩展内存, 使得目标操作系统能 够在运行时根据实际需求增加内存资源, 提高了系统对资源的利用效率和响应速度; 且 预设内存管理函数可以有效地管理和分配扩展内存至目标内存池中,保证了新增内存资 源能被目标操作系统合理、 高效地使用, 避免了内存资源浪费, 同时也提升了系统的整 体性能和稳定性。
[168]上述为本实施例的一种内存扩展装置的示意性方案。需要说明的是,该内存扩展装 置的技术方案与上述的内存扩展方法的技术方案属于同一构思, 内存扩展装置的技术方 案未详细描述的细节内容, 均可以参见上述内存扩展方法的技术方案的描述。
[169]图 7示出了根据本公开一个实施例提供的一种计算设备 700的结构框图。该计算设 备 700的部件包括但不限于存储器 710和处理器 720。 处理器 720与存储器 710通过总 线 730相连接, 数据库 750用于保存数据。
[170]计算设备 700还包括接入设备 740,接入设备 740使得计算设备 700能够经由一个 或多个网络 760通信。 这些网络的示例包括公用交换电话网 ( PSTN, Public Switched Telephone Network )、局域网 ( LAN, Local Area Network )、广域网 ( WAN, Wide Area Network ) 、 个域网 ( PAN, Personal Area Network )或诸如因特网的通信网络的组合。 接入设备 740可以包括有线或无线的任何类型的网络接口 (例如, 网络接口卡 ( NIC, network interface controller ) )中的一个或多个,诸如 IEEE802.11无线局域网 ( WLAN, Wireless Local Area Network )无线接口、 全球微波互联接入 ( Wi-MAX, Worldwide Interoperability for Microwave Access )接口、以太网接口、通用串行总线 ( USB , Universal Serial Bus )接口、蜂窝网络接口、蓝牙接口、近场通信 ( NFC, Near Field Communication )。
[171]在本公开的一个实施例中,计算设备 700的上述部件以及图 7中未示出的其他部件 也可以彼此相连接, 例如通过总线。 应当理解, 图 7所示的计算设备结构框图仅仅是出 于示例的目的, 而不是对本公开范围的限制。 本领域技术人员可以根据需要, 增添或替 换其他部件。
[172]计算设备 700可以是任何类型的静止或移动计算设备,包括移动计算机或移动计算 设备 (例如, 平板计算机、个人数字助理、膝上型计算机、笔记本计算机、上网本等)、 移动电话 (例如, 智能手机)、 可佩戴的计算设备 (例如, 智能手表、 智能眼镜等)或 其他类型的移动设备, 或者诸如台式计算机或个人计算机 ( PC, Personal Computer )的 静止计算设备。 计算设备 700还可以是移动式或静止式的服务器。
[173]其中, 处理器 720用于执行如下计算机程序 /指令, 该计算机程序 /指令被处理器执 行时实现上述内存扩展方法的步骤。
[174]本公开中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互 相参见即可, 每个实施例重点说明的都是与其他实施例的不同之处。 尤其, 对于计算设 备实施例而言, 由于其基本相似于内存扩展方法实施例, 所以描述的比较简单, 相关之 处参见内存扩展方法实施例的部分说明即可。
[175]本公开一实施例还提供一种计算机可读存储介质, 其存储有计算机程序/指令, 该 计算机程序 /指令被处理器执行时实现上述内存扩展方法的步骤。
[176]本公开中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互 相参见即可, 每个实施例重点说明的都是与其他实施例的不同之处。 尤其, 对于计算机 可读存储介质实施例而言, 由于其基本相似于内存扩展方法实施例, 所以描述的比较简 单, 相关之处参见内存扩展方法实施例的部分说明即可。
[177]本公开一实施例还提供一种计算机程序产品, 包括计算机程序 /指令, 该计算机程 序 /指令被处理器执行时实现上述内存扩展方法的步骤。
[178]上述为本实施例的一种计算机程序产品的示意性方案。 需要说明的是,该计算机程 序产品的技术方案与上述的内存扩展方法的技术方案属于同一构思,计算机程序产品的 技术方案未详细描述的细节内容, 均可以参见上述内存扩展方法的技术方案的描述。
[179]上述对本公开特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在 一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行 并且仍然可以实现期望的结果。 另外, 在附图中描绘的过程不一定要求示出的特定顺序 或者连续顺序才能实现期望的结果。 在某些实施方式中, 多任务处理和并行处理也是可 以的或者可能是有利的。
[180]所述计算机指令包括计算机程序代码,所述计算机程序代码可以为源代码形式、对 象代码形式、 可执行文件或某些中间形式等。 所述计算机可读介质可以包括: 能够携带 所述计算机程序代码的任何实体或装置、 记录介质、 U盘、 移动硬盘、 磁碟、 光盘、 计 算机存储器、只读存储器 ( ROM, Read-Only Memory )、随机存取存储器( RAM, Random Access Memory ) 、 电载波信号、 电信信号以及软件分发介质等。 需要说明的是, 所述 计算机可读介质包含的内容可以根据专利实践的要求进行适当的增减,例如在某些地区, 根据专利实践, 计算机可读介质不包括电载波信号和电信信号。
[181]需要说明的是, 对于前述的各方法实施例, 为了简便描述, 故将其都表述为一系列 的动作组合, 但是本领域技术人员应该知悉, 本公开实施例并不受所描述的动作顺序的 限制, 因为依据本公开实施例, 某些步骤可以采用其它顺序或者同时进行。 其次, 本领 域技术人员也应该知悉, 说明书中所描述的实施例均属于优选实施例, 所涉及的动作和 模块并不一定都是本公开实施例所必须的。
[182]在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分, 可以参见其它实施例的相关描述。
[183]以上公开的本公开优选实施例只是用于帮助阐述本公开。可选实施例并没有详尽叙 述所有的细节, 也不限制该发明仅为所述的具体实施方式。 显然, 根据本公开实施例的 内容, 可作很多的修改和变化。 本公开选取并具体描述这些实施例, 是为了更好地解释 本公开实施例的原理和实际应用,从而使所属技术领域技术人员能很好地理解和利用本
公开。 本公开仅受权利要求书及其全部范围和等效物的限制。
Claims
1.一种内存扩展方法, 包括: 接收内存扩展指令, 其中, 所述内存扩展指令关联目标操作系统, 且所述目标操作 系统为由物理模式运行的操作系统转换为虚拟模式运行获得; 根据所述内存扩展指令确定内存扩展参数,并调用所述目标操作系统的内存管理接 口 , 为所述目标操作系统添加所述内存扩展参数对应的扩展内存; 基于内存管理功能预设的内存管理函数,将所述扩展内存分配至所述目标操作系统 对应的目标内存池, 其中, 所述目标内存池中包含的内存供所述目标操作系统使用。
2.根据权利要求 1所述的内存扩展方法, 所述接收内存扩展指令之前, 还包括: 接收针对所述物理模式运行的操作系统、 提交的配置变更指令; 根据所述配置变更指令将所述操作系统, 转换为虚拟模式运行的目标操作系统。
3.根据权利要求 2所述的内存扩展方法, 所述根据所述配置变更指令将所述操作系 统, 转换为虚拟模式运行的目标操作系统, 包括: 根据所述配置变更指令为所述操作系统建立地址映射页表,并保存所述物理模式运 行的操作系统对应的寄存器的初始数据; 根据所述地址映射页表以及所述初始数据, 建立目标数据结构; 对所述目标数据结构中的目标数据进行配置,并将配置完成的目标数据结构加载到 中夬处理器, 触发所述操作系统转换为虚拟模式运行的目标操作系统, 其中, 所述目标 数据为与所述目标操作系统对应的控制信息。
4.根据权利要求 3所述的内存扩展方法, 所述目标操作系统配置有内存管理功能; 所述根据所述配置变更指令将所述操作系统转换为虚拟模式运行的目标操作系统 之后, 还包括: 通过所述内存管理功能,将所述目标操作系统对应的物理内存划分为预设粒度的内 存块; 将所述内存块的内存状态设置为使用状态。
5.根据权利要求 4所述的内存扩展方法, 所述将所述内存块的内存状态设置为使用 状态之后, 还包括: 通过所述内存管理功能, 确定所述目标操作系统对应的、 当前空闲页面, 其中, 所 述空闲页面为当前未被任何进程占用、可供所述目标操作系统分配给进程使用的物理内 存页面, 所述物理内存页面组成所述物理内存; 将所述空闲页面对应的所述地址映射页表中的页表项删除,并将所述空闲页面对应 的内存状态更新为空闲状态, 其中, 所述地址映射页表由所述页表项组成, 所述页表项 记录虚拟地址到物理地址的映射。
6.根据权利要求 1所述的内存扩展方法, 所述根据所述内存扩展指令确定内存扩展 参数, 并调用所述目标操作系统的内存管理接口, 为所述目标操作系统添加所述内存扩 展参数对应的扩展内存, 包括: 根据所述内存扩展指令确定内存扩展参数, 其中, 所述内存扩展参数包括所述扩展 内存对应的虚拟内存地址范围; 调用所述目标操作系统的内存管理接口,在所述目标操作系统对应的所述虚拟内存 地址范围添加所述扩展内存。
7.根据权利要求 1所述的内存扩展方法, 所述将所述扩展内存分配至所述目标操作
系统对应的目标内存池, 包括: 根据目标内存池机制,将所述扩展内存分配至所述目标操作系统对应的目标内存池。
8.根据权利要求 7所述的内存扩展方法, 所述根据目标内存池机制, 将所述扩展内 存分配至所述目标操作系统对应的目标内存池, 包括: 将所述目标内存池设置为目标进程使用,将所述扩展内存分配至所述目标操作系统 对应的目标内存池, 以使所述目标进程使用所述目标内存池中的所述扩展内存, 或者 将所述目标内存池设置为所述目标进程中的代码段和/或数据段使用,将所述扩展内 存分配至所述目标操作系统对应的目标内存池,以使所述目标进程中的代码段和/或数据 段使用所述目标内存池中的所述扩展内存。
9.根据权利要求 7所述的内存扩展方法, 所述根据目标内存池机制, 将所述扩展内 存分配至所述目标操作系统对应的目标内存池, 包括: 根据所述扩展内存的内存扩展参数, 调整所述目标内存池的容量配置, 使得所述目 标内存池的容量与所述扩展内存的大小相匹配; 将所述扩展内存分配至所述目标操作系统对应的、 调整后的目标内存池。
10.根据权利要求 1所述的内存扩展方法,所述将所述扩展内存分配至所述目标操作 系统对应的目标内存池之后, 还包括: 在所述目标操作系统中运行的目标进程、 使用所述目标内存池中的所述扩展内存, 触发缺页异常的情况下肓艮据所述缺页异常,调用与所述缺页异常对应的异常处理函数; 基于所述异常处理函数, 通过所述内存管理功能确定目标内存块, 并建立所述扩展 内存与所述目标内存块对应的页表项, 其中, 目标内存块为内存状态为空闲状态的内存 块; 通过所述扩展内存与所述目标内存块对应的页表项,将所述扩展内存映射到所述目 标内存块。
11.根据权利要求 1所述的内存扩展方法, 还包括: 通过所述内存管理功能在所述目标操作系统对应的物理内存中设置内存空闲空间; 在所述内存空闲空间低于第一阈值高于第二阈值的情况下, 触发内存回收操作, 释 放所述内存状态处于空闲状态的物理内存; 在所述内存空闲空间低于所述第二阈值的情况下, 向运维程序发送处理通知, 以使 所述运维程序根据所述处理通知进行进程迁移以及数据保护操作。
12.-种内存扩展方法, 包括: 接收针对物理模式运行的操作系统、 提交的配置变更指令; 根据所述配置变更指令将所述操作系统转换为虚拟模式运行的目标操作系统,其中, 所述目标操作系统配置有内存管理功能; 在接收到通过所述内存管理功能提交的内存扩展指令的情况下,根据所述内存扩展 指令确定内存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所述目标操作系 统添加所述内存扩展参数对应的扩展内存; 基于所述内存管理功能预设的内存管理函数,将所述扩展内存分配至所述目标操作 系统对应的目标内存池, 其中, 所述目标内存池中包含的目标内存供所述目标操作系统 使用。
13.—种内存扩展装置, 包括: 接收模块, 被配置为接收内存扩展指令, 其中, 所述内存扩展指令关联目标操作系
统, 且所述目标操作系统为由物理模式运行的操作系统转换为虚拟模式运行获得; 确定模块, 被配置为根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操 作系统的内存管理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存; 分配模块, 被配置为基于内存管理功能预设的内存管理函数, 将所述扩展内存分配 至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的目标内存供所 述目标操作系统使用。
14.—种内存扩展装置, 包括: 接收模块, 被配置为接收针对物理模式运行的操作系统、 提交的配置变更指令; 转换模块,被配置为根据所述配置变更指令将所述操作系统转换为虚拟模式运行的 目标操作系统, 其中, 所述目标操作系统配置有内存管理功能; 确定模块,被配置为在接收到通过所述内存管理功能提交的内存扩展指令的情况下, 根据所述内存扩展指令确定内存扩展参数, 并调用所述目标操作系统的内存管理接口, 为所述目标操作系统添加所述内存扩展参数对应的扩展内存; 分配模块, 被配置为基于所述内存管理功能预设的内存管理函数, 将所述扩展内存 分配至所述目标操作系统对应的目标内存池, 其中, 所述目标内存池中包含的目标内存 供所述目标操作系统使用。
15.—种计算设备, 包括: 存储器和处理器; 所述存储器用于存储计算机程序 /指令,所述处理器用于执行所述计算机程序 /指令, 该计算机程序 /指令被处理器执行时实现权利要求 1至 12任意一项所述内存扩展方法的 步骤。
16.—种计算机可读存储介质, 其存储有计算机程序/指令, 该计算机程序 /指令被处 理器执行时实现权利要求 1至 12任意一项所述内存扩展方法的步骤。
17.一种计算机程序产品, 包括计算机程序 /指令, 该计算机程序 /指令被处理器执行 时实现权利要求 1至 12任意一项所述内存扩展方法的步骤。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410225776.7A CN120560773A (zh) | 2024-02-28 | 2024-02-28 | 内存扩展方法及装置、计算设备、计算机可读存储介质、计算机程序产品 |
| CN202410225776.7 | 2024-02-28 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2025181598A1 true WO2025181598A1 (zh) | 2025-09-04 |
Family
ID=96831811
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/IB2025/051388 Pending WO2025181598A1 (zh) | 2024-02-28 | 2025-02-11 | 内存扩展 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN120560773A (zh) |
| WO (1) | WO2025181598A1 (zh) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN121579223B (zh) * | 2026-01-26 | 2026-04-14 | 苏州元脑智能科技有限公司 | 一种设备资源分配方法及服务器 |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111459673A (zh) * | 2020-03-31 | 2020-07-28 | 支付宝(杭州)信息技术有限公司 | 安全内存扩展、释放方法及装置和电子设备 |
| CN115794669A (zh) * | 2021-09-11 | 2023-03-14 | 华为技术有限公司 | 一种扩展内存的方法、装置及相关设备 |
| CN116401010A (zh) * | 2023-03-30 | 2023-07-07 | 阿里巴巴(中国)有限公司 | 一种虚拟机迁移方法、设备及存储介质 |
-
2024
- 2024-02-28 CN CN202410225776.7A patent/CN120560773A/zh active Pending
-
2025
- 2025-02-11 WO PCT/IB2025/051388 patent/WO2025181598A1/zh active Pending
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111459673A (zh) * | 2020-03-31 | 2020-07-28 | 支付宝(杭州)信息技术有限公司 | 安全内存扩展、释放方法及装置和电子设备 |
| CN115794669A (zh) * | 2021-09-11 | 2023-03-14 | 华为技术有限公司 | 一种扩展内存的方法、装置及相关设备 |
| CN116401010A (zh) * | 2023-03-30 | 2023-07-07 | 阿里巴巴(中国)有限公司 | 一种虚拟机迁移方法、设备及存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN120560773A (zh) | 2025-08-29 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11531625B2 (en) | Memory management method and apparatus | |
| US11422698B2 (en) | Method, electronic device, and computer program product for storage management | |
| CN102455942B (zh) | 一种广域网虚拟机动态迁移方法及系统 | |
| CN110247984B (zh) | 业务处理方法、装置及存储介质 | |
| US20220214907A1 (en) | Virtual machine memory management method and device | |
| EP4052126A1 (en) | Management of multiple physical function non-volatile memory devices | |
| CN107480150A (zh) | 一种文件加载方法和装置 | |
| CN113032099A (zh) | 云计算节点、文件管理方法及装置 | |
| CN104571955A (zh) | 提高存储容量的方法和装置 | |
| CN111435302B (zh) | 一种应用程序的处理方法及装置 | |
| CN114416425A (zh) | 进程拷贝方法以及装置 | |
| CN110750221B (zh) | 卷克隆方法、装置、电子设备及机器可读存储介质 | |
| CN115718663A (zh) | Binder驱动内存管理方法、装置、设备及存储介质 | |
| CN115562871A (zh) | 内存分配管理的方法和装置 | |
| WO2025202745A1 (zh) | 数据处理方法、计算机系统、存储介质及程序产品 | |
| CN109947704B (zh) | 一种锁类型切换方法、装置及集群文件系统 | |
| CN107015814A (zh) | 满足异构操作系统业务移植的浏览器操作系统设计方法 | |
| US20200371827A1 (en) | Method, Apparatus, Device and Medium for Processing Data | |
| CN114416426B (zh) | 进程拷贝方法以及装置 | |
| CN120560773A (zh) | 内存扩展方法及装置、计算设备、计算机可读存储介质、计算机程序产品 | |
| CN115687178A (zh) | 数据访问方法以及相关设备 | |
| CN110221868A (zh) | 主机系统的部署方法、装置、电子设备及存储介质 | |
| US20250217180A1 (en) | Method for controlling virtual machine, electronic device and storage medium | |
| EP4660799A1 (en) | Live migration method for container, and processor, host, chip and interface card | |
| CN112035063A (zh) | 一种基于云平台的硬盘及文件系统热扩容的方法 |
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: 25761763 Country of ref document: EP Kind code of ref document: A1 |