这两天再看cgroup的知识,先看了《Linux Cgroups 详解》-- 王喆锋 zhefwang@gmail.com ,
然后开始看代码,先看的cgroup内cpu部分的实现。
在3.10.21里 kernel/sched/core.c : 8059 定义了 cpu的
cgroup_subsys
-
struct cgroup_subsys cpu_cgroup_subsys = {
-
.name = "cpu",
-
.css_alloc = cpu_cgroup_css_alloc,
-
.css_free = cpu_cgroup_css_free,
-
.css_online = cpu_cgroup_css_online,
-
.css_offline = cpu_cgroup_css_offline,
-
.can_attach = cpu_cgroup_can_attach,
-
.attach = cpu_cgroup_attach,
-
.exit = cpu_cgroup_exit,
-
.subsys_id = cpu_cgroup_subsys_id,
-
.base_cftypes = cpu_files,
-
.early_init = 1,
-
};
发现和文章中讲的不一样,2.6到3.10,之间肯定修改了很多东西。
3.10里
cgroup_subsys 各字段的意义在kernel文档的cgroups.txt 内部有说明,这里稍微介绍一下,以做备忘:
每一个subsystem必须包含 css_alloc/free方法的实现。
struct cgroup_subsys_state *css_alloc(struct cgroup *cgrp)
(cgroup_mutex held by caller)
该方法用来为cgrp 分配subsystem 状态对像,返回一个指针,成功的话就指向新的对象,失败的话返回ERR_PTR()。成功的话返回的指针会指向一个cgroup_subsys_state结构体(通常该结构体被包含在一个大的子系统自定义的结构体内),该结构体会被cgroup系统初始化。注意,该方法会在为该子系统创建根子系统状态时被调用,这时传递的cgrp指针的parent 指向NULL,
int css_online(struct cgroup *cgrp)
(cgroup_mutex held by caller)
Called after @cgrp successfully completed all allocations and made
visible to cgroup_for_each_child/descendant_*() iterators. The
subsystem may choose to fail creation by returning -errno. This
callback can be used to implement reliable state sharing and
propagation along the hierarchy. See the comment on
cgroup_for_each_descendant_pre() for details.
该方法在cgrp完成所有分配后被调用,该方法能使cgroup_for_each_child/descendant_*()迭代器看到该cgrp(这段英文不太清楚)。该方法用来在层级之间执行可靠的状态共享和传播。
void css_offline(struct cgroup *cgrp);
(cgroup_mutex held by caller)
This is the counterpart of css_online() and called iff css_online()
has succeeded on @cgrp. This signifies the beginning of the end of
@cgrp. @cgrp is being removed and the subsystem should start dropping
all references it's holding on @cgrp. When all references are dropped,
cgroup removal will proceed to the next step - css_free(). After this
callback, @cgrp should be considered dead to the subsystem.
该方法标识cgrp的终结,cgrp要被移除时,子系统需要删除所以cgrp持有的索引。索引被删除后,cgroup的删除进入下一步css_free().
void css_free(struct cgroup *cgrp)
(cgroup_mutex held by caller)
The cgroup system is about to free @cgrp; the subsystem should free
its subsystem state object. By the time this method is called, @cgrp
is completely unused; @cgrp->parent is still valid. (Note - can also
be called for a newly-created cgroup if an error occurs after this
subsystem's create() method has been called for the new cgroup).
释放子系统状态对象,调用该方法的时候,cgrp已经完全不能用了,不过cgrp->parent还有效。
其他的方法基本和之前是一样的。
阅读(1420) | 评论(0) | 转发(0) |