Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1228247
  • 博文数量: 389
  • 博客积分: 2874
  • 博客等级: 少校
  • 技术积分: 3577
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-24 10:34
文章分类

全部博文(389)

文章存档

2020年(2)

2018年(39)

2017年(27)

2016年(3)

2015年(55)

2014年(92)

2013年(54)

2012年(53)

2011年(64)

分类: LINUX

2014-08-25 17:09:28

这两天再看cgroup的知识,先看了《Linux Cgroups 详解》-- 王喆锋 zhefwang@gmail.com ,
然后开始看代码,先看的cgroup内cpu部分的实现。
在3.10.21里 kernel/sched/core.c : 8059 定义了 cpu的cgroup_subsys

点击(此处)折叠或打开

  1. struct cgroup_subsys cpu_cgroup_subsys = {
  2.     .name        = "cpu",
  3.     .css_alloc    = cpu_cgroup_css_alloc,
  4.     .css_free    = cpu_cgroup_css_free,
  5.     .css_online    = cpu_cgroup_css_online,
  6.     .css_offline    = cpu_cgroup_css_offline,
  7.     .can_attach    = cpu_cgroup_can_attach,
  8.     .attach        = cpu_cgroup_attach,
  9.     .exit        = cpu_cgroup_exit,
  10.     .subsys_id    = cpu_cgroup_subsys_id,
  11.     .base_cftypes    = cpu_files,
  12.     .early_init    = 1,
  13. };
发现和文章中讲的不一样,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还有效。

其他的方法基本和之前是一样的。

阅读(1299) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~