Each cgroup already knows all its ancestors in cgrp->ancestors[] along with
its depth in cgrp->level (see cgroup_is_descendant() and cgroup_ancestor()).
This can be used to implement a generic cgroup_common_ancestor() a lot more
efficiently. Something like:

  static inline struct cgroup *cgroup_common_ancestor(struct cgroup *a,
                                                      struct cgroup *b)
  {
          int level;

          for (level = min(a->level, b->level); level >= 0; level--)
                  if (a->ancestors[level] == b->ancestors[level])
                          return a->ancestors[level];
          return NULL;
  }

This is O(depth) instead of O(n*m). Can you add a helper like the above in
include/linux/cgroup.h and use it here?

Thanks.
-- 
tejun

Reply via email to