• K
    cgroup: CSS ID support · 38460b48
    KAMEZAWA Hiroyuki 提交于
    Patch for Per-CSS(Cgroup Subsys State) ID and private hierarchy code.
    
    This patch attaches unique ID to each css and provides following.
    
     - css_lookup(subsys, id)
       returns pointer to struct cgroup_subysys_state of id.
     - css_get_next(subsys, id, rootid, depth, foundid)
       returns the next css under "root" by scanning
    
    When cgroup_subsys->use_id is set, an id for css is maintained.
    
    The cgroup framework only parepares
    	- css_id of root css for subsys
    	- id is automatically attached at creation of css.
    	- id is *not* freed automatically. Because the cgroup framework
    	  don't know lifetime of cgroup_subsys_state.
    	  free_css_id() function is provided. This must be called by subsys.
    
    There are several reasons to develop this.
    	- Saving space .... For example, memcg's swap_cgroup is array of
    	  pointers to cgroup. But it is not necessary to be very fast.
    	  By replacing pointers(8bytes per ent) to ID (2byes per ent), we can
    	  reduce much amount of memory usage.
    
    	- Scanning without lock.
    	  CSS_ID provides "scan id under this ROOT" function. By this, scanning
    	  css under root can be written without locks.
    	  ex)
    	  do {
    		rcu_read_lock();
    		next = cgroup_get_next(subsys, id, root, &found);
    		/* check sanity of next here */
    		css_tryget();
    		rcu_read_unlock();
    		id = found + 1
    	 } while(...)
    
    Characteristics:
    	- Each css has unique ID under subsys.
    	- Lifetime of ID is controlled by subsys.
    	- css ID contains "ID" and "Depth in hierarchy" and stack of hierarchy
    	- Allowed ID is 1-65535, ID 0 is UNUSED ID.
    
    Design Choices:
    	- scan-by-ID v.s. scan-by-tree-walk.
    	  As /proc's pid scan does, scan-by-ID is robust when scanning is done
    	  by following kind of routine.
    	  scan -> rest a while(release a lock) -> conitunue from interrupted
    	  memcg's hierarchical reclaim does this.
    
    	- When subsys->use_id is set, # of css in the system is limited to
    	  65535.
    
    [bharata@linux.vnet.ibm.com: remove rcu_read_lock() from css_get_next()]
    Signed-off-by: NKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Acked-by: NPaul Menage <menage@google.com>
    Cc: Li Zefan <lizf@cn.fujitsu.com>
    Cc: Balbir Singh <balbir@in.ibm.com>
    Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
    Signed-off-by: NBharata B Rao <bharata@linux.vnet.ibm.com>
    Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    38460b48
idr.h 4.4 KB