Container resource view isolation method and device, storage medium and program product
By mounting a kernel monitoring program on the resource control group of the container, the resource information is obtained from the kernel space, and the problem of container resource view isolation delay is solved, and the process in the container only obtains its own resource information, improving the accuracy of resource management and System stability.
Patent Information
- Application Number
- CN202411396829.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-10-08
AI Technical Summary
The existing container resource view isolation scheme has a long processing delay, which causes the container to be unable to accurately obtain its own resource information, affecting the accuracy of resource management and monitoring.
By mounting a kernel monitoring program on the resource control group associated with the target container, obtaining resource information from the kernel space, and determining the resource view information of the container based on this information, providing it to the target process, realizing the resource view isolation and avoiding user space and kernel Interaction of space.
Reduces the processing delay of container resource view isolation, ensures that processes in the container can only obtain their own resource information, and improves the accuracy of resource management and system stability.
Smart Images

Figure CN118898065A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, storage medium and program product for isolating container resource views. Background Art
[0002] Containers are a lightweight virtualization technology that creates an independent operating environment by isolating applications and their dependencies. Containers share the host's operating system kernel instead of simulating the entire operating system like a virtual machine. This makes containers very lightweight and quick to start.
[0003] In actual applications, the process in the container needs to perform some operations based on the resource information allocated to the container. For example, the container needs to initialize resources based on the amount of resources allocated to the container. This requires the container to be able to obtain its own resource view. Therefore, it is necessary to implement the isolation of container resource views so that the container can only obtain its own resource view. However, the processing delay of the existing container resource view isolation solution is relatively long. Summary of the invention
[0004] Multiple aspects of the present application provide a method, device, storage medium, and program product for isolating container resource views, so as to reduce the processing delay of isolating container resource views.
[0005] The present application embodiment provides a method for isolating a container resource view, including: When the target process in the target container reads the kernel interface, triggering the first kernel monitoring program mounted on the target resource control group to run; the kernel interface is located in the electronic device where the target container is deployed; the target resource control group is the resource control group associated with the target container; Acquiring resource information associated with the target container from the kernel space of the electronic device through the first kernel monitoring program; Determining resource view information of the target container according to resource information associated with the target container through the first kernel monitoring program; The resource view information is provided to the target process through the first kernel monitoring program.
[0006] The embodiment of the present application further provides an electronic device, comprising: a memory and a processor; wherein the memory is used to store a computer program; The processor is coupled to the memory and is configured to execute the computer program to perform the steps of the above-mentioned container resource view isolation method.
[0007] The embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps of the above-mentioned container resource view isolation method.
[0008] An embodiment of the present application further provides a computer program product, including a computer program, which, when executed by one or more processors, causes the one or more processors to execute the steps of the above-mentioned container resource view isolation method.
[0009] In an embodiment of the present application, the resource information associated with the target container is obtained from the kernel space through the kernel monitoring program mounted on the target resource control group associated with the target container, and the resource view information of the target container is determined by the kernel monitoring program based on the resource information associated with the target container, and the resource view information of the target container can be provided to the target process, thereby realizing the isolation of the resource view of the target container, so that the process in the target container can only know the resource information of the target container itself. Among them, the kernel monitoring program is set in the kernel space, and the resource information associated with the target container can be directly obtained from the kernel space, so that when obtaining the resource information associated with the target container, there is no need for the user space to interact with the kernel space. Therefore, the isolation method of the container resource view provided in the embodiment of the present application can reduce the processing delay. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 A schematic diagram of a process for isolating a container resource view provided in an embodiment of the present application; Figure 2 A schematic diagram of a flow chart of another method for isolating a container resource view provided in an embodiment of the present application; Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0011] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. 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 making creative work are within the scope of protection of the present application.
[0012] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0013] The following is an explanation of the terms or concepts involved in the embodiments of the present application.
[0014] Resource Control Group (Cgroup): Cgroup is a mechanism provided by the kernel of the operating system for resource management and control of process groups. It can limit, record and isolate the physical resources used by process groups. Physical resources may include processor resources, memory resources and disk input / output (I / O) resources. It allows system administrators or process schedulers to assign processes to different resource control groups (Cgroups) and then set resource limits, priorities or accounting for these resource control groups. Cgroup is one of the core components of container technology. Cgroup can improve resource utilization and isolation in server and container environments, and is one of the foundations for implementing lightweight virtualization technology.
[0015] Extended Berkeley Packet Filter (eBPF): eBPF is a programmable technology built into the kernel of an operating system (such as Linux) that can be used for network packet filtering. It has been extended to support a wide range of kernel event tracing and system monitoring functions. Compared with traditional BPF, eBPF provides more powerful and flexible programming capabilities, allowing users to write secure execution programs (i.e., eBPF programs) in kernel space. These programs can be triggered when specific events occur (such as system calls, network packet arrival, etc.) without modifying the kernel source code or loading kernel modules. eBPF has a wide range of applications, including network performance analysis, security monitoring, and tracing diagnosis.
[0016] Container resource view: Container resource view refers to a resource abstraction presented by the container management system to the internal process of the container. This abstraction describes the resource status that the container can see and use. The role of the resource view is to provide a clear, consistent and controllable resource usage environment for the container. Through the resource view, you can implement functions such as resource limitation, isolation, metering, monitoring, optimization and scheduling, thereby ensuring the stable operation of the container, efficient use of resources, and the overall performance and service quality of the system.
[0017] In some container scenarios, applications in the container directly access the system resource files of the host (such as " / proc / meminfo", " / proc / cpuinfo", etc.), so the applications in the container see the resource status of the entire host, rather than the amount of resources allocated or restricted to the container. This may lead to misunderstandings or wrong decisions when managing and monitoring resources. For example, when a container needs to initialize resources based on the amount of resources allocated to the container, the container perceives the resource information of the entire host, which will cause the resource pool initialized by the container to be too large. This requires isolation of container resource views so that the container can only obtain its own resource view.
[0018] In order to achieve container resource view isolation, some solutions have proposed the Linux Container File System (LXCFS) solution. Among them, LXCFS is a lightweight file system designed specifically for Linux containers. Its main purpose is to improve the resource statistics and restriction functions within the container. By providing a virtual file system layer, applications running in the container can see the resource restriction information set by the host for the container, such as the central processing unit (CPU), memory usage, etc.
[0019] Without LXCFS, applications in the container directly access the host's system resource files (such as " / proc / meminfo", " / proc / cpuinfo", etc.), so they see the resource status of the entire host, rather than the amount of resources allocated or limited to the container. This may lead to misunderstandings or wrong decisions when managing and monitoring resources.
[0020] LXCFS can isolate the container's resource view. Specifically, LXCFS simulates a portion of the " / proc" file system related to resources inside the container, such as the " / proc / meminfo" file system and the " / proc / cpuinfo" file system. When processes in the container try to access these files, they actually see data that has been "processed" by LXCFS. These data show the resources allocated to the container rather than the global resources of the host.
[0021] LXCFS complies with Cgroups limits. Specifically, LXCFS is tightly integrated with Cgroups to ensure that the resource information displayed to the container's application matches the resource limits set by Cgroups. This means that if a container's CPU share or memory usage is limited via Cgroups, LXCFS ensures that these limits are correctly reflected inside the container.
[0022] LXCFS improves container isolation. By providing this isolation of resource views, LXCFS enhances container isolation, making the applications in the container feel like they are running on an independent system, which is very important for achieving more precise resource management and control, especially in a multi-tenant environment.
[0023] However, LXCFS implements container resource view isolation based on the Filesystem in Userspace (FUSE) system. FUSE is a mechanism that allows non-privileged users to create custom file systems. FUSE allows developers to implement file system logic in user space without modifying kernel code or writing kernel modules. However, the isolation scheme of container resource views based on the FUSE system requires interaction between user space and kernel space when isolating container resource views. For example, FUSE is a file system implemented in user space, and each access to the FUSE file system requires context switching between user space and kernel space, which results in a long processing delay in implementing container resource view isolation.
[0024] In some embodiments of the present application, in order to reduce the processing delay of container resource view isolation, the kernel monitoring program mounted on the target resource control group associated with the target container obtains the resource information associated with the target container from the kernel space, and the kernel monitoring program determines the resource view information of the target container based on the resource information associated with the target container, and the resource view information of the target container can be provided to the target process, thereby realizing the isolation of the resource view of the target container, so that the process in the target container can only know the resource information of the target container itself. Among them, the kernel monitoring program is set in the kernel space, and the resource information associated with the target container can be directly obtained from the kernel space, so that when obtaining the resource information associated with the target container, there is no need for the user space to interact with the kernel space. Therefore, the isolation method of the container resource view provided in the embodiment of the present application can reduce the processing delay.
[0025] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0026] It should be noted that the same reference numerals denote the same objects in the following drawings and embodiments, and therefore, once an object is defined in one drawing or embodiment, it does not need to be further discussed in the subsequent drawings and embodiments.
[0027] Figure 1 A flow chart of a method for isolating a container resource view provided in an embodiment of the present application. Figure 1 As shown, the container resource view isolation method mainly includes the following steps: 101. When a target process in a target container reads a kernel interface, triggering the first kernel monitoring program mounted on a target resource control group to run; the kernel interface is located in an electronic device where the target container is deployed; the target resource control group is a resource control group associated with the target container.
[0028] 102. Obtain resource information associated with the target container from the kernel space of the electronic device through the first kernel monitoring program.
[0029] 103. Determine resource view information of the target container according to resource information associated with the target container through the first kernel monitoring program.
[0030] 104. Provide resource view information to the target process through the first kernel monitoring program.
[0031] In an embodiment of the present application, an electronic device is deployed with a container. The electronic device is also deployed with an operating system. The operating system includes a user space and a kernel space. The user space and the kernel space can distinguish the execution environment of the user program and the operating system kernel, and ensure that the user program cannot directly access the kernel resources, thereby improving the stability and security of the system. Among them, the container is deployed in the user space and cannot directly access the kernel resources, and it is also impossible to directly obtain the resource view information of the container from the kernel data.
[0032] Since the resource control group (Cgroup) is used to limit the total amount of resources that a process group can use, such as CPU time, memory, disk I / O, etc. The resource control group can also track and report the amount of resources used by the process group. The resource control group can also be used to isolate resources to ensure that process groups do not interfere with each other and remain stable even when resources are tight. Through the resource control group, it can be ensured that the process in the container does not consume excessive resources of the host machine. Therefore, if the resource information recorded by the resource control group associated with the container can be obtained, the resource view information of the container can be determined according to the resource information recorded by the resource control group associated with the container, that is, the resource information of the container itself can be determined. Among them, the resource control group (Cgroup) associated with the container can be the resource control group to which the container belongs, or the resource control group (Cgroup) associated with the container can be the resource control group to which the container belongs (such as pod), or the resource control group (Cgroup) associated with the container can be the resource control group to which the container monitors resources for the container (i.e., the monitoring container).
[0033] Based on the above analysis, in order to achieve the isolation of container resource views, the container can see its own resource information, such as Figure 2 As shown in , a kernel monitoring program can be mounted on the resource control group (Cgroup) associated with the container. The kernel monitoring program is used to read the resource information associated with the target container from the memory. For example, Figure 2As shown in "eBPF program reading data", some kernel monitoring programs can read the resource information recorded by the resource control group associated with the container as the resource information associated with the container. For another example, some kernel monitoring programs can read the custom resource information corresponding to the container from the kernel space. Figure 2 As shown, the custom resource information is stored in the BPF map data (BPF map Data) of the kernel space. The custom resource information may include: the minimum resource information of the container, and / or the maximum resource information that can be used by the container, etc. Figure 2 As shown, the custom resource information can be stored in the BPF mapping data in the kernel space through the proxy component in the user space.
[0034] In the embodiments of the present application, the specific implementation of the kernel monitoring program is not limited. In some embodiments, the kernel monitoring program may be an eBPF program. Accordingly, the eBPF technology may be used to mount the kernel monitoring program to the resource control group associated with the container. Using the eBPF program to monitor the kernel can implement complex functions without modifying the kernel code, thereby improving the performance and security of the system. In some embodiments, the kernel monitoring program may use kernel static tracking points to mount the kernel monitoring program (such as the eBPF program) to the resource control group associated with the container. Static tracking points are specific locations predefined in the kernel source code for recording the occurrence of specific events. These tracking points are fixed at compile time and cannot be dynamically modified at runtime. Using static tracking points can record key events in the kernel without modifying the kernel code or inserting probes. Among them, using static tracking technology to monitor the kernel has a lower performance overhead than other kernel tracking methods.
[0035] Specifically, a trace point can be defined in the kernel source code. The trace point is usually defined using the trace event (TRACE_EVENT) macro. The trace point defined in the kernel source agent in the present application can be a resource control group associated with a container. Accordingly, the trace point can be defined in the kernel source code as a resource control group associated with a container. Further, the kernel source code can be compiled, and the trace point will be compiled into a part of the kernel. After compilation, the trace point becomes part of the kernel and cannot be dynamically modified at runtime. The eBPF program can run when the trace point is triggered and process the corresponding event.
[0036] Specifically, Figure 2 As shown in Figure 1, the kernel monitoring program can be loaded into the resource control group associated with the container (corresponding to Figure 2 The BPF program loader is part of the kernel and provides an interface for loading eBPF programs into the kernel. It is also responsible for verifying and managing these programs.
[0037] The kernel monitoring program mounted on the resource control group associated with the container can be triggered when the kernel interface of the electronic device (such as " / proc / cpuinfo" and / or " / proc / meminfo", etc.) is read. For the convenience of description, the container deployed on the electronic device that reads the kernel interface of the electronic device is defined as the target container, and the process in the target container that reads the kernel interface is defined as the target process.
[0038] In the embodiment of the present application, the triggering time of the target container reading the kernel interface is not limited. In the present embodiment, the triggering time of the process in the container reading the kernel interface usually occurs when the process needs to obtain the resource status. In some embodiments, when the process in the container is started, the kernel interface can be read to initialize the resources. For example, / proc / cpuinfo is part of the / proc file system in the operating system (such as the Linux system), which provides a mechanism to access the kernel's information about the processor. By reading the / proc / cpuinfo file, detailed information about the processor installed in the system can be obtained. Therefore, the application in the container can read the / proc / cpuinfo kernel interface to obtain processor information so as to initialize the thread pool according to the number of available processor cores (CPU cores). / proc / meminfo is a virtual file system interface (Virtual File System, VFS) provided in the operating system (such as the Linux system), which is located in the / proc directory and is used to display the memory status information of the system. By reading the / proc / meminfo file, various statistical data on the memory usage of the current system can be obtained. Therefore, the application can also read the / proc / meminfo interface to obtain the available memory size so as to initialize the memory pool according to the available memory size.
[0039] In other embodiments, the process in the resource monitoring container can read the kernel interface to monitor resource usage. For example, / proc / stat is a special file under the / proc file system in the operating system (such as the Linux system) for providing system statistics. The / proc file system is a pseudo file system that does not exist on the hard disk, but is dynamically generated by the kernel to provide information about the system status to the user space program. The / proc / stat file contains data on various statistical information in the system, including processor (such as CPU) statistics, such as processor usage, etc. Therefore, the process in the resource monitoring container can read the kernel interface / proc / stat, etc. to monitor the processor (such as CPU) usage. The process in the resource monitoring container can also read the kernel interface / proc / meminfo to monitor memory usage. / proc / diskstats is part of the / proc file system in the operating system (such as the Linux system), which provides a mechanism to access the disk usage statistics generated by the kernel. Through this file, users can obtain detailed usage of each block device (such as a hard disk, disk, etc.). Therefore, the process in the resource monitoring container can also read the kernel interface / proc / diskstats to monitor disk I / O operations, etc.
[0040] In some other embodiments, when a process in a container needs to adjust resource configuration, it can read the kernel interface to obtain the current resource status. For example, the size of the thread pool can be adjusted according to the current processor usage. For another example, the memory allocation strategy can be adjusted according to the current memory usage.
[0041] Based on the kernel monitoring program mounted on the resource control group associated with the container, in step 101, when the target process in the target container reads the kernel interface, the kernel monitoring program mounted on the resource control group associated with the target container (defined as the target resource control group) can be triggered to run.
[0042] Specifically, Figure 2 As shown, the target container can read the logic of the core interface of the electronic device (such as Figure 2 A hook function is pre-inserted into the computer program corresponding to the "read data" in the target resource control group. The hook function is used to trigger the kernel monitoring program mounted on the target resource control group associated with the target container to run when the kernel interface of the electronic device is read. The target resource control group (Cgroup) may be the resource control group to which the container belongs, or the resource control group (Cgroup) associated with the container is the resource control group to which the container group (such as pod) to which the container belongs, or the resource control group (Cgroup) associated with the container is the resource control group to which the container that monitors resources for the container (i.e., the monitoring container) belongs, etc.
[0043] Which resource control group is used by the specific target resource group is mainly determined by the user based on actual needs. The target process needs to obtain resource information recorded by which resource control group, and that resource control group is the target resource control group. The hook function is then associated with the target resource control group. For example, the identifier of the target resource control group can be written into the hook function. In this way, the hook function is used to trigger the kernel monitoring program mounted on the target resource control group associated with the target container to run when the kernel interface of the electronic device is read.
[0044] The kernel monitoring program can obtain resource information associated with the target container from the kernel space of the electronic device during operation. Accordingly, in step 102, the kernel monitoring program mounted on the target resource control group can obtain resource information associated with the target container from the kernel space of the electronic device.
[0045] The resource information associated with the target container may include: the resource information that the target container can obtain at least and / or the maximum resource information that the target container can use. The resource information may include various types of resource information, such as processor resource information, memory resource information, and disk I / O resource information.
[0046] In user space or application layer, the minimum resource information that a container can obtain can be determined based on the container's request. The request is the minimum amount of resources that a container can obtain, which is the minimum resource guarantee for the container. The request refers to the minimum amount of resources that a container expects to obtain. The scheduler will allocate sufficient resources to the container based on the container's request. The maximum resource information that the target container can use can be determined using the container's limit. The container's limit refers to the maximum amount of resources that a container can use. The container's resource usage must not exceed this upper limit.
[0047] In kernel space, container requests (Request) can be implemented through processor weight policies. Processor weight policies can be implemented as CPU weight (CPU Share). Processor weight policies are used to allocate processor (such as CPU) time among multiple containers by weight. When a container's request (Request) sets processor resources, a processor weight policy (such as CPU Share) can be set in a resource control group (Cgroup) to allocate the container's processor usage time. Processor shares (i.e., CPU Share) can be allocated based on the container's request (Request), thereby allocating processor usage time among multiple containers by weight.
[0048] In kernel space, container limits (Limit) can be implemented through processor quota (Quota) policies. Processor quota (Quota) policies can be CPU quota (CPU Quota) policies. Processor quota policies are used to limit the total amount of time that a container can use the processor (such as CPU) within a certain period. When the container's limit (Limit) sets processor resources, you can set a processor quota policy (such as CPU Quota) in the resource control group (Cgroup) to limit the container's processor resource usage. Specifically, the container's limit (Limit) can be converted to a processor quota policy (such as CPU Quota) in the resource control group (Cgroup), thereby limiting the time that the container can use the processor within a certain period.
[0049] The following is an example of the conversion process between the container's request (Request) and processor weight policy, and the container's limit (Limit) and processor quota (Quota) policy.
[0050] For example, suppose there are two containers, container A and container B. The request of container A is 0.5CPU (i.e., 0.5 CPU core); the limit of container A is 1 CPU (i.e., 1 CPU core). The request of container B is 0.25CPU (i.e., 0.25 CPU core); the limit of container B is 0.5 CPU (i.e., 0.5 CPU core). Then, the resource scheduler can allocate sufficient resources based on the requests of container A and container B. Container A requires at least 0.5 CPU cores, and container B requires at least 0.25 CPU cores. The controller can set the processor quota (such as CPU Quota) and processor weight (such as CPU Share) of the resource control group (Cgroup) according to the limit of the container.
[0051] Specifically, the CPU weight (CPUShares) of container A can be set according to the request of container A. Assuming the default weight is 1024 and the request of container A is 0.5 CPU cores, the CPU weight of container A can be set to 512. Similarly, the CPU weight (CPUShares) of container B can be set according to the request of container B. Assuming the default weight is 1024 and the request of container B is 0.25 CPU cores, the CPU weight of container B can be set to 256.
[0052] Furthermore, the CPU quota (CPUQuota) of container A can be set according to the limit (Limit) of container A. Assume that the CPU usage period is 100 milliseconds. The limit (Limit) of container A is 1 CPU core, so the processor usage duration (quota) of container A can be set to 100 milliseconds. Similarly, the CPU quota (CPUQuota) of container B can be set according to the limit (Limit) of container B. Assume that the CPU usage period is 100 milliseconds. The limit (Limit) of container B is 0.5 CPU cores, so the processor usage duration (quota) of container B can be set to 50 milliseconds.
[0053] Based on the above analysis, the container limit (Limit), that is, the maximum amount of resources that the container can use, can be determined according to the processor quota data recorded by the resource control group (Cgroup). The container request (Request), that is, the minimum amount of resources used by the container, can also be determined according to the processor weight data recorded by the resource control group (Cgroup).
[0054] Based on the resource information recorded by the resource control group described in the above embodiment, one implementation of step 102 is: through the kernel monitoring program mounted on the target resource control group, the resource information recorded by the target resource control group is obtained from the kernel space as the resource information associated with the target container.
[0055] In other embodiments, the kernel monitoring program can read the custom resource information of the target container from the kernel space as the resource information associated with the target container. The custom resource information may include: the minimum resource information of the target container, and / or the maximum resource information that can be used by the container, etc.
[0056] The specific resource information to be used as the resource information associated with the target container can be determined by the user according to actual needs. The user can write the identifier of the data source of the resource information into the kernel monitoring program. The identifier of the data source of the resource information can be the identifier of the target resource control group, or the identifier of the data table storing the custom resource information corresponding to the target container, such as Figure 2 The identification of BPF map data in kernel space, etc.
[0057] After obtaining the resource information associated with the target container, in step 103, the resource view information of the target container can be determined by the kernel monitoring program according to the resource information associated with the target container. The description of the resource view information of the target container can refer to the explanation of the container resource view in the aforementioned term or concept explanation section. In this embodiment, the resource view information of the target container is determined according to the target-associated resource information obtained by the kernel monitoring program, so that the target process in the target container can only know its own resource information, thereby realizing the isolation of the container resource view.
[0058] In the embodiments of the present application, the specific implementation method of the kernel monitoring program determining the resource view information of the target container based on the resource information associated with the target container is not limited. In the aforementioned embodiment of the resource information recorded by the target resource control group obtained from the kernel space by the kernel monitoring program mounted on the target resource control group as the resource information associated with the target container, the resource information recorded by the target resource control group may include: processor allocation data output by multiple processor allocation strategies. Multiple means more than 2 (including 2). For example, multiple processor allocation strategies may include: at least 2 of the processor time quota strategy, processor weight strategy and processor allocation set (Set) strategy.
[0059] The processor allocation set (Set) policy may be a CPUSet policy. A processor allocation set (such as CPUSet) policy may specify the processor cores (such as CPU cores) that a process or container may use. A processor allocation set (such as CPUSet) policy may ensure that a process or container may only use the specified processor cores (such as CPU cores).
[0060] Among them, the processor allocation data output by different processor allocation strategies are different. The processor allocation data output by the processor time quota strategy includes: processor scheduling period (Period) and processor time quota (Quota). The processor time quota refers to the length of time the processor is allocated to the target container for use. The processor allocation data output by the processor weight strategy includes: the processor weight of the target container, which refers to the weight of the length of time the target container uses the processor, which is used to determine the relative usage time of the target container compared to other containers deployed on the electronic device. The processor allocation data output by the processor allocation set (Set) strategy includes: the identifier of the processor core allocated to the target container.
[0061] The specific processor allocation strategy to be adopted to output the processor allocation data is determined by the user according to actual needs. The user can write the identifier of the processor allocation strategy to be adopted into the kernel monitoring program when writing the kernel monitoring program. In this way, the kernel monitoring program can use the processor allocation strategy corresponding to the identifier of the processor allocation strategy written internally as the target processor allocation strategy during operation. Accordingly, the target processor allocation strategy specified by the kernel monitoring program can be determined through the kernel monitoring program mounted on the target resource control group. Specifically, the processor allocation strategy corresponding to the identifier of the processor allocation strategy written in the kernel monitoring program can be determined as the target processor allocation strategy.
[0062] Specifically, the resource view requirement information of the target container can be obtained. The resource view requirement information includes the identifier of the target processor allocation policy. Further, according to the identifier of the target processor allocation policy, the kernel monitoring program corresponding to the target processor allocation policy can be determined from the multiple kernel monitoring programs corresponding to the identifiers of the pre-set multiple processor allocation policies. The number of types of kernel monitoring programs is the same as the number of types of processor allocation policies. Each processor allocation policy can correspond to one kernel monitoring program. Different kernel monitoring programs specify different processor allocation strategies.
[0063] Furthermore, the kernel monitoring program corresponding to the target processor allocation policy can be mounted on the target resource control group. In the same way, the kernel monitoring program can be mounted for the resource control groups associated with other containers deployed on the electronic device. This implementation method can flexibly select the corresponding kernel monitoring program according to the requirements of the resource view requirement information of different containers for the data source, realize the automatic selection of the kernel monitoring program, reduce the need for manual intervention, and reduce the operation and maintenance costs. On the other hand, it can also provide conditions for realizing that different containers use different data sources to determine the resource view of the container.
[0064] In an embodiment of the present application, for ease of description and distinction, the target resource control group associated with the target container is mounted with a kernel monitoring program, which is defined as a first kernel monitoring program. The first kernel monitoring program may be the same as or different from the kernel monitoring programs mounted on the resource control groups associated with other containers. In an embodiment in which the first kernel monitoring program is different from the kernel monitoring programs mounted on the resource control groups associated with other containers, different containers may use different data sources to determine the resource view of the container, which is more flexible.
[0065] However, the container resource view isolation implemented by the aforementioned LXCFS means that each container on the electronic device can only use the same data source to determine the resource view of the container, which is less flexible than the container resource view isolation provided in the embodiment of the present application.
[0066] Based on the target processor allocation policy specified by the first kernel monitoring program, the processor allocation data output by the target processor allocation policy can be obtained from the processor allocation data output by the multiple processor allocation policies stored in the kernel space through the first kernel monitoring program. Further, the processor resource information of the target container can be determined through the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy.
[0067] In some embodiments, the target processor allocation policy is a processor time quota policy. The processor allocation data output by the processor quota policy includes: a processor scheduling cycle and a processor time quota. Accordingly, when determining the resource view information of the target container according to the processor allocation data output by the target processor allocation policy, the first kernel monitoring program may calculate the ratio of the processor time quota to the processor scheduling cycle as the processor resource information of the target container.
[0068] In some other embodiments, the target processor allocation policy is a processor weight policy; the processor allocation data output by the processor weight policy includes: the processor weight of the target container. Accordingly, when the processor resource information of the target container is determined by the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy, the processor weights of other containers provided by the application layer of the electronic device can be obtained by the first kernel monitoring program; and according to the processor weight q1 of the target container and the processor weights q n and the total processor resources of the electronic device, determine the processor resource information of the target container. Among them, other processors refer to containers deployed in the electronic device other than the target container. Among them, the processor weights of other containers q n Where n=2,3…,N. N refers to the total number of containers deployed in the electronic device.
[0069] Specifically, the ratio between the processor weight q1 of the target container and the total weight can be calculated; the total weight is equal to the processor weight q1 of the target container and the processor weights q n Furthermore, the ratio of the processor weight q1 of the target container to the total weight and the product of the total processor resources of the electronic device can be used as the processor resource information of the target container. That is, the processor resource information of the target container can be expressed as: Q represents the total processor resources of the electronic device.
[0070] In some other embodiments, the target processor allocation policy is a processor allocation set policy; the processor allocation data output by the processor allocation set policy includes: the identifier of the processor core allocated to the target container. Accordingly, when the processor resource information of the target container is determined by the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy, the number of processor cores allocated to the target container can be determined by the first kernel monitoring program according to the identifier of the processor core allocated to the target container as the processor resource information of the target container.
[0071] In the embodiment of the present application, other types of resource information of the target container can also be obtained from the resource information associated with the target container through the first kernel monitoring program. Among them, other types refer to resource types other than processor resources, such as kernel resources, disk resources, and disk I / O resources. Further, other types of resource information of the target container and the processor resource information of the target container can be used as resource view information of the target container.
[0072] In an embodiment in which the custom resource information of the target container can be read from the kernel space by the first kernel monitoring program as resource information associated with the target container, the custom resource information of the target container can be used as resource view information of the target container by the first kernel monitoring program, thereby realizing user-defined data sources, which helps to improve the flexibility of container view isolation.
[0073] After determining the resource view information of the target container, in step 104, the resource view information of the target container may be provided to the target process, thereby isolating the resource view of the target container so that the process in the target container can only obtain the resource information of the target container itself.
[0074] In this embodiment, the resource information associated with the target container is obtained from the kernel space through the kernel monitoring program mounted on the target resource control group associated with the target container, and the resource view information of the target container is determined according to the resource information associated with the target container by the kernel monitoring program, and the resource view information of the target container can be provided to the target process, thereby realizing the isolation of the resource view of the target container, so that the process in the target container can only know the resource information of the target container itself. Among them, the kernel monitoring program is set in the kernel space, and the resource information associated with the target container can be directly obtained from the kernel space, so that when obtaining the resource information associated with the target container, there is no need for the user space to interact with the kernel space. Therefore, the isolation method of the container resource view provided in the embodiment of the present application can reduce the processing delay.
[0075] On the other hand, compared with the aforementioned LXCFS solution for implementing container resource view isolation, which is based on FUSE, FUSE itself is a file system implementation mechanism running in user space, and its main feature is that most of the logic of the file system is implemented in user space, which will undoubtedly affect the stability of LXCFS. The kernel monitoring program used in the container resource view isolation method provided in the embodiment of the present application runs in kernel state and has higher stability.
[0076] In the embodiments of the present application, Figure 2As shown, the first kernel monitoring program (such as an eBPF program) writes the resource view information of the target container into the BPF mapping data for user space access. In some embodiments, the BPF mapping data may also include other information provided by the BPF program loader and other information provided by the proxy component.
[0077] The embodiments of the present application do not limit the specific operations performed by the target process after obtaining the resource view information of the target container. For example, in some embodiments, the target process may initialize the resources of the target process according to the resource view information of the target container. Specifically, the target process may determine the thread pool size and memory pool size corresponding to the target process according to the resource view information of the target container; and create a thread pool and memory pool of corresponding size according to the thread pool size and memory pool size corresponding to the target process, thereby initializing the thread pool and memory pool.
[0078] In an embodiment of the present application, dynamic switching of the kernel monitoring program can also be implemented during the operation of the kernel monitoring program. Specifically, the second kernel monitoring program to be switched can be obtained from a variety of kernel monitoring programs during the operation of the target container. In some embodiments, the kernel monitoring program switching event can be monitored during the operation of the target container. In an embodiment of the present application, the specific implementation form of the kernel monitoring program switching event is not limited. In some embodiments, the kernel monitoring program switching can be triggered by the user. Accordingly, the kernel monitoring program switching event can be implemented as receiving a kernel monitoring program switching request. Further, in the case of monitoring the kernel monitoring program switching event, the second kernel monitoring program to be switched can be obtained from a variety of kernel monitoring programs. Specifically, the identifier of the second kernel monitoring program to be switched can be obtained from the kernel monitoring program switching request; thereafter, the second kernel monitoring program to be switched can be obtained from a variety of kernel monitoring programs.
[0079] Furthermore, the aforementioned first kernel monitoring program can be uninstalled, and the second kernel monitoring program can be mounted on the target resource control group, thereby realizing dynamic switching of the kernel monitoring program when the container is running. Among them, the data sources used by the first kernel monitoring program and the second kernel monitoring program can be the same or different. In an embodiment in which the data sources used by the first kernel monitoring program and the second kernel monitoring program are different, it is realized that the data source providing the container resource view information is dynamically changed when the container is running, which has high flexibility.
[0080] It should be noted that the execution subject of each step of the method provided in the above embodiment can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 101 and 102 can be device A; for another example, the execution subject of step 101 can be device A, and the execution subject of step 102 can be device B; and so on.
[0081] In addition, in some of the processes described in the above embodiments and the accompanying drawings, multiple operations appearing in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this document or may be executed in parallel, and the serial numbers of the operations, such as 101, 102, etc., are only used to distinguish between different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel.
[0082] Accordingly, an embodiment of the present application further provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned container resource view isolation method.
[0083] The embodiment of the present application also provides a computer program product, including a computer program. When the computer program is executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned container resource view isolation method.
[0084] In the embodiments of the present application, the specific implementation form of the computer program product is not limited. In some embodiments, the computer program product can be implemented as an application (Application, APP), a small program, a computer-side client, a program module, a plug-in, an installation package, a software development kit (Software Development Kit, SDK), an image file of a disc (such as an ISO file), a plug-in or software as a service (Software as a Service, SaaS) software, etc., but is not limited thereto.
[0085] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 3 As shown, the electronic device includes: a memory 30a and a processor 30b. The memory 30a is used to store computer programs.
[0086] The processor 30b is coupled to the memory 30a and is used to execute a computer program to execute the steps in the container resource view isolation method provided in the above embodiments. The specific implementation of each step can be found in the relevant description of the above embodiments, which will not be repeated here.
[0087] In some optional embodiments, such as Figure 3 As shown, the electronic device may also include optional components such as a communication component 30c, a power component 30d, a display component 30e and an audio component 30f. Figure 3 The components are shown schematically only, and do not mean that the electronic device must include Figure 3The components shown do not necessarily mean that the electronic device can only include Figure 3 Components shown.
[0088] in addition, Figure 3 The components in the dashed box are optional components, not mandatory components, and may depend on the product form of the electronic device. The electronic device of this embodiment may be implemented as a terminal device such as a desktop computer, a laptop computer, a mobile phone, or an IoT device; or it may be various server devices such as a traditional server, a cloud server, or a server cluster.
[0089] In an embodiment of the present application, the memory is used to store a computer program and can be configured to store various other data to support operations on the device where it is located. Among them, the processor can execute the computer program stored in the memory to implement the corresponding control logic. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random-Access Memory, SRAM), electrically erasable programmable read only memory (Electrically Erasable Programmable Read Only Memory, EEPROM), erasable programmable read only memory (Electrical Programmable Read Only Memory, EPROM), programmable read only memory (Programmable Read Only Memory, PROM), read only memory (Read Only Memory, ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0090] In the embodiment of the present application, the processor may be any hardware processing device that can execute the logic of the above method. Optionally, the processor may be a central processing unit (CPU), a graphics processing unit (GPU) or a microcontroller unit (MCU); it may also be a field programmable gate array (FPGA), a programmable array logic device (PAL), a general array logic device (GAL), a complex programmable logic device (CPLD) or other programmable devices; or it may be an advanced reduced instruction set (RISC) processor (Advanced RISC Machines, ARM) or a system on chip (System on Chip, SoC), etc., but not limited thereto.
[0091] In an embodiment of the present application, the communication component is configured to facilitate wired or wireless communication between the device in which it is located and other devices. The device in which the communication component is located can access a wireless network based on a communication standard, such as Wireless Fidelity (WiFi), 2G or 3G, 4G, 5G or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component can also be implemented based on Near Field Communication (NFC) technology, Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra Wide Band (UWB) technology, Bluetooth (BT) technology or other technologies.
[0092] In an embodiment of the present application, the display component may include a liquid crystal display (LCD) and a touch panel (TP). If the display component includes a touch panel, the display component may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0093] In an embodiment of the present application, a power supply component is configured to provide power to various components of the device in which it is located. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply component is located.
[0094] In an embodiment of the present application, the audio component may be configured to output and / or input audio signals. For example, the audio component includes a microphone (Microphone, MIC), and when the device where the audio component is located is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal may be further stored in a memory or sent via a communication component. In some embodiments, the audio component also includes a speaker for outputting an audio signal. For example, for a device with a language interaction function, voice interaction with a user may be achieved through an audio component.
[0095] It should be noted that the descriptions such as “first” and “second” in this article are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence, nor do they limit “first” and “second” to different types.
[0096] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, compact disc read-only memory (CD-ROM), optical storage, etc.) containing computer-usable program codes.
[0097] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0098] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0099] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0100] In a typical configuration, a computing device includes one or more processors (CPU, etc.), input / output interfaces, network interfaces, and memory.
[0101] Memory may include non-permanent storage in a computer-readable medium, in the form of random-access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0102] Computer storage media is readable storage media, also known as readable media. Readable storage 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, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage 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.
[0103] 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 further 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 above elements.
[0104] The above contents are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A method for isolating a container resource view, characterized in that: include: When the target process in the target container reads the kernel interface, triggering the first kernel monitoring program mounted on the target resource control group to run; The kernel interface is located in the electronic device where the target container is deployed; the target resource control group is a resource control group associated with the target container; Acquiring resource information associated with the target container from the kernel space of the electronic device through the first kernel monitoring program; Determining resource view information of the target container according to resource information associated with the target container through the first kernel monitoring program; The resource view information is provided to the target process through the first kernel monitoring program.
2. The method according to claim 1, characterized in that Acquiring resource information associated with the target container from the kernel space of the electronic device through the first kernel monitoring program includes: The resource information recorded by the target resource control group is obtained from the kernel space through the first kernel monitoring program as the resource information associated with the target container.
3. The method according to claim 2, characterized in that The resource information recorded by the target resource control group includes: processor allocation data output by multiple processor allocation strategies; the resource view information of the target container is determined by the first kernel monitoring program according to the resource information associated with the target container, including: determining, by the first kernel monitoring program, a target processor allocation strategy specified by the first kernel monitoring program; Acquire, by the first kernel monitoring program, the processor allocation data output by the target processor allocation policy from the processor allocation data output by the multiple processor allocation policies stored in the kernel space; Determining processor resource information of the target container by the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy; Acquire, through the first kernel monitoring program, resource information of other types of the target container from the resource information associated with the target container; wherein the other types refer to resource types other than processor resources; Other types of resource information of the target container and processor resource information of the target container are used as resource view information of the target container.
4. The method according to claim 3, characterized in that The target processor allocation strategy is a processor time quota strategy; the processor allocation data output by the processor quota strategy includes: a processor scheduling cycle and a processor time quota; the processor time quota refers to the duration of time that the processor is allocated to the target container; The determining, by the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy, resource view information of the target container includes: The ratio of the processor time quota to the processor scheduling cycle is calculated by the first kernel monitoring program as the processor resource information of the target container.
5. The method according to claim 3, characterized in that: The target processor allocation strategy is a processor weight strategy; The processor allocation data output by the processor weight policy includes: the processor weight of the target container; The determining the processor resource information of the target container by the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy includes: Acquire, by the first kernel monitoring program, processor weights of other containers provided by the application layer of the electronic device; The processor resource information of the target container is determined according to the processor weight of the target container, the processor weights of the other containers, and the total processor resources of the electronic device.
6. The method according to claim 3, characterized in that The target processor allocation strategy is a processor allocation set strategy; the processor allocation data output by the processor allocation set strategy includes: an identifier of a processor core to which the target container is allocated; The determining the processor resource information of the target container by the first kernel monitoring program according to the processor allocation data output by the target processor allocation policy includes: The number of processor cores allocated to the target container is determined by the first kernel monitoring program according to the identifier of the processor core allocated to the target container, as the processor resource information of the target container.
7. The method according to any one of claims 1 to 6, characterized in that: The target resource control group is the resource control group to which the target container belongs, or the target resource control group is the resource control group to which a monitoring container that performs resource monitoring on the target container belongs, or the target resource control group is the resource control group to which a container group to which the target container belongs belongs.
8. The method according to claim 1, characterized in that The kernel space stores the custom resource information of the target container; Acquiring resource information associated with the target container from the kernel space of the electronic device through the first kernel monitoring program includes: Acquire, by the first kernel monitoring program, the custom resource information of the target container from the kernel space as the resource information associated with the target container; The determining, by the first kernel monitoring program, resource view information of the target container according to resource information associated with the target container includes: The first kernel monitoring program uses the custom resource information as resource view information of the target container.
9. The method according to claim 3, characterized in that: The method further comprises: Acquire resource view requirement information of the target container; the resource view requirement information includes an identifier of the target processor allocation policy; According to the identifier of the target processor allocation strategy, determining the kernel monitoring program corresponding to the target processor allocation strategy from a plurality of kernel monitoring programs corresponding to the identifiers of the preset plurality of processor allocation strategies as the first kernel monitoring program; The first kernel monitoring program is mounted on the target resource control group.
10. The method according to claim 9, characterized in that The method further comprises: During the operation of the target container, obtaining a second kernel monitoring program to be switched from the multiple kernel monitoring programs; Uninstall the first kernel monitoring program, and mount the second kernel monitoring program to the target resource control group.
11. The method according to claim 3, characterized in that The electronic device is also deployed with other containers in addition to the target container; the kernel monitoring program mounted on the resource control group associated with the other containers is different from the first kernel monitoring program; and different kernel monitoring programs specify different processor allocation strategies.
12. The method according to any one of claims 1 to 6 and 8 to 11, characterized in that: The first kernel monitoring program is an extensible Berkeley Packet Filter (eBPF) program.
13. An electronic device, characterized in that: include: A memory and a processor; wherein the memory is used to store a computer program; The processor is coupled to the memory and is configured to execute the computer program to perform the steps of the method according to any one of claims 1 to 12.
14. A computer-readable storage medium storing computer instructions, characterized in that: When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the method according to any one of claims 1 to 12.
15. A computer program product, characterized in that The method comprises a computer program, which, when executed by one or more processors, causes the one or more processors to execute the steps of the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Host side lightweight container flow monitoring system and method based on eBPF
CN115834448A
Container resource view isolation method and device and electronic equipment
CN115858101A
Container processing method, device, equipment, medium and program product
CN117807039A
Protocol for correlating user space data with kernel space data
US11709720B1
Container isolation method and apparatus for netlink resource
US20200167186A1
