Control group management method and system
By maintaining the control group pool by user-state processes and using the kernel to create control groups, the problem of low concurrent creation of control groups in Linux operating systems is solved, and more efficient control group allocation and container performance improvement is achieved.
Patent Information
- Application Number
- CN202210558059.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-19
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2042-05-19
AI Technical Summary
The concurrent creation efficiency of control groups in Linux operating systems is low, which affects the performance of container services. The existing technology cannot create control groups in parallel, and requires serial processing, which makes it a long time to create multiple control groups.
User-mode processes maintain the control group pool, create control groups through the kernel, and add them to the pool, and allocate them directly to the users to avoid concurrent creation and reduce the kernel load.
Improve the efficiency of control group allocation, avoid concurrent creation, reduce the impact of user-state process exceptions, and improve container business performance.
Smart Images

Figure CN114996000B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of computer technology, and more particularly, to a control group management method and system. Background Art
[0002] cgroup is the abbreviation of control group. The control group mechanism is a mechanism provided by the Linux operating system kernel to control the resources (such as CPU, memory, I / O, etc.) used by a process group. The control group mechanism allows multiple control groups to be created on demand. In this case, how to manage the multiple control groups created to achieve reasonable use of the control groups has become a matter of great concern. Summary of the invention
[0003] One or more embodiments of this specification provide the following technical solutions:
[0004] This specification provides a control group management method, the method comprising:
[0005] The user state process obtains an allocation request sent by a control group user; the allocation request includes a first number of available control groups corresponding to the control group user;
[0006] The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process;
[0007] If the first number is not greater than the second number, the user state process allocates the first number of available control groups from the control group pool to the control group user;
[0008] If the first number is greater than the second number, the user state process calls the kernel to enable the kernel to create a third number of the usable control groups, where the third number is the difference between the first number and the second number. The user state process adds the third number of the usable control groups to the control group pool, and allocates the first number of the usable control groups from the control group pool to the control group users.
[0009] This specification also provides a control group management system, the system includes a user state process and a kernel;
[0010] The user state process and the kernel are used for:
[0011] The user state process obtains an allocation request sent by a control group user; the allocation request includes a first number of control groups that can be used corresponding to the control group user;
[0012] The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process;
[0013] If the first number is not greater than the second number, the user state process allocates the first number of available control groups from the control group pool to the control group user;
[0014] If the first number is greater than the second number, the user state process calls the kernel to enable the kernel to create a third number of the usable control groups, where the third number is the difference between the first number and the second number. The user state process adds the third number of the usable control groups to the control group pool, and allocates the first number of the usable control groups from the control group pool to the control group users.
[0015] This specification also provides an electronic device, including:
[0016] processor;
[0017] a memory for storing processor-executable instructions;
[0018] The processor implements the steps of any of the above methods by running the executable instructions.
[0019] The present specification also provides a computer-readable storage medium on which computer instructions are stored. When the instructions are executed by a processor, the steps of any of the methods described above are implemented.
[0020] In the above technical solution, the user-state process can determine whether the first number of control groups requested for allocation by the control group user is greater than the second number of available control groups corresponding to the control group user in the control group pool maintained by the user-state process. If the first number is not greater than the second number, the user-state process can directly allocate the first number of available control groups from the control group pool to the control group user. If the first number is greater than the second number, the user-state process can call the kernel to create a number of available control groups corresponding to the control group user that is the difference between the first number and the second number, so that the user-state process can first add the available control groups created by the kernel to the control group pool, and then allocate the first number of available control groups from the control group pool to the control group user.
[0021] By adopting the above method, on the one hand, since the user-state process can record the control groups created by the kernel through the maintained control group pool and allocate control groups to the control group users from the control group pool, the kernel can create control groups for the control group users in advance and avoid the need to create control groups concurrently. On the other hand, since the process for maintaining the control group pool is a user-state process and not in the kernel, it is convenient to maintain the process and the impact of abnormalities in the process can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 is a schematic diagram of a control group tree.
[0023] Figure 2 It is a hardware architecture diagram of a control group management system shown in an exemplary embodiment of this specification.
[0024] Figure 3 It is a schematic diagram of a control group management method shown in an exemplary embodiment of this specification.
[0025] Figure 4 It is a schematic diagram of another control group management method shown in an exemplary embodiment of this specification.
[0026] Figure 5 It is a schematic diagram of another control group management method shown in an exemplary embodiment of this specification.
[0027] Figure 6 It is a schematic diagram of another control group management method shown in an exemplary embodiment of this specification.
[0028] Figure 7 It is a hardware structure diagram of an electronic device where a control group management system is located, shown as an exemplary embodiment of this specification.
[0029] Figure 8 It is a block diagram of a control group management system shown as an exemplary embodiment of this specification. DETAILED DESCRIPTION
[0030] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0031] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0032] The control group mechanism is a mechanism provided by the Linux operating system kernel that can control the resources (such as CPU, memory, I / O, etc.) used by a process group. The control group mechanism uses resource subsystems to divide resources; for example, the control group mechanism can use the CPU subsystem, memory subsystem, etc. to control CPU, memory and other resources respectively.
[0033] Under the control group mechanism, resource control is implemented in control groups. A control group is a group of processes divided according to specific criteria. A process can join a control group and migrate from one control group to another. Each process in a control group can use the resources allocated to the control group and is subject to the restrictions set for the control group.
[0034] The control group mechanism allows multiple control groups to be created on demand. Under each control group, you can set the resource attributes corresponding to the control group (for example, how much CPU can be used, how much memory can be used, etc.) to allocate the resources indicated by the resource attributes to the control group.
[0035] For any control group, after deleting the control group, the resources allocated to the control group can be released.
[0036] The control group mechanism uses a tree structure to control the resources of the process group. Multiple control groups can be organized into a control group tree according to the tree structure. That is, there is a hierarchy relationship between different control groups. The child node control group on the control group tree inherits the specific properties of the parent node control group. Among them, the child node control group is the next level of the parent node control group; the parent node control group is the previous level of the child node control group. A control group can have multiple next-level control groups.
[0037] Please refer to Figure 1 , Figure 1 is a schematic diagram of a control group tree.
[0038] like Figure 1As shown in the figure, in the control group tree, cgroup0 is the top-level cgroup, cgroup1 and cgroup2 are the first-level cgroups, and cgroup3, cgroup4, and cgroup5 are the second-level cgroups. The next level of cgroup1 is cgroup3, and the next level of cgroup2 is cgroup4 and cgroup5.
[0039] For a control group user with top-level permissions, the control group user can use cgroup0, cgroup1, cgroup2, cgroup3, cgroup4, and cgroup5; for a control group user with first-level permissions, the control group user can only use cgroup1, cgroup2, cgroup3, cgroup4, and cgroup5, but cannot use cgroup0; for a control group user with second-level permissions, the control group user can only use cgroup3, cgroup4, and cgroup5, but cannot use cgroup0, cgroup1, and cgroup2; and so on.
[0040] The control group mechanism provides a control group virtual file system as a user interface for performing group management and setting various resource subsystems. If you want to use the control group mechanism, you must mount the control group virtual file system to specify the resource subsystem to be used through the mount option.
[0041] The control group virtual file system allows the control group to be presented to the control group user in the form of a file directory. For example, the directory / sys / fs / cgroup / cpu / k8s.io / can represent a control group named k8s.io for controlling CPU resources; the directory / sys / fs / cgroup / mem / k8s.io / pod / can represent a control group named pod for controlling memory resources, and the upper level of the control group is a control group named k8s.io for controlling memory resources. In this case, the control group user can use the control group based on the file directory corresponding to the control group to be used or the name of the control group.
[0042] In actual applications, containers are widely used in both the cloud and the intranet. Container technology is a kernel-lightweight virtualization technology at the operating system layer. Common container technologies usually include Docker, Kubernetes, CoreOS, etc. Taking Docker as an example, Docker is an open source application container engine that allows the application files and the dependent files corresponding to the application to be packaged into a portable image, and the image can be published to any device running the Linux operating system or Windows operating system to achieve virtualization.
[0043] For containers, containers are relatively independent operating environments. Containers completely use the sandbox mechanism, and there are no interfaces between them. In addition, within the container, the impact on the outside world should be minimized, for example: resource control for the container, that is, the host cannot use all the resources in the container.
[0044] The container contains a complete operating environment. In addition to the application files contained in the application itself, the dependent files required to run the application can be packaged into the image. By packaging the application itself and its dependencies, the underlying operating system and related environment can be abstracted.
[0045] Containers have an independent file system. Because containers use system resources, there is no need to have kernel-related code or tools in an independent file system. As long as the set of files in the image is available, the container created based on the image can run.
[0046] Based on this, users can write code to implement specific functions and generate applications based on these codes. The application can run in a container that is completely managed by the platform located in the cloud or on the intranet.
[0047] In the related technologies, there is a high demand for concurrent creation and startup of containers. For containers running in Linux hosts, these container resources are usually managed based on the control group mechanism; for example, the size of the CPU and memory that each container can use is limited. In other words, it is usually necessary to create a control group for each container.
[0048] However, concurrent creation of control groups is usually not possible. When implementing the control group mechanism, the Linux operating system kernel sets a global lock for each subsystem, which makes it impossible for the kernel to create control groups in parallel, but only in serial. Therefore, creating multiple control groups takes a long time and is inefficient, which affects the business performance of the container.
[0049] The present specification proposes a technical solution for control group management, in which a user-state process can determine whether a first number of control groups requested for allocation by a control group user is greater than a second number of available control groups corresponding to the control group user in a control group pool maintained by the user-state process; if the first number is not greater than the second number, the user-state process can directly allocate the first number of available control groups from the control group pool to the control group user; if the first number is greater than the second number, the user-state process can call a kernel to create, by the kernel, available control groups corresponding to the control group user whose number is the difference between the first number and the second number, so that the user-state process can first add the available control groups created by the kernel to the control group pool, and then allocate the first number of available control groups from the control group pool to the control group user.
[0050] In a specific implementation, the user state process may obtain an allocation request sent by the control group user for requesting the allocation of a control group. The allocation request may include the number of control groups that the control group user needs to use (hereinafter referred to as the first number). For the control group user, the control group that it needs to use is part or all of the available control groups corresponding to it.
[0051] The user state process may maintain a control group pool. When the user state process obtains the allocation request, it may respond to the allocation request. Specifically, the user state process may first determine the available control groups corresponding to the control group users in the control group pool it maintains, and count the number of available control groups (hereinafter referred to as the second number). Subsequently, the user state process may determine whether the first number is greater than the second number.
[0052] If the first number is not greater than the second number, the user-mode process may determine a first number of available control groups from the control group pool, and allocate the first number of available control groups to the control group user for use by the control group user.
[0053] If the first number is greater than the second number, the user-mode process may call the kernel so that the kernel continues to create available control groups corresponding to the control group user; at this time, the number of available control groups continued to be created by the kernel (hereinafter referred to as the third number) may be the difference between the first number and the second number. Further, the user-mode process may add the third number of available control groups created by the kernel to the control group pool, and allocate the first number of available control groups from the updated control group pool to the control group user for use by the control group user.
[0054] By adopting the above method, on the one hand, since the user-state process can record the control groups created by the kernel through the maintained control group pool and allocate control groups to the control group users from the control group pool, the kernel can create control groups for the control group users in advance and avoid the need to create control groups concurrently. On the other hand, since the process for maintaining the control group pool is a user-state process and not in the kernel, it is convenient to maintain the process and the impact of abnormalities in the process can be reduced.
[0055] Please refer to Figure 2 , Figure 2 It is a hardware architecture diagram of a control group management system shown in an exemplary embodiment of this specification.
[0056] like Figure 2 As shown, the control group management system may include a network 20, a server 21, and several electronic devices, such as a computer 22, a computer 23, and the like.
[0057] The server 21 may be a physical server including an independent host, or the server 21 may be a virtual server, a cloud server, etc. hosted by a host cluster. Computers 22 to 23 are just one type of electronic device that a user may use. In fact, a user may also use electronic devices such as tablet devices, laptops, PDAs (Personal Digital Assistants), wearable devices (such as smart glasses, smart watches, etc.), etc., and one or more embodiments of this specification do not limit this. The network 20 may include various types of wired or wireless networks.
[0058] In actual applications, the user can request the server 21 to allocate a control group through a process running on the computers 22 to 23, and use the allocated control group. Alternatively, the user can also directly request the server 21 to allocate a control group through a process running on the server 21, and use the allocated control group. The process is the execution process of the application. In this specification, the user and the process can be collectively referred to as the control group user.
[0059] Please refer to Figure 3 , Figure 3 It is a flowchart of a control group management method shown in an exemplary embodiment of this specification.
[0060] The control group management method described above can be applied to Figure 2 The server 22 is shown. Alternatively, the control group management method can also be applied to any electronic device running a Linux operating system.
[0061] For the Linux operating system, its architecture can be divided into user state and kernel state. The kernel is essentially a software that can control the hardware resources of the computer and provide an environment for the upper-level applications to run. The user state is the activity space of the upper-level applications. The execution of the upper-level applications must rely on the resources provided by the kernel (for example: CPU, memory, I / O, etc.). In order for the upper-level applications to access these resources, the kernel can provide an access interface for the upper-level applications, namely the system call function.
[0062] The system call function is the smallest functional unit of the operating system and can be expanded and tailored according to different application scenarios. Library functions can encapsulate the system call function and present a simple business logic interface to the user for easy user calls. Shell is a special application, commonly known as the command line. It is essentially a command interpreter that allows different programs to work together with a clear interface, thereby enhancing the functions of each program. At the same time, the shell is programmable. It can execute text that conforms to the shell syntax. This kind of text is called a shell script. Shell scripts can also encapsulate the system call function. That is, user-mode applications can access the kernel in three ways: native system call functions, library functions, and shell scripts.
[0063] In this embodiment, the control group management method can be implemented through data interaction between the control group user, the user state process, and the kernel. The user state process is the execution process of the user state application program.
[0064] The control group management method may include the following steps:
[0065] Step 301: The user state process obtains an allocation request sent by a control group user; the allocation request includes a first number of available control groups corresponding to the control group user.
[0066] In this embodiment, the user state process may obtain an allocation request sent by the control group user for requesting the allocation of a control group. The allocation request may include the number of control groups that the control group user needs to use (hereinafter referred to as the first number). For the control group user, the control group that it needs to use is part or all of the control groups that can be used corresponding to it.
[0067] In one embodiment shown, the usable control group may be a control group belonging to one or more control group levels (hereinafter referred to as target control group levels). The target control group level may specifically be a control group level specified by the control group user. The control group user may specify the target control group level according to the control group level authority it has.
[0068] In practical applications, the control group user may send the allocation request to the user state process in an interprocess communication (IPC) manner.
[0069] Step 302: The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process.
[0070] In this embodiment, the user mode process may maintain a control group pool, wherein the control group pool may be used to record the control groups created by the kernel.
[0071] In actual applications, when creating any control group, the kernel may allocate resources to the control group and assign an initial name to the control group. Since the control group is usually displayed in the form of a file directory, in this case, the control group pool may be specifically used to record the file directory corresponding to the control group created by the kernel, and the file directory contains the name of the control group.
[0072] It should be noted that the initial name assigned by the above kernel to the created control group can be a random placeholder. That is, the name contained in the file directory corresponding to the control group recorded in the above control group pool can be a random placeholder. After any control group is assigned to the above control group user, the control group user can rename the control group according to actual needs, that is, change the name of the control group from a random placeholder to specific characters, and at this time, the name contained in the file directory corresponding to the control group is also updated from the random placeholder to the specific characters.
[0073] When the user state process obtains the allocation request, it can respond to the allocation request. Specifically, the user state process can first determine the available control groups corresponding to the control group users in the control group pool it maintains, and count the number of available control groups (hereinafter referred to as the second number). Subsequently, the user state process can determine whether the first number is greater than the second number.
[0074] Step 303: If the first number is not greater than the second number, the user state process allocates the first number of available control groups from the control group pool to the control group users.
[0075] In this embodiment, if the first number is not greater than the second number, it means that the kernel has created enough available control groups corresponding to the control group users. In this case, the user mode process can determine the first number of available control groups from the control group pool, and allocate the first number of available control groups to the control group users for use by the control group users.
[0076] In practical applications, when determining the first number of available control groups from the control group pool, the first number of control groups can be randomly selected from all available control groups in the control group pool. When allocating the first number of available control groups to the control group users, a file directory corresponding to the first number of available control groups can be provided to the control group users, so that the control group users can use the first number of available control groups based on the file directory.
[0077] Step 304: If the first number is greater than the second number, the user state process calls the kernel to enable the kernel to create a third number of the usable control groups, where the third number is the difference between the first number and the second number. The user state process adds the third number of the usable control groups to the control group pool, and allocates the first number of the usable control groups from the control group pool to the control group users.
[0078] In this embodiment, if the first number is greater than the second number, it means that the kernel has not yet created enough available control groups corresponding to the control group users. In this case, the user mode process may call the kernel so that the kernel continues to create available control groups corresponding to the control group users; at this time, the number of available control groups continued to be created by the kernel (hereinafter referred to as the third number) may be the difference between the first number and the second number.
[0079] Furthermore, the user-mode process may add the third number of available control groups created by the kernel to the control group pool, and allocate the first number of available control groups from the updated control group pool to the control group user for use by the control group user.
[0080] In actual applications, when the third number of available control groups is added to the control group pool, the file directories corresponding to the third number of available control groups may be added to the control group pool.
[0081] For example, suppose that the control group user requests to allocate M1 control groups through the allocation request; suppose that there are N1 available control groups corresponding to the control group user in the control group pool maintained by the user state process. That is, the first number is M1, and the second number is N1. In this case, the user state process can first compare the sizes of M1 and N1.
[0082] If M1≤N1, the user-mode process may determine M1 available control groups from the N1 available control groups in the control group pool, and allocate the M1 available control groups to the control group users.
[0083] If M1>N1, the user-mode process may call the kernel so that the kernel continues to create X1 (X1=M1-N1, i.e., the third number is X1) usable control groups corresponding to the control group user. Further, the user-mode process may add the X1 usable control groups to the control pool, and allocate M1 usable control groups from the updated control group pool to the control group user, i.e., allocate the X1 usable control groups and the N1 usable control groups (X1+N1=M1) together to the control group user.
[0084] In one embodiment shown, the control group user may send a rename request to the kernel when the first number of available control groups is allocated, wherein the rename request may include a name corresponding to the available control group (hereinafter referred to as a target name).
[0085] When the kernel receives the rename request, it may respond to the rename request. Specifically, the kernel may rename the name of the available control group to the target name. In this case, the control group user may use the available control group based on the target name.
[0086] In one embodiment shown, the control group user may send a release request for the usable control group to the kernel when the use of the usable control group is completed.
[0087] When the kernel obtains the release request, it may respond to the release request. Specifically, the kernel may release the resources corresponding to the usable control group.
[0088] In one embodiment shown, the control group user may, before requesting the user mode process to allocate a control group, request the user mode process to reserve control groups sufficient for the control group user, so that the kernel may pre-create control groups sufficient for the control group user, thereby further improving the subsequent control group allocation efficiency.
[0089] Please refer to Figure 4 , Figure 4 It is a flowchart of another control group management method shown in an exemplary embodiment of this specification.
[0090] With Figure 3 Similar to the embodiment shown in the figure, the above control group management method can also be applied to Figure 2 The server 22 is shown. Alternatively, the control group management method can also be applied to any electronic device running a Linux operating system.
[0091] The control group management method may include the following steps:
[0092] Step 401: The user state process obtains configuration information sent by the control group user; the configuration information includes the fourth number of the usable control groups.
[0093] In this embodiment, the user state process may obtain the configuration information sent by the control group user for requesting to reserve the control group, wherein the configuration information may include the number of available control groups corresponding to the control group user that needs to be reserved (hereinafter referred to as the fourth number).
[0094] In one embodiment shown, the configuration information sent by the control group user may be a control group configuration file submitted by the control group user. For example, when the usable control group is a control group belonging to the target control group level, the control group user may create the control group configuration file for the upper level of the target control group level in a file directory corresponding to the control group of the upper level, so that the user-mode process may obtain the control group configuration file in the file directory.
[0095] Alternatively, the configuration information sent by the control group user may specifically be a configuration request sent by the control group user in an inter-process communication manner.
[0096] Step 402: The user mode process determines whether the fourth number is greater than the second number.
[0097] In this embodiment, when the above-mentioned user-state process obtains the above-mentioned configuration information, it can first determine the usable control groups corresponding to the above-mentioned control group users in the control group pool it maintains, and count the number of the usable control groups (that is, the above-mentioned second number). Subsequently, the user-state process can determine whether the above-mentioned fourth number is greater than the second number.
[0098] Step 403: If the fourth number is greater than the second number, the user state process calls the kernel to enable the kernel to create a fifth number of the usable control groups, where the fifth number is the difference between the fourth number and the second number, and the user state process adds the fifth number of the usable control groups to the control group pool.
[0099] In this embodiment, if the fourth number is greater than the second number, it means that the kernel has not yet created enough available control groups corresponding to the control group users, so the user-mode process cannot reserve enough available control groups. In this case, the user-mode process can call the kernel so that the kernel continues to create available control groups corresponding to the control group users; at this time, the number of available control groups continued to be created by the kernel (hereinafter referred to as the fifth number) can be the difference between the fourth number and the second number.
[0100] Furthermore, the user mode process may add the fifth number of available control groups created by the kernel to the control group pool. At this time, the number of available control groups recorded in the control group pool is the fourth value.
[0101] In actual applications, when adding the fifth number of available control groups to the control group pool, the file directories corresponding to the fifth number of available control groups may be added to the control group pool.
[0102] In one embodiment shown, if the fourth number is not greater than the second number, it means that the kernel has created enough available control groups corresponding to the control group users, so the user-mode process can reserve enough available control groups. In this case, in order to save resources, the user-mode process can determine the fifth number of available control groups from the control group pool and delete the fifth number of available control groups. In addition, the user-mode process can also call the kernel so that the kernel releases the resources corresponding to the fifth number of control groups.
[0103] In actual applications, when the fifth number of available control groups is determined from the control group pool, the fifth number of control groups can be randomly selected from all available control groups in the control group pool. When the fifth number of available control groups is deleted, the file directory corresponding to the fifth number of available control groups can be deleted.
[0104] For example, assuming that the control group user requests to reserve M2 control groups through the configuration information; assuming that there are a total of N2 available control groups corresponding to the control group user in the control group pool maintained by the user-mode process. That is, the fourth number is M2, and the second number is N2. In this case, the user-mode process can first compare the sizes of M2 and N2.
[0105] If M2>N2, the user state process may call the kernel so that the kernel continues to create X2 (X2=M2-N2, i.e., the fifth number is X2) usable control groups corresponding to the user of the control group. Further, the user state process may add the X2 usable control groups to the control pool. That is, the updated control group pool includes the X2 usable control groups and the N2 usable control groups (X2+N2=M2).
[0106] If M2≤N2, the user-mode process may delete X2 available control groups from the N2 available control groups in the control group pool, and call the kernel so that the kernel releases resources corresponding to the X2 available control groups.
[0107] In an embodiment shown, the configuration information may further include a control group status, wherein the control group status may be used to indicate whether the control group is a shared control group.
[0108] The user state process can determine whether the available control group is a shared control group based on the control group state in the configuration information when detecting that the communication with the control group user ends. If not, it means that the available control group can only be used by the control group user, and the control group user no longer needs to use the available control group. Therefore, the user state process can delete the available control group and call the kernel to make the kernel release the resources corresponding to the available control group.
[0109] In an embodiment shown, in order to ensure that sufficient control groups can be provided to the control group user at any time, the user state process can also periodically determine whether the fourth number is greater than the second number according to a preset time period. The specific value of the time period can be preset by the user or can be a default value, which is not limited in this specification.
[0110] It should be noted that the second number is the number of available control groups corresponding to the control group users in the current control group pool, that is, the second number is actually a variable value, not a fixed value.
[0111] If the fourth number is greater than the second number, the user-mode process may call the kernel to allow the kernel to continue to create available control groups corresponding to the control group user; at this time, the number of available control groups continued to be created by the kernel is the fifth number. Further, the user-mode process may add the fifth number of available control groups created by the kernel to the control group pool.
[0112] If the fourth number is not greater than the second number, in order to save resources, the user-state process may determine the fifth number of available control groups from the control group pool and delete the fifth number of available control groups. In addition, the user-state process may also call the kernel so that the kernel releases the resources corresponding to the fifth number of control groups.
[0113] Please refer to Figure 5 , Figure 5 It is a flowchart of another control group management method shown in an exemplary embodiment of this specification.
[0114] The control group management method may include the following steps:
[0115] Step 501: The control group user sends configuration information to the user mode process; the configuration information includes the fourth number of the available control groups.
[0116] Step 502: The user-mode process determines whether the fourth number is greater than the second number; if so, execute steps 503-506; if not, execute steps 507-509.
[0117] Step 503: The user mode process calls the kernel.
[0118] Step 504: The kernel creates a fifth number of the usable control groups, where the fifth number is a difference between the fourth number and the second number.
[0119] Step 505: The kernel returns the fifth number of the available control groups to the user mode process.
[0120] Step 506: The user mode process adds the fifth number of the available control groups to the control group pool.
[0121] Step 507: The user mode process deletes the fifth number of the available control groups from the control group pool.
[0122] Step 508: The user mode process calls the kernel.
[0123] Step 509: The kernel releases resources corresponding to the fifth number of the usable control groups.
[0124] Step 510: The user state process periodically determines whether the fourth number is greater than the second number according to a preset time period. If yes, execute steps 511-514; if not, execute steps 515-517.
[0125] Step 511: The user mode process calls the kernel.
[0126] Step 512: The kernel creates the fifth number of the usable control groups.
[0127] Step 513: The kernel returns the fifth number of the available control groups to the user mode process.
[0128] Step 514: The user mode process adds the fifth number of the available control groups to the control group pool.
[0129] Step 515: The user mode process deletes the fifth number of the available control groups from the control group pool.
[0130] Step 516: The user mode process calls the kernel.
[0131] Step 517: The kernel releases resources corresponding to the fifth number of the usable control groups.
[0132] like Figure 5 The specific implementation of the embodiment shown can refer to Figure 4 The embodiments shown in the specification will not be described in detail here.
[0133] Please refer to Figure 6 , Figure 6 It is a flowchart of another control group management method shown in an exemplary embodiment of this specification.
[0134] The control group management method may include the following steps:
[0135] Step 601: The control group user sends an allocation request to the user mode process; the allocation request includes a first number of usable control groups corresponding to the control group user.
[0136] Step 602: The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process. If not, execute step 603; if yes, execute steps 604-608.
[0137] Step 603: The user state process allocates the first number of available control groups from the control group pool to the control group users.
[0138] Step 604: The user mode process calls the kernel.
[0139] Step 605: The kernel creates a third number of the usable control groups, where the third number is the difference between the first number and the second number.
[0140] Step 606: The kernel returns the third number of the available control groups to the user mode process.
[0141] Step 607: The user mode process adds the third number of available control groups to the control group pool.
[0142] Step 608: The user-mode process allocates the first number of available control groups from the control group pool to the control group users.
[0143] Step 609: After being allocated the usable control group, the control group user sends a renaming request to the kernel; the renaming request includes a target name corresponding to the usable control group.
[0144] Step 610: The kernel renames the name of the usable control group to the target name, so that the control group user uses the usable control group based on the target name.
[0145] Step 611: After completing the use of the available control group, the control group user sends a release request for the available control group to the kernel.
[0146] Step 612: The kernel releases the resources corresponding to the usable control group.
[0147] Step 613: When the user state process detects that the communication with the control group user ends, the user state process determines whether the usable control group is a shared control group based on the control group state in the configuration information. If not, execute steps 614-616.
[0148] Step 614: The user mode process deletes the available control group from the control group pool.
[0149] Step 615: The user mode process calls the kernel.
[0150] Step 616: The kernel releases the resources corresponding to the usable control group.
[0151] like Figure 6 The specific implementation of the embodiment shown can refer to Figure 3 The embodiments shown in the specification will not be described in detail here.
[0152] In the above technical solution, the user-state process can determine whether the first number of control groups requested for allocation by the control group user is greater than the second number of available control groups corresponding to the control group user in the control group pool maintained by the user-state process. If the first number is not greater than the second number, the user-state process can directly allocate the first number of available control groups from the control group pool to the control group user. If the first number is greater than the second number, the user-state process can call the kernel to create a number of available control groups corresponding to the control group user that is the difference between the first number and the second number, so that the user-state process can first add the available control groups created by the kernel to the control group pool, and then allocate the first number of available control groups from the control group pool to the control group user.
[0153] By adopting the above method, on the one hand, since the user-state process can record the control groups created by the kernel through the maintained control group pool and allocate control groups to the control group users from the control group pool, the kernel can create control groups for the control group users in advance and avoid the need to create control groups concurrently. On the other hand, since the process for maintaining the control group pool is a user-state process and not in the kernel, it is convenient to maintain the process and the impact of abnormalities in the process can be reduced.
[0154] Corresponding to the above-mentioned embodiment of the control group management method, this specification also provides an embodiment of the control group management system.
[0155] The control group management system of this specification can be applied to electronic devices. The system embodiment can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a system in a logical sense, it is formed by the processor of the electronic device in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, such as Figure 7 The figure is a hardware structure diagram of the electronic device where the control group management system of this manual is located, except Figure 7In addition to the processor, memory, network interface, and non-volatile memory shown, the electronic device where the system is located in the embodiment may also include other hardware according to the actual functions managed by the control group, which will not be described in detail.
[0156] Please refer to Figure 8 , Figure 8 It is a block diagram of a control group management system shown as an exemplary embodiment of this specification.
[0157] The control group management system described above can be run on Figure 7 The electronic device shown includes a user mode process and a kernel;
[0158] The user state process and the kernel are used for:
[0159] The user state process obtains an allocation request sent by a control group user; the allocation request includes a first number of control groups that can be used corresponding to the control group user;
[0160] The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process;
[0161] If the first number is not greater than the second number, the user state process allocates the first number of available control groups from the control group pool to the control group user;
[0162] If the first number is greater than the second number, the user state process calls the kernel to enable the kernel to create a third number of the usable control groups, where the third number is the difference between the first number and the second number. The user state process adds the third number of the usable control groups to the control group pool, and allocates the first number of the usable control groups from the control group pool to the control group users.
[0163] Optionally, the user state process and the kernel are further used for:
[0164] The user state process obtains configuration information sent by the control group user; the configuration information includes the fourth number of the usable control groups;
[0165] Determining, by the user state process, whether the fourth number is greater than the second number;
[0166] If the fourth number is greater than the second number, the user state process calls the kernel to enable the kernel to create a fifth number of the usable control groups, where the fifth number is the difference between the fourth number and the second number, and the user state process adds the fifth number of the usable control groups to the control group pool.
[0167] Optionally, the user state process and the kernel are further used for:
[0168] If the fourth number is not greater than the second number, the user state process deletes the fifth number of available control groups from the control group pool and calls the kernel to enable the kernel to release resources corresponding to the fifth number of available control groups.
[0169] Optionally, the configuration information further includes a control group status; the control group status is used to indicate whether the usable control group is a shared control group;
[0170] The user mode process and the kernel are also used for:
[0171] When the user state process detects that the communication with the control group user ends, the user state process determines whether the usable control group is a shared control group based on the control group state;
[0172] If the usable control group is not a shared control group, the user state process deletes the usable control group from the control group pool, and calls the kernel to enable the kernel to release resources corresponding to the usable control group.
[0173] Optionally, the user state process and the kernel are further used for:
[0174] The user state process periodically determines whether the fourth number is greater than the second number according to a preset time period;
[0175] If the fourth number is greater than the second number, the user state process calls the kernel to cause the kernel to create the fifth number of the usable control groups, and the user state process adds the fifth number of the usable control groups to the control group pool.
[0176] Optionally, the user state process and the kernel are further used for:
[0177] If the fourth number is not greater than the second number, the user state process deletes the fifth number of available control groups from the control group pool and calls the kernel to enable the kernel to release resources corresponding to the fifth number of available control groups.
[0178] Optionally, the configuration information sent by the control group user includes: a control group configuration file submitted by the control group user; or a configuration request sent by the control group user in an inter-process communication manner.
[0179] Optionally, the user state process and the kernel are further used for:
[0180] The kernel obtains a renaming request sent by the control group user after being assigned the available control group; the renaming request includes a target name corresponding to the available control group;
[0181] The kernel renames the name of the usable control group into the target name, so that the control group user uses the usable control group based on the target name.
[0182] Optionally, the user state process and the kernel are further used for:
[0183] The kernel obtains a release request for the available control group sent by the control group user after the user of the available control group completes the use of the available control group;
[0184] The kernel releases the resources corresponding to the usable control group.
[0185] Optionally, the usable control group is a control group belonging to a target control group level; the target control group level is a control group level specified by the control group user.
[0186] The system embodiment basically corresponds to the method embodiment, so for the relevant parts, please refer to the partial description of the method embodiment.
[0187] The system embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the technical solution of this specification.
[0188] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0189] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0190] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0191] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0192] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0193] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0194] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0195] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0196] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A control group management method, the method comprising: The user-mode process obtains the allocation request sent by the control group user; The allocation request includes a first number of available control groups corresponding to the control group user; The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process; If the first number is not greater than the second number, the user state process allocates the first number of available control groups from the control group pool to the control group user; If the first number is greater than the second number, the user state process calls the kernel to enable the kernel to create a third number of the usable control groups, where the third number is the difference between the first number and the second number. The user state process adds the third number of the usable control groups to the control group pool, and allocates the first number of the usable control groups from the control group pool to the control group users.
2. The method according to claim 1, further comprising: The user state process obtains the configuration information sent by the control group user; The configuration information includes a fourth number of the available control groups; Determining, by the user state process, whether the fourth number is greater than the second number; If the fourth number is greater than the second number, the user state process calls the kernel to enable the kernel to create a fifth number of the usable control groups, where the fifth number is the difference between the fourth number and the second number, and the user state process adds the fifth number of the usable control groups to the control group pool.
3. The method according to claim 2, further comprising: If the fourth number is not greater than the second number, the user state process deletes the fifth number of available control groups from the control group pool and calls the kernel to enable the kernel to release resources corresponding to the fifth number of available control groups.
4. The method according to claim 2, wherein the configuration information further comprises a control group status; the control group status is used to indicate whether the usable control group is a shared control group; The method further comprises: When the user state process detects that the communication with the control group user ends, the user state process determines whether the usable control group is a shared control group based on the control group state; If the usable control group is not a shared control group, the user state process deletes the usable control group from the control group pool, and calls the kernel to enable the kernel to release resources corresponding to the usable control group.
5. The method according to claim 2, further comprising: The user state process periodically determines whether the fourth number is greater than the second number according to a preset time period; If the fourth number is greater than the second number, the user state process calls the kernel to cause the kernel to create the fifth number of the usable control groups, and the user state process adds the fifth number of the usable control groups to the control group pool.
6. The method according to claim 5, further comprising: If the fourth number is not greater than the second number, the user state process deletes the fifth number of available control groups from the control group pool and calls the kernel to enable the kernel to release resources corresponding to the fifth number of available control groups.
7. According to the method of claim 2, the configuration information sent by the control group user includes: The control group configuration file submitted by the control group user; Alternatively, the control group user sends the configuration request in an inter-process communication manner.
8. The method according to claim 1, further comprising: The kernel obtains a renaming request sent by the control group user after being allocated the usable control group; The rename request includes a target name corresponding to the available control group; The kernel renames the name of the usable control group into the target name, so that the control group user uses the usable control group based on the target name.
9. The method according to claim 1, further comprising: The kernel obtains a release request for the available control group sent by the control group user after the user of the available control group completes the use of the available control group; The kernel releases the resources corresponding to the usable control group.
10. According to the method described in any one of claims 1 to 9, the usable control group is a control group belonging to a target control group level; the target control group level is a control group level specified by the control group user.
11. A control group management system, the system comprising a user state process and a kernel; The user state process and the kernel are used for: The user state process obtains an allocation request sent by a control group user; the allocation request includes a first number of control groups that can be used corresponding to the control group user; The user state process determines whether the first number is greater than a second number; the second number is the number of available control groups in the control group pool maintained by the user state process; If the first number is not greater than the second number, the user state process allocates the first number of available control groups from the control group pool to the control group user; If the first number is greater than the second number, the user state process calls the kernel to enable the kernel to create a third number of the usable control groups, where the third number is the difference between the first number and the second number. The user state process adds the third number of the usable control groups to the control group pool, and allocates the first number of the usable control groups from the control group pool to the control group users.
12. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 10 by running the executable instructions.
13. A computer-readable storage medium having computer instructions stored thereon, wherein the instructions are executed by a processor to implement the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Cloud computing method
CN107133099A
Computing resource determination method and device, electronic equipment and medium
CN111078404A