If you want to limit the CPU or memory usage when Ascend DMI is running on the physical machine, refer to this section.
Control groups (cgroups) are a mechanism provided by the Linux kernel to limit the resources used by a single or multiple processes. They can implement refined control on resources such as the CPU and memory. By restricting the CPU and memory usage when Ascend DMI is running, you can prevent Ascend DMI from occupying too many resources. If Ascend DMI occupies too many resources, other programs cannot run properly. The operations are as follows:
cd /sys/fs/cgroup/cpu mkdir ascend-dmi # The directory name can be customized.
After the ascend-dmi directory is created, files such as cpu.cfs_period_us and cpu.cfs_quota_us are automatically generated in the directory.
File |
Description |
|---|---|
cpu.cfs_period_us |
CPU cycle, in microseconds. The value ranges from 1000 to 1000000. The default value is 100000. |
cpu.cfs_quota_us |
CPU time that can be occupied in the configured period (time of a single core, which needs to be accumulated for multiple cores during configuration). The default value is -1, indicating that the CPU time is not limited.
|
tasks |
PID list of the processes to be restricted. For a child process derived from the PID after the restriction takes effect, the PID of the child process is automatically added to the file. You are advised to add the PID of the shell that runs the program to the tasks by running the echo $$ command, and then start the program. |
For example, to set the maximum CPU usage to 50%, perform the following operations:
Retain the default value in the cpu.cfs_period_us file and change the value in the cpu.cfs_quota_us file to 50000. In the shell window where Ascend DMI is to be run, run the echo $$ command to query the PID and write it to the tasks file.
cd /sys/fs/cgroup/memory mkdir ascend-dmi # The directory name can be customized.
After the ascend-dmi directory is created, files such as memory.limit_in_bytes and tasks are automatically generated in the directory.
File |
Description |
|---|---|
memory.limit_in_bytes |
Limits the memory usage of a process. For example, to set the maximum memory usage to 500 MB, change the value in the memory.limit_in_bytes file to 524288000 (500 x 1024 x 1024). |
tasks |
PID list of the processes to be restricted. For a child process derived from the PID after the restriction takes effect, the PID of the child process is automatically added to the file. You are advised to add the PID of the shell that runs the program to the tasks by running the echo $$ command, and then start the program. |
For example, to set the maximum memory usage to 500 MB, change the value in the memory.limit_in_bytes file to the calculated value 524288000. In the shell window where Ascend DMI is to be run, run the echo $$ command to query the PID and write it to the tasks file.