Managing System Resources Using Control Groups

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will focus on managing system resource limits using `control groups` (`cgroups`). Using `top` or a similar tool, you will review CPU activity and identify the `PID` of a high CPU process, then create a control group and set a limit using the `PID` value and confirm the limits were properly applied. The final task will be to start a service, monitor the CPU utilization, and create a permanent resource limit using a `systemd` control file for the service.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Use cgroups to Manage Settings at the PID Level
  1. Launch the cg-review.sh script as a background application.
  2. Launch your preferred utility to monitor processes and monitor CPU and memory utilization, such as top.
    • Identify any processes that are consuming excess CPU and note the PID value.
  3. Configure the limit values:
    • Create a directory called lab in /sys/fs/cgroup/cpu/.
      • Confirm the directory is populated.
    • As the root user, set the limits as follows:
      • cpu.cfs_period_us = 1000000
      • cpu.cfs_quota_us = 200000
      • Confirm the values are configured.
    • Add the process PID to the cpu/lab/cgroup.procs file for the lab cgroup.
      • Confirm the limit was applied by checking in /proc.
    • Launch top and check for the process, confirming the CPU usage has been limited as expected.
  4. Kill the process.
  5. Exit the root account
Manage Resource Limits Using systemd
  1. Enable and start the evotl service.

    Note: This service will cause the systemd-journald service to consume around 50% of the CPU at times. This is ok for the purposes of the lab.

    • This service spawns a tail process that consumes around 2G of memory.
  2. Check the status of the evotl service.
  3. Launch top and review the top memory processes.
    • You should see the tail process consuming approximately 50-55% of the memory.
  4. Use systemctl to set the MemoryLimit property to 1000M.

    Note: This could take a several seconds to complete, be patient.

  5. Check the status of the change.
    • Use systemctl to view the evotl service and confirm a limit file was created.
    • Launch top and confirm the tail process now consumes around 25% of the memory.
Reboot the Lab and Confirm Configuration Persists
  1. Use systemctl to check the status of the evotl service.
    • Confirm the service still has the memory limit in place.
  2. Launch top and monitor the status of the tail process.
    • Confirm the process is currently consuming around 25% of the memory.
Revert the Memory Limit and Disable the Service
  1. Stop the evotl service.
  2. Remove the 50-MemoryLimit.conf file for the evotl service.
  3. Disable the evotl service.

Additional Resources

SCENARIO:

You are a Linux System Administrator working for a software development company. A newly deployed script and service are consuming too many resources on the system, impacting other applications and your end users' abilities to effectively work on the system. The script is only a temporary issue since it only needs to be run once to generate a report; the service will need to run continually in the background, as it is a core part of the company's suite of tools.

Your manager has assigned you the task of controlling CPU resource utilization for the script, as well as finding a longer-term solution for the service's memory-related utilization until the software team can identify and correct the issue. You are in the process of testing and validating the use of cgroups on a test system and, once confirmed, you will be able to work with the developers and architects to deploy the changes to all the identified systems.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?