Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Private Member Functions | Private Attributes | List of all members
IonMemoryPlugin Class Referencefinal

Plugin used to setup the ION cgroup controller for the container. More...

#include <IonMemoryPlugin.h>

Inheritance diagram for IonMemoryPlugin:
Inheritance graph
[legend]
Collaboration diagram for IonMemoryPlugin:
Collaboration graph
[legend]

Public Member Functions

 IonMemoryPlugin (std::shared_ptr< rt_dobby_schema > &containerConfig, const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::string &rootfsPath)
 
std::string name () const override
 Should return the name of the plugin. More...
 
unsigned hookHints () const override
 Set the bit flags for which hooks we're going to use.
 
bool createRuntime () override
 OCI Hook - Run in host namespace. We use this point to create a cgroup and put the containered process into it. More...
 
bool postStop () override
 Poststop hook, we use this point to remove the cgroup directory created in the pre start phase. More...
 
- Public Member Functions inherited from RdkPluginBase
virtual bool postInstallation ()
 
virtual bool preCreation ()
 
virtual bool createContainer ()
 
virtual bool postStart ()
 
virtual bool postHalt ()
 
std::vector< std::string > getDependencies () const override
 Should return the names of the plugins this plugin depends on. More...
 

Private Member Functions

std::string findIonCGroupMountPoint () const
 Attempts to get the mount points of the ION cgroup filesystem. More...
 
bool setupContainerIonLimits (const std::string &cGroupDirPath, pid_t containerPid, const std::map< std::string, uint64_t > &heapLimits, uint64_t defaultLimit)
 Creates a ion cgroup for the container and moves the container into it. More...
 

Private Attributes

const std::string mName
 
std::shared_ptr< rt_dobby_schema > mContainerConfig
 
const std::shared_ptr< DobbyRdkPluginUtilsmUtils
 
const std::string mRootfsPath
 
bool mValid
 
const rt_defs_plugins_ion_memory_data * mPluginData
 

Additional Inherited Members

- Public Types inherited from IDobbyRdkPlugin
enum  HintFlags : unsigned {
  PostInstallationFlag = (1 << 0) , PreCreationFlag = (1 << 1) , CreateRuntimeFlag = (1 << 2) , CreateContainerFlag = (1 << 3) ,
  PostStartFlag = (1 << 5) , PostHaltFlag = (1 << 6) , PostStopFlag = (1 << 7) , Unknown = 0
}
 Bit flags that should be returned by hookHints. More...
 

Detailed Description

Plugin used to setup the ION cgroup controller for the container.

ION is the raw memory allocator from Android, it is used on RDK platforms by some vendors to allocate memory buffers for the following systems:

Member Function Documentation

◆ createRuntime()

bool IonMemoryPlugin::createRuntime ( )
overridevirtual

OCI Hook - Run in host namespace. We use this point to create a cgroup and put the containered process into it.

We also set any limits from the plugin JSON data provided.

The cgroup is given the same name as the container.

Returns
True on success, false on failure.

Reimplemented from RdkPluginBase.

◆ findIonCGroupMountPoint()

std::string IonMemoryPlugin::findIonCGroupMountPoint ( ) const
private

Attempts to get the mount points of the ION cgroup filesystem.

This scans the mount table looking for the cgroups mounts. This is typically the name of the cgroup prefixed with "/sys/fs/cgroup"

Returns
path to the ION cgroup mount, or empty string if failed to find it.

◆ name()

std::string IonMemoryPlugin::name ( ) const
inlineoverridevirtual

Should return the name of the plugin.

Returns
string with the name of the hook.

Implements IDobbyRdkPlugin.

◆ postStop()

bool IonMemoryPlugin::postStop ( )
overridevirtual

Poststop hook, we use this point to remove the cgroup directory created in the pre start phase.

The directory will have the same name as the container id.

Parameters
[in]idThe id of the container.
[in]configThe container config.
[in]rootfsThe path to the container rootfs.
Returns
true if successful otherwise false.

Reimplemented from RdkPluginBase.

◆ setupContainerIonLimits()

bool IonMemoryPlugin::setupContainerIonLimits ( const std::string &  cGroupDirPath,
pid_t  containerPid,
const std::map< std::string, uint64_t > &  heapLimits,
uint64_t  defaultLimit 
)
private

Creates a ion cgroup for the container and moves the container into it.

The amount of memory to assign is retrieved from the config object.

The cgroup is given the same name as the container.

Warning
This requires a version of crun with the following PR: https://github.com/containers/crun/pull/609 to ensure cgroup controllers are correctly mounted. Without the PR applied, the ION cgroup is mounted incorrectly, see https://github.com/containers/crun/issues/625 for more info
Parameters
[in]idThe id of the container.
[in]containerPidThe pid of the process in the container.
[in]heapLimitsMap of the heap name to its limits.
[in]defaultLimitThe default limit to set on a heap if not in the heapLimits map.
Returns
true if successful otherwise false.

The documentation for this class was generated from the following files: