Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
The technical means described in the embodiments of the present invention may be arbitrarily combined without conflict.
In addition, in the embodiments of the present invention, "first", "second", and the like are used for distinguishing similar objects, and are not necessarily used for describing a specific order or a sequential order.
In addition, the user interface diagram in the embodiment of the present invention is not intended to limit the present invention.
Fig. 1 is a schematic flow chart of a resource allocation method according to an embodiment of the present invention. As shown in fig. 1, the method includes:
s101: setting a resource parameter of at least one NUMA node of at least two NUMA nodes in a server to a first type of resource parameter; wherein the first type of resource parameter characterization can create a virtual machine on a corresponding NUMA node.
NUMA is a computer memory design for multiple processors. A NUMA architecture can divide a server into NUMA nodes that contain separate processors and memory. Here, the resource parameter of at least one NUMA node in the server is set to a first type of resource parameter, and a virtual machine can be created on the NUMA node by the first type of resource parameter set by the NUMA node, and the first type of resource parameter can determine the amount of resources that the virtual machine created on the NUMA node needs to allocate. Resource parameters of NUMA nodes of the server can be set through a browser in OpenStack, the OpenStack is an open-source cloud computing management platform project and is a combination of a series of software open-source projects, and specific codes for setting the resource parameters are as follows:
Openstack flavor set FLAVOR-NAME
--property hw:numa_nodes=FLAVOR-NODES
--property hw:numa_cpus.N=FLAVOR-CORES
--property hw:numa_mem.N=FLAVOR-MEMORY
wherein, the FLAVOR-NAME refers to the NAME of NUMA node of the server, and is used for distinguishing the NUMA node between different servers. hw: NUMA _ NODES refers to NUMA node numbers and FLAVOR-NODES is a specific NUMA node number value. NUMA _ cpu.n and NUMA _ mem.n belong to resource parameters of NUMA nodes with node numbers N, in practical applications, N ═ 0 is usually used to represent the first NUMA node of the server, and flag-core and flag-MEMORY refer to specific values of resource parameter settings. For example, when the resource parameter of the first NUMA node in the server is set as the first parameter, the specific code is:
property hw:numa_cpu.0=0,1
property hw:numa_mem.0=2048
NUMA _ cpu.0 refers to the number of processors created in the first NUMA node, the first parameter may be set to a sequence, and represents the number of virtual machines created in the first NUMA node, each virtual machine corresponds to one sequence number in the sequence set by the processor parameter, for example, when the first parameter is 0 or 1, it represents that two virtual machines are created in the first NUMA node, the sequence number corresponding to the first virtual machine is 0, and the sequence number corresponding to the second virtual machine is 1. Nummemm.0 refers to the amount of memory capacity available to the first NUMA node for allocation to the virtual machine, representing 2048 of memory capacity available to the virtual machine created in the first NUMA node.
S102: setting resource parameters of NUMA nodes other than the at least one NUMA node in the server to resource parameters of a second type; and the resource parameters of the second type represent that the corresponding NUMA node does not support the creation of the virtual machine.
Here, in addition to setting the resource parameter of the first type to at least one NUMA node in the server, it is also necessary to set the resource parameter of another NUMA node to the resource parameter of the second type, and when the resource parameter of the NUMA node is set to the resource parameter of the second type, the corresponding NUMA node does not support the creation of the virtual machine, and corresponding resource allocation is not performed. In practical application, when resource allocation is performed on a virtual machine on a NUMA node, the virtual machine is created from a first NUMA node of a server, and after corresponding resource allocation is performed, the virtual machine can be transferred to a next NUMA node to perform resource allocation. Therefore, in addition to setting the resource parameters of the NUMA nodes in the server to the first type of resource parameters, it is necessary to set the resource parameters of other NUMA nodes. The resource parameters of the first type are different from the resource parameters of the second type, the first type parameters are used for creating a virtual machine on a NUMA node and completing resource allocation on the virtual machine, the second type parameters are used for not supporting the creation of the virtual machine on the NUMA node and not needing to perform resource allocation, and the NUMA node needing to create the virtual machine is distinguished through the resource parameters of the first type and the resource parameters of the second type. When the resource parameter of the first NUMA node in the server is set as the second parameter, the specific code is:
property hw:numa_cpu.0=,
property hw:numa_mem.0=0
NUMA _ cpu.0 indicates that the first NUMA node in the server does not support virtual machine creation, and thus processor resource allocation cannot be performed. And 2, the fact that NUMA _ mem.0-0 indicates that the first NUMA node in the server does not perform the operation of allocating the memory resources, so that a virtual machine is not created on the first NUMA node in the server, and the resources are not allocated to the virtual machine. The set parameter of the processor parameter in the second type resource parameter may be a parameter outside the sequence, for example, a specific parameter may be set as a punctuation mark. For the memory parameter, the value of the second type of resource parameter is usually set to 0.
S103: and according to the corresponding resource parameters, creating a virtual machine based on the at least two NUMA nodes and allocating resources for the virtual machine.
Here, after the resource parameters of at least two NUMA nodes in the server are set, a virtual machine is created based on the at least two NUMA nodes in the server according to the resource parameters corresponding to the NUMA nodes to perform resource allocation. Specifically, when the resource parameter of the NUMA node is the first type of resource parameter, a virtual machine is created on the corresponding NUMA node, and resource allocation is performed for the virtual machine according to the resource parameter corresponding to the NUMA node. When the resource parameters of the NUMA node are of the second type, then there is no need to create a virtual machine on the NUMA node, nor is there a need to allocate resources to the virtual machine.
In the above embodiment, by setting the resource parameter of at least one NUMA node of at least two NUMA nodes in the server to the first type of resource parameter, the first type of resource parameter characterization may create a virtual machine on the corresponding NUMA node, and setting the resource parameter of another NUMA node other than the at least one NUMA node in the server to the second type of resource parameter, the second type of resource parameter characterization may not support creating a virtual machine on the corresponding NUMA node, and according to the resource parameter set by the NUMA node in the server, creating a virtual machine and performing resource allocation for the virtual machine, it is possible to create a virtual machine on the NUMA node in the designated server, and perform resource allocation for the created virtual machine, thereby improving the utilization efficiency of resources.
In an embodiment, as shown in fig. 2, the resource parameters include a processor parameter and a memory parameter, and the creating a virtual machine and allocating resources for the virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters further includes:
s201: processor parameters for each of the at least two NUMA nodes are obtained.
Here, when setting a resource parameter for a NUMA node in a server, a processor parameter and a memory parameter need to be set, respectively. Where the processor parameter represents the number of virtual machines created on the corresponding NUMA node and the memory parameter represents the amount of memory available for allocation to the virtual machines. After the resource parameters of the NUMA nodes of the server are set, a virtual machine is created for the NUMA nodes in the server, and when the resources of the virtual machine are distributed, the processor parameters of each NUMA node in the server need to be acquired.
S202: and determining the NUMA node of the processor parameter which accords with the first type of resource parameter, and acquiring the node sequence number of the NUMA node of the processor parameter which accords with the first type of resource parameter.
Here, after acquiring the processor parameters of all the NUMA nodes in the server, the acquired processor parameters are analyzed, the type of the processor parameters is determined, whether the processor parameters are the processor parameters in the first type of resource parameters or the processor parameters in the second type of resource parameters is determined, specifically, whether the parameter characterization of the processor can create a virtual machine on the NUMA nodes is determined, NUMA nodes of the processor parameters in the server that meet the first type of resource parameters are determined, and node numbers of the NUMA nodes are acquired. When there is a setting of the processor parameter for the NUMA node that conforms to a processor parameter in the first type of resource parameter, then the processor parameter for the NUMA node can be determined to be the processor parameter of the first type and the node sequence number for the NUMA node is determined.
S203: and determining the memory parameters of the NUMA node corresponding to the acquired node serial number according to the acquired node serial number.
Here, the object of resource allocation is actually a virtual machine created on a NUMA node, that is, resource allocation is performed on a virtual machine created on a NUMA node set as the first type of processor parameter, but a NUMA node not set as the first type of processor parameter does not support creation of a virtual machine and does not need resource allocation to a virtual machine, and therefore, resource allocation can be completed on a virtual machine created on a corresponding NUMA node by acquiring a processor parameter and a memory parameter in accordance with the first type of resource parameter. After the node serial number of the processor parameter in the resource parameter according with the first type is obtained, the memory parameter of the NUMA node of the obtained node serial number is inquired according to the obtained node serial number, so that the NUMA node of which the resource parameter in the server is the resource parameter of the first type can be obtained, and the setting of the specific resource parameter corresponding to the NUMA node is obtained.
S204: and creating a virtual machine and performing resource allocation for the virtual machine according to the processor parameter and the memory parameter of the NUMA node corresponding to the acquired node serial number.
Here, a virtual machine is created on the NUMA node according to the acquired node number of the NUMA node belonging to the first type of resource parameter, and resource allocation including allocation of processor resources and allocation of memory resources is performed on the created virtual machine according to the acquired specific parameter of the first type of resource parameter of the NUMA node.
In the above embodiment, by obtaining the processor parameter of each NUMA node, determining a NUMA node of the processor parameter that meets the first type of resource parameter, and obtaining the node number of the NUMA node of the processor parameter that meets the first type of resource parameter, according to the obtained node number, determining the memory parameter of the NUMA node corresponding to the node number, and according to the processor parameter and the memory parameter of the NUMA node of the obtained node number, creating a virtual machine and performing resource allocation for the virtual machine, it is possible to quickly locate the NUMA node that needs to create the virtual machine, and complete resource allocation for the created virtual machine, thereby improving the efficiency of searching for a target NUMA node and the efficiency of resource allocation.
In an embodiment, as shown in FIG. 3, when creating a virtual machine based on the at least two NUMA nodes and allocating resources for the virtual machine according to the corresponding resource parameters, the method includes:
s301: acquiring a node serial number of a current NUMA node; each of the at least two NUMA nodes corresponds to a node sequence number.
Here, the node sequence number of the current NUMA node is obtained, where each NUMA node corresponds to one node sequence number. In practical applications, 0 is usually used to represent the first NUMA node in the server, 1 is used to represent the serial number of the second NUMA node in the server, and so on, and each NUMA node in the server is distinguished by the node serial number.
S302: and when the node sequence number of the current NUMA node is different from the node sequence numbers of all NUMA nodes corresponding to the first type of resource parameters, skipping the current NUMA node.
Here, after the node serial number of the current NUMA node is acquired, the node serial number of the current NUMA node is compared with the node serial numbers of all NUMA nodes provided with the first type of resource parameters, and it is determined whether the node serial number of the current NUMA node is different from the node serial numbers of all NUMA nodes provided with the first type of resource parameters.
S303: and when the node serial number of the current NUMA node is the same as the node serial number of any NUMA node corresponding to the first type of resource parameters, creating a virtual machine on the current NUMA node.
Here, if the node sequence number of the current NUMA node is the same as the node sequence number of any NUMA node corresponding to the first type of resource parameter, it may be determined that the resource parameter set by the current NUMA node is the first type of resource parameter, that is, a virtual machine is created on the current NUMA node. In practical application, a user can set a resource parameter of at least one NUMA node in a server to a first type of resource parameter according to an actual requirement, and then, when judging whether a current NUMA node is set to the first type of resource parameter, compare a node sequence number of the current NUMA node with a node sequence number of a NUMA node corresponding to the first type of resource parameter. In practical applications, after a virtual machine is created on a NUMA node corresponding to one of the first type of resource parameters, when a current NUMA node sequence number that is performed later is compared with a node sequence number of a NUMA node corresponding to the first type of resource parameter, a NUMA node that has already created the virtual machine may not be included. For example, the node numbers of the NUMA nodes corresponding to the first type of resource parameter are 1 and 3, respectively. And obtaining that the node sequence number of the current NUMA node is 1, and determining that the node sequence number 1 of the current NUMA node is in the node sequence number of the NUMA node corresponding to the first type of resource parameter through comparison, so that it can be determined that a virtual machine is created on the NUMA node with the node sequence number of 1. After resource allocation is completed, the node serial number of the next NUMA node, that is, 2, is obtained, so when the node serial number of the current NUMA node is compared with the node serial number of the NUMA node corresponding to the first type of resource parameter, since the NUMA node having the node serial number of 1 has already created the virtual machine, when the comparison is performed, it is only necessary to determine whether the node serial number 2 of the current NUMA node is the same as the node serial number 3, and it is not necessary to determine the node serial number 1 again.
In the above embodiment, by obtaining the node serial number of the current NUMA node, comparing the node serial number of the current NUMA node with the node serial numbers of all NUMA nodes whose resource parameters are the first type of resource parameters, and when the node serial number of the current NUMA node is the same as the node serial number of any NUMA node whose resource parameters are the first type of resource parameters, performing resource allocation on the virtual machine corresponding to the current NUMA node according to the resource parameters corresponding to the current NUMA node, the NUMA node that needs to perform resource allocation can be quickly determined, so that resource allocation can be performed on the virtual machine of the specific NUMA node, and the utilization efficiency of resources is improved.
In an embodiment, as shown in fig. 4, creating a virtual machine based on the at least two NUMA nodes and allocating resources for the virtual machine according to the corresponding resource parameters includes:
s401: and traversing all NUMA nodes in the server to obtain the total node amount of the NUMA nodes in the server.
Here, the total node amount of the NUMA nodes in the server refers to the number of nodes of the NUMA nodes in the server, and can be obtained by performing a preliminary search on all NUMA nodes in the server.
S402: when the node sequence numbers of all the NUMA nodes simultaneously meet all the following conditions, according to the corresponding resource parameters, creating a virtual machine based on the at least two NUMA nodes and performing resource allocation for the virtual machine:
the node serial numbers of all NUMA nodes are continuous;
and the total node sequence number of all NUMA nodes is equal to the total node number.
After the total number of nodes of the NUMA nodes in all the servers is obtained, whether the node numbers of the NUMA nodes in which the resource parameters are set in the servers are continuous is judged by acquiring the node numbers of the NUMA nodes in which the resource parameters are set in the servers, and when the node numbers of the NUMA nodes in which the resource parameters are set in the servers are discontinuous, it is indicated that the NUMA nodes exist in the servers and the resource parameters are not set. And whether the total node number of the NUMA nodes with the resource parameters set in the server is equal to the total node number of all the NUMA nodes in the server needs to be judged, so that each NUMA node in the server is ensured to set the resource parameters. When the node sequence numbers of the NUMA nodes in the server, which are subjected to the resource parameter setting, are continuous and the total node sequence numbers are equal to the total node numbers of all the NUMA nodes in the server, a virtual machine may be created on the corresponding NUMA node according to the resource parameter set by the NUMA node and resource allocation to the virtual machine may be completed. In practical application, an existing code framework sequentially creates virtual machines for NUMA nodes according to node serial numbers of the NUMA nodes and completes resource allocation to the created virtual machines, and does not support creation of virtual machines for NUMA nodes with discontinuous node serial numbers and completion of resource allocation to the created virtual machines. In order to create a virtual machine for a specified NUMA node and complete resource allocation of the virtual machine while being compatible with an existing code framework, it is necessary to set resource parameters for each NUMA node, specifically, set resource parameters of a NUMA node that needs to create a virtual machine and complete resource allocation as a first type of resource parameters, and set resource parameters of a NUMA node that does not support creation of a virtual machine and cannot complete resource allocation for the virtual machine as a second type of resource parameters.
In the above embodiment, the total number of nodes of the NUMA nodes in the server is obtained by traversing all the NUMA nodes in the server, and when it is determined that the node numbers of all the NUMA nodes are consecutive and the total number of the node numbers of all the NUMA nodes is equal to the total number of nodes, a virtual machine is created based on the NUMA nodes and resource allocation is performed for the virtual machine according to the corresponding resource parameters, so that the resource allocation of the virtual machine created on the specified NUMA node is completed while the existing code framework is compatible, and the use efficiency of the resource is improved.
In an embodiment, when creating and allocating resources for a virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters, the method further comprises:
generating first prompt information under the condition that empty parameter values exist in all the first type of resource parameters; the first prompt information represents that the resource parameter setting fails.
Here, only if the first type of resource parameter is set with a corresponding parameter can the virtual machine be created on the NUMA node on which the first type of resource parameter is set on the existing code framework, and resource allocation is performed for the created virtual machine. And when the resource parameter of the NUMA node is the first type of resource parameter, indicating that the corresponding NUMA node supports the creation of the virtual machine. When all the first type resource parameters have empty parameter values, that is, when the processor parameters and the memory parameters have empty parameter values, the corresponding NUMA nodes cannot create corresponding virtual machines and cannot complete resource allocation. When the empty parameter values exist in all the first type of resource parameters and the codes for setting the resource parameters are compiled, an error report is generated, that is, a first prompt message is generated to remind that the resource parameters are set to be in error, and the setting of the resource parameters needs to be modified to be compatible with the existing code framework.
In the above embodiment, by generating the first prompt information indicating that the resource parameter setting fails when the empty parameter value exists in the first type of resource parameter, the method and the device can be compatible with the existing code framework, ensure the integrity of the code logic of the resource setting, ensure the successful completion of the resource allocation to the virtual machine on the NUMA node, and improve the use efficiency of the resource.
In an embodiment, the resource parameters include processor parameters; the creating a virtual machine based on the at least two NUMA nodes and performing resource allocation for the virtual machine according to the corresponding resource parameters includes:
and under the condition that the processor parameters in the first type of resource parameters are not null parameter values, creating a virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters and performing resource allocation on the virtual machine.
After the resource parameters are set for the NUMA nodes in the server, if the processor parameters in the resource parameters belonging to the first type are not null parameter values, the virtual machines are created on the corresponding NUMA nodes according to the resource parameters set by the NUMA nodes, and the resources of the created virtual machines are allocated. The fact that the processor parameters in the first type of resource parameters are not null parameter values means that specific sequences are set on the processor parameters, and the number of processors allocated to the corresponding virtual machines is determined through the set sequences. In practical application, it may also occur that the resource parameter of the NUMA node belongs to a first type of resource parameter, and when the processor parameter is not a null parameter value, but the memory parameter is 0, the virtual machine is created on the NUMA node, and after the resource allocation is completed for the virtual machine, because the virtual machine fails to allocate the memory resource, when the virtual machine operates, the virtual machine may satisfy the memory resource required by the virtual machine during operation by acquiring the idle memory resources on other NUMA nodes. Automatic allocation may be performed in the event that a processor parameter of the first type of resource parameter is empty. Specifically, the processor resources and the memory resources provided by the server may be acquired, and the processor resources and the memory resources are evenly distributed to the corresponding NUMA nodes.
In the above embodiment, when the processor parameters in the first type of resource parameters are not null parameter values, the virtual machine is created based on the at least two NUMA nodes and resource allocation is performed on the virtual machine according to the corresponding resource parameters, so that it can be ensured that the virtual machine created in the NUMA nodes can be allocated to corresponding processor resources, the virtual machine can operate normally, and the use efficiency of the resources is improved.
In one embodiment, as shown in FIG. 5, when creating and allocating a virtual machine for a virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters, the method comprises:
s501: a virtual machine is created on a NUMA node corresponding to the first type of resource parameter.
Here, the characterization of the first type of resource parameter can create a virtual machine on the NUMA node, and thus, acquiring a NUMA node to which the resource parameter is set as the first type of resource parameter corresponds, and creating a virtual machine on the corresponding NUMA node.
S502: for a first NUMA node of which a virtual machine is created, allocating processor resources and memory resources which belong to the first NUMA node to the corresponding first virtual machine; and the first NUMA node is a NUMA node of which both the processor parameter and the memory parameter are effective parameters.
Here, the first NUMA node is a NUMA node in which both the processor parameter and the memory parameter are valid parameters, and when both the processor parameter and the memory parameter are valid parameters, the processor resource is allocated to the virtual machine created by the first NUMA node according to the processor parameter, and the memory resource is allocated to the virtual machine created by the first NUMA node according to the memory parameter. The valid parameter of the processor parameter may be a sequence representing the number of virtual machines, and the valid parameter of the memory parameter may be a specific size representing the amount of memory available for allocation to the virtual machines. For example, when the processor parameter of the NUMA node having the node sequence number 0 is set to 0, 1 sequence and the memory parameter is set to 2048, both the processor parameter and the memory parameter belong to valid parameters, and the corresponding NUMA node having the node sequence number 0 is the first node. Two virtual machines are allocated at a NUMA node with a node number of 0, and the size of memory capacity allocatable to the virtual machines is provided at 2048.
S503: for a second NUMA node where a virtual machine is created, allocating processor resources belonging to the second NUMA node to the corresponding second virtual machine, and allocating memory resources belonging to the first NUMA node to the second virtual machine.
Here, the resource parameter of the second NUMA node is a first type of resource parameter, the processor parameter is a valid parameter, and the memory parameter is a NUMA node of an invalid parameter, where the memory parameter is an invalid parameter indicating that the virtual machine cannot allocate memory resources when allocating resources to the virtual machine. When resource allocation is performed on the virtual machine on the second NUMA node according to the processor parameter and the memory parameter, the virtual machine on the second NUMA node can be allocated to the corresponding processor resource, and the virtual machine on the second NUMA node cannot be allocated to the memory resource because the memory parameter is an invalid parameter. Because the virtual machine needs certain processor resources and memory resources to work normally, on this basis, the memory resources can be allocated to the virtual machine on the second NUMA node according to the memory parameters of the first NUMA node. For example, if the processor parameter of the first NUMA node is 0, 1, the memory parameter is 2048, the processor parameter of the second NUMA node is 0, 1, and the memory parameter is 0, then when resource allocation is performed on the virtual machine on the second NUMA node, two virtual machines can be created on the second NUMA node, but the memory resource available for allocation to the virtual machine is 0, at this time, the memory resource can be allocated to the virtual machine on the second NUMA node according to the memory parameter of the first NUMA node, and finally, two virtual machines can be created on the second NUMA node, and the memory capacity available for allocation to the virtual machines is 2048, so that the virtual machine on the second NUMA node can operate normally. As shown in fig. 6, fig. 6 is a flowchart illustrating resource allocation performed in a NUMA node under a NUMA architecture, where a Memory in the flowchart represents a Memory, a CPU represents a processor, and each processor corresponds to one Memory resource, so as to improve the operating speed of a virtual machine. For a NUMA node, the memory access time depends on the memory location, when the memory accessed by the processor is the memory in the node, the access speed is high, the memory access time is short, and when the memory accessed by the processor is the memory of other nodes, the access speed is slow, and the memory access time is increased. When the CPU 0 accesses the Memory0, the CPU 0 directly accesses the Memory0, so the access speed is high, and when the CPU 0 accesses the Memory1, the CPU 1 first obtains the content of the Memory1, and then transmits the content of the Memory1 to the CPU 0 through the CPU 1, so the access speed is low.
In the above embodiment, by creating a virtual machine on a NUMA node corresponding to a first type of resource, allocating a processor resource and a memory resource belonging to a first NUMA node to which a processor parameter and a memory parameter are both valid parameters, allocating a processor resource and a memory resource belonging to a second NUMA node, and allocating a memory resource belonging to the first NUMA node, it is possible to complete resource allocation under different settings of resource parameters, so that the virtual machine created on the NUMA node can obtain sufficient resources to operate, and the resource utilization efficiency is improved.
The present invention also provides an application embodiment, as shown in fig. 7, fig. 7 shows a specific algorithm flowchart of resource allocation.
S701: and acquiring the total number of NUMA nodes.
S702: and judging whether the total number of the NUMA nodes is greater than 0.
S703: and taking i as 0. Here, i is the node number of the NUMA node of the acquired server, and i ═ 0 represents the first NUMA node in the acquisition server.
S704: and judging whether i is smaller than the NUMA node total amount. When i is less than the NUMA node total amount, go to S7041, and when i is greater than the NUMA node total amount, go to S705. Here, by determining the size of the total of i and NUMA nodes, it is possible to know whether or not to process all NUMA nodes in the server.
S7041: and acquiring the processor parameters of the NUMA node with the node serial number i.
S7042: the next node sequence number i is obtained and the process goes to S704.
S705: the CPU sequence for all NUMA nodes in the server is determined.
S706: and j is taken to be 0. Here, j is the acquired node number of the NUMA node of the server, and is distinguished from i.
S707: and judging whether j is smaller than the NUMA node total amount. When j is less than the NUMA node total amount, go to S7071, and when j is greater than the NUMA node total amount, go to S708.
S7071: and acquiring the memory parameters of the NUMA node of the node serial number j.
S7072: the next node number j is obtained and the process goes to S707.
S708: and determining the size of the memory capacity of all NUMA nodes in the server.
S709: and judging whether the CPU sequence is a null value, if so, turning to S710, and if not, turning to S711.
S710: and according to the total amount of the processors and the total amount of the memories of the server, evenly distributing resources corresponding to the NUMA nodes.
S711: and according to the processor parameters and the memory parameters, performing resource allocation on the virtual machine corresponding to the NUMA node.
In order to implement the method for resource allocation according to the embodiment of the present invention, an embodiment of the present invention further provides a resource allocation apparatus, as shown in fig. 8, where the resource allocation apparatus includes:
a first setting unit 801, configured to set a resource parameter of at least one NUMA node of at least two non-uniform memory access NUMA nodes in a server to a first type of resource parameter; wherein the first type of resource parameter characterization can create a virtual machine on a corresponding NUMA node;
a second setting unit 802, configured to set the resource parameters of the NUMA nodes other than the at least one NUMA node in the server to a second type of resource parameters; the resource parameters of the second type represent that the corresponding NUMA node does not support the creation of a virtual machine;
an allocating unit 803, configured to create a virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters and perform resource allocation for the virtual machine.
In an embodiment, the resource parameters include a processor parameter and a memory parameter, and the allocating unit creates a virtual machine based on the at least two NUMA nodes and allocates resources to the virtual machine according to the corresponding resource parameters, further including:
acquiring processor parameters of each NUMA node in the at least two NUMA nodes;
determining NUMA nodes of processor parameters conforming to the first type of resource parameters, and acquiring node sequence numbers of the NUMA nodes of the processor parameters conforming to the first type of resource parameters;
determining the memory parameters of the NUMA node corresponding to the acquired node serial number according to the acquired node serial number;
and creating a virtual machine and performing resource allocation for the virtual machine according to the processor parameter and the memory parameter of the NUMA node corresponding to the acquired node serial number.
In an embodiment, when the allocation unit creates a virtual machine based on the at least two NUMA nodes and allocates resources to the virtual machine according to the corresponding resource parameters, the method includes:
acquiring a node serial number of a current NUMA node; each NUMA node in the at least two NUMA nodes corresponds to a node sequence number;
when the node serial number of the current NUMA node is different from the node serial numbers of all NUMA nodes corresponding to the first type of resource parameters, skipping over the current NUMA node;
and when the node serial number of the current NUMA node is the same as the node serial number of any NUMA node corresponding to the first type of resource parameters, creating a virtual machine on the current NUMA node.
In an embodiment, the allocating unit creates a virtual machine based on the at least two NUMA nodes and allocates resources to the virtual machine according to the corresponding resource parameters, including:
traversing all NUMA nodes in the server to obtain the total node amount of the NUMA nodes in the server;
when the node sequence numbers of all the NUMA nodes simultaneously meet all the following conditions, according to the corresponding resource parameters, creating a virtual machine based on the at least two NUMA nodes and performing resource allocation for the virtual machine:
the node serial numbers of all NUMA nodes are continuous;
and the total node sequence number of all NUMA nodes is equal to the total node number.
In an embodiment, when the allocation unit creates a virtual machine based on the at least two NUMA nodes and allocates resources to the virtual machine according to the corresponding resource parameters, the method further includes:
generating first prompt information under the condition that empty parameter values exist in all the first type of resource parameters; the first prompt information represents that the resource parameter setting fails.
In an embodiment, the resource parameters include processor parameters, and the allocating unit creates and allocates resources for the virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters includes:
and under the condition that the processor parameters in the first type of resource parameters are not null parameter values, creating a virtual machine based on the at least two NUMA nodes according to the corresponding resource parameters and performing resource allocation on the virtual machine.
In an embodiment, when the allocating unit creates a virtual machine based on the at least two NUMA nodes and allocates resources to the virtual machine according to the corresponding resource parameters, the apparatus further includes:
creating a virtual machine on a NUMA node corresponding to the first type of resource parameter;
for a first NUMA node of which a virtual machine is created, allocating processor resources and memory resources which belong to the first NUMA node to the corresponding first virtual machine; the first NUMA node is an NUMA node of which both processor parameters and memory parameters are effective parameters;
for a second NUMA node where a virtual machine is created, allocating processor resources belonging to the second NUMA node to the corresponding second virtual machine, and allocating memory resources belonging to the first NUMA node to the second virtual machine.
In practical applications, the first setting unit 801, the second setting unit 802, and the allocating unit 803 may be implemented by a processor in the resource allocating apparatus. Of course, the processor needs to run the program stored in the memory to realize the functions of the above-described program modules.
It should be noted that, when the resource allocation apparatus provided in the embodiment of fig. 8 performs resource allocation, the division of each program module is merely used as an example, and in practical applications, the processing allocation may be completed by different program modules according to needs, that is, the internal structure of the apparatus may be divided into different program modules to complete all or part of the processing described above. In addition, the resource allocation apparatus and the resource allocation method provided in the foregoing embodiments belong to the same concept, and specific implementation processes thereof are described in the method embodiments for details, which are not described herein again.
Based on the hardware implementation of the program module, and in order to implement the method according to the embodiment of the present invention, an embodiment of the present invention further provides an electronic device, fig. 9 is a schematic diagram of a hardware composition structure of the electronic device according to the embodiment of the present invention, and as shown in fig. 9, the electronic device includes:
a communication interface 1 capable of information interaction with other devices such as network devices and the like;
and the processor 2 is connected with the communication interface 1 to realize information interaction with other equipment, and is used for executing the resource allocation method provided by one or more technical schemes when running a computer program. And the computer program is stored on the memory 3.
In practice, of course, the various components in the electronic device are coupled together by the bus system 4. It will be appreciated that the bus system 4 is used to enable connection communication between these components. The bus system 4 comprises, in addition to a data bus, a power bus, a control bus and a status signal bus. For the sake of clarity, however, the various buses are labeled as bus system 4 in fig. 9.
The memory 3 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program for operating on an electronic device. It will be appreciated that the memory 3 may be either volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. Among them, the nonvolatile Memory may be a Read Only Memory (ROM), a Programmable Read Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a magnetic random access Memory (FRAM), a Flash Memory (Flash Memory), a magnetic surface Memory, an optical disk, or a Compact Disc Read-Only Memory (CD-ROM); the magnetic surface storage may be disk storage or tape storage. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of illustration and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), Enhanced Synchronous Dynamic Random Access Memory (Enhanced Synchronous Dynamic Random Access Memory), Synchronous link Dynamic Random Access Memory (DRAM, Synchronous Dynamic Random Access Memory), Direct Memory (DRmb Random Access Memory). The memory 3 described in the embodiments of the present invention is intended to comprise, without being limited to, these and any other suitable types of memory.
The method disclosed by the above embodiment of the present invention can be applied to the processor 2, or implemented by the processor 2. The processor 2 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 2. The processor 2 described above may be a general purpose processor, a DSP, or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor 2 may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present invention. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed by the embodiment of the invention can be directly implemented by a hardware decoding processor, or can be implemented by combining hardware and software modules in the decoding processor. The software modules may be located in a storage medium located in the memory 3, and the processor 2 reads the program in the memory 3 and in combination with its hardware performs the steps of the aforementioned method.
When the processor 2 executes the program, the corresponding processes in the methods according to the embodiments of the present invention are realized, and for brevity, are not described herein again.
In an exemplary embodiment, the present invention further provides a storage medium, i.e. a computer storage medium, in particular a computer readable storage medium, for example comprising a memory 3 storing a computer program, which is executable by a processor 2 to perform the steps of the aforementioned method. The computer readable storage medium may be Memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface Memory, optical disk, or CD-ROM.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, terminal and method can be implemented in other ways. The above-described device embodiments are only illustrative, for example, the division of the unit is only one logical function division, and there may be other division ways in actual implementation, such as: multiple units or components may be combined, or may be integrated into another system, or some features may be omitted, or not implemented. In addition, the coupling, direct coupling or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between the devices or units may be electrical, mechanical or other forms.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed on a plurality of network units; some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, all the functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately regarded as one unit, or two or more units may be integrated into one unit; the integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
Those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: a removable storage device, a ROM, a RAM, a magnetic or optical disk, or various other media that can store program code.
Alternatively, the integrated unit of the present invention may be stored in a computer-readable storage medium if it is implemented in the form of a software functional module and sold or used as a separate product. Based on such understanding, the technical solutions of the embodiments of the present invention may be essentially implemented or a part contributing to the prior art may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling an electronic device (which may be a personal computer, a server, or a network device) to execute all or part of the methods described in the embodiments of the present invention. And the aforementioned storage medium includes: a removable storage device, a ROM, a RAM, a magnetic or optical disk, or various other media that can store program code.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.