Skip to the content.

cgroup 的基础设施

主要数据结构

创建 struct cgroup 的流程:

fork && exit

从 kernfs 到具体的行为

// 读写文件的
static struct kernfs_ops cgroup_kf_single_ops = {

}

// 同上,但是应该是单个文件
static struct kernfs_ops cgroup_kf_ops = {
}

// 目录相关的
static struct kernfs_syscall_ops cgroup_kf_syscall_ops = {
}

struct cgroup_file; // kernfs 文件的文件需要携带 cgroup 相关的信息
struct cftype; // 提前定义的 cgroup file 的静态信息

struct file_system_type cgroup_fs_type;
static const struct fs_context_operations cgroup_fs_context_ops; // 处理 mount 参数
/* look up cgroup associated with given css_set on the specified hierarchy */
static struct cgroup *cset_cgroup_from_root(struct css_set *cset,
              struct cgroup_root *root)
{
  struct cgroup *res = NULL;

  lockdep_assert_held(&cgroup_mutex);
  lockdep_assert_held(&css_set_lock);

  // 这个暂时看不懂
  if (cset == &init_css_set) {
    res = &root->cgrp;
  // 如果说是 v2 那么就靠 css_set 定义的 dfl_cgrp
  } else if (root == &cgrp_dfl_root) {
    res = cset->dfl_cgrp;
  // v1 的情况 : task should move to same root
  } else {
    struct cgrp_cset_link *link;

    list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
      struct cgroup *c = link->cgrp;

      if (c->root == root) {
        res = c;
        break;
      }
    }
  }

  BUG_ON(!res);
  return res;
}

利用整体框架的,内容就是展示 cgroup 中的进程

migrate

/* used to track tasks and csets during migration */
struct cgroup_taskset {
  /* the src and dst cset list running through cset->mg_node */
  struct list_head  src_csets;
  struct list_head  dst_csets;

  /* the number of tasks in the set */
  int     nr_tasks;

  /* the subsys currently being processed */
  int     ssid;

  /*
   * Fields for cgroup_taskset_*() iteration.
   *
   * Before migration is committed, the target migration tasks are on
   * ->mg_tasks of the csets on ->src_csets.  After, on ->mg_tasks of
   * the csets on ->dst_csets.  ->csets point to either ->src_csets
   * or ->dst_csets depending on whether migration is committed.
   *
   * ->cur_csets and ->cur_task point to the current task position
   * during iteration.
   */
  struct list_head  *csets;
  struct css_set    *cur_cset;
  struct task_struct  *cur_task;
};

操作方法:

cgclassify -g subsystems:path_to_cgroup pidlist

[ ] 实际上,cgroup 的热迁移是默认不迁移内存的

关注下的函数

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。