Large-page memory pre-allocation method and device for starting virtual machine

By scheduling multiple subthreads to different CPUs in CPU isolation scenarios to perform large-page memory preallocation tasks, the problem of long-term large-page memory preallocation during virtual machine startup is solved, and the virtual machine startup speed is improved.

CN119201340APending Publication Date: 2024-12-27BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411274674.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

In the CPU isolation scenario, the pre-allocation of large pages of memory during the virtual machine startup process takes a long time, resulting in limited virtual machine startup speed.

Method used

By creating multiple child threads and scheduling them to different CPUs to run, the one-to-one correspondence between child threads is used to perform large-page memory preallocation tasks, ensuring that each child thread can perform large-page memory preallocation sub on different CPUs tasks, thereby accelerating large-page memory pre-allocation during virtual machine startup in CPU isolation scenarios.

Benefits of technology

Through this method, the large-page memory preallocation task during virtual machine startup can be greatly accelerated, solving the problem of long-term large-page memory preallocation during virtual machine startup in CPU isolation scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201340A_ABST
    Figure CN119201340A_ABST
Patent Text Reader

Abstract

The invention provides a large-page memory pre-allocation method and device for starting a virtual machine, and the method is applied to a main thread and comprises the steps: obtaining a virtual machine starting instruction for starting a target virtual machine; in response to the virtual machine starting instruction, determining an operation scene of a target virtual machine; under the condition that it is determined that the running scene is the CPU isolation scene, each sub-thread in the created N sub-threads is dispatched to different CPUs of the target virtual machine to run, each sub-thread is used for executing the corresponding large-page memory pre-allocation sub-task, and N is an integer larger than or equal to 1; the large-page memory pre-allocation task of the target virtual machine is completed through the sub-thread dispatched to the CPU, and the large-page memory pre-allocation task comprises a large-page memory pre-allocation sub-task. By means of the method and device, the problem that in the prior art, in the virtual machine starting process under the isolation scene, long time is consumed for large-page memory pre-allocation is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of virtual machines, and in particular to a method and device for pre-allocating large page memory for starting a virtual machine. Background Art

[0002] Currently, cloud service providers face customers with very strict requirements on the computing performance and computing stability of virtual machines. Therefore, cloud service providers often allocate a physical core for each core of the virtual machine. Not only do they bind the virtual machine core to the corresponding physical machine core, but they also need to isolate the physical machine core to avoid interference from other programs. Virtual machines using huge pages need to pre-allocate all required huge pages of memory during the startup process. In the CPU isolation scenario, these operations can only be run on one physical core, resulting in a long startup time for the virtual machine. Therefore, it is necessary to accelerate the pre-allocation of huge pages of memory to speed up the virtual machine startup process and improve the efficiency of related business scenarios. Huge page memory is to increase the size of the memory page (Page) allocated by the operating system to the process from the traditional small page (usually 4KB) to a larger size (usually 2MB or 1GB), which can reduce the number and size of page tables, reduce TLB (Translation Lookaside Buffer) misses, and improve memory access efficiency.

[0003] In the related art, for non-isolated scenarios, QEMU (an open source virtualization management software that can simulate various types of devices through software) is used to accelerate the virtual machine startup process, and by default, QEMU uses a multi-threaded approach to accelerate the virtual machine startup process. This multi-threaded acceleration logic performs well in non-isolated scenarios, that is, when the virtual machine does not need to be strictly isolated, this acceleration method can effectively increase the speed of virtual machine startup. However, for CPU isolation scenarios, because the virtual machine is restricted to run on a specific physical core, the kernel scheduling system cannot effectively schedule multiple threads, which will cause QEMU's multi-threaded acceleration logic to be unable to use other physical cores to parallelly process the large page memory pre-allocation task during the virtual machine startup process, that is, the large page memory pre-allocation task can only be performed by threads on one physical core, resulting in poor acceleration effect, and the large page memory pre-allocation process during the virtual machine startup process takes a long time.

[0004] Therefore, in the related art, there is a problem that large page memory pre-allocation takes a long time during the startup of a virtual machine in an isolation scenario. Summary of the invention

[0005] The present application provides a method and device for pre-allocating large page memory when starting a virtual machine, so as to at least solve the problem in the related art that large page memory pre-allocation takes a long time during the startup of a virtual machine in an isolation scenario.

[0006] According to one aspect of an embodiment of the present application, a large page memory pre-allocation method for virtual machine startup is provided, which is applied to a main thread and includes:

[0007] Obtaining a virtual machine startup instruction for starting a target virtual machine;

[0008] In response to the virtual machine startup instruction, determining an operation scenario of the target virtual machine;

[0009] When it is determined that the running scenario is a CPU isolation scenario, each of the N created sub-threads is scheduled to run on a different CPU of the target virtual machine, wherein each sub-thread is used to execute a corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1;

[0010] The large page memory pre-allocation task for the target virtual machine is completed by scheduling a sub-thread on the CPU, wherein the large page memory pre-allocation task includes the large page memory pre-allocation sub-task.

[0011] Optionally, as in the foregoing method, determining the operating scenario of the target virtual machine includes:

[0012] Create N child threads, where N is an integer greater than or equal to 2;

[0013] Each of the N sub-threads determines the first CPU serial number of the currently running CPU;

[0014] In the case where it is determined that each first CPU serial number is consistent with the second CPU serial number of the main thread, determining that the running scenario of the target virtual machine is a CPU isolation scenario, wherein the second CPU serial number is the serial number of the CPU on which the main thread is currently running;

[0015] When it is determined that at least one of all the first CPU serial numbers is different from the second CPU serial number, it is determined that the running scenario of the target virtual machine is a CPU non-isolation scenario.

[0016] Optionally, as in the aforementioned method, after creating N sub-threads, the method further includes:

[0017] The main thread enters a sleep state;

[0018] After each of the N sub-threads determines the first CPU serial number of the currently running CPU, the method further includes:

[0019] In response to the communication request of the sub-thread, the main thread is awakened from the sleep state, wherein the communication request is used to request to record the first CPU serial number of the CPU on which each sub-thread is currently running in the main thread.

[0020] Optionally, as in the aforementioned method, when it is determined that the running scenario is a CPU isolation scenario, scheduling each of the N sub-threads created by the main thread to run on a different CPU of the target virtual machine includes:

[0021] Get its own CPU affinity set;

[0022] When it is determined that the running scenario is a CPU isolation scenario, a one-to-one correspondence between each target CPU in the CPU affinity set and each sub-thread is established;

[0023] According to the one-to-one correspondence, each of the sub-threads is respectively scheduled to run on different target CPUs of the target virtual machine.

[0024] Optionally, as in the aforementioned method, scheduling each of the sub-threads to run on different target CPUs of the target virtual machine according to the one-to-one correspondence includes:

[0025] According to the one-to-one correspondence, the original affinity of each sub-thread is modified to obtain a modified affinity corresponding to each sub-thread, so that each sub-thread runs on the target CPU indicated by the corresponding modified affinity, wherein all original affinities point to the same CPU.

[0026] Optionally, as in the aforementioned method, the method further comprises:

[0027] When it is determined that the running scenario is a CPU non-isolation scenario, each of the N sub-threads is scheduled to run on a different CPU in the CPU non-isolation scenario.

[0028] Optionally, as in the aforementioned method, completing the task of pre-allocating large page memory for the target virtual machine by scheduling a subthread on the CPU includes:

[0029] Blocking and recycling the subthread that completes the large page memory pre-allocation subtask;

[0030] After completing the recycling of all child threads, the large page memory pre-allocation task for the target virtual machine is completed.

[0031] According to another aspect of an embodiment of the present application, a large page memory pre-allocation device started by a virtual machine is also provided, which is applied to a main thread and includes:

[0032] An acquisition module, used to acquire a virtual machine startup instruction for starting a target virtual machine;

[0033] An operation scenario determination module, configured to determine an operation scenario of the target virtual machine in response to the virtual machine startup instruction;

[0034] A scheduling module, for, when it is determined that the running scenario is a CPU isolation scenario, scheduling each of the N created sub-threads to run on different CPUs of the target virtual machine, wherein each sub-thread is used to execute a corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1;

[0035] The pre-allocation module is used to complete the large page memory pre-allocation task of the target virtual machine by scheduling a sub-thread on the CPU, wherein the large page memory pre-allocation task includes the large page memory pre-allocation sub-task.

[0036] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.

[0037] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.

[0038] In an embodiment of the present application, a method of reallocating the CPUs on which each sub-thread runs is adopted in a CPU isolation scenario. When it is determined that the running scenario is a CPU isolation scenario, each of the N sub-threads created is scheduled to run on different CPUs in the CPU isolation scenario, wherein each sub-thread is used to execute the corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1. Since the sub-threads used to execute the corresponding large page memory pre-allocation subtask are scheduled to run on different CPUs, the purpose of all N sub-threads being able to perform the large page memory pre-allocation task together can be achieved, thereby achieving the technical effect of greatly accelerating the large page memory pre-allocation task in the virtual machine startup process in the CPU isolation scenario, thereby solving the problem of long time-consuming large page memory pre-allocation in the virtual machine startup process in the isolation scenario in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0041] Figure 1 It is a schematic diagram of a hardware environment of an optional large page memory pre-allocation method for virtual machine startup according to an embodiment of the present application;

[0042] Figure 2 It is a flowchart of an optional large page memory pre-allocation method for virtual machine startup according to an embodiment of the present application;

[0043] Figure 3 It is a schematic diagram of another optional large page memory pre-allocation method for virtual machine startup according to an embodiment of the present application;

[0044] Figure 4 It is a flowchart of another optional large page memory pre-allocation method for virtual machine startup according to an embodiment of the present application;

[0045] Figure 5 It is a schematic diagram of an optional process of determining whether the current environment of the target virtual machine is a CPU isolation scenario according to an embodiment of the present application;

[0046] Figure 6 It is an optional flowchart of adjusting the CPU affinity of each sub-thread in a CPU isolation scenario according to an embodiment of the present application;

[0047] Figure 7 It is a structural block diagram of an optional large page memory pre-allocation device for virtual machine startup according to an embodiment of the present application;

[0048] Figure 8 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0051] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretation:

[0052] 1. Physical machine: The real physical environment where the virtual machine actually runs, providing computing, storage, network and other functions.

[0053] 2. Virtualization: It refers to the simulation, splitting, and integration of physical machine hardware resources through software and hardware technologies to display the complete hardware resource status to the outside world, including the virtualization of common resources such as CPU, memory, disk, and network card. Virtualization can manage hardware resources in a more fine-grained manner, more safely isolate multiple users in the same hardware set, and more efficiently schedule user requests and business pressure.

[0054] 3. QEMU: An open source virtualization management software that can simulate various types of devices through software.

[0055] 4. Large Page Memory: A technology for optimizing memory management in an operating system. Its main idea is to increase the size of the memory page (Page) allocated by the operating system to the process from the traditional small page (usually 4KB) to a larger size (usually 2MB or 1GB). This technology reduces the number and size of page tables, reduces TLB (Translation Lookaside Buffer) misses, and improves memory access efficiency.

[0056] 5. Kernel: refers to the Linux kernel, which is widely used in the server field. It manages various hardware downward and provides a user-mode program interface upward.

[0057] 6. Scheduling domain: A range of CPUs built by the kernel for a multi-core computer system. Within this range, the kernel can schedule different processes to run on different CPUs. The scheduling domain can be composed of one or more CPUs, or it can be a collection of all CPUs in the entire system.

[0058] 7. CPU isolation: The kernel on the physical machine isolates some CPUs and does not build scheduling domains for these CPUs. When needed, it specifies specific CPU cores for specific tasks or processes to ensure that tasks can monopolize the CPU cores to avoid interference from other tasks. At the same time, this also causes the kernel scheduling system's process wakeup / load balancing mechanisms to fail, which in some scenarios will lead to load imbalance and the concentration of processes on a certain CPU.

[0059] 8. CPU affinity: Limit the process to run only on certain physical machine CPUs. The set of these CPU serial numbers is called the CPU affinity set.

[0060] According to one aspect of an embodiment of the present application, a method for pre-allocating large page memory started by a virtual machine is provided. Optionally, in this embodiment, the method for pre-allocating large page memory started by a virtual machine can be applied to Figure 1 In the hardware environment composed of terminal 1402 and server 1404 shown in FIG. Figure 1 As shown, server 1404 is connected to terminal 1402 via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for server 1404.

[0061] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.

[0062] The large page memory pre-allocation method started by the virtual machine of the embodiment of the present application can be executed by the server, or by the terminal, or by the server and the terminal together. Among them, the terminal can also execute the large page memory pre-allocation method started by the virtual machine of the embodiment of the present application by the client installed thereon.

[0063] Taking the method for pre-allocating large page memory started by a server in this embodiment as an example, Figure 2 A large page memory pre-allocation method for virtual machine startup provided in an embodiment of the present application is applied to a main thread and includes the following steps:

[0064] Step S202: Obtain a virtual machine startup instruction for starting a target virtual machine.

[0065] The large page memory pre-allocation method for starting a virtual machine in this embodiment can be applied to a scenario where a virtual machine needs to be started, and can be applied to the main thread of QEMU.

[0066] The startup of the target virtual machine is usually triggered by a specific trigger action or command. Optionally, the trigger action can come from a user interface, a command line tool, a script or an automated management system. Specifically, the virtual machine startup instruction can be generated after a manual startup trigger, for example, a user manually triggers the generation of the virtual machine startup instruction through a graphical user interface (GUI) or a command line tool to start the virtual machine. In addition, the virtual machine startup instruction can also be generated by a virtual machine script, for example, automatically triggering the generation of a virtual machine startup instruction when the system starts to start the target virtual machine. In addition, the virtual machine startup instruction can also be generated after a scheduled task is started, for example, triggering the generation of a virtual machine startup instruction at a specific time of the day (for example: 8 o'clock in the evening, 1 o'clock in the morning, etc.) to automatically start the backup virtual machine. At the same time, the virtual machine startup instruction can also be generated by event-driven, for example, when a certain application crash is detected, a virtual machine startup instruction is generated to start the backup virtual machine. In addition, the virtual machine startup instruction can also be generated by a resource manager, for example, a virtual machine startup instruction is generated by tools such as vCenter (a centralized management platform) or libvirt (an open source software collection for managing virtualization infrastructure) to start the virtual machine.

[0067] Step S204: In response to the virtual machine startup instruction, determine the operation scenario of the target virtual machine.

[0068] After obtaining the virtual machine startup instruction, since the virtual machine startup methods are different in different scenarios, it is necessary to determine the running scenario of the target virtual machine.

[0069] like Figure 3 As shown, as an optional implementation, the operation scenario of the target virtual machine can be determined through the following steps S302 to S308:

[0070] Step S302: Create N sub-threads, where N is an integer greater than or equal to 2.

[0071] Specifically, since the method of this embodiment is applied to the main thread, the main thread can determine the number of sub-threads with default configuration in the Qemu code, the number of CPUs of the target virtual machine, and the number of CPUs of the host machine. In addition, the minimum value of the above three numbers can be taken to determine N.

[0072] The child thread may be a thread for executing the corresponding large page memory pre-allocation subtask, that is, each child thread may be used to execute part of the large page memory pre-allocation task.

[0073] Further optionally, after creating N child threads, the main thread enters a sleep state because the main thread needs to wait for the child threads to complete corresponding tasks before executing the next action.

[0074] Step S304: Each of the N sub-threads determines the first CPU serial number of the currently running CPU.

[0075] Specifically, after N subthreads are created, for any of the subthreads, in the Linux system, the subthread can obtain which CPU of the physical machine the thread is running on through the sched_getaffinity() function, and the first CPU serial number of this running is the serial number of the CPU on the physical machine; the system call is used to obtain the first CPU serial number of the CPU currently running. In addition, every time a subthread obtains its corresponding first CPU serial number, it can establish a communication request with the main thread, and the main thread can be awakened from the sleep state in response to the communication request of the subthread, wherein the communication request is used to request to record the first CPU serial number of the CPU currently running each subthread in the main thread. And wake up the main thread, in addition to determining the first CPU serial number of the CPU currently running each subthread, the main thread can also determine the number of all subthreads that have obtained the first CPU serial number by adding 1 to the number of subthreads that have currently determined the corresponding first CPU serial number.

[0076] Step S306, when it is determined that each first CPU serial number is consistent with the second CPU serial number of the main thread, it is determined that the running scenario of the target virtual machine is a CPU isolation scenario, wherein the second CPU serial number is the serial number of the CPU currently running the main thread.

[0077] Specifically, the main thread can use a similar method to the child thread to determine the second CPU serial number of its current running. Furthermore, the second CPU serial number is the serial number of the CPU on the physical machine where the main thread is currently running. After the main thread determines that all current child threads have obtained the first CPU serial number, the first CPU serial number of each child thread can be compared with the second CPU serial number of the main thread. Because in the isolation scenario, the main thread only contains one second CPU serial number, and the child thread can only run on the CPU indicated by the second CPU serial number, therefore, if each first CPU serial number is consistent with the second CPU serial number of the main thread, it can be determined that the operation scenario of the target virtual machine is a CPU isolation scenario.

[0078] Step S308: When it is determined that at least one of all the first CPU serial numbers is different from the second CPU serial numbers, it is determined that the running scenario of the target virtual machine is a CPU non-isolation scenario.

[0079] Based on the above analysis, if at least one of the first CPU serial numbers is different from the second CPU serial number, it means that at least one sub-thread is assigned to run on a CPU other than the CPU indicated by the second CPU serial number. Therefore, it can be determined that the running scenario of the target virtual machine is a CPU non-isolation scenario.

[0080] Step S206, when it is determined that the running scenario is a CPU isolation scenario, each of the N created sub-threads is scheduled to run on different CPUs of the target virtual machine, wherein each sub-thread is used to execute the corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1.

[0081] Specifically, when it is determined that the running scenario is a CPU isolation scenario, in order to allow each thread to have as many running resources as possible, each of the N created sub-threads can be scheduled to a different CPU of the target virtual machine. In this case, the number of CPUs of the target virtual machine is greater than or equal to N. Furthermore, each sub-thread can have a unique corresponding CPU. The CPU of the target virtual machine is the CPU allocated to the target virtual machine by the physical machine.

[0082] like Figure 4 As shown, as an optional implementation, as in the aforementioned method, the following steps S402 to S406 can be used to implement step S206, where when it is determined that the running scenario is a CPU isolation scenario, each of the N sub-threads created by the main thread is scheduled to run on a different CPU of the target virtual machine:

[0083] Step S402, obtaining its own CPU affinity set.

[0084] Specifically, in a Linux system, the main thread (or any other thread) can use the sched_getaffinity() function to obtain its own CPU affinity set, which allows a program to query or set the set of CPUs on which a process or thread can run.

[0085] Step S404: when it is determined that the running scenario is a CPU isolation scenario, a one-to-one correspondence between each target CPU in the CPU affinity set and each sub-thread is established.

[0086] When it is determined that the running scenario is a CPU isolation scenario, because when the main thread of QEMU in the related art creates a child thread, in the CPU isolation scenario, all child threads will run on one CPU, so there is a problem of low operating efficiency. This embodiment establishes a one-to-one correspondence between each target CPU in the CPU affinity set and each child thread, so that different child threads can run on different target CPUs in the later stage. The target CPU can be a CPU to which a child thread is assigned among all CPUs of the target virtual machine. Optionally, the one-to-one correspondence can be that after determining the correspondence between a target CPU and a child thread, the correspondence between the next target CPU and the next child thread is determined, or the correspondence between each target CPU and each child thread is determined at one time.

[0087] Step S406: Schedule each child thread to run on a different target CPU of the target virtual machine according to a one-to-one correspondence.

[0088] As an optional implementation, the step S406 can be implemented by the following steps to schedule each subthread to run on different target CPUs of the target virtual machine according to a one-to-one correspondence: according to the one-to-one correspondence, the original affinity of each subthread is modified to obtain the modified affinity corresponding to each subthread, so that each subthread runs on the target CPU indicated by the corresponding modified affinity, wherein all original affinities point to the same CPU. That is to say, in this embodiment, the one-to-one correspondence is obtained by successively determining each subthread corresponding to each target CPU. Specifically, the main thread selects a CPU from its own CPU affinity set. When the number of CPUs in the CPU affinity set is greater than or equal to the number of subthreads, it is necessary to ensure that the CPU selected each time is not repeated. In addition, the main thread selects a subthread from all subthreads each time, and the subthread selected each time also needs to be non-repeated, and the affinity of the selected subthread is modified to the selected CPU, and this cycle is repeated until the affinity of all subthreads is modified.

[0089] As an optional implementation, as in the aforementioned method, the method further includes the following steps: when it is determined that the running scenario is a CPU non-isolated scenario, each of the N sub-threads is scheduled to run on a different CPU in the CPU non-isolated scenario. That is to say, when it is determined that the running scenario is a CPU non-isolated scenario, any CPU in the CPU non-isolated scenario can be scheduled as a sub-thread, so each of the N sub-threads can be scheduled to run on a different CPU in the CPU non-isolated scenario, so that each sub-thread is scheduled to run on a different CPU in the CPU non-isolated scenario, so that each sub-thread is scheduled to a different CPU, thereby improving the efficiency of executing large page memory pre-allocation tasks.

[0090] Step S208, completing the large page memory pre-allocation task for the target virtual machine by scheduling the sub-thread on the CPU, wherein the large page memory pre-allocation task includes a large page memory pre-allocation sub-task.

[0091] Specifically, when the child threads are scheduled to run on the CPU and each child thread completes the corresponding large page memory pre-allocation subtask, since the page memory pre-allocation task includes the large page memory pre-allocation subtask, the large page memory pre-allocation task of the target virtual machine is also completed.

[0092] As an optional implementation, as in the aforementioned method, the aforementioned step S208 can be implemented by the following steps to complete the large page memory pre-allocation task for the target virtual machine by scheduling the sub-thread on the CPU: blocking and recycling the sub-thread that completes the large page memory pre-allocation sub-task; after completing the recycling of all sub-threads, completing the large page memory pre-allocation task for the target virtual machine. That is, the main thread will wait for the sub-thread to complete its corresponding large page memory pre-allocation sub-task, and then recycle the sub-thread resources, and after completing the recycling of all sub-threads, the large page memory pre-allocation task for the target virtual machine is completed.

[0093] This embodiment adopts a method of reallocating the CPUs on which each sub-thread runs in a CPU isolation scenario. When it is determined that the running scenario is a CPU isolation scenario, each of the N created sub-threads is scheduled to run on a different CPU in the CPU isolation scenario, wherein each sub-thread is used to execute a corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1. Since each sub-thread used to execute the corresponding large page memory pre-allocation subtask is scheduled to run on a different CPU, the purpose of all N sub-threads being able to perform the large page memory pre-allocation task together can be achieved, thereby achieving the technical effect of greatly accelerating the large page memory pre-allocation task in the virtual machine startup process in the CPU isolation scenario, thereby solving the problem of long time-consuming large page memory pre-allocation in the virtual machine startup process in the isolation scenario in the related technology.

[0094] As described below, an application example of applying any of the above embodiments is provided:

[0095] like Figure 5 As shown, a method for determining whether the current environment of the target virtual machine is a CPU isolation scenario is provided:

[0096] 51. The main thread creates N child threads to accelerate the startup process of the target virtual machine, mainly used to accelerate the related processes of the large page memory pre-allocation task. The main thread sleeps after creating N child threads.

[0097] 52. The child thread obtains the serial number of the first CPU currently running through a system call. For example, the child thread can obtain the serial number of the first CPU currently running through a getcpu() system call.

[0098] 53. After waiting for all child threads to obtain the corresponding first CPU serial number, the main thread is awakened.

[0099] 54. The main thread checks the first CPU serial numbers of all child threads to determine whether the first CPU serial numbers of all child threads are consistent with the second CPU serial number of the main thread. If any of the first CPU serial numbers are different, it is a CPU non-isolation scenario; if all are the same, it is a CPU isolation scenario.

[0100] like Figure 6 The present invention provides a method for adjusting the CPU affinity of each sub-thread in a CPU isolation scenario:

[0101] 61. The main thread obtains its own CPU affinity set.

[0102] 62.According to Figure 5 The method shown determines whether it is a CPU isolation scenario. If not, jump to step 65, otherwise execute step 63.

[0103] 63. The main thread selects a CPU from its own CPU affinity set. When the number of CPUs in the CPU affinity set is greater than or equal to the number of child threads, it is necessary to ensure that the CPUs selected each time are not repeated.

[0104] 64. The main thread selects a sub-thread from all sub-threads each time, and the sub-threads selected each time need to be unique, and the affinity of the selected sub-thread is modified to the CPU selected in step 63, and then jumps to step 3, and repeats this cycle until the affinity of all sub-threads is modified.

[0105] 65. At this time, the affinity of each child thread is specified, and each child thread can only run on the CPU corresponding to the affinity. By executing the large page memory pre-allocation subtask by each child thread, the large page memory pre-allocation task can be executed.

[0106] 66. After the child thread completes the large page memory pre-allocation subtask, it is recycled by the main thread. After the main thread blocks and recycles all child threads, it continues to execute other logic.

[0107] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0108] 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 a 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. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.

[0109] According to another aspect of an embodiment of the present application, a large page memory pre-allocation device for virtual machine startup is provided for implementing the large page memory pre-allocation method for virtual machine startup described above. Figure 7 is a structural block diagram of a large page memory pre-allocation device optionally applied to a main thread virtual machine startup according to an embodiment of the present application, such as Figure 7 As shown, the device may include:

[0110] An acquisition module 71 is used to acquire a virtual machine startup instruction for starting a target virtual machine;

[0111] An operation scenario determination module 72, configured to determine an operation scenario of a target virtual machine in response to a virtual machine startup instruction;

[0112] The scheduling module 73 is used to schedule each of the N created sub-threads to run on different CPUs of the target virtual machine when it is determined that the running scenario is a CPU isolation scenario, wherein each sub-thread is used to execute the corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1;

[0113] The pre-allocation module 74 is used to complete the large page memory pre-allocation task for the target virtual machine by scheduling a sub-thread on the CPU, wherein the large page memory pre-allocation task includes a large page memory pre-allocation sub-task.

[0114] It should be noted that the acquisition module 71 in this embodiment can be used to execute the above step S202, the operation scenario determination module 72 in this embodiment can be used to execute the above step S204, the scheduling module 73 in this embodiment can be used to execute the above step S206, and the pre-allocation module 74 in this embodiment can be used to execute the above step S208.

[0115] Through the above module, in the CPU isolation scenario, the CPU running each sub-thread is reallocated. When it is determined that the running scenario is a CPU isolation scenario, each of the N sub-threads created is scheduled to run on different CPUs in the CPU isolation scenario, wherein each sub-thread is used to execute the corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1. Since each sub-thread used to execute the corresponding large page memory pre-allocation subtask is scheduled to run on different CPUs, the purpose of N sub-threads jointly performing the large page memory pre-allocation task can be achieved, and the technical effect of greatly accelerating the large page memory pre-allocation task in the virtual machine startup process in the CPU isolation scenario is achieved, thereby solving the problem of long time-consuming large page memory pre-allocation in the virtual machine startup process in the isolation scenario in the related art. .

[0116] As an optional implementation, as in the aforementioned device, the acquisition module 71 is configured to:

[0117] Create N child threads, where N is an integer greater than or equal to 2;

[0118] Each of the N sub-threads determines the first CPU serial number of the currently running CPU;

[0119] When it is determined that each first CPU sequence number is consistent with the second CPU sequence number of the main thread, determining that the operation scenario of the target virtual machine is a CPU isolation scenario, wherein the second CPU sequence number is the sequence number of the CPU on which the main thread is currently running;

[0120] When it is determined that at least one of all the first CPU serial numbers is different from the second CPU serial numbers, it is determined that the running scenario of the target virtual machine is a CPU non-isolation scenario.

[0121] As an optional implementation, the aforementioned device further includes:

[0122] The sleep module is used to put the main thread into sleep state after creating N child threads;

[0123] A wake-up module is used to wake up the main thread from a sleep state in response to a communication request of the sub-thread after each of the N sub-threads determines the first CPU serial number of the currently running CPU, wherein the communication request is used to request to record the first CPU serial number of the currently running CPU of each sub-thread in the main thread.

[0124] As an optional implementation, as in the aforementioned device, the scheduling module 73 includes:

[0125] The acquisition unit is used to obtain its own CPU affinity set;

[0126] A corresponding unit, used for establishing a one-to-one correspondence between each target CPU in the CPU affinity set and each sub-thread when it is determined that the running scenario is a CPU isolation scenario;

[0127] The scheduling unit is used to schedule each sub-thread to run on different target CPUs of the target virtual machine according to a one-to-one correspondence.

[0128] As an optional implementation manner, as in the aforementioned device, the scheduling unit is configured to:

[0129] According to a one-to-one correspondence, the original affinity of each subthread is modified to obtain a modified affinity corresponding to each subthread, so that each subthread runs on the target CPU indicated by the corresponding modified affinity, wherein all original affinities point to the same CPU.

[0130] As an optional implementation, as in the aforementioned device, the scheduling module 73 is further used for:

[0131] When it is determined that the running scenario is a CPU non-isolated scenario, each of the N sub-threads is scheduled to run on a different CPU in the CPU non-isolated scenario.

[0132] As an optional implementation, as in the aforementioned device, the pre-allocation module 74 is configured as follows:

[0133] Block and recycle the subthread that completes the large page memory pre-allocation subtask;

[0134] After completing the recycling of all child threads, the large page memory pre-allocation task of the target virtual machine is completed.

[0135] The device in this embodiment, in addition to the above modules, may also include a module for executing any method in the embodiments of the large page memory pre-allocation method for starting any virtual machine as described above.

[0136] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.

[0137] According to another aspect of an embodiment of the present application, an electronic device for implementing the large page memory pre-allocation method for starting a virtual machine is also provided. The electronic device may be a server, a terminal, or a combination thereof.

[0138] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 8 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .

[0139] Memory 1503, used for storing computer programs;

[0140] The processor 1501 is used to implement the following steps when executing the program stored in the memory 1503:

[0141] Step S202: Obtain a virtual machine startup instruction for starting a target virtual machine.

[0142] Step S204: In response to the virtual machine startup instruction, determine the operation scenario of the target virtual machine.

[0143] Step S206, when it is determined that the running scenario is a CPU isolation scenario, each of the N created sub-threads is scheduled to run on different CPUs of the target virtual machine, wherein each sub-thread is used to execute the corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1.

[0144] Step S208, completing the large page memory pre-allocation task for the target virtual machine by scheduling the sub-thread on the CPU, wherein the large page memory pre-allocation task includes a large page memory pre-allocation sub-task.

[0145] Optionally, in this embodiment, the above-mentioned communication bus can be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above-mentioned electronic device and other devices.

[0146] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0147] As an example, the memory 1503 may include, but is not limited to, the acquisition module 71, the operation scenario determination module 72, the scheduling module 73, and the pre-allocation module 74 in the large page memory pre-allocation device started by the virtual machine. In addition, it may also include, but is not limited to, other module units in the large page memory pre-allocation device started by the virtual machine, which will not be repeated in this example.

[0148] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0149] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.

[0150] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.

[0151] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0152] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0153] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0154] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0155] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.

[0156] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0157] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A large page memory pre-allocation method for virtual machine startup, characterized in that: Applied to the main thread, including: Obtaining a virtual machine startup instruction for starting a target virtual machine; In response to the virtual machine startup instruction, determining an operation scenario of the target virtual machine; When it is determined that the running scenario is a CPU isolation scenario, each of the N created sub-threads is scheduled to run on a different CPU of the target virtual machine, wherein each sub-thread is used to execute a corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1; The large page memory pre-allocation task for the target virtual machine is completed by scheduling a sub-thread on the CPU, wherein the large page memory pre-allocation task includes the large page memory pre-allocation sub-task.

2. The method according to claim 1, characterized in that The determining the operation scenario of the target virtual machine includes: Create N child threads, where N is an integer greater than or equal to 2; Each of the N sub-threads determines the first CPU serial number of the currently running CPU; In the case where it is determined that each first CPU serial number is consistent with the second CPU serial number of the main thread, determining that the running scenario of the target virtual machine is a CPU isolation scenario, wherein the second CPU serial number is the serial number of the CPU on which the main thread is currently running; When it is determined that at least one of all the first CPU serial numbers is different from the second CPU serial number, it is determined that the running scenario of the target virtual machine is a CPU non-isolation scenario.

3. The method according to claim 2, characterized in that After creating N sub-threads, the method further includes: The main thread enters a sleep state; After each of the N sub-threads determines the first CPU serial number of the currently running CPU, the method further includes: In response to the communication request of the sub-thread, the main thread is awakened from the sleep state, wherein the communication request is used to request to record the first CPU serial number of the CPU on which each sub-thread is currently running in the main thread.

4. The method according to claim 1, characterized in that: When it is determined that the running scenario is a CPU isolation scenario, scheduling each of the N sub-threads created by the main thread to run on a different CPU of the target virtual machine, respectively, includes: Get its own CPU affinity set; When it is determined that the running scenario is a CPU isolation scenario, a one-to-one correspondence between each target CPU in the CPU affinity set and each sub-thread is established; According to the one-to-one correspondence, each of the sub-threads is respectively scheduled to run on different target CPUs of the target virtual machine.

5. The method according to claim 4, characterized in that The step of scheduling each of the sub-threads to run on different target CPUs of the target virtual machine according to the one-to-one correspondence includes: According to the one-to-one correspondence, the original affinity of each sub-thread is modified to obtain a modified affinity corresponding to each sub-thread, so that each sub-thread runs on the target CPU indicated by the corresponding modified affinity, wherein all original affinities point to the same CPU.

6. The method according to claim 1, characterized in that The method further comprises: When it is determined that the running scenario is a CPU non-isolation scenario, each of the N sub-threads is scheduled to run on a different CPU in the CPU non-isolation scenario.

7. The method according to any one of claims 1 to 6, characterized in that The task of pre-allocating the large page memory of the target virtual machine by scheduling the subthread on the CPU includes: Blocking and recycling the subthread that completes the large page memory pre-allocation subtask; After completing the recycling of all child threads, the large page memory pre-allocation task for the target virtual machine is completed.

8. A large page memory pre-allocation device for starting a virtual machine, characterized in that: Applied to the main thread, including: An acquisition module, used to acquire a virtual machine startup instruction for starting a target virtual machine; An operation scenario determination module, configured to determine an operation scenario of the target virtual machine in response to the virtual machine startup instruction; A scheduling module, for, when it is determined that the running scenario is a CPU isolation scenario, scheduling each of the N created sub-threads to run on different CPUs of the target virtual machine, wherein each sub-thread is used to execute a corresponding large page memory pre-allocation subtask, and N is an integer greater than or equal to 1; The pre-allocation module is used to complete the large page memory pre-allocation task of the target virtual machine by scheduling a sub-thread on the CPU, wherein the large page memory pre-allocation task includes the large page memory pre-allocation sub-task.

9. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 7 by running the computer program stored in the memory.

10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.