Tuning CPUs and Hugepages on a Linux System

45 minutes
  • 5 Learning Objectives

About this Hands-on Lab

This hands-on lab will focus on CPU tuning and configuring `hugepages` on a lab system. You will be using `tuna` to view open CPU threads, filtering the output for a specific script, then isolating the script to a specific CPU. When CPU tuning is complete, you will set a value for `hugepages` and disable transparent `hugepages`, then confirm the changes after loading the new configuration.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Manage CPU Affinity Using a PID or Process Name
  1. Install the tuna package.
  2. Launch the affinity.sh script in the background.
    • The script spawns a dd process in the background.
  3. Use tuna to show open threads, filtering for dd.
    • Make note of the current thread affinity.
  4. Use tuna to move the dd instance to CPU 0.
  5. Confirm the process has moved using tuna, filtering for dd.
    • Verify the current thread affinity is set to 0.
  6. Kill the dd process.
Manage CPU Affinity Using Systemd
  1. Enable and start the evodd service.
    • The service spawns a dd process in the background.
  2. Use systecmctl to create an override file for the evodd service.
    • Under [Service], and an entry CPUAffinity and set the value to CPU 0.
    • Execute the daemon-reload.
    • Cycle the evodd service.
  3. Confirm the process has moved using tuna, filtering for dd.
    • Verify the current thread affinity is set to 0.
  4. Stop and disable the evodd service.
Review the System’s Hugepages Configuration
  1. Check for any kernel configurations.
    • Check the values in /proc/cmdline.
    • Check the grub configuration file.
  2. Review the current hugepages values.
    • Review the values in /proc/meminfo.
    • Check the values using sysctl.
  3. Determine if transparent hugepages are enabled.
    • Check the value of /sys/kernel/mm/transparent_hugepage/enabled.
Configure a Hugepages Value and Disable Transparent Hugepages
  1. Option 1: Create a control file in /etc/sysctl.d/.
    • Enter new hugepages value.
    • Save the file.
    • Load changes using sysctl -p
    • Not the solution used in this lab.
  2. Option 2: Add the kernel options to the grub configuration.
    • Edit /etc/default/grub.
    • Scroll down to the GRUB_CMDLINE_LINUX row in the file.
      • To enable and set the number of hugepages, scroll to the end of the line and add hugepages=, followed by the value.
      • To set the default hugepages size, you can added default_hugepagesz=.
      • To disable transparent hugepages, you would add transparent_hugepages=never.
    • Save the file and complete the grub updates steps, then reboot the system to pick up the changes.
    • Not the final solution for the lab.
  3. Option 3: Use tuned to manage hugepages.
    • Create a tuned profile called huge_profile.
    • Create the configuration file and open it for editing.
      • Create the [main] section and include the virtual-guest profile.
      • To enable huge pages, go to the [sysctl] section, add the vm.nr_hugepages entry and set the value to 10.
      • To disable transparent huge pages, add a section called [vm], add an entry called transparent_hugepages and set the value to never.
    • Enable and validate the custom profile.
      • Using the appropriate tuned command, enable the profile.
      • Verify the profile has been loaded and settings applied using the appropriate tuned command.
    • Validate the changes on the system.
  4. Review the current hugepages values.
    • Review the values in /proc/meminfo.
    • Check the values using sysctl.
  5. Confirm transparent hugepages are disabled.
  6. This will be the option focused on for the lab.
Reboot the Lab and Confirm Changes Persist
  1. Verify the custom profile is active.
  2. Validate the changes on the system.
    • Review the current hugepages values.
      • Review the values in /proc/meminfo.
      • Check the values using sysctl.
    • Confirm transparent hugepages are disabled.

Additional Resources

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?