Resource control device, resource control method, and program
The cgroup mechanism in Linux OS stabilizes CPU resource allocation in CPS by defining allocation rules and authority delegation within the cgroup framework, addressing the lack of unified control in existing systems and ensuring reliable processing by preventing unauthorized changes.
Patent Information
- Application Number
- PCT/JP2023/008854
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-08
- Publication Date
- 2024-09-12
AI Technical Summary
In Cyber-Physical Systems (CPS), the lack of unified control mechanisms for CPU resource allocation in Linux OS leads to instability and inability to stably allocate CPU resources, causing jitter and period disturbances in control systems.
A resource control mechanism using cgroup to manage CPU resources through files like cpuset.cpus and cgroup.subtree_control, ensuring consistent and stable allocation by defining allocation rules and authority delegation rules, and implementing a uni-profile to prevent unauthorized changes.
This approach enables consistent and stable CPU resource allocation according to unified rules, suppressing jitter and ensuring reliable processing in CPS by preventing unauthorized changes to CPU resource settings.
Smart Images

Figure JP2023008854_12092024_PF_FP
Abstract
Description
Resource control device, resource control method and program
[0001] The present invention relates to a resource control device, a resource control method, and a program.
[0002] Traditionally, efforts have been made to develop Cyber-Physical Systems (CPSs) that collect sensor information from the real world (physical systems), analyze the collected information in cyberspace, and use it to control real-world systems and distribute data between systems.
[0003] In CPS, the locally closed physical system is separated into actuators and control logic, with the control logic located at a remote edge. To perform (periodic) control from the control logic over a network, it is essential to guarantee the (periodic) "total processing time (TAT)" required for the series of processes: (1) control calculation, (2) control instruction signal, (3) remote control, and (4) control result signal. To achieve this, it is necessary to suppress jitter throughout the entire system, including both the computational and communication processes that lead to periodic disruptions. Jitter can be broadly divided into two causes: control logic jitter and communication jitter, and both jitter must be suppressed. In particular, because the control logic is executed using computational resources, stable resource allocation is required.
[0004] Pablo Neira Ayuso, Rafael M. Gasca, Laurent Lefevre, "Communicating between the kernel and user-space in Linux using Netlink sockets", SOFTWARE-PRACTICE AND EXPERIENCE, Softw. Pract. Exper. 2010, [online], Internet <URL: https: / / perso.ens-lyon.fr / laurent.lefevre / pdf / JS2010_Neira_Gasca_Lefevre.pdf>cgrulesengd, [online], Internet <URL: https: / / github.c om / hiboma / hiboma / blob / master / kernel / cgrulesengd.md>cgroup-v2, [online], Internet <URL: https: / / www.kernel.org / doc / html / latest / admin-guide / cgroup-v2.html>Linux security module, [online], Internet <URL: https: / / www.kernel.org / doc / html / latest / security / lsm.html>
[0005] CPS utilizes edge computing, which is generally configured with server infrastructure such as IaaS, PaaS, and SaaS.
[0006] In such a server infrastructure, a multitasking OS (Operating System) such as the Linux (registered trademark) OS (hereinafter simply referred to as "OS") has the following problems.
[0007] First, as a basic concept, the OS allocates and releases the resources of multiple CPU cores (hereinafter referred to as "CPU resources") that exist on one or more CPU sockets by switching them among multiple applications in a time-sharing manner, and therefore does not generally allocate CPU resources in a fixed manner.
[0008] On the other hand, APIs that allocate CPU resources in a fixed manner are sometimes provided, and Linux (registered trademark) provides a number of different APIs.
[0009] As a result, the following situation has arisen:
[0010] (1) Multiple APIs for managing "CPU resources" are provided, and there is no unified control API. For example, there are two mechanisms: sched_setaffinity and cgroup. For example, after a certain application (hereinafter referred to as "app") changes the allocation of CPU resources using sched_setaffinity, it can change the allocation using cgroup, and the previous state (hereinafter referred to as "state") is not managed by the OS.
[0011] (2) In addition to (1), there is no mechanism for unified management of CPU resources allocated by the OS to each application (i.e., management of CPU resources is left to the discretion of the administrator, and the OS does not support this function).
[0012] (3) After the desired CPU resources are allocated to each application, the OS does not have the management function to maintain and continue that state (i.e., the CPU resource manager responsible for the system must guarantee the allocation of CPU resources).
[0013] The impact of the above (1) to (3) is that the CPU resource setting state may be intentionally changed after CPU resources are allocated, which may result in a problem that stable CPU resource allocation is not possible and processing by the application cannot be stabilized.
[0014] The present invention has been made in view of the above points, and has as its object to realize a mechanism for consistently and stably allocating CPU resources according to a unified rule.
[0015] In order to solve the above problem, a resource control device has: a first mechanism that allocates CPU cores to a program based on a first file, if specified information indicating that the first file storing information indicating a list of CPU cores actually allocated to each of a plurality of groups set for a program's operating unit is valid is recorded in a second file; and a second mechanism that executes specified processing when it detects an opportunity to change the specified file.The resource control device has a first setting unit configured to reflect first setting information regarding the CPU cores to be allocated to the group in the first file, and a second setting unit configured to specify to the second mechanism the first file and the second file, and to prevent changes to the first file and the second file, depending on second setting information regarding whether or not the first file and the second file in which the specified information is recorded can be changed.
[0016] It is possible to realize a mechanism for consistently and stably allocating CPU resources according to a unified rule.
[0017] FIG. 1 is a diagram for explaining a cgroup mechanism. FIG. 2 is a diagram for explaining an example of a hardware configuration of the resource control device 10 in an embodiment of the present invention. FIG. 3 is a diagram for explaining an example of a functional configuration of the resource control device 10 in an embodiment of the present invention. FIG. 4 is a flowchart for explaining an example of a processing procedure executed by the resource control device 10. FIG. 5 is a diagram for explaining an example of a configuration of an allocation rule file r1. FIG. 6 is a diagram for explaining an example of a configuration of an exclusion rule file r2. FIG. 7 is a diagram for explaining the timing of each step related to a uniprofile reflection procedure and a CPU resource reflection procedure.
[0018] DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS The present invention will be described below with reference to the accompanying drawings. In this embodiment, the cgroup mechanism, which is one method of managing CPU core resources in Linux (registered trademark), is used.
[0019] Figure 1 is a diagram illustrating the cgroup mechanism. cgroup is a mechanism for managing not only CPU core resources but also resources such as memory and networks. In cgroup, a process / thread group is defined for each node in a tree structure, and resource allocation is controlled for each group (cgroup).
[0020] In the tree structure in Figure 1, the rounded rectangles with dashed borders correspond to directories. A cgroup corresponds to one directory, and the necessary information is written to each file in that directory. The parent-child relationship of directories corresponds to the parent-child relationship of cgroups. Figure 1 shows an example in which " / sys / fs / cgroup" corresponds to the root cgroup, and " / sys / fs / cgroup / init.scope", " / sys / fs / cgroup / system.slice", and " / sys / fs / cgroup / user.slice" correspond to child cgroups with root as their parent.
[0021] The directory structure in FIG. 1 is merely an example (the number of CPU cores is 12 (numbers 0 to 11)).
[0022] Of the files belonging to each directory, cpuset.cpus and cgroup.subtree_control are particularly relevant to this embodiment.
[0023] The cpuset.cpus file in a directory specifies which CPU cores will be used by the cgroup corresponding to that directory. In other words, the cpuset.cpus file in a directory specifies the number (list) of CPU cores to be allocated to all processes belonging to the cgroup corresponding to that directory and to all processes belonging to the cgroups corresponding to each directory under that directory. Because the Linux® OS (hereinafter simply referred to as "OS") controls CPU allocation based on the cpuset.cpus file, the information stored in the cpuset.cpus file can be considered to be information indicating a list of CPU cores actually allocated to each cgroup.
[0024] The cgroup.subtree_control of a directory is a file that manages the delegation of authority to control CPU allocation (hereinafter referred to as "CPU allocation authority") to child cgroups corresponding to the child directories of the directory. If the string "cpuset" (controller name) is written in this file, the cgroup one level below can change the CPU core allocation for processes and threads belonging to the cgroup. Specifically, when "cpuset" is written to the cgroup.subtree_control of a directory (cgroup) (when CPU allocation authority is delegated), the OS generates cpuset.cpus in all child directories (all child cgroups) of the directory. In other words, the cpuset.cpus files in directories corresponding to cgroups other than the root cgroup are not files that exist in each directory from the beginning, but are files generated in the directories of child cgroups to which CPU allocation authority has been delegated from the parent cgroup. The OS determines whether to delegate CPU allocation authority based on cgroup.subtree_control. Therefore, the information stored in cgroup.subtree_control can be said to be information indicating the actual correspondence between the CPU allocation authority delegation source and the delegation destination.
[0025] For reference, cgroup.procs is a file that exists in the leaf cgroup and the root cgroup, and describes the PIDs of the processes and threads that actually belong to the cgroup.
[0026] Next, the terms used in this embodiment will be explained.
[0027] CPU resources: The total number of one or more CPU sockets installed in a server system and one or more CPU cores present on each socket is called the CPU resources.
[0028] Resource: CPU resource may be called resource.
[0029] Process / Thread: When a program is run on a multitasking OS, a single unit (operational unit) is called a process or a thread. A process consists of one or more threads. Therefore, a fine-grained operational unit is a thread.
[0030] Resource group: A group to which processes / threads belong, to which a certain CPU resource allocation rule (for example, allocating the first 5 to 10 CPU cores out of 20 cores) is applied. In this embodiment, an example will be described in which the above cgroup directory is used as a resource group.
[0031] Allocation rule: A rule regarding allocation of CPU resources that is applied to a resource group.
[0032] Authority delegation rule: In order to apply an allocation rule to a resource group, CPU allocation authority must be delegated to the resource group. Specifically, "cpuset" must be written in the cgroup.subtree_control of the parent resource group of the resource group. This description establishes a correspondence between the resource group from which authority is delegated and the resource group to which authority is delegated (a correspondence between a parent group with "cpuset" written in cgroup.subtree_control and its child group). In this embodiment, the rule regarding this correspondence is called an authority delegation rule.
[0033] CPU allocation authority: The authority of a resource group to allocate CPU resources to processes and threads belonging to that resource group within the range of CPU resources allocated to that resource group. As mentioned above, in order for a resource group (cgroup) to obtain CPU allocation authority, it must be delegated CPU allocation authority from its parent resource group (cgroup).
[0034] 2 is a diagram showing an example of the hardware configuration of a resource control device 10 according to an embodiment of the present invention. The resource control device 10 shown in Fig. 2 includes a drive device 100, an auxiliary storage device 102, a memory device 103, one or more CPUs 104, and an interface device 105, all of which are interconnected via a bus B.
[0035] A program that realizes processing in the resource control device 10 is provided by a recording medium 101 such as a CD-ROM. When the recording medium 101 storing the program is set in the drive device 100, the program is installed from the recording medium 101 to the auxiliary storage device 102 via the drive device 100. However, the program does not necessarily have to be installed from the recording medium 101, but may be downloaded from another computer via a network. The auxiliary storage device 102 stores the installed program as well as necessary files, data, etc.
[0036] When an instruction to start a program is received, the memory device 103 reads the program from the auxiliary storage device 102 and stores it. The CPU 104 executes functions related to the resource control device 10 in accordance with the program stored in the memory device 103. In this embodiment, it is assumed that one or more CPUs 104 include multiple CPU cores. The interface device 105 is used as an interface for connecting to a network.
[0037] 3 is a diagram showing an example of the functional configuration of a resource control device 10 according to an embodiment of the present invention. In FIG. 3, the resource control device 10 includes a starting unit 11, an allocation rule file reading unit 12, an allocation rule file analysis unit 13, a CPU resource allocation setting unit 14, a startup script generation unit 15, an exclusion rule file reading unit 16, an exclusion rule file analysis unit 17, and a change rule setting unit 18. The resource control device 10 also includes a resource control mechanism 21 and an LSM 22 as mechanisms (functional units) of an operating system (OS). Each of these units is realized by the CPU 104 executing one or more programs installed in the resource control device 10.
[0038] The resource control mechanism 21 is an example of a mechanism that allocates CPU cores to a program based on the cpuset.cpus file, which stores information indicating a list of CPU cores actually allocated to each of multiple groups (resource groups) set for the program's operating unit, if specified information ("cpuset") indicating that the cpuset.cpus file is valid is recorded in the cgroup.subtree_control file.
[0039] The LSM 22 is a Linux (registered trademark) Security Module, and is an example of a mechanism that executes a specified process when it detects an opportunity to change a specified file.
[0040] The processing procedure executed by the resource control device 10 will be described below.
[0041] 4 is a flowchart for explaining an example of a processing procedure executed by the resource control device 10. The processing procedure in FIG.
[0042] In step S101, the initiation unit 11 determines whether the allocation rule file r1 has been updated. When the allocation rule file r1 has been updated, this refers to when a new allocation rule file r1 has been created or when an allocation rule file r1 that was previously the target of processing in step S102 and subsequent steps has been updated. The allocation rule file r1 is a file in which information to be set in the resource control device 10 is defined. The determination in step S101 is equivalent to determining whether the definition contents of the current allocation rule file r1 have already been set in the resource control device 10.
[0043] If the allocation rule file r1 has not been updated (No in S101), the process proceeds to step S107. If the allocation rule file r1 has been updated (including the case where the definition contents of the allocation rule file r1 have never been set in the resource control device 10) (Yes in S101), the initiation unit 11 calls the allocation rule file reading unit 12.
[0044] In response to the call, the allocation rule file reading unit 12 reads the definition contents of the allocation rule file r1 and inputs the definition contents to the allocation rule file analysis unit 13 (S102). The allocation rule file analysis unit 13 analyzes the definition contents and generates allocation rules, allocation change rules, and authority delegation change rules (S103).
[0045] 5 is a diagram showing an example of the configuration of the allocation rule file r1. As shown in FIG. 5, the allocation rule file r1 includes setting information for each resource group (hereinafter referred to as "resource group rules"). One resource group rule includes "directory path," "allocated CPU resources," "allocation change rule setting," and "authority delegation change rule setting," etc.
[0046] "Directory path" is the path name of the directory corresponding to the resource group (in this embodiment, the path name of the directory corresponding to the resource group in the cgroup mechanism). A line (resource group rule) in which the value of "directory path" is "default" indicates a default rule, and is applied to all resource groups not listed in the allocation rule file r1.
[0047] The "allocated CPU resources" of a resource group is configuration information related to the rules (i.e., allocation rules) that define the list of CPU cores allocated to that resource group and its descendant resource groups. Here, "resource group and its descendant resource groups" refers to the resource group and its descendant resource groups. Therefore, the "allocated CPU resources" of a resource group can be specified within the range of the "allocated CPU resources" of its parent resource group. Therefore, a resource group cannot be allocated CPU resources that exceed those of its parent resource group. If the "allocated CPU resources" of a resource group include a definition that exceeds those of its parent resource group, the allocation rule file analyzer 13 determines that the contents of the allocation rule file r1 are invalid and halts subsequent processing. Note that, as described below, the contents of the "allocated CPU resources" of a resource group are set in cpuset.cpus in the directory corresponding to that resource group. A resource group with an "allocated CPU resources" value of "all" is allocated all CPU resources. In this case, nothing is set in cpuset.cpus in the directory of that resource group. This is because an empty cpuset.cpus file means that all CPU resources are allocated. For resource groups whose "Allocated CPU Resources" value contains a hyphen, such as "1-5," consecutive CPU cores numbered 1 through 5 are assigned. The cpuset.cpus file in the directory of that resource group reflects the allocation of 1-5. For resource groups whose "Allocated CPU Resources" value contains a format such as "1|5|7," non-consecutive CPU cores 1, 5, and 7 are assigned. The cpuset.cpus file in the directory of that resource group reflects the allocation of 1, 5, and 7.
[0048] The "allocation change rule setting" for a certain resource group is setting information related to the rules (allocation change rules) that indicate whether or not changes to the allocated CPU resources corresponding to the resource group (i.e., to cpuset.cpus) from any program are permitted. The "allocation change rule setting" can be set to "revoke" or "none." "Revoke" means that changes are not permitted, and "none" means that changes are permitted.
[0049] The "authority delegation change rule setting" for a resource group is configuration information regarding a rule (authority delegation change rule) that indicates whether or not changes are permitted from any program to the CPU allocation authority of that resource group (i.e., to cgroup.subtree_control in the parent directory (hereinafter simply referred to as the "parent directory") of the "directory path" of that resource group). For example, the parent directory of " / sys / fs / cgroup / init.scope" is " / sys / fs / cgroup". There is no parent directory for the root cgroup. The "authority delegation change rule setting" can be set to "revoke" or "none". "Revoke" means that changes are not permitted, and "none" means that changes are permitted.
[0050] The allocation rule file r1 is defined (set) in advance by the user of this embodiment.
[0051] The allocation rule file analysis unit 13 analyzes the allocation rule file r1 line by line, and generates allocation rules, allocation change rules, and authority delegation change rules for each resource group.
[0052] Specifically, the allocation rule for a certain resource group is generated to reflect the "allocated CPU resources" in the "directory path" / cpuset.cpus file of the resource group. The allocation change rule for a certain resource group is generated as whether or not changes can be made to the "directory path" / cpuset.cpus file of the resource group (the value of the "allocation change rule setting"). The authority delegation change rule for a certain resource group is generated as whether or not changes can be made to the parent directory / cgroup.subtree_control file of the "directory path" of the resource group (the value of the "authority delegation change rule setting"). The authority delegation change rules of resource groups that share a common parent directory are aggregated into one. In this case, if the values of the "authority delegation change rule setting" differ between the resource groups involved in the aggregation, "revoke" takes precedence.
[0053] When generating each rule, if the "directory path" indicates a path that does not have an entity, such as a symbolic link, the allocation rule file analysis unit 13 converts the "directory path" into an entity path and applies the converted path to each rule.
[0054] Next, for each generated allocation rule, the CPU resource allocation setting unit 14 changes the "directory path" / cpuset.cpus file in the allocation rule, and reflects the contents of the "allocated CPU resources" in the allocation rule in each changed portion (S104). Note that if "cpuset" has not been written to the parent directory / cgroup.subtree_control of the "directory path" in the allocation rule, the CPU resource allocation setting unit 14 writes "cpuset" to the cgroup.subtree_control and then reflects the contents of the "allocated CPU resources" in the allocation rule in the "directory path" / cpuset.cpus file.
[0055] The update to the cpuset.cpus file in step S104 is hereinafter referred to as "static update." Static update is essentially a permanent update. Permanent update refers to updates that remain valid even after the system (such as the OS) is restarted. However, for some resource groups (e.g., the cgroup to which the init process belongs ( / sys / fs / cgroup / init.scope) and the cgroup to which the kubelet process belongs ( / sys / fs / cgroup / systemd / system.slice)), the "directory path" is regenerated each time the system is started. In other words, for such resource groups, the cpuset.cpus file is deleted each time the system is started, so static update is not permanent. For such resource groups, a separate mechanism must be built into the OS to set allocation rules in the cpuset.cpus file each time the system is started. Therefore, steps S105 to S112 are executed.
[0056] In step S105, the CPU resource allocation setting unit 14 sets the "CPU resource setting completion flag" for each change to "incomplete." The "CPU resource setting completion flag" is a flag that indicates whether or not the reflection of the allocation rule for the change to the system (resource control device 10) has been completed, and is stored in the auxiliary storage device 102 for each change, for example.
[0057] Next, the CPU resource allocation setting unit 14 restarts the system (S106). When the system restarts, step S101 and subsequent steps are executed again.
[0058] If the answer is No in step S101, the CPU resource allocation setting unit 14 determines whether all the "CPU resource setting completion flags" are set to "Complete" (S107). If all the "CPU resource setting completion flags" are set to "Complete" (Yes in S107), the process proceeds to step S113. If one or more "CPU resource setting completion flags" are set to "Incomplete" (No in S107), the CPU resource allocation setting unit 14 refers to the "directory" / cpuset.cpus file of all resource groups related to the allocation rule, checks whether the allocation rule has been reflected for the change points where the "CPU resource setting completion flag" is set to "Incomplete" (S108), and sets the "CPU resource setting completion flag" for the change points where the allocation rule has been reflected to "Complete" (S109). Next, the CPU resource allocation setting unit 14 determines whether all the "CPU resource setting completion flags" are set to "Complete" (S110). If one or more "CPU resource setting flags" are "incomplete" (as described above, if there is a resource group in which the "directory" has been regenerated and static reflection of the allocation rules has been disabled) (No in S110), the CPU resource allocation setting unit 14 calls the startup script generation unit 15 (S111).
[0059] In response to the call, the startup script generator 15 generates a startup script including a procedure (hereinafter referred to as the "CPU resource reflection procedure") for reflecting the contents of the allocation rules in the "directory" / cpuset.cpus file every time the system starts up for resource groups for which static reflection of allocation rules is disabled, and registers the startup script in the system (S112). The definition of the startup script at this point (i.e., the CPU resource reflection procedure) is as follows: (1) Wait for the "directory" of the resource group that is the target of dynamic reflection to be created (cr1). (2) When the "directory" is created, check whether there is a "directory" / cpuset.cpus of the resource group that is the target of dynamic reflection (cr2). (3) If there is no corresponding "directory" / cpuset.cpus, write "cpuset" to the parent directory / cgroup.subtree_control file of the "directory". As a result, "directory" / cpuset.cpus is created (cr3). (4) Following (3) or (4), write data to the "directory" / cpuset.cpus file of the resource group in accordance with the allocation rules (cr4).
[0060] Note that the numbers cr1 to cr4 at the end of each of the steps (1) to (4) are identifiers for each step in the CPU resource reflection procedure. As will be described later, not only the CPU resource reflection procedure but also procedures for ensuring that the CPU resource reflection procedure operates correctly (procedures identified by up1 and up2, as will be described later) are added to the startup script. Therefore, cr1 to cr4 are assigned for convenience to distinguish the CPU resource reflection procedure from the procedures to be added.
[0061] Next, step S106 is executed. After the restart in the re-executed step S106, the CPU resource update procedure based on the startup script is executed to perform dynamic update. Next, step S101 and subsequent steps are repeated.
[0062] On the other hand, when all the "CPU resource setting completion flags" are set to "Completed" through the CPU resource reflection procedure (Yes in S110), the process proceeds to step S113. At this point, the allocation change rule and authority delegation change rule have not been reflected in the system.
[0063] If the answer is Yes in step S110 or if the answer is Yes in step S107, the initiation unit 11 determines whether the exclusion rule file r2 has been updated (S113). An updated exclusion rule file r2 refers to a case where a new exclusion rule file r2 has been created, or an exclusion rule file r2 that was previously subject to processing in step S114 and subsequent steps has been updated. The exclusion rule file r2 is a file in which information to be set in the resource control device 10 is defined. The determination in step S113 is equivalent to a determination of whether the definition contents of the current exclusion rule file r2 have already been set in the resource control device 10. If the exclusion rule file r2 has not been updated (No in S113), the processing procedure in FIG. 4 ends.
[0064] If the exclusion rule file r2 has been updated (including the case where the definition contents of the exclusion rule file r2 have never been set in the resource control device 10) (Yes in S113), the initiation unit 11 calls the exclusion rule file reading unit 16.
[0065] In response to the call, the exclusion rule file reading unit 16 reads the definition contents of the exclusion rule file r2 and inputs the definition contents to the exclusion rule file analysis unit 17 (S114). The exclusion rule file analysis unit 17 analyzes the definition contents and generates exclusion rules (S115).
[0066] 6 is a diagram showing an example of the configuration of an exclusion rule file r2. The exclusion rule file r2 is a file that contains rules for excluding some programs that have a large impact on the system from the application of allocation change rules and authority delegation change rules in accordance with a unified profile (hereinafter referred to as "uniprofile") that sets file access to the system, which will be described later. As shown in FIG. 6, the exclusion rule file r2 includes, for each program to be excluded, a "program name," an "exclusion type," and a "rule file specification to be applied for Px."
[0067] "Program name" is the file path of the executable file of the program to be excluded.
[0068] The "exclusion type" is an item that indicates whether to simply exclude or to exclude the application of the uniprofile and apply another rule (profile). "Ux" indicates exclusion, and "Px" indicates the application of another profile.
[0069] "Specifying a rule file to be applied in the case of Px" indicates the file path of a profile (hereinafter referred to as an "individual profile") to be applied to a program whose "exclusion type" is "Px".
[0070] The exclusion rule file r2 is defined (set) in advance by the user of this embodiment.
[0071] The exclusion rule file analysis unit 17 analyzes the exclusion rule file r2 line by line, and generates an exclusion rule for each program to be excluded, including a "file path name," an "exclusion type," and a "rule file specification to be applied in case of Px." At this time, if the "program name" indicates a path that does not have an entity, such as a symbolic link, the exclusion rule file analysis unit 17 converts the "program name" into an entity path, and applies the converted path to the exclusion rule.
[0072] Next, when the exclusion rule file analysis unit 17 calls the change rule setting unit 18, the change rule setting unit 18 causes the startup script generation unit 15 to generate a profile including a declaration of which functions provided by the LSM 22 to use in order to reflect each file access rule based on the allocation change rule, authority delegation change rule, and exclusion rule in the system (S116).
[0073] Basically, a profile for file access of the LSM 22 is a file that describes file paths that are accessible or inaccessible to the program to which the profile applies (and all child processes derived from that program).
[0074] Specifically, the startup script generator 15 generates a uniprofile that includes file access rules defined by the allocation change rule, the authority delegation change rule, and the exclusion rule, with the init process as the target program of the profile. The init process is the target program because the init process with PID=1 is the ancestor of all processes, and access control cannot be enabled for the entire Linux (registered trademark) system unless the settings of the LSM 22 are reflected from the init process.
[0075] Here, the resource group (cgroup) to which the init process belongs is " / sys / fs / cgroup / init.scope." Therefore, if the "allocation change rule setting" of " / sys / fs / cgroup / init.scope / cpuset.cpus" in the allocation change rule is "revoke" as shown in FIG. 5, the startup script generation unit 15 generates a file access rule that specifies prohibition (suppression) of changes to " / sys / fs / cgroup / init.scope / cpuset.cpus."
[0076] Similarly, the startup script generation unit 15 generates file access rules that specify prohibition (prevention) of changes to cpuset.cpus for " / sys / fs / cgroup / system.slice," " / sys / fs / cgroup / user.slice," " / sys / fs / cgroup / user.slice / user1000.slice," and "default" in Figure 5, where the "allocation change rule setting" is "revoke."
[0077] Furthermore, if the "authority delegation change rule setting" of " / sys / fs / cgroup / init.scope / cpuset.cpus" in the authority delegation change rule is "revoke" as shown in FIG. 5, the startup script generation unit 15 generates a file access rule that specifies prohibition (suppression) of changes to cgroup.subtree_control (i.e., " / sys / fs / cgroup / cgroup.subtree_control") of the parent directory of the resource group to which the init process belongs.
[0078] Similarly, the startup script generation unit 15 generates file access rules that specify prohibition (suppression) of changes to the parent directory / cgroup.subtree_control for " / sys / fs / cgroup / system.slice," " / sys / fs / cgroup / user.slice," " / sys / fs / cgroup / user.slice / user1000.slice," " / sys / fs / cgroup / systemd / system.slice," and "default," whose "Permission Change Rule Setting" is "revoke" in Fig. 5. In this case, the parent directory of " / sys / fs / cgroup / system.slice" and " / sys / fs / cgroup / user.slice" is the same as the parent directory of " / sys / fs / cgroup / init.scope," so these are aggregated into one file access rule.
[0079] The startup script generation unit 15 further generates file access rules for making programs that are subject to the exclusion rules excluded (excluded) from the file access rules. At this time, for programs whose "exclusion type" is "Px," the startup script generation unit 15 generates the access rules so that "the specification of the rule file to be applied in the case of Px" is applied.
[0080] The startup script generating unit 15 compiles the above file access rules into a uniprofile to be registered in the LSM 22 .
[0081] The definition of the uniprofile generated as described above has the following format (in the example below, a profile by AppArmor, a type of LSM 22, is described as an example): "profile uniprofile name absolute path of the entity program of the init process { : file, : file access restriction rule 1 file access restriction rule 2 ...}" A specific example of a uniprofile based on the above format is shown below. 「profile init-profile / usr / lib / systemd / systemd flags=(attach_disconnected, complain) { # Allow all rules capability, network, file, mount, umount, remount, pivot_root, ptrace, signal, dbus, change_profile, # Exclusion rules / usr / bin / crio Ux, / usr / local / bin / kubelet Ux, # Prevent changes by allocation change rules and authority delegation change rules deny / sys / fs / cgroup / cgroup.subtree_control w, deny / sys / fs / cgroup / init.scope / cpuset.cpus w, deny / sys / fs / cgroup / system.slice / cpuset.cpus w, deny / sys / fs / cgroup / user.slice / cpuset.cpus w, deny / sys / fs / cgroup / user.slice / cgroup.subtree_control w, deny / sys / fs / cgroup / user.slice / user1000.slice / cpuset.cpus w, deny / sys / fs / cgroup / systemd / cgroup.subtree_control w, # Add default rule.In the case of revoke, it is commented out as deny, and in the case of none, it is commented out as deny / sys / fs / cgroup / ** / cpuset.cpus w, deny / sys / fs / cgroup / ** / cgroup.subtree_control w,}" Next, the change rule setting unit 18 calls the startup script generation unit 15 to reflect the settings for implementing access control using the uniprofile through the "startup script generation unit" (S117).
[0082] At this point, the timing of execution of the CPU resource reflection procedure and the UniProfile reflection procedure when the system is rebooted will be described.
[0083] Even if you execute the CPU resource reflection procedure when UniProfile is applied, you cannot correctly set the CPU resource to cpuset.cpus, which is the target of the CPU resource setting, because UniProfile has already prohibited changes to cpuset.cpus.
[0084] In this way, the order in which the "UniProfile reflection procedure" and the "CPU resource reflection procedure" are executed is very important.
[0085] However, when the system is running, it is not possible to completely reflect the settings in the LSM 22 for the uniprofile based on the allocation change rules, authority delegation change rules, and exclusion rules to all processes from the init process at system startup, because the settings in the LSM 22 are reflected after the init process is started.
[0086] Therefore, in this embodiment, in order to reflect the uniprofile in all processes including the init process from the time of system startup, the uniprofile of the LSM 22 is included in the temporary RAM-based root file system (temporary root file system) that is called first at system startup, so that the uniprofile is read before the init process is read and reflected in the LSM 22. For this reason, the uniprofile is incorporated (saved) in the initramfs.
[0087] Next, the startup script generator 15 modifies the startup script definition as follows so that the UniProfile reflection procedure and CPU resource reflection procedure operate correctly, and re-registers the startup script to the system (S118). (1) Changes the UniProfile access restrictions so that the cpuset.cpus file and the cgroup.subtree_control file can be modified (up1). (2) Waits for the "directory" of the resource group that is the target of dynamic reflection to be created (cr1). (3) When the "directory" is created, checks whether "directory" / cpuset.cpus exists for the resource group that is the target of dynamic reflection (cr2). (4) If the corresponding "directory" / cpuset.cpus does not exist, writes "cpuset" to the parent directory / cgroup.subtree_control file of the "directory". As a result, "directory" / cpuset.cpus is created (cr3). (5) Following (3) or (4), writes to the "directory" / cpuset.cpus file of the resource group in accordance with the allocation rules (cr4). (6) After the writing is completed, the uniprofile is returned to its original state (up2).
[0088] Among the above steps (1) to (6), the steps with up1 or up2 added to the end are the steps that are added in step S118.
[0089] That is, the uniprofile access restrictions are released (disabled) (up1) so that the CPU resource reflection procedure is enabled, and after the CPU resource reflection procedure is executed, the startup script is modified (up2) so that the uniprofile access restrictions are restored (enabled).
[0090] To execute up1, for example, following the example of the uniprofile described above, a uniprofile with the same uniprofile name is created and reflected in the LSM 22, enabling the execution of procedure up1. "profile init-profile / usr / lib / systemd / systemd flags=(attach_disconnected, complain) { # Allow all rules capability, network, file, mount, umount, remount, pivot_root, ptrace, signal, dbus, change_profile, # Exclusion rules / usr / bin / crio Ux, / usr / local / bin / kubelet Ux,}" Next, step S106 is repeated. After the restart in the re-executed step S106, in addition to the CPU resource reflection procedure, the uniprofile reflection procedure is also executed based on the startup script and the uniprofile.
[0091] Specifically, in the restart in step S106 executed following step S118, the resource control device 10 executes each procedure as shown in FIG.
[0092] Figure 7 is a diagram for explaining the timing of each step related to the UniProfile reflection procedure and the CPU resource reflection procedure. Figure 7 shows three horizontal axes: "UniProfile reflection procedure," "System operation," and "CPU resource reflection procedure." Time progresses to the right on each horizontal axis, and the points where a perpendicular line intersects with each horizontal axis represent the same timing on each horizontal axis. Note that the definitions (1) to (6) of the startup script in the explanation of Figure 7 correspond to steps (1) to (6) in the startup script definition content described above.
[0093] "System operation" indicates a processing procedure that is executed each time the system is started, even if this embodiment is not applied. Therefore, in Fig. 4, the system operation is executed in step S106 following step S105, step S106 following step S112, and step S106 following step S118.
[0094] The "CPU resource reflection procedure" is a processing procedure executed based on cp1 to cp4 of the startup script, and is therefore a processing procedure executed every time the system is started after the startup script is registered in the system. Therefore, in Figure 4, the CPU resource reflection procedure is executed in step S106 after step S112 is executed.
[0095] Since the "UniProfile Reflection Procedure" is a processing procedure executed based on the UniProfile and the startup scripts up1 and up2, it is executed in step S106 after the UniProfile is registered in the system and the startup script is modified in step S118.
[0096] That is, all three processing procedures are executed in step S106 following step S118 (or at the subsequent system startup). Here, the timing of the three processing procedures in step S106 following step S118 will be described.
[0097] When system startup begins (S201) and reading of initramfs begins (S202), the kernel reads the uniprofile from initramfs and applies it to the LSM 22 (S203). As a result, writing to cpuset.cpus or cgroup.subtree_control is prohibited based on the allocation change rule or the authority delegation change rule.
[0098] Thereafter, when the init process is started (S204), an Apparmor (hereinafter simply referred to as "Apparmor"), which is a type of LSM 22, is called from a shell program (hereinafter simply referred to as "shell program"), which is a child process of the init process, and the Apparmor changes the uniprofile based on the definition (1) of the startup script so that access to files that are prohibited in the allocation change rules or authority change rules for the resource group that is the target of dynamic reflection is permitted, and reflects the changed uniprofile to LSM 22 (S205).
[0099] Next, the shell program waits for the creation of a directory for the resource group (cgroup) to which the init process belongs, based on definition (2) of the startup script. Once the directory is created, the shell program sets allocation rules for the resource group to the cpuset.cpus (" / sys / fs / cgroup / init.scope / cpuset.cpus") of the resource group to which the init process, which is the target of dynamic reflection, belongs, based on definitions (3) and (5) of the startup script (S206). If the cpuset.cpus does not exist, the shell program writes "cpuset" to " / sys / fs / cgroup / cgroup.subtree_control" based on definition (4) of the startup script, waits for the cpuset.cpus to be created, and then sets allocation rules for the cpuset.cpus based on definition (5) of the startup script.
[0100] Thereafter, for example, when the kubelet process is started, the shell program waits for the creation of a directory for the resource group (cgroup) to which the kubelet process belongs, based on the definition (2) of the start-up script (S207).
[0101] When the directory is created, the iShell program sets allocation rules for the resource group to the cpuset.cpus (" / sys / fs / cgroup / systemd / system.slice / cpuset.cpus") of the resource group to which the kubelet process that is the target of dynamic reflection belongs, based on the definitions (3) and (5) of the startup script (S208). If the cpuset.cpus does not exist, the shell program writes "cpuset" to " / sys / fs / cgroup / systemd / cgroup.subtree_control" based on the definition (4) of the startup script, waits for the cpuset.cpus to be created based on the definition (5) of the startup script, and then sets allocation rules for the cpuset.cpus.
[0102] When dynamic reflection is completed for all resource groups that require dynamic reflection, Apparmor restores (enables) the uniprofile that was changed (disabled) in step S205 based on the definition (6) of the startup script and reflects it to LSM22 (S209).
[0103] As a result, the allocation rules are applied to the system, and the allocation change rules, authority delegation change rules, and exclusion rules are also applied to the system. As a result, the resource control mechanism 21 executes CPU resource allocation based on the allocation rules. In addition, in this state, the LSM 22 can detect an opportunity to change cpuset.cpus or cgroup.subtree_control, which are prohibited from being changed in the allocation change rules or authority delegation change rules, and can suppress the change.
[0104] Thereafter, the detection unit 221, determination unit 222, and process execution unit 223 of the LSM 22 prevent writing to files (cpuset.cpus, cgroup.subtree_control) related to the allocation rule or authority delegation rule according to the allocation change rule, authority delegation change rule, and exclusion rule.
[0105] That is, the detection unit 221 detects an opportunity to access (change) any file on the resource control device 10 .
[0106] The determination unit 222 determines, based on UniProfile, whether the file for which a change trigger has been detected is a file for which changes are prohibited under the allocation change rule or the authority delegation change rule. The determination unit 222 also determines whether the program attempting to change the file is excluded from the allocation change rule or the authority delegation change rule under the exclusion rule.
[0107] When a trigger for a change is detected for a file that is prohibited from being changed and it is determined that the program attempting to change the file is not subject to exclusion, the processing execution unit 223 executes processing to prevent the change.
[0108] As described above, this embodiment monitors the trigger for a change to the settings of CPU resources allocated to a certain resource group, and when such a trigger is detected, it is possible to perform control (such as prevention) based on the allocation rule file r1. As a result, it is possible to prevent the rewriting of cpuset.cpus and cgroup.subtree_control before they are rewritten. Therefore, it is possible to realize a mechanism for consistently and stably allocating CPU resources according to unified rules.
[0109] In this embodiment, cpuset.cpus is an example of a first file. cgroup.subtree_control is an example of a second file. The resource control mechanism 21 is an example of a first mechanism. The LSM 22 is an example of a second mechanism. The CPU resource allocation setting unit 14 is an example of a first setting unit. The change rule setting unit 18 is an example of a second setting unit. The startup script generation unit 15 is an example of a generation unit. The allocation rules in the allocation rule file r1 are an example of first setting information. The allocation change rules and the authority delegation change rules are examples of second setting information. The exclusion rules are an example of third setting information.
[0110] Although the embodiments of the present invention have been described in detail above, the present invention is not limited to such specific embodiments, and various modifications and changes are possible within the scope of the gist of the present invention described in the claims.
[0111] 10 Resource control device 11 Start unit 12 Allocation rule file reading unit 13 Allocation rule file analysis unit 14 CPU resource allocation setting unit 15 Start-up script generation unit 16 Exclusion rule file reading unit 17 Exclusion rule file analysis unit 18 Change rule setting unit 21 Resource control mechanism 22 LSM 100 Drive device 101 Recording medium 102 Auxiliary storage device 103 Memory device 104 CPU 105 Interface device 221 Detection unit 222 Determination unit 223 Processing execution unit B Bus
Claims
1. A resource control device having: a first mechanism that allocates CPU cores to a program based on a first file if specific information indicating that a first file, the first file storing information indicating a list of CPU cores actually allocated to each of a plurality of groups set for a program's operating unit, is valid is recorded in a second file; and a second mechanism that executes a specified process when it detects an opportunity to change the specified file. The resource control device has: a first setting unit configured to reflect first setting information regarding the CPU cores to be allocated to the group in the first file; and a second setting unit configured to specify to the second mechanism the first file and the second file, and the prevention of changes to the first file and the second file, in accordance with second setting information regarding whether or not the first file and the second file in which the specific information is recorded can be changed.
2. The resource control device according to claim 1, characterized in that the second setting unit is configured to specify to the second mechanism that a program to be excluded from the specified processing based on third setting information for the program to be excluded from the second setting information.
3. A resource control device as described in claim 1 or 2, characterized in that the first setting unit is configured to restart the resource control device after reflecting the first setting information in the first file, and a generation unit configured to generate a script to be executed by the resource control device when the resource control device is started up, the script being configured to reflect the first setting information in the first file if the reflection of the first setting information in the first file is disabled after the restart.
4. A resource control device as described in claim 3, characterized in that the generation unit is configured to generate the script so that a procedure for invalidating the specification made by the second setting unit for the second mechanism, reflecting the first setting information in the first file, and enabling the specification for the second mechanism is executed when the resource control device is started.
5. A resource control method comprising: a first mechanism for allocating CPU cores to a program based on a first file if specified information indicating that a first file storing information indicating a list of CPU cores actually allocated to each of a plurality of groups set for a program's operating unit is valid is recorded in a second file; and a second mechanism for executing a specified process when a trigger for a change to the specified file is detected, the resource control device executing a first setting procedure for reflecting first setting information regarding the CPU cores to be allocated to the group in the first file; and a second setting procedure for specifying to the second mechanism the first file and the second file, and the prevention of changes to the first file and the second file, depending on second setting information regarding whether or not the first file and the second file in which the specified information is recorded can be changed.
6. A program for causing a resource control device having: a first mechanism for allocating CPU cores to a program based on a first file if specified information indicating that a first file storing information indicating a list of CPU cores actually allocated to each of a plurality of groups set for a program's operating unit is valid is recorded in a second file; and a second mechanism for executing a specified process when a trigger for a change to the specified file is detected; a first setting procedure for reflecting first setting information regarding the CPU cores to be allocated to the group in the first file; and a second setting procedure for specifying to the second mechanism the first file and the second file, and the prevention of changes to the first file and the second file, depending on second setting information regarding whether or not the first file and the second file in which the specified information is recorded can be changed.
Citation Information
Patent Citations
Distributed control system
JP2000259589A
Communication device and processor allocation method of the same
JP2016162266A
