WO2024148864A1 - 虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置 - Google Patents

虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置 Download PDF

Info

Publication number
WO2024148864A1
WO2024148864A1 PCT/CN2023/121786 CN2023121786W WO2024148864A1 WO 2024148864 A1 WO2024148864 A1 WO 2024148864A1 CN 2023121786 W CN2023121786 W CN 2023121786W WO 2024148864 A1 WO2024148864 A1 WO 2024148864A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
target
virtual machine
allocated
state
Prior art date
Application number
PCT/CN2023/121786
Other languages
English (en)
French (fr)
Inventor
谢志勇
张闯
王敏
Original Assignee
苏州元脑智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 苏州元脑智能科技有限公司 filed Critical 苏州元脑智能科技有限公司
Publication of WO2024148864A1 publication Critical patent/WO2024148864A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the embodiments of the present application relate to the field of computers, and in particular, to a method and device for adjusting virtual machine memory, a non-volatile readable storage medium, and an electronic device.
  • the embodiments of the present application provide a method and device for adjusting virtual machine memory, a non-volatile readable storage medium, and an electronic device, so as to at least solve the problem of low matching degree between virtual machine memory allocation and usage requirements in the related art.
  • a method for adjusting virtual machine memory comprising:
  • the current overall memory status of the multiple virtual machines is obtained, wherein the multiple virtual machines are operated on the same host, and the overall memory status is used to indicate the overall usage of the memory allocated by the host by the multiple virtual machines;
  • obtain the current overall memory status of multiple virtual machines including:
  • the allocated memory and used memory of each virtual machine as the memory parameter, where the allocated memory is used to indicate the memory usage of each virtual machine.
  • the used memory is used to indicate the memory size used by each virtual machine in the currently allocated memory.
  • determine the overall memory state based on a set of memory parameters including:
  • the memory free ratio is calculated as the overall memory status based on the total used memory and the total allocated memory.
  • the total memory used is calculated as the sum of the memory used in the memory parameter set, including:
  • the total memory used M 1 is calculated by the following formula:
  • the multiple virtual machines include n virtual machines, n is a positive integer, M 1i is the amount of used memory corresponding to the i-th virtual machine among the n virtual machines, and i is a positive integer.
  • the total memory allocated is calculated as the sum of the memory allocated in the memory parameter set, including:
  • the total allocated memory M2 is calculated by the following formula:
  • the multiple virtual machines include n virtual machines, n is a positive integer, M 2i is the allocated memory amount corresponding to the i-th virtual machine among the n virtual machines, and i is a positive integer.
  • the memory free ratio is calculated based on the total used memory and the total allocated memory as the overall memory status, including:
  • the memory idle ratio ⁇ 2 is calculated by the following formula:
  • M1 is the total memory used
  • M2 is the total memory allocated
  • calculate the target memory state based on the overall memory state and the target priority including:
  • the target memory state is determined based on the adjustment ratio and the overall memory state.
  • determine the adjustment ratio of each virtual machine based on the target priority including:
  • the adjustment ratio K is calculated by the following formula:
  • PR m is the target priority of the mth virtual machine.
  • a target memory state is determined according to the adjustment ratio and the overall memory state, including:
  • ⁇ 2 is the overall memory state and K is the adjustment ratio.
  • the method before allocating a target memory state to each virtual machine according to the overall memory state and the target priority of each virtual machine, the method further includes:
  • target task attribute parameters of the tasks processed by each virtual machine wherein the target task attribute parameters are used to indicate the size of memory resources and computing power resources required to process the tasks;
  • the priority of each virtual machine is configured according to the target task attribute parameters to obtain the target priority.
  • configure the priority of each virtual machine according to the target task attribute parameters to obtain the target priority including:
  • adjust the memory allocated to each virtual machine based on the target memory state including:
  • obtaining a current initial memory state of the target virtual machine For each virtual machine used as a target virtual machine, obtaining a current initial memory state of the target virtual machine, wherein the initial memory state is used to indicate a current memory occupancy of the target virtual machine;
  • the current initial memory state of the target virtual machine is obtained, including:
  • the target memory parameter corresponding to the target virtual machine is searched from the read memory parameter set, wherein the memory parameter set records virtual machines and memory parameters having a corresponding relationship, and the memory parameter set is used to determine the overall memory state.
  • a memory adjustment amount is determined according to the initial memory state and the target memory state, including:
  • the target allocated memory is used to indicate the memory size currently allocated to the target virtual machine under the host, and the target used memory is used to indicate the memory size used by the target virtual machine in the currently allocated memory;
  • the memory adjustment amount is calculated based on the target allocated memory amount, the target used memory amount, and the target memory state.
  • the memory adjustment amount is calculated based on the target allocated memory amount, the target used memory amount, and the target memory state, including:
  • the memory adjustment amount is calculated by the following formula
  • M 1m is the target used memory
  • M 2m is the target allocated memory
  • E( ⁇ 1m ) is the target memory state.
  • adjust the memory allocated to the target virtual machine on the host by a memory adjustment amount including:
  • the memory allocated to the target virtual machine on the host is expanded by the memory adjustment value indicated by the memory adjustment amount;
  • the memory allocated to the target virtual machine on the host is reduced by the memory adjustment value indicated by the memory adjustment amount.
  • adjust the memory allocated to the target virtual machine on the host by a memory adjustment amount including:
  • the memory allocated to the target virtual machine on the host is adjusted by the memory adjustment amount
  • the memory allocation amount is less than the adjustment amount threshold, the memory allocated to the target virtual machine on the host remains unchanged.
  • a device for adjusting virtual machine memory including:
  • a first acquisition module is configured to acquire the current overall memory status of the multiple virtual machines during the operation of the multiple virtual machines, wherein the multiple virtual machines are operated on the same host, and the overall memory status is used to indicate the overall usage of the memory allocated by the host by the multiple virtual machines;
  • an allocation module configured to allocate a target memory state to each virtual machine according to the overall memory state and a target priority of each virtual machine, wherein the target priority is used to indicate a priority of each virtual machine in using memory under the host;
  • the adjustment module is configured to adjust the memory allocated to each virtual machine according to the target memory state.
  • a non-volatile readable storage medium in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned virtual machine memory adjustment method when running.
  • an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the virtual machine memory adjustment method through the computer program.
  • the current overall memory status of the multiple virtual machines is obtained, wherein the multiple virtual machines are running on the same host, and the overall memory status is used to indicate the overall usage of the memory allocated to the host by the multiple virtual machines; a target memory status is assigned to each virtual machine according to the overall memory status and the target priority of each virtual machine, wherein the target priority is used to indicate the priority of each virtual machine in using memory on the host; the memory allocated to each virtual machine is adjusted according to the target memory status, that is, during the operation of multiple virtual machines on the same host, first, the current overall memory status of the multiple virtual machines is obtained, and the overall memory status is used to indicate the overall usage of the memory allocated to the host by the multiple virtual machines; then, according to the overall memory status and the target priority of each virtual machine, a target memory status is assigned to each virtual machine, and the target priority is used to indicate the priority of each virtual machine in using memory on the host;
  • the memory state adjusts the memory allocated to each virtual machine, that is, the memory allocated
  • FIG1 is a schematic diagram of a hardware environment of a method for adjusting a virtual machine memory according to an embodiment of the present application
  • FIG2 is a flow chart of a method for adjusting virtual machine memory according to an embodiment of the present application
  • FIG3 is a schematic diagram of a method for generating a memory capacity parameter set according to an embodiment of the present application
  • FIG4 is a schematic diagram of a virtual machine memory adjustment process according to an embodiment of the present application.
  • FIG5 is a structural block diagram of a device for adjusting virtual machine memory according to an embodiment of the present application.
  • FIG. 1 is a hardware environment schematic diagram of a method for adjusting the memory of a virtual machine according to an embodiment of the present application.
  • the computer terminal may include one or more (only one is shown in FIG. 1 ) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data.
  • the above-mentioned computer terminal may also include a transmission device 106 and an input and output device 108 for communication functions.
  • FIG. 1 is only for illustration, and it does not limit the structure of the above-mentioned computer terminal.
  • the computer terminal may also include more or fewer components than those shown in FIG. 1 , or have different configurations with equivalent functions as shown in FIG. 1 or more functions than those shown in FIG. 1 .
  • the memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for adjusting the virtual machine memory in the embodiment of the present application.
  • the processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method.
  • the memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
  • the memory 104 may include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
  • FIG. 2 is a flow chart of a method for adjusting the memory of a virtual machine according to an embodiment of the present application. As shown in FIG. 2 , the process includes the following steps:
  • Step S202 during the operation of the multiple virtual machines, obtaining the current overall memory status of the multiple virtual machines, wherein the multiple virtual machines are operated on the same host, and the overall memory status is used to indicate the overall usage of the memory allocated by the host by the multiple virtual machines;
  • Step S204 assigning a target memory state to each virtual machine according to the overall memory state and the target priority of each virtual machine, wherein the target priority is used to indicate the priority of each virtual machine in using memory under the host;
  • Step S206 adjusting the memory allocated to each virtual machine according to the target memory state.
  • the current overall memory status of the multiple virtual machines is obtained, and the overall memory status is used to indicate the overall usage of the memory allocated by the host by the multiple virtual machines; then, a target memory status is assigned to each virtual machine according to the overall memory status and the target priority of each virtual machine, and the target priority is used to indicate the priority of each virtual machine in using memory on the host; the memory allocated to each virtual machine is adjusted according to the target memory status, that is, the memory allocated to each virtual machine matches the priority of each virtual machine in using memory on the host.
  • the mainstream solution is for the administrator to shut down the virtual machine and readjust the memory size configuration of the virtual machine; there is also a technical solution that sets an upper and lower threshold for the memory usage of the virtual machine, monitors the running status of the virtual machine in real time to obtain the memory usage, and dynamically expands the virtual machine memory online when the memory usage is greater than the upper threshold, and shrinks the virtual machine memory online when the memory usage is less than the lower threshold.
  • the administrator's manual adjustment plan cannot dynamically adjust the memory of each virtual machine online in real time.
  • the plan that sets the upper and lower thresholds for dynamic adjustment is adjusted according to the priority and amplitude. Since the priority and amplitude are also statically set, there are situations where the virtual machine needs to be adjusted and expanded multiple times to meet the needs of the virtual machine and there is a priority inversion situation, that is, since the low-priority virtual machine adjusts the memory in advance but does not exceed the upper limit, the high-priority virtual machine that needs memory expansion later cannot get the memory.
  • step S202 multiple virtual machines run on the same host. Therefore, before allocation, it is preferred to obtain the current overall memory status of the multiple virtual machines. According to the overall memory status, the overall usage of the memory allocated to the host by the current multiple virtual machines can be known.
  • the current overall memory status of multiple virtual machines can be obtained in the following manner but is not limited to: reading the memory parameters of each virtual machine to obtain a memory parameter set, wherein the memory parameter set is used to record virtual machines and memory parameters with corresponding relationships; and determining the overall memory status according to the memory parameter set.
  • Figure 3 is a schematic diagram of a method for generating a memory parameter set according to an embodiment of the present application.
  • virtual machines 1 to n run on the same host, and the memory parameters of each virtual machine are read to obtain a memory parameter set (memory parameter 1 to memory parameter n).
  • the overall memory status can be determined based on the memory parameter set.
  • the memory parameters of each virtual machine can be read in the following manner, but is not limited to, to obtain a memory parameter set: read the allocated memory and used memory of each virtual machine as memory parameters, wherein the allocated memory is used to indicate the memory size currently allocated to each virtual machine under the host, and the used memory is used to indicate the memory size used by each virtual machine in the currently allocated memory; construct a virtual machine, allocated memory, and used memory with a corresponding relationship to obtain a memory parameter set.
  • the memory parameter may include, but is not limited to, the allocated memory and used memory of each virtual machine.
  • the allocated memory may be used to indicate the memory size currently allocated to each virtual machine under the host, and the used memory may be used to indicate the current memory size of each virtual machine under the host.
  • the size of the memory used in the allocated memory Therefore, according to the memory parameter set, the allocated memory and used memory corresponding to each virtual machine can be known.
  • the overall memory status can be determined based on the memory parameter set in the following manner, but is not limited to: calculating the sum of the used memory in the memory parameter set as the total used memory; calculating the sum of the allocated memory in the memory parameter set as the total allocated memory; calculating the memory free ratio based on the total used memory and the total allocated memory as the overall memory status.
  • the overall memory status may be, but is not limited to, used to indicate overall memory usage, so the memory free ratio calculated by using the total memory and the total allocated memory may be used as the overall memory status.
  • the sum of the used memory amounts in the memory amount parameter set may be calculated as the total used memory by, but is not limited to, the following method:
  • the total used memory is calculated by the following formula:
  • the multiple virtual machines include n virtual machines, n is a positive integer, M 1i is the amount of used memory corresponding to the i-th virtual machine among the n virtual machines, and i is a positive integer.
  • the sum of the used memory amounts in the memory amount parameter set may be used as the total used memory, that is, the used memory amount of each virtual machine is accumulated to obtain the total used memory M 1 .
  • the total allocated memory may be calculated as the total allocated memory by, but not limited to, calculating the total allocated memory in the memory parameter set in the following manner:
  • the total allocated memory M 2 is calculated by the following formula:
  • the multiple virtual machines include n virtual machines, n is a positive integer, M 2i is the allocated memory amount corresponding to the i-th virtual machine among the n virtual machines, and i is a positive integer.
  • the sum of the allocated memory amounts in the memory amount parameter set may be used as the total allocated memory, that is, the allocated memory amount of each virtual machine is accumulated to obtain the total allocated memory M 2 .
  • the memory idle ratio may be calculated as the overall memory state according to the total used memory and the total allocated memory in the following manner, but is not limited to: the memory idle ratio ⁇ 2 is calculated by the following formula:
  • M1 is the total memory used
  • M2 is the total memory allocated
  • the memory free ratio ⁇ 2 can indicate the overall memory status.
  • the overall memory status can indicate the average memory usage of the multiple virtual machines included in the whole, that is, the overall memory status is an indicator indicating the average memory usage, but it is inappropriate to simply adjust each virtual machine to the overall memory status.
  • a more reasonable way is to make targeted adjustments based on the overall memory status and considering the target priority of each virtual machine. For example, some virtual machines with higher target priorities need to use more memory, so more memory can be allocated based on the average memory usage indicator indicated by the overall memory status, while virtual machines with lower target priorities do not need to use more memory, so they can be maintained in the overall memory status.
  • a target memory state can be assigned to each virtual machine based on the overall memory state and the target priority of each virtual machine in the following manner, but is not limited to: accessing the configuration parameters of each virtual machine to obtain the target priority corresponding to each virtual machine; and calculating the target memory state based on the overall memory state and the target priority.
  • multiple virtual machines are run under the same host, and the tasks and functions performed by each virtual machine may be different, and therefore the memory usage requirements are also different.
  • the configuration parameters of each virtual machine can be pre-configured, and a higher target priority can be configured for a virtual machine that has a greater memory usage requirement for processing tasks.
  • the target memory state can be calculated according to the overall memory state and the target priority in the following manner but is not limited to: determining the adjustment ratio of each virtual machine according to the target priority; and determining the target memory state according to the adjustment ratio and the overall memory state.
  • a proportional adjustment is performed based on the overall memory status, wherein the size of the adjustment ratio is related to the respective target priorities; the lower the target priority, the smaller the adjustment ratio, and the higher the target priority, the larger the adjustment ratio.
  • the adjustment ratio of each virtual machine may be determined according to the target priority in the following manner, but is not limited to: the adjustment ratio K is calculated by the following formula:
  • PR m is the target priority of the mth virtual machine.
  • the adjustment ratio K approaches 1; when the target priority level PR m approaches positive infinity, the adjustment ratio K approaches 1.5.
  • the actual formula can be adjusted according to actual needs, the purpose is to control the size of the adjustment ratio and the The adjustment ratio is linked to the target priority. If the target priority is low, the adjustment ratio is small; if the target priority is high, the adjustment ratio is large.
  • the target memory state may be determined according to the adjustment ratio and the overall memory state in the following manner, but is not limited to: the target memory state E( ⁇ 1m ) of the mth virtual machine is calculated by the following formula: E( ⁇ 1m )K ⁇ 2 ;
  • ⁇ 2 is the overall memory state and K is the adjustment ratio.
  • the adjustment ratio is based on the overall memory state.
  • the adjustment ratio is 1
  • the target memory state is consistent with the overall memory state.
  • the adjustment ratio is greater than 1
  • the target memory state is greater than the overall memory state, and the allocated memory is higher than the overall memory state.
  • the target task attribute parameters of the task processed by each virtual machine can also be obtained in the following ways, but not limited to, wherein the target task attribute parameters are used to indicate the size of memory resources and computing power resources required to process the task; and the priority of each virtual machine is configured according to the target task attribute parameters to obtain the target priority.
  • the configuration method of the target priority is determined based on the memory resource size and computing power resource size required for the virtual machine to process the task.
  • a higher target priority can be configured.
  • a lower target priority can be configured.
  • the priority of each virtual machine can be configured according to the target task attribute parameters to obtain the target priority in the following manner, but is not limited to: determining the target priority corresponding to the target task attribute parameters from task attribute parameters and priorities with a corresponding relationship; configuring the priority parameters of each virtual machine as the target priority.
  • the target priority corresponding to the target task attribute parameter can be determined from the task attribute parameters and priorities having a corresponding relationship.
  • step S206 after determining the target memory state, the memory allocated to each virtual machine is adjusted to the target memory state.
  • the memory allocated to each virtual machine can be adjusted according to the target memory state in the following manner, but is not limited to: for each virtual machine used as a target virtual machine, the current initial memory state of the target virtual machine is obtained, wherein the initial memory state is used to indicate the current memory usage of the target virtual machine; the memory adjustment amount is determined according to the initial memory state and the target memory state; and the memory allocated to the target virtual machine on the host is adjusted by the memory adjustment amount.
  • multiple virtual machines are running on the same host, and the current initial memory state of the target virtual machine is obtained.
  • the current memory usage of the target virtual machine can be known according to the initial memory state, and the memory adjustment amount can be determined according to the target memory state; the memory allocated to the target virtual machine on the host is adjusted by the memory adjustment amount. That is, the target virtual machine can be guaranteed to reach the target memory state.
  • the current initial memory state of the target virtual machine can be obtained for each virtual machine as a target virtual machine in the following manner but is not limited to: searching for a target memory parameter corresponding to the target virtual machine from a read memory parameter set, wherein the memory parameter set records virtual machines and memory parameters with corresponding relationships, and the memory parameter set is used to determine the overall memory state.
  • the target memory parameters corresponding to the target virtual machine can be searched from the read memory parameter set to obtain the current initial memory state of the target virtual machine.
  • the memory adjustment amount can be determined based on the initial memory state and the target memory state in the following manner, but is not limited to: obtaining the target allocated memory amount and the target used memory amount included in the target memory amount parameter as the initial memory state, wherein the target allocated memory amount is used to indicate the memory size currently allocated to the target virtual machine under the host, and the target used memory amount is used to indicate the memory size used by the target virtual machine in the currently allocated memory; and calculating the memory adjustment amount based on the target allocated memory amount, the target used memory amount and the target memory state.
  • the target memory state indicates a memory state to be reached by the target virtual machine
  • the memory adjustment amount is calculated according to the target allocated memory amount, the target used memory amount and the target memory state.
  • the memory adjustment amount can be calculated according to the target allocated memory amount, the target used memory amount and the target memory state in the following manner, but is not limited to: the memory adjustment amount is calculated by the following formula:
  • M 1m is the target used memory
  • M 2m is the target allocated memory
  • E( ⁇ 1m ) is the target memory state.
  • the memory adjustment amount The amount of memory you want to increase or decrease for the virtual machine.
  • the memory allocated to the target virtual machine under the host can be adjusted by a memory adjustment amount in the following manner, but is not limited to: when the memory adjustment amount is positive, the memory allocated to the target virtual machine under the host is expanded by the memory adjustment value indicated by the memory adjustment amount; when the memory adjustment amount is negative, the memory allocated to the target virtual machine under the host is reduced by the memory adjustment value indicated by the memory adjustment amount.
  • the memory adjustment amount The amount of memory that the virtual machine expects to expand or reduce.
  • the memory adjustment amount is positive, the memory allocated to the target virtual machine on the host is expanded by the memory adjustment value indicated by the memory adjustment amount.
  • the memory adjustment amount is negative, the memory allocated to the target virtual machine on the host is reduced by the memory adjustment value indicated by the memory adjustment amount.
  • the memory allocated to the target virtual machine under the host can be adjusted by, but is not limited to, the following methods: obtaining an adjustment amount threshold corresponding to the host; comparing the memory adjustment amount with the adjustment amount threshold; when the memory adjustment amount is greater than or equal to the adjustment amount threshold, adjusting the memory allocated to the target virtual machine under the host by the memory adjustment amount; when the memory adjustment amount is less than the adjustment amount threshold, keeping the memory allocated to the target virtual machine under the host unchanged.
  • the memory adjustment amount calculated through evaluation The minimum memory adjustment value MAmin may not be reached, so a comparison is required.
  • the virtual machine memory adjustment amount is:
  • FIG. 4 is a schematic diagram of a process for adjusting the memory of a virtual machine according to an embodiment of the present application. As shown in FIG. 4 , the method mainly includes the following steps:
  • Step S401 Configuration step, reading the initial value of the memory capacity (initial memory state) set for each virtual machine, configuring the virtual machine priority PRm (1 to 10), the minimum memory adjustment value MAmin and the adjustment time interval T, assuming that it is all available memory on the physical host, V is the set of all running virtual machines, and n is the number of virtual machines;
  • Step S402 data collection step, collecting data on the size of memory used by each virtual machine and the current memory capacity in real time, the memory size used by the virtual machine VMm is M1m and the current capacity is M2m;
  • Step S403 an evaluation step, calculating the overall memory idle ratio of all virtual machines and the memory idle ratio of each virtual machine;
  • Step S404 Output step, due to the estimated and calculated memory size of the virtual machine VMm that is expected to be expanded or reduced
  • the minimum memory adjustment value MAmin may not be reached, so a comparison is required. Adjustment is only required if it is greater than or equal to MAmin;
  • Step S405 Allocation step, based on the amount of memory that should be actually expanded or reduced for the virtual machine VMm calculated in the evaluation step
  • the virtual machine memory manager sends instructions to the virtual machine monitor to adjust the memory of the virtual machine.
  • the host computer on which multiple virtual machines of this application run uses a Unix-like system (operating system), including but not limited to FreeBSD, OpenBSD, Solaris, and Linux.
  • the virtualization platform of the host machine is QEMU-KVM.
  • the virtual machine memory dynamic manager is developed based on the interface provided by the libvirt (virtualization management software) virtualization library. Since libvirt is an open source API for managing virtualization platforms, this application also supports a series of virtualization platforms that support libvirt, such as QEMU (virtual operating system emulator), KVM (Keyboard Video Mouse, keyboard, video or mouse), VMware, etc.
  • the virtual machine memory dynamic manager includes a configuration module, a collection module, an evaluation module, an output module, and an execution module.
  • the configuration module is responsible for reading the configuration files of each virtual machine to obtain the initial size of the virtual machine's memory capacity, the minimum memory adjustment value MAmin, and the adjustment time interval T;
  • the collection module reads the current content capacity of each virtual machine and the size of the actual memory used through the libvirt interface periodically;
  • the evaluation module calculates the overall memory idle ratio of all virtual machines and the memory idle ratio of each virtual machine, and the amount of memory that the virtual machine VMi expects to expand or reduce at a time interval T.
  • the output module expects the virtual machine VMi to expand or reduce the amount of memory With MAmin By comparison, the actual amount of memory expanded or reduced is obtained; when the control module finds that the actual amount of memory expanded or reduced of a virtual machine is not zero and needs to adjust the memory, it sends an instruction to expand or reduce the memory of the virtual machine through the libvirt interface and memory balloon technology.
  • FIG5 is a structural block diagram of a device for adjusting virtual machine memory according to an embodiment of the present application; as shown in FIG5 , the device comprises:
  • the first acquisition module 502 is configured to acquire the current overall memory status of the multiple virtual machines during the operation of the multiple virtual machines, wherein the multiple virtual machines are operated on the same host, and the overall memory status is used to indicate the overall usage of the memory allocated by the host by the multiple virtual machines;
  • the adjustment module 506 is configured to adjust the memory allocated to each virtual machine according to the target memory state.
  • the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
  • the current overall memory status of the multiple virtual machines is obtained, and the overall memory status is used to indicate the overall usage of the memory allocated by the host by the multiple virtual machines; then, a target memory status is assigned to each virtual machine according to the overall memory status and the target priority of each virtual machine, and the target priority is used to indicate the priority of each virtual machine in using memory on the host; the memory allocated to each virtual machine is adjusted according to the target memory status, that is, the memory allocated to each virtual machine matches the priority of each virtual machine in using memory on the host.
  • the first acquisition module includes:
  • a reading unit is configured to read the memory parameter of each virtual machine to obtain a memory parameter set, wherein the memory parameter set is used to record virtual machines and memory parameters having a corresponding relationship;
  • the first determining unit is configured to determine the overall memory state according to a memory quantity parameter set.
  • the reading unit is further configured to:
  • a virtual machine with a corresponding relationship is constructed, and a memory amount and a memory amount are allocated and used to obtain a memory amount parameter set.
  • the first determining unit is further configured to:
  • the memory free ratio is calculated as the overall memory status based on the total used memory and the total allocated memory.
  • the first determining unit is further configured to:
  • the total memory used M 1 is calculated by the following formula:
  • the multiple virtual machines include n virtual machines, n is a positive integer, M 1i is the amount of used memory corresponding to the i-th virtual machine among the n virtual machines, and i is a positive integer.
  • the total allocated memory M2 is calculated by the following formula:
  • the multiple virtual machines include n virtual machines, n is a positive integer, M 2i is the allocated memory amount corresponding to the i-th virtual machine among the n virtual machines, and i is a positive integer.
  • the first determining unit is further configured to:
  • the memory idle ratio ⁇ 2 is calculated by the following formula:
  • M1 is the total memory used
  • M2 is the total memory allocated
  • the allocation module includes:
  • the access unit is configured to access the configuration parameters of each virtual machine and obtain the target priority corresponding to each virtual machine;
  • the calculation unit is configured to calculate a target memory state according to the overall memory state and the target priority.
  • the computing unit is further configured to:
  • the target memory state is determined based on the adjustment ratio and the overall memory state.
  • the computing unit is further configured to:
  • the adjustment ratio K is calculated by the following formula:
  • PR m is the target priority.
  • the computing unit is further configured to:
  • ⁇ 2 is the overall memory state and K is the adjustment ratio.
  • the device further comprises:
  • a second acquisition module is configured to acquire target task attribute parameters of tasks processed by each virtual machine before allocating a target memory state to each virtual machine according to the overall memory state and the target priority of each virtual machine, wherein the target task attribute parameters are used to indicate the size of memory resources and computing power resources required to process the task;
  • the configuration module is configured to configure the priority of each virtual machine according to the target task attribute parameters to obtain the target priority.
  • the configuration module includes:
  • the adjustment module includes:
  • An acquisition unit is configured to acquire, for each virtual machine as a target virtual machine, a current initial memory state of the target virtual machine, wherein the initial memory state is used to indicate a current memory occupancy of the target virtual machine;
  • a second determining unit is configured to determine a memory adjustment amount according to an initial memory state and a target memory state
  • the adjustment unit is configured to adjust the memory allocated to the target virtual machine under the host by a memory adjustment amount.
  • the target memory parameter corresponding to the target virtual machine is searched from the read memory parameter set, wherein the memory parameter set records virtual machines and memory parameters having a corresponding relationship, and the memory parameter set is used to determine the overall memory state.
  • the second determining unit is further configured to:
  • the target allocated memory is used to indicate the memory size currently allocated to the target virtual machine under the host, and the target used memory is used to indicate the memory size used by the target virtual machine in the currently allocated memory;
  • the memory adjustment amount is calculated based on the target allocated memory amount, the target used memory amount, and the target memory state.
  • the second determining unit is further configured to:
  • the memory adjustment amount is calculated by the following formula
  • M 1m is the target used memory
  • M 2m is the target allocated memory
  • E( ⁇ 1m ) is the target memory state.
  • the adjustment unit is further configured to:
  • the memory allocated to the target virtual machine on the host is expanded by the memory adjustment value indicated by the memory adjustment amount;
  • the memory allocated to the target virtual machine on the host is reduced by the memory adjustment value indicated by the memory adjustment amount.
  • the adjustment unit is further configured to:
  • the memory allocated to the target virtual machine on the host is adjusted by the memory adjustment amount
  • An embodiment of the present application further provides a non-volatile readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
  • the above-mentioned non-volatile readable storage medium may include, but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
  • An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
  • modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation.
  • the present application is not limited to any specific combination of hardware and software.

Landscapes

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

Abstract

本申请公开了一种虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置,涉及计算机领域,该虚拟机内存的调整方法包括:在多个虚拟机运行的过程中,获取多个虚拟机当前的整体内存状态,其中,多个虚拟机运行在同一主机下,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,其中,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;根据目标内存状态调整每个虚拟机所分配到的内存,采用上述技术方案,解决了虚拟机内存分配与使用需求的匹配度低等问题。

Description

虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置
相关申请的交叉引用
本申请要求于2023年01月09日提交中国专利局,申请号为202310029630.0,申请名称为“虚拟机内存的调整方法和装置、存储介质及电子装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及计算机领域,特别的,涉及一种虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置。
背景技术
在现代数据中心,虚拟化技术在资源管理、服务器整合、提高资源利用率等方面发挥了巨大的作用,已成为云计算架构中关键的抽象层次和重要的支撑性技术。随着虚拟化技术的不断发展,云计算的不断使用,虚拟机与物理机的性能差距不断减少。随着虚拟化技术的发展,虚拟化系统的部署已经越来越多,由于虚拟机系统并非一直有效地利用其分配到的内存,并且宿主机上客户机一般也不会同时运行在较高的内存使用率的条件下,所以虚拟化系统内存过载分配是可行的。
在现有的云计算环境中,一般管理员静态指定虚拟机内存大小。当管理员给虚拟机分配了过多的内存,而虚拟机系统不需要使用这么多内存,这势必造成资源浪费。当用户的关键应用运行在虚拟化服务器上的虚拟机中时,某些特定时刻虚拟机需要较多的内存。虚拟机系统内存不足时,虚拟机系统的性能将严重下降,上述内存分配过程中,存在分配精准度较差的情况,也就是实际分配的内存与实际的使用需求不匹配,导致资源浪费或者分配不足的情况出现。
针对相关技术中,虚拟机内存分配与使用需求的匹配度低等问题,缺少有效的解决方案。
发明内容
本申请实施例提供了一种虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置,以至少解决相关技术中,虚拟机内存分配与使用需求的匹配度低等问题。
第一方面,提供了一种虚拟机内存的调整方法,包括:
在多个虚拟机运行的过程中,获取多个虚拟机当前的整体内存状态,其中,多个虚拟机运行在同一主机下,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;
根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,其中,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;
根据目标内存状态调整每个虚拟机所分配到的内存。
可选的,获取多个虚拟机当前的整体内存状态,包括:
读取每个虚拟机的内存量参数,得到内存量参数集合,其中,内存量参数集合用于记录具有对应关系的虚拟机和内存量参数;
根据内存量参数集合确定整体内存状态。
可选的,读取每个虚拟机的内存量参数,得到内存量参数集合,包括:
读取每个虚拟机的分配内存量和使用内存量作为内存量参数,其中,分配内存量用于指示每个虚拟机 在主机下当前分配到的内存大小,使用内存量用于指示每个虚拟机在当前分配到的内存中已使用的内存大小;
构建具有对应关系的虚拟机、分配内存量和使用内存量得到内存量参数集合。
可选的,根据内存量参数集合确定整体内存状态,包括:
计算内存量参数集合中使用内存量的总和作为使用总内存;
计算内存量参数集合中分配内存量的总和作为分配总内存;
根据使用总内存和分配总内存计算内存空闲比作为整体内存状态。
可选的,计算内存量参数集合中使用内存量的总和作为使用总内存,包括:
通过以下公式计算使用总内存M1
其中,多个虚拟机包括n个虚拟机,n为正整数,M1i为n个虚拟机中第i个虚拟机对应的使用内存量,i为正整数。
可选的,计算内存量参数集合中分配内存量的总和作为分配总内存,包括:
通过以下公式计算分配总内存M2
其中,多个虚拟机包括n个虚拟机,n为正整数,M2i为n个虚拟机中第i个虚拟机对应的分配内存量,i为正整数。
可选的,根据使用总内存和分配总内存计算内存空闲比作为整体内存状态,包括:
通过以下公式计算内存空闲比δ2
其中,M1为使用总内存,M2为分配总内存。
可选的,根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,包括:
访问每个虚拟机的配置参数,得到每个虚拟机对应的目标优先级;
根据整体内存状态和目标优先级计算目标内存状态。
可选的,根据整体内存状态和目标优先级计算目标内存状态,包括:
根据目标优先级确定每个虚拟机的调整比例;
根据调整比例和整体内存状态确定目标内存状态。
可选的,根据目标优先级确定每个虚拟机的调整比例,包括:
通过以下公式计算调整比例K:
其中,PRm为第m个虚拟机的目标优先级。
可选的,根据调整比例和整体内存状态确定目标内存状态,包括:
通过以下公式计算第m个虚拟机的目标内存状态E(δ1m):E(δ1m)=Kδ2
其中,δ2为整体内存状态,K为调整比例。
可选的,在根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态之前,方法还包括:
获取每个虚拟机处理的任务的目标任务属性参数,其中,目标任务属性参数用于指示处理任务需要的内存资源大小和算力资源大小;
根据目标任务属性参数配置每个虚拟机的优先级,得到目标优先级。
可选的,根据目标任务属性参数配置每个虚拟机的优先级,得到目标优先级,包括:
从具有对应关系的任务属性参数和优先级中确定目标任务属性参数对应的目标优先级;
将每个虚拟机的优先级参数配置为目标优先级。
可选的,根据目标内存状态调整每个虚拟机所分配到的内存,包括:
对于每个虚拟机作为目标虚拟机获取目标虚拟机当前的初始内存状态,其中,初始内存状态用于指示目标虚拟机当前的内存占用情况;
根据初始内存状态和目标内存状态确定内存调整量;
将目标虚拟机在主机下分配到的内存调整内存调整量。
可选的,对于每个虚拟机作为目标虚拟机获取目标虚拟机当前的初始内存状态,包括:
从读取到的内存量参数集合中查找目标虚拟机对应的目标内存量参数,其中,内存量参数集合记录了具有对应关系的虚拟机和内存量参数,内存量参数集合用于确定整体内存状态。
可选的,根据初始内存状态和目标内存状态确定内存调整量,包括:
获取目标内存量参数所包括的目标分配内存量和目标使用内存量作为初始内存状态,其中,目标分配内存量用于指示目标虚拟机在主机下当前分配到的内存大小,目标使用内存量用于指示目标虚拟机在当前分配到的内存中已使用的内存大小;
根据目标分配内存量,目标使用内存量和目标内存状态计算内存调整量。
可选的,根据目标分配内存量,目标使用内存量和目标内存状态计算内存调整量,包括:
通过以下公式计算内存调整量
其中,M1m为目标使用内存量,M2m为目标分配内存量,E(δ1m)为目标内存状态。
可选的,将目标虚拟机在主机下分配到的内存调整内存调整量,包括:
在内存调整量为正的情况下,将目标虚拟机在主机下分配到的内存扩大内存调整量所指示的内存调整值;
在内存调整量为负的情况下,将目标虚拟机在主机下分配到的内存缩减内存调整量所指示的内存调整值。
可选的,将目标虚拟机在主机下分配到的内存调整内存调整量,包括:
获取主机对应的调整量阈值;
比对内存调整量与调整量阈值;
在内存调整量大于或者等于调整量阈值的情况下,将目标虚拟机在主机下分配到的内存调整内存调整量;
在内存调整量小于调整量阈值的情况下,保持目标虚拟机在主机下分配到的内存不变。
第二方面,还提供了一种虚拟机内存的调整装置,包括:
第一获取模块,被设置为在多个虚拟机运行的过程中,获取多个虚拟机当前的整体内存状态,其中,多个虚拟机运行在同一主机下,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;
分配模块,被设置为根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,其中,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;
调整模块,被设置为根据目标内存状态调整每个虚拟机所分配到的内存。
第三方面,还提供了一种非易失性可读存储介质,该非易失性可读存储介质中存储有计算机程序,其中,该计算机程序被设置为运行时执行上述虚拟机内存的调整方法。
第四方面,还提供了一种电子装置,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,上述处理器通过计算机程序执行上述的虚拟机内存的调整方法。
在本申请实施例中,在多个虚拟机运行的过程中,获取多个虚拟机当前的整体内存状态,其中,多个虚拟机运行在同一主机下,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,其中,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;根据目标内存状态调整每个虚拟机所分配到的内存,即,在多个虚拟机运行在同一主机下的过程中,首先,获取多个虚拟机当前的整体内存状态,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;然后,根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;根据目标 内存状态调整每个虚拟机所分配到的内存,也就是说,每个虚拟机所分配到的内存与每个虚拟机在主机下使用内存的优先程度匹配。采用上述技术方案,解决了相关技术中,虚拟机内存分配与使用需求的匹配度低等问题,实现了提高虚拟机内存分配与使用需求的匹配度的技术效果。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并与说明书一起用于解释本申请的原理。
为了更清楚地说明本申请实施例或相关技术中的技术方案,下面将对实施例或相关技术描述中所需要使用的附图作简单地介绍,显而易见地,对于本领域普通技术人员而言,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1是根据本申请实施例的一种虚拟机内存的调整方法的硬件环境示意图;
图2是根据本申请实施例的一种虚拟机内存的调整方法的流程图;
图3是根据本申请实施例的一种内存量参数集合的生成方法的示意图;
图4是根据本申请实施例的一种虚拟机内存的调整流程的示意图;
图5是根据本申请实施例的一种虚拟机内存的调整装置的结构框图。
具体实施方式
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分的实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。
需要说明的是,本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
本申请实施例所提供的方法实施例可以在计算机终端、设备终端或者类似的运算装置中执行。以运行在计算机终端上为例,图1是根据本申请实施例的一种虚拟机内存的调整方法的硬件环境示意图。如图1所示,计算机终端可以包括一个或多个(图1中仅示出一个)处理器102(处理器102可以包括但不限于微处理器MCU或可编程逻辑器件FPGA等的处理装置)和用于存储数据的存储器104,在一个示例性实施例中,上述计算机终端还可以包括用于通信功能的传输设备106以及输入输出设备108。本领域普通技术人员可以理解,图1所示的结构仅为示意,其并不对上述计算机终端的结构造成限定。例如,计算机终端还可包括比图1中所示更多或者更少的组件,或者具有与图1所示等同功能或比图1所示功能更多的不同的配置。
存储器104可用于存储计算机程序,例如,应用软件的软件程序以及模块,如本申请实施例中的虚拟机内存的调整方法对应的计算机程序,处理器102通过运行存储在存储器104内的计算机程序,从而执行各种功能应用以及数据处理,即实现上述的方法。存储器104可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器104可包括相对于处理器102远程设置的存储器,这些远程存储器可以通过网络连接至计算机终端。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
传输设备106被设置为经由一个网络接收或者发送数据。上述的网络可选实例可包括计算机终端的通 信供应商提供的无线网络。在一个实例中,传输设备106包括一个网络适配器(NetworkInterface Controller,简称为NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输设备106可以为射频(RadioFrequency,简称为RF)模块,其被设置为通过无线方式与互联网进行通讯。
在本实施例中提供了一种虚拟机内存的调整方法,应用于上述计算机终端,图2是根据本申请实施例的一种虚拟机内存的调整方法的流程图,如图2所示,该流程包括如下步骤:
步骤S202,在多个虚拟机运行的过程中,获取多个虚拟机当前的整体内存状态,其中,多个虚拟机运行在同一主机下,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;
步骤S204,根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,其中,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;
步骤S206,根据目标内存状态调整每个虚拟机所分配到的内存。
通过上述步骤,在多个虚拟机运行在同一主机下的过程中,首先,获取多个虚拟机当前的整体内存状态,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;然后,根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;根据目标内存状态调整每个虚拟机所分配到的内存,也就是说,每个虚拟机所分配到的内存与每个虚拟机在主机下使用内存的优先程度匹配。采用上述技术方案,解决了相关技术中,虚拟机内存分配与使用需求的匹配度低等问题,实现了提高虚拟机内存分配与使用需求的匹配度的技术效果。
当前为了解决内存分配过程中,存在分配精准度较差的情况,也就是实际分配的内存与实际的使用需求不匹配,导致资源浪费或者分配不足的情况出现,主流方案由管理员关闭虚拟机重新调整虚拟机的内存大小配置;也有技术方案通过给虚拟机的内存使用量设定上限阈值和下限阈值,实时监控虚拟机的运行状态获取内存使用量,当内存使用量大于上限阈值时线上动态扩展虚拟机内存,当内存使用量小于下限阈值则进行线上收缩虚拟机内存。
但是,管理员手动调整方案不能实时线上动态的调整各虚拟机的内存,而设定上限、下限阈值动态调整的方案在多个虚拟机内存需要调整的时候,当空闲内存不够时,按优先级和幅值进行调整,由于优先级和幅值也是静态设置的,存在虚拟机需要多次调整扩展才能满足虚拟机需要的情况以及优先级反转的情况,即由于优先级低的虚拟机提前调整占用内存但未超过上限,后面需要内存扩展的优先级高的虚拟机却得不到内存。
在上述步骤S202提供的技术方案中,多个虚拟机运行在同一主机下,因此在分配之前,首选获取多个虚拟机当前的整体内存状态,根据整体内存状态可以知道当前多个虚拟机对主机所分配的内存的整体使用情况。
在一个示例性实施例中,可以但不限于通过以下方式获取多个虚拟机当前的整体内存状态:读取每个虚拟机的内存量参数,得到内存量参数集合,其中,内存量参数集合用于记录具有对应关系的虚拟机和内存量参数;根据内存量参数集合确定整体内存状态。
可选地,在本实施例中,图3是根据本申请实施例的一种内存量参数集合的生成方法的示意图,如图3所示,虚拟机1至虚拟机n运行在同一主机下,读取每一个虚拟机的内存参数,得到内存量参数集合(内存量参数1至内存量参数n),根据内存量参数集合可以确定整体内存状态。
在一个示例性实施例中,可以但不限于通过以下方式读取每个虚拟机的内存量参数,得到内存量参数集合:读取每个虚拟机的分配内存量和使用内存量作为内存量参数,其中,分配内存量用于指示每个虚拟机在主机下当前分配到的内存大小,使用内存量用于指示每个虚拟机在当前分配到的内存中已使用的内存大小;构建具有对应关系的虚拟机、分配内存量和使用内存量得到内存量参数集合。
可选地,在本实施例中,内存量参数可以但不限于包括每个虚拟机的分配内存量和使用内存量,分配内存量可以用于指示每个虚拟机在主机下当前分配到的内存大小,使用内存量用于指示每个虚拟机在当前 分配到的内存中已使用的内存大小,因此根据内存量参数集合可以知道每一个虚拟机对应的分配内存量和使用内存量。
在一个示例性实施例中,可以但不限于通过以下方式根据内存量参数集合确定整体内存状态:计算内存量参数集合中使用内存量的总和作为使用总内存;计算内存量参数集合中分配内存量的总和作为分配总内存;根据使用总内存和分配总内存计算内存空闲比作为整体内存状态。
可选地,在本实施例中,整体内存状态可以但不限于用于指示整体内存的使用情况,因此可以将使用总内存和分配总内存计算内存空闲比作为整体内存状态。
在一个示例性实施例中,可以但不限于通过以下方式计算内存量参数集合中使用内存量的总和作为使用总内存:通过以下公式计算使用总内存:
其中,多个虚拟机包括n个虚拟机,n为正整数,M1i为n个虚拟机中第i个虚拟机对应的使用内存量,i为正整数。
可选地,在本实施例中,可以将内存量参数集合中使用内存量的总和作为使用总内存,也就是将每一个虚拟机的使用内存量进行累加,得到使用总内存M1
在一个示例性实施例中,可以但不限于通过以下方式计算内存量参数集合中分配内存量的总和作为分配总内存:通过以下公式计算分配总内存M2
其中,多个虚拟机包括n个虚拟机,n为正整数,M2i为n个虚拟机中第i个虚拟机对应的分配内存量,i为正整数。
可选地,在本实施例中,可以将内存量参数集合中分配内存量的总和作为分配总内存,也就是将每一个虚拟机的分配内存量进行累加,得到分配总内存M2
在一个示例性实施例中,可以但不限于通过以下方式根据使用总内存和分配总内存计算内存空闲比作为整体内存状态:通过以下公式计算内存空闲比δ2
其中,M1为使用总内存,M2为分配总内存。
可选地,在本实施例中,内存空闲比δ2可以指示整体内存状态,内存空闲比δ2越大,即表征当前整体内存状态为内存使用率较低,整体处于较为空闲的状态,内存空闲比δ2越小,即表征当前整体内存状态为内存使用率较高,整体处于较为忙碌的状态。
在上述步骤S204提供的技术方案中,整体内存状态可以指示整体所包括的多个虚拟机的内存平均使用情况,也就是说,整体内存状态是指示平均内存使用情况的一个指标,但是如果仅仅将每一个虚拟机都调整至整体内存状态是不合适的,更为合理的一种方式是基于整体内存状态,并考虑各自虚拟机的目标优先级进行针对性调整,比如,某些目标优先级更高的虚拟机,需要使用更多的内存,因此可以在整体内存状态指示的平均内存使用指标基础上分配更多的内存,而对于目标优先级更低的虚拟机,不需要使用更多的内存,因此可以将其维持在整体内存状态。
在一个示例性实施例中,可以但不限于通过以下方式根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态:访问每个虚拟机的配置参数,得到每个虚拟机对应的目标优先级;根据整体内存状态和目标优先级计算目标内存状态。
可选地,在本实施例中,同一主机下运行多个虚拟机,每一个虚拟机对应执行的任务和功能可能不同,因此内存的使用需求也不同,可以预先配置每个虚拟机的配置参数,对于处理的任务内存的使用需求更大的虚拟机可以配置更高的目标优先级。
在一个示例性实施例中,可以但不限于通过以下方式根据整体内存状态和目标优先级计算目标内存状态:根据目标优先级确定每个虚拟机的调整比例;根据调整比例和整体内存状态确定目标内存状态。
可选地,在本实施例中,对于多个虚拟机中的每一个虚拟机进行内存调整的过程中,都是基于整体内存状态进行比例调整,其中,调整比例的大小与各自的目标优先级相关,目标优先级较低,调整比例较小,目标优先级较高,调整比例较大。
在一个示例性实施例中,可以但不限于通过以下方式根据目标优先级确定每个虚拟机的调整比例:通过以下公式计算调整比例K:
其中,PRm为第m个虚拟机的目标优先级。
可选地,在本实施例中,在目标优先级PRm趋近于0的情况下,调整比例K趋近于1,在目标优先级PRm趋近于正无穷的情况下,调整比例K趋近于1.5。
可选地,在本实施例中,公式的实际可以根据实际需求进行调整,目的在于控制调整比例的大小与各 自的目标优先级挂钩,目标优先级较低,调整比例较小,目标优先级较高,调整比例较大。
在一个示例性实施例中,可以但不限于通过以下方式根据调整比例和整体内存状态确定目标内存状态:通过以下公式计算第m个虚拟机的目标内存状态E(δ1m):
E(δ1m)Kδ2
其中,δ2为整体内存状态,K为调整比例。
可选地,在本实施例中,调整比例是基于整体内存状态而言的,当调整比例为1的情况下,目标内存状态与整体内存状态一致,当调整比例大于1的情况下,目标内存状态大于整体内存状态,分配内存高于整体内存状态。
在一个示例性实施例中,在根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态之前,还可以但不限于包括以下方式获取每个虚拟机处理的任务的目标任务属性参数,其中,目标任务属性参数用于指示处理任务需要的内存资源大小和算力资源大小;根据目标任务属性参数配置每个虚拟机的优先级,得到目标优先级。
可选地,在本实施例中,目标优先级的配置方式是根据虚拟机处理任务需要的内存资源大小和算力资源大小确定出的,当虚拟机处理任务需要的内存资源大小和算力资源大小较大的情况下,可以配置更高的目标优先级,当虚拟机处理任务需要的内存资源大小和算力资源大小较小的情况下,可以配置更低的目标优先级。
在一个示例性实施例中,可以但不限于通过以下方式根据目标任务属性参数配置每个虚拟机的优先级,得到目标优先级:从具有对应关系的任务属性参数和优先级中确定目标任务属性参数对应的目标优先级;将每个虚拟机的优先级参数配置为目标优先级。
可选地,在本实施例中,在已知目标任务属性参数的情况下,可以从具有对应关系的任务属性参数和优先级中确定目标任务属性参数对应的目标优先级。
在上述步骤S206提供的技术方案中,在确定目标内存状态之后,将每个虚拟机所分配到的内存调整至目标内存状态即可。
在一个示例性实施例中,可以但不限于通过以下方式根据目标内存状态调整每个虚拟机所分配到的内存:对于每个虚拟机作为目标虚拟机获取目标虚拟机当前的初始内存状态,其中,初始内存状态用于指示目标虚拟机当前的内存占用情况;根据初始内存状态和目标内存状态确定内存调整量;将目标虚拟机在主机下分配到的内存调整内存调整量。
可选地,在本实施例中,多个虚拟机运行在同一主机上,获取目标虚拟机当前的初始内存状态,根据初始内存状态可以知道目标虚拟机当前的内存占用情况,经过上述目标内存状态可以确定出内存调整量;将目标虚拟机在主机下分配到的内存调整内存调整量。即可以保证目标虚拟机达到目标内存状态。
在一个示例性实施例中,可以但不限于通过以下方式对于每个虚拟机作为目标虚拟机获取目标虚拟机当前的初始内存状态:从读取到的内存量参数集合中查找目标虚拟机对应的目标内存量参数,其中,内存量参数集合记录了具有对应关系的虚拟机和内存量参数,内存量参数集合用于确定整体内存状态。
可选地,在本实施例中,由于内存量参数集合记录了具有对应关系的虚拟机和内存量参数,因此可以从读取到的内存量参数集合中查找目标虚拟机对应的目标内存量参数,进而获取目标虚拟机当前的初始内存状态。
在一个示例性实施例中,可以但不限于通过以下方式根据初始内存状态和目标内存状态确定内存调整量:获取目标内存量参数所包括的目标分配内存量和目标使用内存量作为初始内存状态,其中,目标分配内存量用于指示目标虚拟机在主机下当前分配到的内存大小,目标使用内存量用于指示目标虚拟机在当前分配到的内存中已使用的内存大小;根据目标分配内存量,目标使用内存量和目标内存状态计算内存调整量。
可选地,在本实施例中,目标内存状态指示目标虚拟机待达到的内存状态,根据目标分配内存量,目标使用内存量和目标内存状态计算内存调整量。
在一个示例性实施例中,可以但不限于通过以下方式根据目标分配内存量,目标使用内存量和目标内存状态计算内存调整量:通过以下公式计算内存调整量
其中,M1m为目标使用内存量,M2m为目标分配内存量,E(δ1m)为目标内存状态。
可选地,在本实施例中,内存调整量为虚拟机期望扩大或缩减的内存量。
在一个示例性实施例中,可以但不限于通过以下方式将目标虚拟机在主机下分配到的内存调整内存调整量:在内存调整量为正的情况下,将目标虚拟机在主机下分配到的内存扩大内存调整量所指示的内存调整值;在内存调整量为负的情况下,将目标虚拟机在主机下分配到的内存缩减内存调整量所指示的内存调整值。
可选地,在本实施例中,内存调整量为虚拟机期望扩大或缩减的内存量,在内存调整量为正的情况下,将目标虚拟机在主机下分配到的内存扩大内存调整量所指示的内存调整值,在内存调整量为负的情况下,将目标虚拟机在主机下分配到的内存缩减内存调整量所指示的内存调整值。
在一个示例性实施例中,可以但不限于通过以下方式将目标虚拟机在主机下分配到的内存调整内存调整量:获取主机对应的调整量阈值;比对内存调整量与调整量阈值;在内存调整量大于或者等于调整量阈值的情况下,将目标虚拟机在主机下分配到的内存调整内存调整量;在内存调整量小于调整量阈值的情况下,保持目标虚拟机在主机下分配到的内存不变。
可选地,在本实施例中,由于经过评估计算出的内存调整量可能达不到最小内存调整值MAmin,因此,需要进行比较判断。当期望扩大或缩减的内存量大小大于等于MAmin,才需要进行调整。因此,虚拟机内存调整量为:
为了更好的理解上述虚拟机内存的调整的过程,以下再结合可选实施例对上述虚拟机内存的调整流程进行说明,但不用于限定本申请实施例的技术方案。
在本实施例中提供了一种虚拟机内存的调整方法,图4是根据本申请实施例的一种虚拟机内存的调整流程的示意图,如图4所示,主要包括如下步骤:
步骤S401:配置步骤,读取各虚拟机设定的内存容量初始值(初始内存状态),配置虚拟机优先级PRm(1至10)、最小内存调整值MAmin和调整时间间隔T,假设是物理主机上所有可用内存,V是所有运行的虚拟机的集合,n为虚拟机数量;
步骤S402:数据采集步骤,实时收集各虚拟机使用内存的大小以及当前内存容量的数据,虚拟机VMm使用内存大小为M1m和当前容量M2m;
步骤S403:评估步骤,计算所有虚拟机的整体的内存空闲比和各虚拟机的内存空闲比;
步骤S404:输出步骤,由于经过评估计算出的虚拟机VMm期望扩大或缩减的内存量大小可能达不到最小内存调整值MAmin,因此,需要进行比较判断。当期望扩大或缩减的内存量大小大于等于MAmin,才需要进行调整;
步骤S405:调配步骤,根据评估步骤中计算虚拟机VMm实际应扩大或缩减的内存量由虚拟机内存管理器发送指令给虚拟机监控器对虚拟机进行内存调整。
本申请多个虚拟机运行的主机使用类Unix系统(操作系统),包括但不限于FreeBSD、OpenBSD、Solaris和Linux等。宿主机的虚拟化平台为QEMU-KVM。虚拟机内存动态管理器是基于libvirt(虚拟化管理软件)虚拟化库提供的接口开发的,由于libvirt是一个管理虚拟化平台的开源API,因此本申请同时也支持QEMU(虚拟操作系统模拟器)、KVM(Keyboard Video Mouse,键盘、视频或鼠标)、VMware等支持libvirt的一系列虚拟化平台。
虚拟机内存动态管理器包括配置模块、采集模块、评估模块、输出模块、执行模块。配置模块负责读取各虚拟机的配置文件获取虚拟机的内存容量初始大小,读取最小内存调整值MAmin和调整时间间隔T;采集模块通过libvirt接口周期读取各虚拟机的当前内容容量以及实际使用内存的大小;评估模块以时间间隔T周期进行运算计算所有虚拟机的整体的内存空闲比和各虚拟机的内存空闲比、虚拟机VMi期望扩大或缩减的内存量输出模块将虚拟机VMi期望扩大或缩减的内存量与MAmin 进行比较,得到实际扩大或缩减的内存量;控制模块当发现某个虚拟机的实际扩大或缩减的内存量不为零需要调整内存时,发送指令通过libvirt接口和内存气球技术,扩展或缩小虚拟机的内存。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对相关技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个非易失性可读存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例的方法。
图5是根据本申请实施例的一种虚拟机内存的调整装置的结构框图;如图5所示,包括:
第一获取模块502,被设置为在多个虚拟机运行的过程中,获取多个虚拟机当前的整体内存状态,其中,多个虚拟机运行在同一主机下,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;
分配模块504,被设置为根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,其中,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;
调整模块506,被设置为根据目标内存状态调整每个虚拟机所分配到的内存。
需要说明的是,上述各个模块是可以通过软件或硬件来实现的,对于后者,可以通过以下方式实现,但不限于此:上述模块均位于同一处理器中;或者,上述各个模块以任意组合的形式分别位于不同的处理器中。
通过上述实施例,在多个虚拟机运行在同一主机下的过程中,首先,获取多个虚拟机当前的整体内存状态,整体内存状态用于指示多个虚拟机对主机所分配的内存的整体使用情况;然后,根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态,目标优先级用于指示每个虚拟机在主机下使用内存的优先程度;根据目标内存状态调整每个虚拟机所分配到的内存,也就是说,每个虚拟机所分配到的内存与每个虚拟机在主机下使用内存的优先程度匹配。采用上述技术方案,解决了相关技术中,虚拟机内存分配与使用需求的匹配度低等问题,实现了提高虚拟机内存分配与使用需求的匹配度的技术效果。
在一个可选的实施例中,第一获取模块,包括:
读取单元,被设置为读取每个虚拟机的内存量参数,得到内存量参数集合,其中,内存量参数集合用于记录具有对应关系的虚拟机和内存量参数;
第一确定单元,被设置为根据内存量参数集合确定整体内存状态。
在一个可选的实施例中,读取单元,还被设置为:
读取每个虚拟机的分配内存量和使用内存量作为内存量参数,其中,分配内存量用于指示每个虚拟机在主机下当前分配到的内存大小,使用内存量用于指示每个虚拟机在当前分配到的内存中已使用的内存大小;
构建具有对应关系的虚拟机、分配内存量和使用内存量得到内存量参数集合。
在一个可选的实施例中,第一确定单元,还被设置为:
计算内存量参数集合中使用内存量的总和作为使用总内存;
计算内存量参数集合中分配内存量的总和作为分配总内存;
根据使用总内存和分配总内存计算内存空闲比作为整体内存状态。
在一个可选的实施例中,第一确定单元,还被设置为:
通过以下公式计算使用总内存M1
其中,多个虚拟机包括n个虚拟机,n为正整数,M1i为n个虚拟机中第i个虚拟机对应的使用内存量,i为正整数。
在一个可选的实施例中,第一确定单元,还被设置为:
通过以下公式计算分配总内存M2
其中,多个虚拟机包括n个虚拟机,n为正整数,M2i为n个虚拟机中第i个虚拟机对应的分配内存量,i为正整数。
在一个可选的实施例中,第一确定单元,还被设置为:
通过以下公式计算内存空闲比δ2
其中,M1为使用总内存,M2为分配总内存。
在一个可选的实施例中,分配模块,包括:
访问单元,被设置为访问每个虚拟机的配置参数,得到每个虚拟机对应的目标优先级;
计算单元,被设置为根据整体内存状态和目标优先级计算目标内存状态。
在一个可选的实施例中,计算单元,还被设置为:
根据目标优先级确定每个虚拟机的调整比例;
根据调整比例和整体内存状态确定目标内存状态。
在一个可选的实施例中,计算单元,还被设置为:
通过以下公式计算调整比例K:
其中,PRm为目标优先级。
在一个可选的实施例中,计算单元,还被设置为:
通过以下公式计算目标内存状态E(δ1m):E(δ1m)=Kδ2
其中,δ2为整体内存状态,K为调整比例。
在一个可选的实施例中,装置还包括:
第二获取模块,被设置为在根据整体内存状态和每个虚拟机的目标优先级为每个虚拟机分配目标内存状态之前,获取每个虚拟机处理的任务的目标任务属性参数,其中,目标任务属性参数用于指示处理任务需要的内存资源大小和算力资源大小;
配置模块,被设置为根据目标任务属性参数配置每个虚拟机的优先级,得到目标优先级。
在一个可选的实施例中,配置模块,包括:
从具有对应关系的任务属性参数和优先级中确定目标任务属性参数对应的目标优先级;
将每个虚拟机的优先级参数配置为目标优先级。
在一个可选的实施例中,调整模块,包括:
获取单元,被设置为对于每个虚拟机作为目标虚拟机获取目标虚拟机当前的初始内存状态,其中,初始内存状态用于指示目标虚拟机当前的内存占用情况;
第二确定单元,被设置为根据初始内存状态和目标内存状态确定内存调整量;
调整单元,被设置为将目标虚拟机在主机下分配到的内存调整内存调整量。
在一个可选的实施例中,获取单元,还被设置为:
从读取到的内存量参数集合中查找目标虚拟机对应的目标内存量参数,其中,内存量参数集合记录了具有对应关系的虚拟机和内存量参数,内存量参数集合用于确定整体内存状态。
在一个可选的实施例中,第二确定单元,还被设置为:
获取目标内存量参数所包括的目标分配内存量和目标使用内存量作为初始内存状态,其中,目标分配内存量用于指示目标虚拟机在主机下当前分配到的内存大小,目标使用内存量用于指示目标虚拟机在当前分配到的内存中已使用的内存大小;
根据目标分配内存量,目标使用内存量和目标内存状态计算内存调整量。
在一个可选的实施例中,第二确定单元,还被设置为:
通过以下公式计算内存调整量
其中,M1m为目标使用内存量,M2m为目标分配内存量,E(δ1m)为目标内存状态。
在一个可选的实施例中,调整单元,还被设置为:
在内存调整量为正的情况下,将目标虚拟机在主机下分配到的内存扩大内存调整量所指示的内存调整值;
在内存调整量为负的情况下,将目标虚拟机在主机下分配到的内存缩减内存调整量所指示的内存调整值。
在一个可选的实施例中,调整单元,还被设置为:
获取主机对应的调整量阈值;
比对内存调整量与调整量阈值;
在内存调整量大于或者等于调整量阈值的情况下,将目标虚拟机在主机下分配到的内存调整内存调整量;
在内存调整量小于调整量阈值的情况下,保持目标虚拟机在主机下分配到的内存不变。
本申请的实施例还提供了一种非易失性可读存储介质,该非易失性可读存储介质中存储有计算机程序,其中,该计算机程序被设置为运行时执行上述任一项方法实施例中的步骤。
在一个示例性实施例中,上述非易失性可读存储介质可以包括但不限于:U盘、只读存储器(Read-Only Memory,简称为ROM)、随机存取存储器(Random Access Memory,简称为RAM)、移动硬盘、磁碟或者光盘等各种可以存储计算机程序的介质。
本申请的实施例还提供了一种电子设备,包括存储器和处理器,该存储器中存储有计算机程序,该处理器被设置为运行计算机程序以执行上述任一项方法实施例中的步骤。
在一个示例性实施例中,上述电子设备还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。
本实施例中的可选示例可以参考上述实施例及示例性实施方式中所描述的示例,本实施例在此不再赘述。
显然,本领域的技术人员应该明白,上述的本申请的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本申请不限制于任何特定的硬件和软件结合。
以上仅为本申请的可选实施例而已,并不用于限制本申请,对于本领域的技术人员来说,本申请可以有各种更改和变化。凡在本申请的原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。

Claims (22)

  1. 一种虚拟机内存的调整方法,其特征在于,包括:
    在多个虚拟机运行的过程中,获取所述多个虚拟机当前的整体内存状态,其中,所述多个虚拟机运行在同一主机下,所述整体内存状态用于指示所述多个虚拟机对所述主机所分配的内存的整体使用情况;
    根据所述整体内存状态和每个虚拟机的目标优先级为所述每个虚拟机分配目标内存状态,其中,所述目标优先级用于指示所述每个虚拟机在所述主机下使用内存的优先程度;
    根据所述目标内存状态调整所述每个虚拟机所分配到的内存。
  2. 根据权利要求1所述的方法,其特征在于,所述获取所述多个虚拟机当前的整体内存状态,包括:
    读取所述每个虚拟机的内存量参数,得到内存量参数集合,其中,所述内存量参数集合用于记录具有对应关系的虚拟机和内存量参数;
    根据所述内存量参数集合确定所述整体内存状态。
  3. 根据权利要求2所述的方法,其特征在于,所述读取所述每个虚拟机的内存量参数,得到内存量参数集合,包括:
    读取所述每个虚拟机的分配内存量和使用内存量作为所述内存量参数,其中,所述分配内存量用于指示所述每个虚拟机在所述主机下当前分配到的内存大小,所述使用内存量用于指示所述每个虚拟机在当前分配到的内存中已使用的内存大小;
    构建具有对应关系的虚拟机、分配内存量和使用内存量得到所述内存量参数集合。
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述内存量参数集合确定所述整体内存状态,包括:
    计算所述内存量参数集合中使用内存量的总和作为使用总内存;
    计算所述内存量参数集合中分配内存量的总和作为分配总内存;
    根据所述使用总内存和所述分配总内存计算内存空闲比作为所述整体内存状态。
  5. 根据权利要求4所述的方法,其特征在于,所述计算所述内存量参数集合中使用内存量的总和作为使用总内存,包括:
    通过以下公式计算所述使用总内存M1
    其中,所述多个虚拟机包括n个虚拟机,n为正整数,M1i为n个虚拟机中第i个虚拟机对应的使用内存量,i为正整数。
  6. 根据权利要求5所述的方法,其特征在于,所述计算所述内存量参数集合中分配内存量的总和作为分配总内存,包括:
    通过以下公式计算所述分配总内存M2
    其中,所述多个虚拟机包括n个虚拟机,n为正整数,M2i为n个虚拟机中第i个虚拟机对应的分配内存量,i为正整数。
  7. 根据权利要求6所述的方法,其特征在于,所述根据所述使用总内存和所述分配总内存计算内存空闲比作为所述整体内存状态,包括:
    通过以下公式计算所述内存空闲比δ2
    其中,所述M1为所述使用总内存,所述M2为所述分配总内存。
  8. 根据权利要求1所述的方法,其特征在于,所述根据所述整体内存状态和每个虚拟机的目标优先级为所述每个虚拟机分配目标内存状态,包括:
    访问所述每个虚拟机的配置参数,得到所述每个虚拟机对应的所述目标优先级;
    根据所述整体内存状态和所述目标优先级计算所述目标内存状态。
  9. 根据权利要求8所述的方法,其特征在于,所述根据所述整体内存状态和所述目标优先级计算所述目标内存状态,包括:
    根据所述目标优先级确定所述每个虚拟机的调整比例;
    根据所述调整比例和所述整体内存状态确定所述目标内存状态。
  10. 根据权利要求9所述的方法,其特征在于,所述根据所述目标优先级确定所述每个虚拟机的调整比例,包括:
    通过以下公式计算所述调整比例K:
    其中,PRm为第m个虚拟机的所述目标优先级。
  11. 根据权利要求10所述的方法,其特征在于,所述根据所述调整比例和所述整体内存状态确定所述目标内存状态,包括:
    通过以下公式计算第m个虚拟机的所述目标内存状态E(δ1m):
    E(δ1m)=Kδ2
    其中,所述δ2为所述整体内存状态,K为所述调整比例。
  12. 根据权利要求1所述的方法,其特征在于,在所述根据所述整体内存状态和每个虚拟机的目标优先级为所述每个虚拟机分配目标内存状态之前,所述方法还包括:
    获取所述每个虚拟机处理的任务的目标任务属性参数,其中,所述目标任务属性参数用于指示处理所述任务需要的内存资源大小和算力资源大小;
    根据所述目标任务属性参数配置所述每个虚拟机的优先级,得到所述目标优先级。
  13. 根据权利要求12所述的方法,其特征在于,所述根据所述目标任务属性参数配置所述每个虚拟机的优先级,得到所述目标优先级,包括:
    从具有对应关系的任务属性参数和优先级中确定所述目标任务属性参数对应的所述目标优先级;
    将所述每个虚拟机的优先级参数配置为所述目标优先级。
  14. 根据权利要求1所述的方法,其特征在于,所述根据所述目标内存状态调整所述每个虚拟机所分配到的内存,包括:
    对于所述每个虚拟机作为目标虚拟机获取所述目标虚拟机当前的初始内存状态,其中,所述初始内存状态用于指示所述目标虚拟机当前的内存占用情况;
    根据所述初始内存状态和所述目标内存状态确定内存调整量;
    将所述目标虚拟机在所述主机下分配到的内存调整所述内存调整量。
  15. 根据权利要求14所述的方法,其特征在于,所述对于所述每个虚拟机作为目标虚拟机获取所述目标虚拟机当前的初始内存状态,包括:
    从读取到的内存量参数集合中查找所述目标虚拟机对应的目标内存量参数,其中,所述内存量参数集合记录了具有对应关系的虚拟机和内存量参数,所述内存量参数集合用于确定所述整体内存状态。
  16. 根据权利要求15所述的方法,其特征在于,所述根据所述初始内存状态和所述目标内存状态确定内存调整量,包括:
    获取所述目标内存量参数所包括的目标分配内存量和目标使用内存量作为所述初始内存状态,其中,所述目标分配内存量用于指示所述目标虚拟机在所述主机下当前分配到的内存大小,所述目标使用内存量用于指示所述目标虚拟机在当前分配到的内存中已使用的内存大小;
    根据所述目标分配内存量,所述目标使用内存量和所述目标内存状态计算所述内存调整量。
  17. 根据权利要求16所述的方法,其特征在于,所述根据所述目标分配内存量,所述目标使用内存量和所述目标内存状态计算所述内存调整量,包括:
    通过以下公式计算所述内存调整量
    其中,所述M1m为所述目标使用内存量,所述M2m为所述目标分配内存量,所述E(δ1m)为所述目标内存状态。
  18. 根据权利要求14所述的方法,其特征在于,所述将所述目标虚拟机在所述主机下分配到的内存调整所述内存调整量,包括:
    在所述内存调整量为正的情况下,将所述目标虚拟机在所述主机下分配到的内存扩大所述内存调整量所指示的内存调整值;
    在所述内存调整量为负的情况下,将所述目标虚拟机在所述主机下分配到的内存缩减所述内存调整量所指示的内存调整值。
  19. 根据权利要求14所述的方法,其特征在于,所述将所述目标虚拟机在所述主机下分配到的内存调整所述内存调整量,包括:
    获取所述主机对应的调整量阈值;
    比对所述内存调整量与所述调整量阈值;
    在所述内存调整量大于或者等于所述调整量阈值的情况下,将所述目标虚拟机在所述主机下分配到的内存调整所述内存调整量;
    在所述内存调整量小于所述调整量阈值的情况下,保持所述目标虚拟机在所述主机下分配到的内存不变。
  20. 一种虚拟机内存的调整装置,其特征在于,包括:
    第一获取模块,被设置为在多个虚拟机运行的过程中,获取所述多个虚拟机当前的整体内存状态,其中,所述多个虚拟机运行在同一主机下,所述整体内存状态用于指示所述多个虚拟机对所述主 机所分配的内存的整体使用情况;
    分配模块,被设置为根据所述整体内存状态和每个虚拟机的目标优先级为所述每个虚拟机分配目标内存状态,其中,所述目标优先级用于指示所述每个虚拟机在所述主机下使用内存的优先程度;
    调整模块,被设置为根据所述目标内存状态调整所述每个虚拟机所分配到的内存。
  21. 一种非易失性可读存储介质,其特征在于,所述非易失性可读存储介质包括存储的程序,其中,所述程序运行时执行权利要求1至19中任一项所述的方法。
  22. 一种电子装置,包括存储器和处理器,其特征在于,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行权利要求1至19中任一项所述的方法。
PCT/CN2023/121786 2023-01-09 2023-09-26 虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置 WO2024148864A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202310029630.0A CN115794305B (zh) 2023-01-09 2023-01-09 虚拟机内存的调整方法和装置、存储介质及电子装置
CN202310029630.0 2023-01-09

Publications (1)

Publication Number Publication Date
WO2024148864A1 true WO2024148864A1 (zh) 2024-07-18

Family

ID=85428831

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/121786 WO2024148864A1 (zh) 2023-01-09 2023-09-26 虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置

Country Status (2)

Country Link
CN (1) CN115794305B (zh)
WO (1) WO2024148864A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115794305B (zh) * 2023-01-09 2023-05-09 苏州浪潮智能科技有限公司 虚拟机内存的调整方法和装置、存储介质及电子装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105204948A (zh) * 2015-10-29 2015-12-30 广州云宏信息科技股份有限公司 虚拟机物理内存配置方法及装置
CN106445690A (zh) * 2016-10-17 2017-02-22 深圳市深信服电子科技有限公司 虚拟机资源的动态调配方法及装置
CN111651236A (zh) * 2020-05-11 2020-09-11 腾讯科技(深圳)有限公司 虚拟机内存优化处理方法及相关装置
CN112965792A (zh) * 2021-05-18 2021-06-15 云宏信息科技股份有限公司 为多个虚拟机分配内存的方法、计算机可读存储介质
CN115794305A (zh) * 2023-01-09 2023-03-14 苏州浪潮智能科技有限公司 虚拟机内存的调整方法和装置、存储介质及电子装置

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106776048A (zh) * 2017-01-24 2017-05-31 郑州云海信息技术有限公司 一种实时虚拟机内存调度方法及装置
CN107463430B (zh) * 2017-08-03 2020-10-02 哈尔滨工业大学 一种基于内存和Swap空间的虚拟机内存动态管理系统及方法
CN112513821A (zh) * 2018-08-01 2021-03-16 华为技术有限公司 用于scm应用的多实例2lm架构
CN115269118A (zh) * 2022-07-29 2022-11-01 天翼云科技有限公司 一种虚拟机的调度方法、装置及设备
CN115390993A (zh) * 2022-09-09 2022-11-25 深圳威科软件科技有限公司 一种虚拟机内存处理方法、装置、电子设备和存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105204948A (zh) * 2015-10-29 2015-12-30 广州云宏信息科技股份有限公司 虚拟机物理内存配置方法及装置
CN106445690A (zh) * 2016-10-17 2017-02-22 深圳市深信服电子科技有限公司 虚拟机资源的动态调配方法及装置
CN111651236A (zh) * 2020-05-11 2020-09-11 腾讯科技(深圳)有限公司 虚拟机内存优化处理方法及相关装置
CN112965792A (zh) * 2021-05-18 2021-06-15 云宏信息科技股份有限公司 为多个虚拟机分配内存的方法、计算机可读存储介质
CN115794305A (zh) * 2023-01-09 2023-03-14 苏州浪潮智能科技有限公司 虚拟机内存的调整方法和装置、存储介质及电子装置

Also Published As

Publication number Publication date
CN115794305A (zh) 2023-03-14
CN115794305B (zh) 2023-05-09

Similar Documents

Publication Publication Date Title
EP3606008B1 (en) Method and device for realizing resource scheduling
US9104498B2 (en) Maximizing server utilization within a datacenter
US9977689B2 (en) Dynamic scaling of management infrastructure in virtual environments
US8701108B2 (en) Apparatus and method for controlling live-migrations of a plurality of virtual machines
US9588789B2 (en) Management apparatus and workload distribution management method
WO2018149221A1 (zh) 一种设备管理方法及网管系统
US10055244B2 (en) Boot control program, boot control method, and boot control device
US9442763B2 (en) Resource allocation method and resource management platform
US9183016B2 (en) Adaptive task scheduling of Hadoop in a virtualized environment
US9405572B2 (en) Optimized resource allocation and management in a virtualized computing environment
CN103399778B (zh) 一种虚拟机在线整体迁移方法和设备
US20170031622A1 (en) Methods for allocating storage cluster hardware resources and devices thereof
WO2015196931A1 (zh) 基于磁盘io的虚拟资源分配方法及装置
US9529642B2 (en) Power budget allocation in a cluster infrastructure
US20120221730A1 (en) Resource control system and resource control method
CN105049268A (zh) 分布式计算资源分配系统和任务处理方法
CN117370029A (zh) 分布式计算系统中的集群资源管理
US20140282540A1 (en) Performant host selection for virtualization centers
CN108874502B (zh) 云计算集群的资源管理方法、装置及设备
WO2024148864A1 (zh) 虚拟机内存的调整方法和装置、非易失性可读存储介质及电子装置
US11831410B2 (en) Intelligent serverless function scaling
US11436231B2 (en) Continuous query scheduling and splitting in a cluster-based data storage system
US20200272526A1 (en) Methods and systems for automated scaling of computing clusters
CN107203256B (zh) 一种网络功能虚拟化场景下的节能分配方法与装置
US20210389994A1 (en) Automated performance tuning using workload profiling in a distributed computing environment

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: 23915622

Country of ref document: EP

Kind code of ref document: A1