cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 46 Views

systemd Units - Resource Control

systemd uses several different unit types:
- target
- socket
- device
- automount
- path
- swap
- timer
- snapshot
- scope
- busname

A unit is a systemd object - that performs or controls a particular task or action.

Systemd uses units to start/stop/manage services, organize the boot process, maintain tasks and processes, create sockets, mount filesystems, and initialize hardware.

Of all the unit types used by systemd, three unit types are relevant for resource control:
slice
scope
service

A brief description of each of these three unit types is provided below:

  • Service — A process or a group of processes, which systemd started based on a unit configuration file. Services encapsulate the specified processes so that they can be started and stopped as one set. Services are named in the following way:


    name.service

    Where name stands for the name of the service.

  • Scope — A group of externally created processes. Scopes encapsulate processes that are started and stopped by arbitrary processes through the fork() function and then registered by systemd at runtime. For instance, user sessions, containers, and virtual machines are treated as scopes. Scopes are named as follows:
     


    name.scope

    Here, name stands for the name of the scope.

  • Slice — A group of hierarchically organized units. Slices do not contain processes, they organize a hierarchy in which scopes and services are placed. The actual processes are contained in scopes or in services. In this hierarchical tree, every name of a slice unit corresponds to the path - a location in the hierarchy. The dash ("-") character acts as a separator of the path components. For example, if the name of a slice looks as follows:
     


    parent-name.slice

    This means that a slice called parent-name.slice is a subslice of the parent.slice. This slice can have its own subslice named parent-name-name2.slice, and so on.

    There is one root slice denoted as:

    -.slice
     
 
Service, Scope, and Slice units directly map to objects in the cgroup tree. When these units are activated, they map directly to cgroup paths built from the unit names. For example, the ex.service residing in the test-waldo.slice is mapped to the cgroup test.slice/test-waldo.slice/ex.service/.
 
Services, scopes, and slices are created manually by the system administrator or dynamically by programs. By default, the operating system defines a number of built-in services that are necessary to run the system. Also, there are four slices created by default:
  • -.slice — the root slice;
  • system.slice — the default place for all system services;
  • user.slice — the default place for all user sessions;
  • machine.slice — the default place for all virtual machines and Linux containers.
Note that all user sessions are automatically placed in a separated scope unit, as well as virtual machines and container processes. Furthermore, all users are assigned with an implicit subslice. Besides the above default configuration, the system administrator can define new slices and assign services and scopes to them.


*** The focus of this post was to highlight the systemd units that are pertinent to resource control.

Note: The great majority of systemd units are beyond the scope of what's covered in the RHCSA and RHCE courses.  Of the three systemd units relevant to resource control, the Service unit gets the lion's share of the coverage!

 

 

Additional info:  Not intended to extend the focus of the resource control purpose of
the Service, Slice, and Scope units:
                               
Service
t  units and slice units can be configured with persistent unit files
or created dynamically at runtime by API calls to PID 1

Scope units can be created only dynamically.

Units created dynamically with API calls are transient and exist only during runtime.

Transient units are released automatically as soon as they finish, get deactivated, or the system is rebooted.

 

Trevor "Red Hat Evangelist" Chandler
Labels (3)
Tags (1)
0 Replies
Join the discussion
You must log in to join this conversation.