cgroup

Posted 天地有大美而不言

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cgroup相关的知识,希望对你有一定的参考价值。

参考:Linux资源管理之cgroups简介

      linux源码分析(四)-start_kernel-cgroup

   从cgroup_init_early函数学习cgroup——框架

          cgroup中的cgroup_subsys[]数组解析

 

/*
* 系统中共有多少个cgroup_subsys_state结构体?include/linux/cgroup.h
* 
*/
/* Define the enumeration of all cgroup subsystems */
#define SUBSYS(_x) _x ## _subsys_id,
/*
cgroup_subsys.h内容如下

SUBSYS(cpuset)         cpuset_subsys_id
SUBSYS(debug)          debug_subsys_id
SUBSYS(ns)             ns_subsys_id
SUBSYS(cpu_cgroup)     cpu_cgroup_subsys_id
SUBSYS(cpuacct)        cpuacct_subsys_id
SUBSYS(mem_cgroup)     mem_cgroup_subsys_id
SUBSYS(devices)           devices_subsys_id
SUBSYS(freezer)        freezer_subsys_id
SUBSYS(net_cls)        net_cls_subsys_id
*/
enum cgroup_subsys_id {
#include <linux/cgroup_subsys.h>
    CGROUP_SUBSYS_COUNT
};
#undef SUBSYS

/*以上枚举量展开为*/
enum cgroup_subsys_id {
    cpuset_subsys_id
    debug_subsys_id
    ns_subsys_id
    cpu_cgroup_subsys_id
    cpuacct_subsys_id
    mem_cgroup_subsys_id
    devices_subsys_id
    freezer_subsys_id
    net_cls_subsys_id
    CGROUP_SUBSYS_COUNT
};

/*系统中定义的全局cgroup_subsys数组*/
/* Generate an array of cgroup subsystem pointers */
#define SUBSYS(_x) &_x ## _subsys,

static struct cgroup_subsys *subsys[] = {
#include <linux/cgroup_subsys.h>
};
/*以上数组展开为*/
static struct cgroup_subsys *subsys[] = {
    cpuset_subsys,
    debug_subsys,
    ns_subsys,
    cpu_cgroup_subsys,
    cpuacct_subsys,
    mem_cgroup_subsys,
    devices_subsys,
    freezer_subsys,
    net_cls_subsys,
};
/*以上数组中的成员在不同的C文件中定义,例如kernel/cpuset.c*/
struct cgroup_subsys cpuset_subsys = {
    .name = "cpuset",
    .create = cpuset_create,
    .destroy = cpuset_destroy,
    .can_attach = cpuset_can_attach,
    .attach = cpuset_attach,
    .populate = cpuset_populate,
    .post_clone = cpuset_post_clone,
    .subsys_id = cpuset_subsys_id,
    .early_init = 1,
};

static int cpuset_mems_generation;

static struct cpuset top_cpuset = {
    .flags = ((1 << CS_CPU_EXCLUSIVE) | (1 << CS_MEM_EXCLUSIVE)),
};
struct cpuset {
    struct cgroup_subsys_state css;

    unsigned long flags;        /* "unsigned long" so bitops work */
    cpumask_var_t cpus_allowed;    /* CPUs allowed to tasks in cpuset */
    nodemask_t mems_allowed;    /* Memory Nodes allowed to tasks */

    struct cpuset *parent;        /* my parent */

    /*
     * Copy of global cpuset_mems_generation as of the most
     * recent time this cpuset changed its mems_allowed.
     */
    int mems_generation;

    struct fmeter fmeter;        /* memory_pressure filter */

    /* partition number for rebuild_sched_domains() */
    int pn;

    /* for custom sched domain */
    int relax_domain_level;

    /* used for walking a cpuset heirarchy */
    struct list_head stack_list;
};

 

以上是关于cgroup的主要内容,如果未能解决你的问题,请参考以下文章

极简组调度-CGroup如何限制cpu

cgroup小记

CGroup系列二CGroup管理模式

cgroup

CGroup原理篇V11.2 CGroup的用法

CGroup原理篇V11.3 CGroup Kernel API介绍