Central processing unit core distribution method and device, equipment, medium and program product
By creating first and second control groups on the host machine to manage different types of virtual machines respectively, the problem of CPU core resource contention between virtual machines is solved, thereby improving computing performance and resource utilization efficiency.
Patent Information
- Application Number
- CN202511232153.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2025-10-21
AI Technical Summary
In existing technologies, the problem of CPU core resource contention between virtual machines has not been effectively resolved, affecting the computing performance of virtual machines in handling critical workloads.
Create a first control group and a second control group on the host machine to manage virtual machines that require exclusive CPU cores and those that do not. Determine the virtual machine type through resource attribute parameters, and allocate CPU cores to virtual machines that require exclusive CPU cores under the first control group, marking them as dedicated to avoid resource contention.
This effectively avoids competition for central processing unit core resources between different virtual machines, improving the computing performance and resource utilization efficiency of virtual machines when handling critical workloads.
Smart Images

Figure CN120821577A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic computers, and in particular to a method, apparatus, device, medium, and program product for allocating central processing unit cores. Background Art
[0002] As more and more applications and businesses migrate to the cloud, the load on cloud servers, which often utilize virtualization technology, is also increasing. Therefore, properly allocating CPU core resources is crucial to ensuring the computing performance of virtual machines hosting critical workloads.
[0003] Currently, some technologies use binding mechanisms to address the random scheduling of virtual machines across different CPU cores, but the issue of CPU core contention between different VMs remains unresolved. Therefore, a technical solution is urgently needed to address CPU core resource contention between different VMs, ensuring the performance of VMs handling critical workloads. Summary of the Invention
[0004] The present application provides a central processing unit (CPU) core allocation method, a CPU core allocation device, an electronic device, a computer-readable storage medium, and a computer program product to at least solve the problem of competition for CPU core resources between different virtual machines in the related art.
[0005] This application provides a method for allocating CPU cores, including:
[0006] Creating a first control group and a second control group on the host, the first control group being used to manage the allocation of central processing unit cores to first-type virtual machines, and the second control group being used to manage the allocation of central processing unit cores to second-type virtual machines. The first-type virtual machines are virtual machines that require exclusive use of central processing unit cores, and the second-type virtual machines are virtual machines that do not require exclusive use of central processing unit cores. The second control group records a list of central processing unit cores shared by the second-type virtual machines.
[0007] When a virtual machine is created, obtain resource attribute parameters of the virtual machine;
[0008] If the resource attribute parameter indicates that the virtual machine is a first type virtual machine, a first subdirectory corresponding to the virtual machine is created under the first control group, a central processing unit core is allocated to the virtual machine based on the number of central processing unit cores allowed to be exclusively occupied in the host as a constraint, and the allocated central processing unit core and the threads of the virtual machine are recorded in the first subdirectory;
[0009] The CPU cores recorded in the first subdirectory are deleted from the CPU core list of the second control group, and the CPU cores in the first subdirectory are marked as being in a dedicated state.
[0010] The present application also provides a central processing unit core allocation device, comprising:
[0011] a control group creation module, configured to create a first control group and a second control group in a host, wherein the first control group is configured to manage the allocation of central processing unit cores to first-type virtual machines, and the second control group is configured to manage the allocation of central processing unit cores to second-type virtual machines. The first-type virtual machines are virtual machines that require exclusive use of central processing unit cores, and the second-type virtual machines are virtual machines that do not require exclusive use of central processing unit cores. The second control group records a list of central processing unit cores shared by the second-type virtual machines;
[0012] A parameter acquisition module is used to obtain resource attribute parameters of a virtual machine when the virtual machine is created;
[0013] a core allocation module configured to, if the resource attribute parameter indicates that the virtual machine is a first type virtual machine, create a first subdirectory corresponding to the virtual machine under the first control group, allocate a central processing unit core to the virtual machine based on the number of central processing unit cores allowed to be exclusively occupied in the host as a constraint, and record the allocated central processing unit core and threads of the virtual machine in the first subdirectory;
[0014] The core marking module is used to delete the CPU cores recorded in the first subdirectory from the CPU core list of the second control group and mark the CPU cores in the first subdirectory as dedicated.
[0015] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned central processing unit core allocation methods when executing the computer program.
[0016] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned central processing unit core allocation methods are implemented.
[0017] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned central processing unit core allocation methods when executed by a processor.
[0018] In the technical solutions of some embodiments of the present application, a first control group and a second control group are created in the host, which are used to manage the first virtual machine that needs to exclusively use the central processing unit core and the second virtual machine that does not need to exclusively use the central processing unit core. When the virtual machine starts running, it is determined whether the virtual machine belongs to the virtual machine that exclusively uses the central processing unit core based on the resource attribute parameters of the virtual machine. If the virtual machine belongs to the above-mentioned first virtual machine, a first subdirectory is created under the first control group, and a central processing unit core is allocated to the virtual machine, and the allocated central processing unit core is recorded in the first subdirectory. Afterwards, the above-mentioned allocated central processing unit core is deleted from the list of central processing unit cores in the second control group, and at the same time, the allocated central processing unit core is marked as a dedicated state. In this way, by managing the virtual machines through two control groups, the use of the central processing unit core by different types of virtual machines can be distinguished, thereby avoiding competition for central processing unit core resources between different virtual machines. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0020] Figure 1 A flowchart of a method for allocating CPU cores according to an embodiment of the present invention;
[0021] Figure 2 A flowchart of another CPU core allocation method provided in an embodiment of the present application;
[0022] Figure 3 A schematic diagram of a module of a central processing unit core allocation device provided in some embodiments of the present application;
[0023] Figure 4 A schematic diagram of a module of an electronic device provided for some embodiments of the present application. DETAILED DESCRIPTION
[0024] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0025] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements but also other elements not explicitly listed, or also includes elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or precedence.
[0026] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0027] With the development of virtualization technology, ensuring the computing performance of virtual machines (VMs) hosting important workloads is crucial. The performance of these VMs directly impacts the stability of workload operations and the timeliness of workload processing. There are three main approaches to improving the computing performance of VMs, but these three technologies have the following problems:
[0028] 1) CPU (Central Processing Unit) binding. CPU binding technology is to restrict processes or threads to run in one or more CPU cores. For process binding, when a process is bound to a specific CPU core, all threads of the process can only run on that specific CPU core; for thread binding, each thread in the process can be bound to a different CPU core to run. This method is usually used in virtualization technology. Although CPU binding can reduce the context switching overhead caused by switching threads between different CPU cores, due to binding, the operating system cannot perform load balancing scheduling. When the load on a CPU core is too high, part of the load cannot be scheduled to other relatively idle CPU cores, resulting in reduced CPU utilization.
[0029] 2) NUMA (Non-Uniform Memory Access) binding. NUMA binding improves virtual machine performance by binding processes or threads to specific NUMA nodes, reducing memory access latency. However, similar to CPU binding, when a NUMA node is overloaded, load balancing cannot be performed, resulting in uneven resource utilization.
[0030] 3) Physically isolated CPUs. Physically isolated CPUs use the operating system and virtualization technology to logically dedicate certain CPU cores to specific virtual machines. While this prevents interference from other services, since these isolated CPU cores can only serve specific virtual machines, executing other services requires a host reboot, limiting the ability to execute dynamic services.
[0031] In view of this, the present application provides a method for allocating CPU cores to address the aforementioned issues. This method can be applied to virtual machines or electronic devices using virtualization technology. These electronic devices may include, but are not limited to, desktop computers, tablet computers, laptop computers, and servers.
[0032] See also Figure 1 , Figure 1 A flowchart of a method for allocating CPU cores provided in some embodiments of the present application is shown in FIG. Figure 1 As shown, the CPU core allocation method includes the following steps:
[0033] In step S101, a first control group and a second control group are created in the host. The first control group is used to manage the allocation of central processing unit cores of first-type virtual machines, and the second control group is used to manage the allocation of central processing unit cores of second-type virtual machines. The first-type virtual machine refers to a virtual machine that requires exclusive use of a central processing unit core, and the second-type virtual machine refers to a virtual machine that does not require exclusive use of a central processing unit core. The second control group records a list of central processing unit cores shared by the second-type virtual machines.
[0034] Specifically, a first control group and a second control group are created on the host. The first control group manages CPU core allocation for first-type virtual machines that require exclusive CPU cores, while the second control group manages CPU core allocation for second-type virtual machines that do not require exclusive CPU cores. Furthermore, the second control group contains a list of CPU cores shared by the second-type virtual machines.
[0035] In this embodiment, the cpuset subsystem of the Cgroups (Control Groups) feature of the Linux system can be enabled to create the first and second control groups. The first control group can be named machineslice (used to manage general or ordinary virtual machines), and the second control group can be named reservedvm (used to manage virtual machines that require dedicated computing power).
[0036] Step S102: When a virtual machine is created, resource attribute parameters of the virtual machine are obtained.
[0037] Specifically, when a virtual machine that has been created exists in the electronic device executing the method of the present application, resource attribute parameters of the virtual machine are obtained, and the resource attribute parameters are used to indicate whether the virtual machine needs to exclusively occupy the CPU core.
[0038] In this embodiment, this resource attribute parameter controls whether a virtual machine requires dedicated CPU computing power. Generally, this attribute is disabled by default, meaning that all virtual machines are placed in the machine slice control group and share the CPU core resources within the machine slice. When a virtual machine needs to perform a computationally demanding task, this resource attribute parameter is enabled and the virtual machine is migrated to the reservedvm control group.
[0039] In step S103, if the resource attribute parameters characterize the virtual machine as a first type of virtual machine, a first subdirectory corresponding to the virtual machine is created under the first control group, and a central processing unit core is allocated to the virtual machine based on the number of central processing unit cores allowed to be exclusively occupied in the host as a constraint, and the allocated central processing unit core and the virtual machine's threads are recorded in the first subdirectory.
[0040] Specifically, when the resource attribute parameters indicate that the virtual machine is a first-type virtual machine requiring exclusive CPU core use, a first subdirectory corresponding to the virtual machine is created under the first control group. Furthermore, based on the maximum available ratio of dedicated CPUs preset in the host and the number of CPU cores in the host, the number of CPU cores currently running and exclusively used on the host is determined. Then, using the aforementioned number of CPU cores allowed to be exclusively used as a constraint, CPU cores are allocated to the virtual machine, and the allocated CPU cores and threads of the virtual machine are recorded in the first subdirectory.
[0041] In this embodiment, each virtual machine can have a subdirectory located under the top-level machineslice and reservedvm control groups. The available CPUs in the second subdirectory under the machineslice control group can be inherited from the available CPU cores in the machineslice control group, and these cores serve as shared CPU cores for the second type of virtual machines. The available CPUs in the first subdirectory under the reservedvm control group are set during the aforementioned allocation process and are not inherited from the available CPU cores in the reservedvm control group.
[0042] Step S104: deleting the CPU cores recorded in the first subdirectory from the CPU core list of the second control group, and marking the CPU cores in the first subdirectory as being in a dedicated state.
[0043] Specifically, after the first subdirectory is created and the corresponding CPU cores are allocated under the first control group, the CPU cores recorded in the first subdirectory need to be deleted from the CPU core list of the second control group, and these allocated CPU cores need to be marked as dedicated.
[0044] In this embodiment, for the CPU cores marked as dedicated in the above manner, only the virtual machines located in the first subdirectory and the threads that have bound the virtual CPUs of the virtual machines to the dedicated CPU cores can use these dedicated cores. The remaining unbound threads or virtual machines located in other control groups cannot preempt or use these CPU core resources that have been marked as dedicated.
[0045] The central processing unit (CPU) core allocation method provided in this embodiment creates a first control group and a second control group in a host, respectively used to manage a first virtual machine that requires exclusive CPU core use and a second virtual machine that does not. When a virtual machine begins running, the resource attribute parameters of the virtual machine are used to determine whether the virtual machine is a virtual machine that exclusively uses a CPU core. If the virtual machine is the first virtual machine, the first control group creates a first subdirectory, allocates a CPU core to the virtual machine, and records the allocated CPU core in the first subdirectory. The allocated CPU core is then deleted from the CPU core list in the second control group and marked as dedicated. In this way, by managing virtual machines through two control groups, the use of CPU cores by different types of virtual machines can be differentiated. Second-type virtual machines in the second control group cannot use dedicated CPU cores for computing, and other first-type virtual machines in the first control group cannot use dedicated CPU cores that have already been bound, thereby avoiding competition for CPU core resources between different virtual machines.
[0046] See also Figure 2 In some embodiments, the CPU cores and memory in the host are divided into multiple access nodes, each access node includes at least one CPU core and at least one memory connected to the CPU core; the number of CPU cores allowed to be exclusively used in the host is determined based on the following steps S201 to S204.
[0047] Step S201, obtaining the maximum proportion of dedicated CPU cores.
[0048] Specifically, the electronic device that executes the method of the present application obtains the maximum available ratio of the dedicated CPU in the host pre-set by the user, which can usually be set in the range of 10% to 80%. For example, the host has a total of 60 CPU cores, and the maximum available ratio pre-set by the user is 80%, then the maximum available number of dedicated CPU cores is 48. The remaining 12 CPU cores are shared by other non-dedicated virtual machines or objects. It should be noted that not all CPU cores in the host can be set as dedicated. At least a part of the CPU cores must be reserved for basic services, interrupt programs, clock services, hyper-convergence services, monitoring services and other functions of the basic operating system on the host, otherwise it will affect the normal operation of the host's own system.
[0049] Step S202 : determining a first available number of dedicated CPU cores based on the number of CPU cores of the host and the maximum ratio.
[0050] Specifically, after obtaining the maximum proportion of preset dedicated CPU cores, the first available number of current dedicated CPU cores is calculated based on the number of important processor cores of the current host. The first available number is also the maximum number of dedicated CPU cores allowed to be allocated to the current host.
[0051] Step S203 : determining a second available number of dedicated CPU cores based on the total number of CPU cores of the host, the number of CPU cores to be reserved by the host, the number of CPU cores exclusively used by virtual machines in the host, and the access node.
[0052] Specifically, after confirming the first available number (i.e., the maximum number allowed to be allocated as dedicated CPU cores), the number of dedicated CPU cores that can be allocated subsequently (i.e., the second available number) is determined based on the number of CPU cores reserved in the current host and the number of CPU cores exclusively occupied by virtual machines.
[0053] In this embodiment, since not all CPU cores in the host are used as dedicated CPU cores, for example, CPU cores that have been allocated as dedicated CPU cores cannot be used because the same CPU core cannot be allocated twice; cores that have been bound to virtual CPUs used for virtual machines cannot be used because in this case the dedicated CPU runs multiple virtual machines at the same time, causing conflicts; in addition, virtual machine NUMA requires that the virtual machine CPU of the virtual machine must be bound to at least one CPU core on each NUMA node, so a CPU core needs to be reserved for each NUMA node. At the same time, this also shows that the CPU cores in the NUMA node cannot be completely allocated to virtual machines as dedicated CPU cores.
[0054] In this embodiment, if the number of CPU cores is zero, the core cannot run a virtual machine due to the particularity of this type of operating system.
[0055] Step S204: The minimum number between the first available number and the second available number is used as the number of CPU cores allowed to be exclusively used in the host.
[0056] Specifically, the first available number and the second available number are compared, and the smallest number is selected as the number of CPU cores allowed to be exclusively occupied in the current host.
[0057] In the above embodiment, the available number of dedicated CPU cores is adjusted by the preset maximum proportion and the actual resource allocation, ensuring that the dedicated CPU cores can reasonably allocate CPU resources without affecting the normal operation of the host itself, thereby improving the execution efficiency of the virtual machine using the dedicated CPU core to perform computing tasks, and can reduce the performance degradation caused by the competition for CPU resources when the virtual machine is running.
[0058] In some embodiments, the second control group includes a current-level directory, and the current-level directory records a list of central processing unit cores shared by the second type of virtual machines; the central processing unit core allocation method further includes:
[0059] If the resource attribute parameter indicates that the virtual machine is a second type virtual machine, creating a second subdirectory corresponding to the virtual machine under the second control group;
[0060] The second subdirectory is made to inherit the CPU core list recorded in the current directory, and the threads of the virtual machine are recorded in the second subdirectory, so that the virtual machine runs in one or more CPU cores in the CPU core list.
[0061] Specifically, since the resource attribute parameters are set to the closed state by default, when the resource attribute parameters are not changed, all virtual machines are second-type virtual machines. At the same time, the electronic device executing the method of the present application creates a second subdirectory corresponding to the second-type virtual machine in the second control group.
[0062] In this embodiment, the second control group's primary directory contains a list of CPU cores shared by the second type of virtual machines, while the CPU cores in the second subdirectory inherit the CPU core list from the second control group's primary directory. Thus, when a second type of virtual machine migrates a thread to the second subdirectory, its thread is scheduled to run on any core in the shared CPU core list.
[0063] In the above embodiment, the CPU core list of the second control group determines which type II virtual machines will run on one or more of the shared CPU cores through the directory structure inheritance mechanism. Thus, by using directory structure inheritance to manage type II virtual machines, flexible reuse and load balancing of shared CPU core resources are achieved.
[0064] In some embodiments, the second control group includes a current-level directory, and the current-level directory records a list of central processing unit cores shared by the second type of virtual machines; the central processing unit core allocation method further includes:
[0065] If the virtual machine changes from the first type virtual machine to the second type virtual machine, the CPU core recorded in the first subdirectory is re-added to the CPU core list recorded in the current level directory, and the dedicated status of the corresponding CPU core is canceled;
[0066] Create a third subdirectory corresponding to the virtual machine under the second control group, and make the third subdirectory inherit the central processing unit core list recorded in the current directory, and record the virtual machine's threads in the third subdirectory so that the virtual machine runs in one or more central processing unit cores in the central processing unit core list.
[0067] Specifically, when a virtual machine changes from the first type to the second type, the virtual machine does not have the need for an exclusive CPU core. Therefore, the electronic device that executes the method of the present application will re-add the dedicated CPU core originally assigned to the virtual machine to the current-level directory of the second control group, and cancel the dedicated status of the dedicated CPU core, restoring it to a shared state.
[0068] In this embodiment, when the dedicated CPU core supporting the virtual machine is changed to a shared state, a third subdirectory corresponding to the virtual machine is created in the second control group. This subdirectory inherits the CPU core list in the second control group's primary directory. The virtual machine's threads are then recorded in the third subdirectory and scheduled based on the CPU core list inherited by the third subdirectory.
[0069] In the above embodiment, when a virtual machine type changes, the dedicated CPU core originally used for the virtual machine is re-included in the shared CPU core list, and the threads of the virtual machine are migrated from the first control group to the second control group. In this way, when the virtual machine no longer needs to exclusively use the CPU core, the CPU core is not always in a dedicated state, which would waste CPU resources. This achieves dynamic scheduling and efficient utilization of CPU core resources.
[0070] In some embodiments, the triggering condition for the virtual machine to change from the first type of virtual machine to the second type of virtual machine includes any one of the following conditions:
[0071] The resource attribute parameters of the virtual machine are updated;
[0072] The virtual machine is abnormal.
[0073] Specifically, under normal circumstances, after a first-type virtual machine completes a task that requires exclusive CPU use, subsequent tasks of the virtual machine may no longer require exclusive CPU core use. In this case, by setting the resource attribute parameters of the virtual machine, the type of the virtual machine is changed from the first type to the second type, and its previously dedicated CPU core is released. However, if an exception occurs during the operation of the virtual machine (such as a virtual machine crash), it is necessary to capture the exception in a timely manner and release the dedicated CPU core occupied by the virtual machine to avoid wasting resources and degrading system performance.
[0074] In this embodiment, when the first type virtual machine has completed its own tasks and no longer needs to process other tasks, it can be shut down. In this case, when the shutdown signal of the virtual machine is detected, the dedicated CPU cores originally occupied by the virtual machine will be released and added back to the current level directory of the second control group.
[0075] In the above embodiment, when a change in resource attribute parameters, an abnormal event, or a shutdown signal is detected for a first-type virtual machine, the first-type virtual machine is changed to a second-type virtual machine, and the previously occupied dedicated CPU core is released. In this way, the dedicated CPU core can be released in a timely manner, thereby avoiding CPU resource waste caused by changes in virtual machine status.
[0076] In some embodiments, the second control group includes a current directory and at least one subdirectory, the current directory records a list of CPU cores shared by the second type virtual machines, the subdirectory corresponds one-to-one to at least one second type virtual machine, and the subdirectory inherits the list of CPU cores recorded in the current directory;
[0077] Deleting the CPU core recorded in the first subdirectory from the CPU core list of the second control group includes:
[0078] After deleting the CPU core recorded in the first subdirectory from the subdirectory, the CPU core recorded in the first subdirectory is deleted from the directory at this level.
[0079] Specifically, when one or more second-type virtual machines need to exclusively occupy a CPU core due to changes in resource attribute parameters, the second-type virtual machine will be upgraded to a first-type virtual machine. At this time, the CPU core of the virtual machine will become dedicated and recorded in the first subdirectory. At the same time, the CPU core information in the first subdirectory corresponding to the second control group needs to be removed from the current-level directory. Since the second-type virtual machine and the second subdirectory are in a one-to-one correspondence, when removing the CPU core information of the first subdirectory in the second control group, it is usually chosen to first delete the CPU core information recorded in the second subdirectory, and then delete the corresponding CPU core information from the current-level directory of the second control group.
[0080] In the above embodiment, the control group directory structure is processed using a depth-first traversal method to ensure that the inheritance relationships between directories at all levels remain consistent even when CPU core information changes due to changes in virtual machine types. This can also avoid resource conflicts and duplicate allocations during CPU resource adjustment, further improving CPU resource utilization.
[0081] In some embodiments, the CPU cores and memory in the host are divided into a plurality of access nodes, each access node including at least one CPU core and at least one memory connected to the CPU core;
[0082] Allocate CPU cores to virtual machines, including:
[0083] Sorting the multiple access nodes for the first time according to the memory size of each access node to obtain a first sorted list among the access nodes;
[0084] Sort the access nodes in the first sorted list for the second time according to the number of remaining CPU cores of each access node to obtain a second sorted list;
[0085] According to the second sorted list, a central processing unit core is allocated to the virtual machine.
[0086] Specifically, when allocating dedicated CPU cores to first-type virtual machines, factors including, but not limited to, the number of CPUs, NUMA scheduling, and available memory on NUMA nodes need to be considered. Based on these factors, a first sorting is performed based on the memory size of each access node, resulting in a first sorted list of access nodes. The access nodes in the first sorted list are then sorted a second time based on the number of CPU cores remaining on each access node, resulting in a second sorted list. Finally, dedicated CPU cores are allocated to the first-type virtual machines based on the second sorted list.
[0087] In this embodiment, the sorting can be performed according to the available memory in each NUMA, and then the sorting can be performed according to the size of the NUMA node. In addition, when performing the sorting, it is also necessary to combine the actual situation of the virtual machine. For example, if the virtual machine uses large page memory, then the first sorting needs to be performed according to the available large page memory, and then the number of virtual CPUs currently configured for the virtual machine is compared. If the number of CPU cores remaining on the NUMA node is greater than the number of virtual CPUs of the virtual machine, the CPU core on the first NUMA in the sorting result is allocated to the virtual machine in a sequential manner; if the number of virtual CPUs of the virtual machine is greater than the number of available CPU cores of all single NUMA nodes, the required CPU cores are allocated from each NUMA node in turn according to the sorting result of the NUMA node.
[0088] In the above embodiment, by reasonably sorting the access nodes, the allocated CPU cores can be made to come from nodes with sufficient memory resources and more remaining CPU resources as much as possible, thereby reducing the performance loss caused by cross-node access.
[0089] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0090] Corresponding to the central processing unit core allocation method, the present application also provides a central processing unit core allocation device. Figure 3 , which is a module diagram of a central processing unit core allocation device provided in some embodiments of the present application. Figure 3 In the embodiment, the central processing unit core allocation device includes:
[0091] A control group creation module 201 is configured to create a first control group and a second control group in a host, wherein the first control group is configured to manage the allocation of CPU cores to first-type virtual machines, and the second control group is configured to manage the allocation of CPU cores to second-type virtual machines. First-type virtual machines are virtual machines that require exclusive use of CPU cores, while second-type virtual machines are virtual machines that do not require exclusive use of CPU cores. The second control group contains a list of CPU cores shared by second-type virtual machines.
[0092] The parameter acquisition module 302 is used to obtain resource attribute parameters of the virtual machine when the virtual machine is created;
[0093] The core allocation module 303 is configured to, if the resource attribute parameter indicates that the virtual machine is a first type virtual machine, create a first subdirectory corresponding to the virtual machine under the first control group, allocate a central processing unit core to the virtual machine based on the number of central processing unit cores allowed to be exclusively used in the host as a constraint, and record the allocated central processing unit core and the threads of the virtual machine in the first subdirectory;
[0094] The core marking module 304 is configured to delete the CPU cores recorded in the first subdirectory from the CPU core list of the second control group, and mark the CPU cores in the first subdirectory as being in a dedicated state.
[0095] In some embodiments, the second control group includes a current-level directory, which records a list of CPU cores shared by the second-type virtual machines; the control group creation module 201 is used to:
[0096] If the resource attribute parameter indicates that the virtual machine is a second type virtual machine, creating a second subdirectory corresponding to the virtual machine under the second control group;
[0097] The second subdirectory is made to inherit the CPU core list recorded in the current directory, and the threads of the virtual machine are recorded in the second subdirectory, so that the virtual machine runs in one or more CPU cores in the CPU core list.
[0098] In some embodiments, the second control group includes a current-level directory, which records a list of CPU cores shared by the second-type virtual machines; the control group creation module 201 is further configured to:
[0099] If the virtual machine changes from the first type virtual machine to the second type virtual machine, the CPU core recorded in the first subdirectory is re-added to the CPU core list recorded in the current level directory, and the dedicated status of the corresponding CPU core is canceled;
[0100] Create a third subdirectory corresponding to the virtual machine under the second control group, and make the third subdirectory inherit the central processing unit core list recorded in the current directory, and record the virtual machine's threads in the third subdirectory so that the virtual machine runs in one or more central processing unit cores in the central processing unit core list.
[0101] In some embodiments, the parameter acquisition module 302 is used to:
[0102] The resource attribute parameters of the virtual machine are updated and the virtual machine is abnormal, triggering the virtual machine to change from the first type virtual machine to the second type virtual machine.
[0103] In some embodiments, the CPU cores and memory in the host are divided into multiple access nodes, each access node including at least one CPU core and at least one memory connected to the CPU core; the core allocation module 303 is configured to:
[0104] Get the maximum percentage of dedicated CPU cores;
[0105] Determining a first available number of dedicated CPU cores based on the number of CPU cores of the host and the maximum percentage;
[0106] determining a second available number of dedicated CPU cores based on a total number of CPU cores of the host, a number of CPU cores to be reserved on the host, a number of CPU cores on the host that are already exclusively used by virtual machines, and the access node;
[0107] The minimum number between the first available number and the second available number is used as the number of CPU cores in the host that are allowed to be exclusively used.
[0108] In some embodiments, the second control group includes a current directory and at least one subdirectory, the current directory records a list of CPU cores shared by the second type virtual machines, the subdirectory corresponds one-to-one to at least one second type virtual machine, and the subdirectory inherits the list of CPU cores recorded in the current directory;
[0109] The CPU core recorded in the first subdirectory is deleted from the CPU core list of the second control group. The core marking module 304 is further configured to:
[0110] After deleting the CPU core recorded in the first subdirectory from the subdirectory, the CPU core recorded in the first subdirectory is deleted from the directory at this level.
[0111] In some embodiments, the CPU cores and memory in the host are divided into a plurality of access nodes, each access node including at least one CPU core and at least one memory connected to the CPU core;
[0112] To allocate a CPU core to a virtual machine, the core marking module 304 is further configured to:
[0113] Sorting the multiple access nodes for the first time according to the memory size of each access node to obtain a first sorted list among the access nodes;
[0114] Sort the access nodes in the first sorted list for the second time according to the number of remaining CPU cores of each access node to obtain a second sorted list;
[0115] According to the second sorted list, a central processing unit core is allocated to the virtual machine.
[0116] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0117] See also Figure 4 An embodiment of the present application further provides an electronic device including a memory 10 and a processor 20, wherein the memory 10 stores a computer program, and the processor 20 is configured to run the computer program to execute the steps in any of the above-mentioned central processing unit core allocation method embodiments.
[0118] An embodiment of the present application further provides a computer-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-mentioned central processing unit core allocation method embodiments when running.
[0119] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as 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.
[0120] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned central processing unit core allocation method embodiments are implemented.
[0121] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of any of the above-mentioned central processing unit core allocation method embodiments.
[0122] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0123] The above is a detailed introduction to a central processing unit core allocation method, device, equipment and storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only intended to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A method for allocating CPU cores, characterized in that: The method comprises: Creating a first control group and a second control group on a host, wherein the first control group is used to manage the allocation of central processing unit cores to first-type virtual machines, and the second control group is used to manage the allocation of central processing unit cores to second-type virtual machines. The first-type virtual machines are virtual machines that require exclusive use of central processing unit cores, and the second-type virtual machines are virtual machines that do not require exclusive use of central processing unit cores. The second control group records a list of central processing unit cores shared by the second-type virtual machines. When a virtual machine is created, obtaining resource attribute parameters of the virtual machine; If the resource attribute parameter indicates that the virtual machine is a virtual machine of the first type, creating a first subdirectory corresponding to the virtual machine under the first control group, allocating a central processing unit core to the virtual machine based on the number of central processing unit cores allowed to be exclusively occupied in the host as a constraint, and recording the allocated central processing unit core and the thread of the virtual machine in the first subdirectory; The CPU cores recorded in the first subdirectory are deleted from the CPU core list of the second control group, and the CPU cores in the first subdirectory are marked as dedicated.
2. The method according to claim 1, characterized in that The central processing unit cores and memory in the host are divided into a plurality of access nodes, each of the access nodes including at least one central processing unit core and a memory connected to the at least one central processing unit core; the number of central processing unit cores in the host that are allowed to be exclusively used is determined based on the following method: Obtaining a maximum percentage of the dedicated central processing unit cores; Determining a first available number of the dedicated CPU cores based on the number of CPU cores of the host and the maximum percentage; determining a second available number of dedicated CPU cores based on the total number of CPU cores of the host, the number of CPU cores to be reserved by the host, the number of CPU cores in the host that are exclusively used by virtual machines, and the access node; The minimum number between the first available number and the second available number is used as the number of central processing unit cores in the host that are allowed to be exclusively occupied.
3. The method according to claim 1, characterized in that The second control group includes a current-level directory, and the current-level directory records a list of central processing unit cores shared by the second-type virtual machines; the method further includes: If the resource attribute parameter indicates that the virtual machine is a virtual machine of the second type, creating a second subdirectory corresponding to the virtual machine under the second control group; The second subdirectory is made to inherit the CPU core list recorded in the current directory, and the threads of the virtual machine are recorded in the second subdirectory, so that the virtual machine runs in one or more CPU cores in the CPU core list.
4. The method according to claim 1, wherein The second control group includes a current-level directory, and the current-level directory records a list of central processing unit cores shared by the second-type virtual machines; the method further includes: If the virtual machine changes from the first type virtual machine to the second type virtual machine, the CPU core recorded in the first subdirectory is re-added to the list of CPU cores recorded in the current-level directory, and the dedicated status of the corresponding CPU core is canceled; Create a third subdirectory corresponding to the virtual machine under the second control group, and make the third subdirectory inherit the central processing unit core list recorded in the current directory, and record the threads of the virtual machine in the third subdirectory so that the virtual machine runs in one or more central processing unit cores in the central processing unit core list.
5. The method according to claim 4, characterized in that The triggering condition for the virtual machine to change from the first type virtual machine to the second type virtual machine includes any one of the following conditions: The resource attribute parameters of the virtual machine are updated; The virtual machine is abnormal.
6. The method according to claim 1, characterized in that The second control group includes a current directory and at least one subdirectory, wherein the current directory records a list of CPU cores shared by the second-type virtual machines, the subdirectory corresponds one-to-one to at least one second-type virtual machine, and the subdirectory inherits the list of CPU cores recorded in the current directory; The deleting the CPU core recorded in the first subdirectory from the CPU core list of the second control group includes: After deleting the central processing unit core recorded in the first subdirectory from the subdirectory, the central processing unit core recorded in the first subdirectory is deleted from the current-level directory.
7. The method according to claim 1, characterized in that The CPU core and memory in the host are divided into a plurality of access nodes, each of the access nodes includes at least one CPU core and a memory connected to the at least one CPU core; The allocating a central processing unit core to the virtual machine includes: Sorting the plurality of access nodes for the first time according to the memory size of each access node to obtain a first sorted list of the access nodes; sorting the access nodes in the first sorted list for a second time according to the number of remaining CPU cores of each access node to obtain a second sorted list; According to the second sorted list, a central processing unit core is allocated to the virtual machine.
8. A central processing unit core allocation device, characterized in that: include: a control group creation module, configured to create a first control group and a second control group in a host, wherein the first control group is configured to manage the allocation of central processing unit cores to first-type virtual machines, and the second control group is configured to manage the allocation of central processing unit cores to second-type virtual machines, wherein the first-type virtual machines are virtual machines that require exclusive use of central processing unit cores, and the second-type virtual machines are virtual machines that do not require exclusive use of central processing unit cores, and the second control group records a list of central processing unit cores shared by the second-type virtual machines; A parameter acquisition module is used to obtain resource attribute parameters of the virtual machine when the virtual machine is created; a core allocation module configured to, if the resource attribute parameter indicates that the virtual machine is a virtual machine of the first type, create a first subdirectory corresponding to the virtual machine under the first control group, allocate a central processing unit core to the virtual machine based on the number of central processing unit cores allowed to be exclusively used in the host as a constraint, and record the allocated central processing unit core and the threads of the virtual machine in the first subdirectory; The core marking module is used to delete the CPU cores recorded in the first subdirectory from the CPU core list of the second control group, and mark the CPU cores in the first subdirectory as dedicated.
9. An electronic device, characterized in that: include: Memory: used to store computer programs; A processor, configured to implement the steps of the central processing unit core allocation method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the central processing unit core allocation method according to any one of claims 1 to 7 are implemented.
