cgroup-rts-threads-0.1.0.0: A container-/cgroup-aware substitute for the GHC RTS `-N` flag
Safe HaskellNone
LanguageHaskell2010

System.CGroup.Controller.Internal

Description

Internal types and functions for cgroup controllers

Synopsis

CGroup Controllers

newtype Controller a Source #

A CGroup controller path for a specific subsystem

Constructors

Controller 

Instances

Instances details
Eq (Controller a) Source # 
Instance details

Defined in System.CGroup.Controller.Internal

Methods

(==) :: Controller a -> Controller a -> Bool #

(/=) :: Controller a -> Controller a -> Bool #

Ord (Controller a) Source # 
Instance details

Defined in System.CGroup.Controller.Internal

Show (Controller a) Source # 
Instance details

Defined in System.CGroup.Controller.Internal

resolveCGroupController :: Text -> IO (Controller a) Source #

Resolve a CGroup controller by name, as viewed by the current process

see cgroups(7): /proc/self/cgroup is a file that contains information about control groups applied to this process

see proc(5): /proc/self/mountinfo is a file that contains information about mounts available to this process

Throws an Exception when the controller is not able to be found, or when running outside of a cgroup

resolveCGroupController' :: Path Abs File -> Path Abs File -> Text -> IO (Controller a) Source #

Resolve a CGroup controller by name, under the given cgroup and mountinfo paths

Throws an Exception when the controller is not able to be found, or when running outside of a cgroup

CGroups

data CGroup Source #

A cgroup, as viewed within /proc/[pid]/cgroup

see cgroups(7): /proc/[pid]/cgroup section

Instances

Instances details
Show CGroup Source # 
Instance details

Defined in System.CGroup.Controller.Internal

Mounts

data Mount Source #

A mount, as viewed within /proc/[pid]/mountinfo

see proc(5): /proc/[pid]/mountinfo section

Instances

Instances details
Show Mount Source # 
Instance details

Defined in System.CGroup.Controller.Internal

Methods

showsPrec :: Int -> Mount -> ShowS #

show :: Mount -> String #

showList :: [Mount] -> ShowS #

Internal intermediate operations

findMatchingCGroup :: Text -> [CGroup] -> Maybe CGroup Source #

Find a CGroup matching a controller name

For cgroups version 1, we use containsController to explicitly look for the controller within a cgroup

For cgroups version 2, we use emptyControllers to find a cgroup without any controllers

see cgroups(7): /proc/[pid]/cgroup section

resolveControllerMountPath :: Text -> CGroup -> [Mount] -> Maybe (Path Abs Dir) Source #

Find a Mount matching a controller name and cgroup, returning the absolute resolved path of a controller

tryResolveMount :: Text -> CGroup -> Mount -> Maybe (Path Abs Dir) Source #

Attempt to match a cgroup controller to a mount, returning the absolute resolved path of the controller

Returns Nothing if the mount does not match the cgroup controller

A matching mount must have a filesystem type of "cgroup" and contain the controller name within its "super options".

Per cgroups(7), the cgroup path is relative to a mount root in the process's mount hierarchy. Notably, a mount root is not the same as its mount point. A mount point is the path at which the mount is visible to the process.

As such, we need to look for a mount whose mount root either..

  • ..exactly matches our cgroup's path, in which case we directly return the mount's mount path; OR
  • ..is a prefix of our cgroup's path, in which case we return the relative path from the mount root appended to the mount's mount path

parseMountInfo :: Parser [Mount] Source #

Parse an entire /proc/[pid]/mountinfo file into a list of mounts

parseCGroups :: Parser [CGroup] Source #

Parse an entire /proc/[pid]/cgroup file into a list of cgroups

type Parser = Parsec Void Text Source #

Megaparsec Parser