memcontrol.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /* memcontrol.c - Memory Controller
  2. *
  3. * Copyright IBM Corporation, 2007
  4. * Author Balbir Singh <balbir@linux.vnet.ibm.com>
  5. *
  6. * Copyright 2007 OpenVZ SWsoft Inc
  7. * Author: Pavel Emelianov <xemul@openvz.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/res_counter.h>
  20. #include <linux/memcontrol.h>
  21. #include <linux/cgroup.h>
  22. #include <linux/mm.h>
  23. #include <linux/smp.h>
  24. #include <linux/page-flags.h>
  25. #include <linux/backing-dev.h>
  26. #include <linux/bit_spinlock.h>
  27. #include <linux/rcupdate.h>
  28. #include <linux/slab.h>
  29. #include <linux/swap.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/fs.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/vmalloc.h>
  34. #include <linux/mm_inline.h>
  35. #include <linux/page_cgroup.h>
  36. #include <asm/uaccess.h>
  37. struct cgroup_subsys mem_cgroup_subsys __read_mostly;
  38. #define MEM_CGROUP_RECLAIM_RETRIES 5
  39. /*
  40. * Statistics for memory cgroup.
  41. */
  42. enum mem_cgroup_stat_index {
  43. /*
  44. * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss.
  45. */
  46. MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */
  47. MEM_CGROUP_STAT_RSS, /* # of pages charged as rss */
  48. MEM_CGROUP_STAT_PGPGIN_COUNT, /* # of pages paged in */
  49. MEM_CGROUP_STAT_PGPGOUT_COUNT, /* # of pages paged out */
  50. MEM_CGROUP_STAT_NSTATS,
  51. };
  52. struct mem_cgroup_stat_cpu {
  53. s64 count[MEM_CGROUP_STAT_NSTATS];
  54. } ____cacheline_aligned_in_smp;
  55. struct mem_cgroup_stat {
  56. struct mem_cgroup_stat_cpu cpustat[NR_CPUS];
  57. };
  58. /*
  59. * For accounting under irq disable, no need for increment preempt count.
  60. */
  61. static inline void __mem_cgroup_stat_add_safe(struct mem_cgroup_stat_cpu *stat,
  62. enum mem_cgroup_stat_index idx, int val)
  63. {
  64. stat->count[idx] += val;
  65. }
  66. static s64 mem_cgroup_read_stat(struct mem_cgroup_stat *stat,
  67. enum mem_cgroup_stat_index idx)
  68. {
  69. int cpu;
  70. s64 ret = 0;
  71. for_each_possible_cpu(cpu)
  72. ret += stat->cpustat[cpu].count[idx];
  73. return ret;
  74. }
  75. /*
  76. * per-zone information in memory controller.
  77. */
  78. struct mem_cgroup_per_zone {
  79. /*
  80. * spin_lock to protect the per cgroup LRU
  81. */
  82. spinlock_t lru_lock;
  83. struct list_head lists[NR_LRU_LISTS];
  84. unsigned long count[NR_LRU_LISTS];
  85. };
  86. /* Macro for accessing counter */
  87. #define MEM_CGROUP_ZSTAT(mz, idx) ((mz)->count[(idx)])
  88. struct mem_cgroup_per_node {
  89. struct mem_cgroup_per_zone zoneinfo[MAX_NR_ZONES];
  90. };
  91. struct mem_cgroup_lru_info {
  92. struct mem_cgroup_per_node *nodeinfo[MAX_NUMNODES];
  93. };
  94. /*
  95. * The memory controller data structure. The memory controller controls both
  96. * page cache and RSS per cgroup. We would eventually like to provide
  97. * statistics based on the statistics developed by Rik Van Riel for clock-pro,
  98. * to help the administrator determine what knobs to tune.
  99. *
  100. * TODO: Add a water mark for the memory controller. Reclaim will begin when
  101. * we hit the water mark. May be even add a low water mark, such that
  102. * no reclaim occurs from a cgroup at it's low water mark, this is
  103. * a feature that will be implemented much later in the future.
  104. */
  105. struct mem_cgroup {
  106. struct cgroup_subsys_state css;
  107. /*
  108. * the counter to account for memory usage
  109. */
  110. struct res_counter res;
  111. /*
  112. * Per cgroup active and inactive list, similar to the
  113. * per zone LRU lists.
  114. */
  115. struct mem_cgroup_lru_info info;
  116. int prev_priority; /* for recording reclaim priority */
  117. /*
  118. * statistics.
  119. */
  120. struct mem_cgroup_stat stat;
  121. };
  122. static struct mem_cgroup init_mem_cgroup;
  123. enum charge_type {
  124. MEM_CGROUP_CHARGE_TYPE_CACHE = 0,
  125. MEM_CGROUP_CHARGE_TYPE_MAPPED,
  126. MEM_CGROUP_CHARGE_TYPE_SHMEM, /* used by page migration of shmem */
  127. MEM_CGROUP_CHARGE_TYPE_FORCE, /* used by force_empty */
  128. NR_CHARGE_TYPE,
  129. };
  130. /* only for here (for easy reading.) */
  131. #define PCGF_CACHE (1UL << PCG_CACHE)
  132. #define PCGF_USED (1UL << PCG_USED)
  133. #define PCGF_ACTIVE (1UL << PCG_ACTIVE)
  134. #define PCGF_LOCK (1UL << PCG_LOCK)
  135. #define PCGF_FILE (1UL << PCG_FILE)
  136. static const unsigned long
  137. pcg_default_flags[NR_CHARGE_TYPE] = {
  138. PCGF_CACHE | PCGF_FILE | PCGF_USED | PCGF_LOCK, /* File Cache */
  139. PCGF_ACTIVE | PCGF_USED | PCGF_LOCK, /* Anon */
  140. PCGF_ACTIVE | PCGF_CACHE | PCGF_USED | PCGF_LOCK, /* Shmem */
  141. 0, /* FORCE */
  142. };
  143. /*
  144. * Always modified under lru lock. Then, not necessary to preempt_disable()
  145. */
  146. static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
  147. struct page_cgroup *pc,
  148. bool charge)
  149. {
  150. int val = (charge)? 1 : -1;
  151. struct mem_cgroup_stat *stat = &mem->stat;
  152. struct mem_cgroup_stat_cpu *cpustat;
  153. VM_BUG_ON(!irqs_disabled());
  154. cpustat = &stat->cpustat[smp_processor_id()];
  155. if (PageCgroupCache(pc))
  156. __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_CACHE, val);
  157. else
  158. __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_RSS, val);
  159. if (charge)
  160. __mem_cgroup_stat_add_safe(cpustat,
  161. MEM_CGROUP_STAT_PGPGIN_COUNT, 1);
  162. else
  163. __mem_cgroup_stat_add_safe(cpustat,
  164. MEM_CGROUP_STAT_PGPGOUT_COUNT, 1);
  165. }
  166. static struct mem_cgroup_per_zone *
  167. mem_cgroup_zoneinfo(struct mem_cgroup *mem, int nid, int zid)
  168. {
  169. return &mem->info.nodeinfo[nid]->zoneinfo[zid];
  170. }
  171. static struct mem_cgroup_per_zone *
  172. page_cgroup_zoneinfo(struct page_cgroup *pc)
  173. {
  174. struct mem_cgroup *mem = pc->mem_cgroup;
  175. int nid = page_cgroup_nid(pc);
  176. int zid = page_cgroup_zid(pc);
  177. return mem_cgroup_zoneinfo(mem, nid, zid);
  178. }
  179. static unsigned long mem_cgroup_get_all_zonestat(struct mem_cgroup *mem,
  180. enum lru_list idx)
  181. {
  182. int nid, zid;
  183. struct mem_cgroup_per_zone *mz;
  184. u64 total = 0;
  185. for_each_online_node(nid)
  186. for (zid = 0; zid < MAX_NR_ZONES; zid++) {
  187. mz = mem_cgroup_zoneinfo(mem, nid, zid);
  188. total += MEM_CGROUP_ZSTAT(mz, idx);
  189. }
  190. return total;
  191. }
  192. static struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
  193. {
  194. return container_of(cgroup_subsys_state(cont,
  195. mem_cgroup_subsys_id), struct mem_cgroup,
  196. css);
  197. }
  198. struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
  199. {
  200. /*
  201. * mm_update_next_owner() may clear mm->owner to NULL
  202. * if it races with swapoff, page migration, etc.
  203. * So this can be called with p == NULL.
  204. */
  205. if (unlikely(!p))
  206. return NULL;
  207. return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
  208. struct mem_cgroup, css);
  209. }
  210. static void __mem_cgroup_remove_list(struct mem_cgroup_per_zone *mz,
  211. struct page_cgroup *pc)
  212. {
  213. int lru = LRU_BASE;
  214. if (PageCgroupUnevictable(pc))
  215. lru = LRU_UNEVICTABLE;
  216. else {
  217. if (PageCgroupActive(pc))
  218. lru += LRU_ACTIVE;
  219. if (PageCgroupFile(pc))
  220. lru += LRU_FILE;
  221. }
  222. MEM_CGROUP_ZSTAT(mz, lru) -= 1;
  223. mem_cgroup_charge_statistics(pc->mem_cgroup, pc, false);
  224. list_del(&pc->lru);
  225. }
  226. static void __mem_cgroup_add_list(struct mem_cgroup_per_zone *mz,
  227. struct page_cgroup *pc)
  228. {
  229. int lru = LRU_BASE;
  230. if (PageCgroupUnevictable(pc))
  231. lru = LRU_UNEVICTABLE;
  232. else {
  233. if (PageCgroupActive(pc))
  234. lru += LRU_ACTIVE;
  235. if (PageCgroupFile(pc))
  236. lru += LRU_FILE;
  237. }
  238. MEM_CGROUP_ZSTAT(mz, lru) += 1;
  239. list_add(&pc->lru, &mz->lists[lru]);
  240. mem_cgroup_charge_statistics(pc->mem_cgroup, pc, true);
  241. }
  242. static void __mem_cgroup_move_lists(struct page_cgroup *pc, enum lru_list lru)
  243. {
  244. struct mem_cgroup_per_zone *mz = page_cgroup_zoneinfo(pc);
  245. int active = PageCgroupActive(pc);
  246. int file = PageCgroupFile(pc);
  247. int unevictable = PageCgroupUnevictable(pc);
  248. enum lru_list from = unevictable ? LRU_UNEVICTABLE :
  249. (LRU_FILE * !!file + !!active);
  250. if (lru == from)
  251. return;
  252. MEM_CGROUP_ZSTAT(mz, from) -= 1;
  253. /*
  254. * However this is done under mz->lru_lock, another flags, which
  255. * are not related to LRU, will be modified from out-of-lock.
  256. * We have to use atomic set/clear flags.
  257. */
  258. if (is_unevictable_lru(lru)) {
  259. ClearPageCgroupActive(pc);
  260. SetPageCgroupUnevictable(pc);
  261. } else {
  262. if (is_active_lru(lru))
  263. SetPageCgroupActive(pc);
  264. else
  265. ClearPageCgroupActive(pc);
  266. ClearPageCgroupUnevictable(pc);
  267. }
  268. MEM_CGROUP_ZSTAT(mz, lru) += 1;
  269. list_move(&pc->lru, &mz->lists[lru]);
  270. }
  271. int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
  272. {
  273. int ret;
  274. task_lock(task);
  275. ret = task->mm && mm_match_cgroup(task->mm, mem);
  276. task_unlock(task);
  277. return ret;
  278. }
  279. /*
  280. * This routine assumes that the appropriate zone's lru lock is already held
  281. */
  282. void mem_cgroup_move_lists(struct page *page, enum lru_list lru)
  283. {
  284. struct page_cgroup *pc;
  285. struct mem_cgroup_per_zone *mz;
  286. unsigned long flags;
  287. if (mem_cgroup_subsys.disabled)
  288. return;
  289. /*
  290. * We cannot lock_page_cgroup while holding zone's lru_lock,
  291. * because other holders of lock_page_cgroup can be interrupted
  292. * with an attempt to rotate_reclaimable_page. But we cannot
  293. * safely get to page_cgroup without it, so just try_lock it:
  294. * mem_cgroup_isolate_pages allows for page left on wrong list.
  295. */
  296. pc = lookup_page_cgroup(page);
  297. if (!trylock_page_cgroup(pc))
  298. return;
  299. if (pc && PageCgroupUsed(pc)) {
  300. mz = page_cgroup_zoneinfo(pc);
  301. spin_lock_irqsave(&mz->lru_lock, flags);
  302. __mem_cgroup_move_lists(pc, lru);
  303. spin_unlock_irqrestore(&mz->lru_lock, flags);
  304. }
  305. unlock_page_cgroup(pc);
  306. }
  307. /*
  308. * Calculate mapped_ratio under memory controller. This will be used in
  309. * vmscan.c for deteremining we have to reclaim mapped pages.
  310. */
  311. int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem)
  312. {
  313. long total, rss;
  314. /*
  315. * usage is recorded in bytes. But, here, we assume the number of
  316. * physical pages can be represented by "long" on any arch.
  317. */
  318. total = (long) (mem->res.usage >> PAGE_SHIFT) + 1L;
  319. rss = (long)mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS);
  320. return (int)((rss * 100L) / total);
  321. }
  322. /*
  323. * prev_priority control...this will be used in memory reclaim path.
  324. */
  325. int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
  326. {
  327. return mem->prev_priority;
  328. }
  329. void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem, int priority)
  330. {
  331. if (priority < mem->prev_priority)
  332. mem->prev_priority = priority;
  333. }
  334. void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, int priority)
  335. {
  336. mem->prev_priority = priority;
  337. }
  338. /*
  339. * Calculate # of pages to be scanned in this priority/zone.
  340. * See also vmscan.c
  341. *
  342. * priority starts from "DEF_PRIORITY" and decremented in each loop.
  343. * (see include/linux/mmzone.h)
  344. */
  345. long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone,
  346. int priority, enum lru_list lru)
  347. {
  348. long nr_pages;
  349. int nid = zone->zone_pgdat->node_id;
  350. int zid = zone_idx(zone);
  351. struct mem_cgroup_per_zone *mz = mem_cgroup_zoneinfo(mem, nid, zid);
  352. nr_pages = MEM_CGROUP_ZSTAT(mz, lru);
  353. return (nr_pages >> priority);
  354. }
  355. unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan,
  356. struct list_head *dst,
  357. unsigned long *scanned, int order,
  358. int mode, struct zone *z,
  359. struct mem_cgroup *mem_cont,
  360. int active, int file)
  361. {
  362. unsigned long nr_taken = 0;
  363. struct page *page;
  364. unsigned long scan;
  365. LIST_HEAD(pc_list);
  366. struct list_head *src;
  367. struct page_cgroup *pc, *tmp;
  368. int nid = z->zone_pgdat->node_id;
  369. int zid = zone_idx(z);
  370. struct mem_cgroup_per_zone *mz;
  371. int lru = LRU_FILE * !!file + !!active;
  372. BUG_ON(!mem_cont);
  373. mz = mem_cgroup_zoneinfo(mem_cont, nid, zid);
  374. src = &mz->lists[lru];
  375. spin_lock(&mz->lru_lock);
  376. scan = 0;
  377. list_for_each_entry_safe_reverse(pc, tmp, src, lru) {
  378. if (scan >= nr_to_scan)
  379. break;
  380. if (unlikely(!PageCgroupUsed(pc)))
  381. continue;
  382. page = pc->page;
  383. if (unlikely(!PageLRU(page)))
  384. continue;
  385. /*
  386. * TODO: play better with lumpy reclaim, grabbing anything.
  387. */
  388. if (PageUnevictable(page) ||
  389. (PageActive(page) && !active) ||
  390. (!PageActive(page) && active)) {
  391. __mem_cgroup_move_lists(pc, page_lru(page));
  392. continue;
  393. }
  394. scan++;
  395. list_move(&pc->lru, &pc_list);
  396. if (__isolate_lru_page(page, mode, file) == 0) {
  397. list_move(&page->lru, dst);
  398. nr_taken++;
  399. }
  400. }
  401. list_splice(&pc_list, src);
  402. spin_unlock(&mz->lru_lock);
  403. *scanned = scan;
  404. return nr_taken;
  405. }
  406. /**
  407. * mem_cgroup_try_charge - get charge of PAGE_SIZE.
  408. * @mm: an mm_struct which is charged against. (when *memcg is NULL)
  409. * @gfp_mask: gfp_mask for reclaim.
  410. * @memcg: a pointer to memory cgroup which is charged against.
  411. *
  412. * charge against memory cgroup pointed by *memcg. if *memcg == NULL, estimated
  413. * memory cgroup from @mm is got and stored in *memcg.
  414. *
  415. * Returns 0 if success. -ENOMEM at failure.
  416. */
  417. int mem_cgroup_try_charge(struct mm_struct *mm,
  418. gfp_t gfp_mask, struct mem_cgroup **memcg)
  419. {
  420. struct mem_cgroup *mem;
  421. int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
  422. /*
  423. * We always charge the cgroup the mm_struct belongs to.
  424. * The mm_struct's mem_cgroup changes on task migration if the
  425. * thread group leader migrates. It's possible that mm is not
  426. * set, if so charge the init_mm (happens for pagecache usage).
  427. */
  428. if (likely(!*memcg)) {
  429. rcu_read_lock();
  430. mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
  431. if (unlikely(!mem)) {
  432. rcu_read_unlock();
  433. return 0;
  434. }
  435. /*
  436. * For every charge from the cgroup, increment reference count
  437. */
  438. css_get(&mem->css);
  439. *memcg = mem;
  440. rcu_read_unlock();
  441. } else {
  442. mem = *memcg;
  443. css_get(&mem->css);
  444. }
  445. while (unlikely(res_counter_charge(&mem->res, PAGE_SIZE))) {
  446. if (!(gfp_mask & __GFP_WAIT))
  447. goto nomem;
  448. if (try_to_free_mem_cgroup_pages(mem, gfp_mask))
  449. continue;
  450. /*
  451. * try_to_free_mem_cgroup_pages() might not give us a full
  452. * picture of reclaim. Some pages are reclaimed and might be
  453. * moved to swap cache or just unmapped from the cgroup.
  454. * Check the limit again to see if the reclaim reduced the
  455. * current usage of the cgroup before giving up
  456. */
  457. if (res_counter_check_under_limit(&mem->res))
  458. continue;
  459. if (!nr_retries--) {
  460. mem_cgroup_out_of_memory(mem, gfp_mask);
  461. goto nomem;
  462. }
  463. }
  464. return 0;
  465. nomem:
  466. css_put(&mem->css);
  467. return -ENOMEM;
  468. }
  469. /*
  470. * commit a charge got by mem_cgroup_try_charge() and makes page_cgroup to be
  471. * USED state. If already USED, uncharge and return.
  472. */
  473. static void __mem_cgroup_commit_charge(struct mem_cgroup *mem,
  474. struct page_cgroup *pc,
  475. enum charge_type ctype)
  476. {
  477. struct mem_cgroup_per_zone *mz;
  478. unsigned long flags;
  479. /* try_charge() can return NULL to *memcg, taking care of it. */
  480. if (!mem)
  481. return;
  482. lock_page_cgroup(pc);
  483. if (unlikely(PageCgroupUsed(pc))) {
  484. unlock_page_cgroup(pc);
  485. res_counter_uncharge(&mem->res, PAGE_SIZE);
  486. css_put(&mem->css);
  487. return;
  488. }
  489. pc->mem_cgroup = mem;
  490. /*
  491. * If a page is accounted as a page cache, insert to inactive list.
  492. * If anon, insert to active list.
  493. */
  494. pc->flags = pcg_default_flags[ctype];
  495. mz = page_cgroup_zoneinfo(pc);
  496. spin_lock_irqsave(&mz->lru_lock, flags);
  497. __mem_cgroup_add_list(mz, pc);
  498. spin_unlock_irqrestore(&mz->lru_lock, flags);
  499. unlock_page_cgroup(pc);
  500. }
  501. /*
  502. * Charge the memory controller for page usage.
  503. * Return
  504. * 0 if the charge was successful
  505. * < 0 if the cgroup is over its limit
  506. */
  507. static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
  508. gfp_t gfp_mask, enum charge_type ctype,
  509. struct mem_cgroup *memcg)
  510. {
  511. struct mem_cgroup *mem;
  512. struct page_cgroup *pc;
  513. int ret;
  514. pc = lookup_page_cgroup(page);
  515. /* can happen at boot */
  516. if (unlikely(!pc))
  517. return 0;
  518. prefetchw(pc);
  519. mem = memcg;
  520. ret = mem_cgroup_try_charge(mm, gfp_mask, &mem);
  521. if (ret)
  522. return ret;
  523. __mem_cgroup_commit_charge(mem, pc, ctype);
  524. return 0;
  525. }
  526. int mem_cgroup_newpage_charge(struct page *page,
  527. struct mm_struct *mm, gfp_t gfp_mask)
  528. {
  529. if (mem_cgroup_subsys.disabled)
  530. return 0;
  531. if (PageCompound(page))
  532. return 0;
  533. /*
  534. * If already mapped, we don't have to account.
  535. * If page cache, page->mapping has address_space.
  536. * But page->mapping may have out-of-use anon_vma pointer,
  537. * detecit it by PageAnon() check. newly-mapped-anon's page->mapping
  538. * is NULL.
  539. */
  540. if (page_mapped(page) || (page->mapping && !PageAnon(page)))
  541. return 0;
  542. if (unlikely(!mm))
  543. mm = &init_mm;
  544. return mem_cgroup_charge_common(page, mm, gfp_mask,
  545. MEM_CGROUP_CHARGE_TYPE_MAPPED, NULL);
  546. }
  547. /*
  548. * same as mem_cgroup_newpage_charge(), now.
  549. * But what we assume is different from newpage, and this is special case.
  550. * treat this in special function. easy for maintenance.
  551. */
  552. int mem_cgroup_charge_migrate_fixup(struct page *page,
  553. struct mm_struct *mm, gfp_t gfp_mask)
  554. {
  555. if (mem_cgroup_subsys.disabled)
  556. return 0;
  557. if (PageCompound(page))
  558. return 0;
  559. if (page_mapped(page) || (page->mapping && !PageAnon(page)))
  560. return 0;
  561. if (unlikely(!mm))
  562. mm = &init_mm;
  563. return mem_cgroup_charge_common(page, mm, gfp_mask,
  564. MEM_CGROUP_CHARGE_TYPE_MAPPED, NULL);
  565. }
  566. int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
  567. gfp_t gfp_mask)
  568. {
  569. if (mem_cgroup_subsys.disabled)
  570. return 0;
  571. if (PageCompound(page))
  572. return 0;
  573. /*
  574. * Corner case handling. This is called from add_to_page_cache()
  575. * in usual. But some FS (shmem) precharges this page before calling it
  576. * and call add_to_page_cache() with GFP_NOWAIT.
  577. *
  578. * For GFP_NOWAIT case, the page may be pre-charged before calling
  579. * add_to_page_cache(). (See shmem.c) check it here and avoid to call
  580. * charge twice. (It works but has to pay a bit larger cost.)
  581. */
  582. if (!(gfp_mask & __GFP_WAIT)) {
  583. struct page_cgroup *pc;
  584. pc = lookup_page_cgroup(page);
  585. if (!pc)
  586. return 0;
  587. lock_page_cgroup(pc);
  588. if (PageCgroupUsed(pc)) {
  589. unlock_page_cgroup(pc);
  590. return 0;
  591. }
  592. unlock_page_cgroup(pc);
  593. }
  594. if (unlikely(!mm))
  595. mm = &init_mm;
  596. if (page_is_file_cache(page))
  597. return mem_cgroup_charge_common(page, mm, gfp_mask,
  598. MEM_CGROUP_CHARGE_TYPE_CACHE, NULL);
  599. else
  600. return mem_cgroup_charge_common(page, mm, gfp_mask,
  601. MEM_CGROUP_CHARGE_TYPE_SHMEM, NULL);
  602. }
  603. void mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr)
  604. {
  605. struct page_cgroup *pc;
  606. if (mem_cgroup_subsys.disabled)
  607. return;
  608. if (!ptr)
  609. return;
  610. pc = lookup_page_cgroup(page);
  611. __mem_cgroup_commit_charge(ptr, pc, MEM_CGROUP_CHARGE_TYPE_MAPPED);
  612. }
  613. void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *mem)
  614. {
  615. if (mem_cgroup_subsys.disabled)
  616. return;
  617. if (!mem)
  618. return;
  619. res_counter_uncharge(&mem->res, PAGE_SIZE);
  620. css_put(&mem->css);
  621. }
  622. /*
  623. * uncharge if !page_mapped(page)
  624. */
  625. static void
  626. __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
  627. {
  628. struct page_cgroup *pc;
  629. struct mem_cgroup *mem;
  630. struct mem_cgroup_per_zone *mz;
  631. unsigned long flags;
  632. if (mem_cgroup_subsys.disabled)
  633. return;
  634. /*
  635. * Check if our page_cgroup is valid
  636. */
  637. pc = lookup_page_cgroup(page);
  638. if (unlikely(!pc || !PageCgroupUsed(pc)))
  639. return;
  640. lock_page_cgroup(pc);
  641. if ((ctype == MEM_CGROUP_CHARGE_TYPE_MAPPED && page_mapped(page))
  642. || !PageCgroupUsed(pc)) {
  643. /* This happens at race in zap_pte_range() and do_swap_page()*/
  644. unlock_page_cgroup(pc);
  645. return;
  646. }
  647. ClearPageCgroupUsed(pc);
  648. mem = pc->mem_cgroup;
  649. mz = page_cgroup_zoneinfo(pc);
  650. spin_lock_irqsave(&mz->lru_lock, flags);
  651. __mem_cgroup_remove_list(mz, pc);
  652. spin_unlock_irqrestore(&mz->lru_lock, flags);
  653. unlock_page_cgroup(pc);
  654. res_counter_uncharge(&mem->res, PAGE_SIZE);
  655. css_put(&mem->css);
  656. return;
  657. }
  658. void mem_cgroup_uncharge_page(struct page *page)
  659. {
  660. /* early check. */
  661. if (page_mapped(page))
  662. return;
  663. if (page->mapping && !PageAnon(page))
  664. return;
  665. __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_MAPPED);
  666. }
  667. void mem_cgroup_uncharge_cache_page(struct page *page)
  668. {
  669. VM_BUG_ON(page_mapped(page));
  670. VM_BUG_ON(page->mapping);
  671. __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE);
  672. }
  673. /*
  674. * Before starting migration, account against new page.
  675. */
  676. int mem_cgroup_prepare_migration(struct page *page, struct page *newpage)
  677. {
  678. struct page_cgroup *pc;
  679. struct mem_cgroup *mem = NULL;
  680. enum charge_type ctype = MEM_CGROUP_CHARGE_TYPE_MAPPED;
  681. int ret = 0;
  682. if (mem_cgroup_subsys.disabled)
  683. return 0;
  684. pc = lookup_page_cgroup(page);
  685. lock_page_cgroup(pc);
  686. if (PageCgroupUsed(pc)) {
  687. mem = pc->mem_cgroup;
  688. css_get(&mem->css);
  689. if (PageCgroupCache(pc)) {
  690. if (page_is_file_cache(page))
  691. ctype = MEM_CGROUP_CHARGE_TYPE_CACHE;
  692. else
  693. ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM;
  694. }
  695. }
  696. unlock_page_cgroup(pc);
  697. if (mem) {
  698. ret = mem_cgroup_charge_common(newpage, NULL, GFP_KERNEL,
  699. ctype, mem);
  700. css_put(&mem->css);
  701. }
  702. return ret;
  703. }
  704. /* remove redundant charge if migration failed*/
  705. void mem_cgroup_end_migration(struct page *newpage)
  706. {
  707. /*
  708. * At success, page->mapping is not NULL.
  709. * special rollback care is necessary when
  710. * 1. at migration failure. (newpage->mapping is cleared in this case)
  711. * 2. the newpage was moved but not remapped again because the task
  712. * exits and the newpage is obsolete. In this case, the new page
  713. * may be a swapcache. So, we just call mem_cgroup_uncharge_page()
  714. * always for avoiding mess. The page_cgroup will be removed if
  715. * unnecessary. File cache pages is still on radix-tree. Don't
  716. * care it.
  717. */
  718. if (!newpage->mapping)
  719. __mem_cgroup_uncharge_common(newpage,
  720. MEM_CGROUP_CHARGE_TYPE_FORCE);
  721. else if (PageAnon(newpage))
  722. mem_cgroup_uncharge_page(newpage);
  723. }
  724. /*
  725. * A call to try to shrink memory usage under specified resource controller.
  726. * This is typically used for page reclaiming for shmem for reducing side
  727. * effect of page allocation from shmem, which is used by some mem_cgroup.
  728. */
  729. int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask)
  730. {
  731. struct mem_cgroup *mem;
  732. int progress = 0;
  733. int retry = MEM_CGROUP_RECLAIM_RETRIES;
  734. if (mem_cgroup_subsys.disabled)
  735. return 0;
  736. if (!mm)
  737. return 0;
  738. rcu_read_lock();
  739. mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
  740. if (unlikely(!mem)) {
  741. rcu_read_unlock();
  742. return 0;
  743. }
  744. css_get(&mem->css);
  745. rcu_read_unlock();
  746. do {
  747. progress = try_to_free_mem_cgroup_pages(mem, gfp_mask);
  748. progress += res_counter_check_under_limit(&mem->res);
  749. } while (!progress && --retry);
  750. css_put(&mem->css);
  751. if (!retry)
  752. return -ENOMEM;
  753. return 0;
  754. }
  755. static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
  756. unsigned long long val)
  757. {
  758. int retry_count = MEM_CGROUP_RECLAIM_RETRIES;
  759. int progress;
  760. int ret = 0;
  761. while (res_counter_set_limit(&memcg->res, val)) {
  762. if (signal_pending(current)) {
  763. ret = -EINTR;
  764. break;
  765. }
  766. if (!retry_count) {
  767. ret = -EBUSY;
  768. break;
  769. }
  770. progress = try_to_free_mem_cgroup_pages(memcg, GFP_KERNEL);
  771. if (!progress)
  772. retry_count--;
  773. }
  774. return ret;
  775. }
  776. /*
  777. * This routine traverse page_cgroup in given list and drop them all.
  778. * *And* this routine doesn't reclaim page itself, just removes page_cgroup.
  779. */
  780. #define FORCE_UNCHARGE_BATCH (128)
  781. static void mem_cgroup_force_empty_list(struct mem_cgroup *mem,
  782. struct mem_cgroup_per_zone *mz,
  783. enum lru_list lru)
  784. {
  785. struct page_cgroup *pc;
  786. struct page *page;
  787. int count = FORCE_UNCHARGE_BATCH;
  788. unsigned long flags;
  789. struct list_head *list;
  790. list = &mz->lists[lru];
  791. spin_lock_irqsave(&mz->lru_lock, flags);
  792. while (!list_empty(list)) {
  793. pc = list_entry(list->prev, struct page_cgroup, lru);
  794. page = pc->page;
  795. if (!PageCgroupUsed(pc))
  796. break;
  797. get_page(page);
  798. spin_unlock_irqrestore(&mz->lru_lock, flags);
  799. /*
  800. * Check if this page is on LRU. !LRU page can be found
  801. * if it's under page migration.
  802. */
  803. if (PageLRU(page)) {
  804. __mem_cgroup_uncharge_common(page,
  805. MEM_CGROUP_CHARGE_TYPE_FORCE);
  806. put_page(page);
  807. if (--count <= 0) {
  808. count = FORCE_UNCHARGE_BATCH;
  809. cond_resched();
  810. }
  811. } else {
  812. spin_lock_irqsave(&mz->lru_lock, flags);
  813. break;
  814. }
  815. spin_lock_irqsave(&mz->lru_lock, flags);
  816. }
  817. spin_unlock_irqrestore(&mz->lru_lock, flags);
  818. }
  819. /*
  820. * make mem_cgroup's charge to be 0 if there is no task.
  821. * This enables deleting this mem_cgroup.
  822. */
  823. static int mem_cgroup_force_empty(struct mem_cgroup *mem)
  824. {
  825. int ret = -EBUSY;
  826. int node, zid;
  827. css_get(&mem->css);
  828. /*
  829. * page reclaim code (kswapd etc..) will move pages between
  830. * active_list <-> inactive_list while we don't take a lock.
  831. * So, we have to do loop here until all lists are empty.
  832. */
  833. while (mem->res.usage > 0) {
  834. if (atomic_read(&mem->css.cgroup->count) > 0)
  835. goto out;
  836. /* This is for making all *used* pages to be on LRU. */
  837. lru_add_drain_all();
  838. for_each_node_state(node, N_POSSIBLE)
  839. for (zid = 0; zid < MAX_NR_ZONES; zid++) {
  840. struct mem_cgroup_per_zone *mz;
  841. enum lru_list l;
  842. mz = mem_cgroup_zoneinfo(mem, node, zid);
  843. for_each_lru(l)
  844. mem_cgroup_force_empty_list(mem, mz, l);
  845. }
  846. cond_resched();
  847. }
  848. ret = 0;
  849. out:
  850. css_put(&mem->css);
  851. return ret;
  852. }
  853. static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)
  854. {
  855. return res_counter_read_u64(&mem_cgroup_from_cont(cont)->res,
  856. cft->private);
  857. }
  858. /*
  859. * The user of this function is...
  860. * RES_LIMIT.
  861. */
  862. static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
  863. const char *buffer)
  864. {
  865. struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
  866. unsigned long long val;
  867. int ret;
  868. switch (cft->private) {
  869. case RES_LIMIT:
  870. /* This function does all necessary parse...reuse it */
  871. ret = res_counter_memparse_write_strategy(buffer, &val);
  872. if (!ret)
  873. ret = mem_cgroup_resize_limit(memcg, val);
  874. break;
  875. default:
  876. ret = -EINVAL; /* should be BUG() ? */
  877. break;
  878. }
  879. return ret;
  880. }
  881. static int mem_cgroup_reset(struct cgroup *cont, unsigned int event)
  882. {
  883. struct mem_cgroup *mem;
  884. mem = mem_cgroup_from_cont(cont);
  885. switch (event) {
  886. case RES_MAX_USAGE:
  887. res_counter_reset_max(&mem->res);
  888. break;
  889. case RES_FAILCNT:
  890. res_counter_reset_failcnt(&mem->res);
  891. break;
  892. }
  893. return 0;
  894. }
  895. static int mem_force_empty_write(struct cgroup *cont, unsigned int event)
  896. {
  897. return mem_cgroup_force_empty(mem_cgroup_from_cont(cont));
  898. }
  899. static const struct mem_cgroup_stat_desc {
  900. const char *msg;
  901. u64 unit;
  902. } mem_cgroup_stat_desc[] = {
  903. [MEM_CGROUP_STAT_CACHE] = { "cache", PAGE_SIZE, },
  904. [MEM_CGROUP_STAT_RSS] = { "rss", PAGE_SIZE, },
  905. [MEM_CGROUP_STAT_PGPGIN_COUNT] = {"pgpgin", 1, },
  906. [MEM_CGROUP_STAT_PGPGOUT_COUNT] = {"pgpgout", 1, },
  907. };
  908. static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft,
  909. struct cgroup_map_cb *cb)
  910. {
  911. struct mem_cgroup *mem_cont = mem_cgroup_from_cont(cont);
  912. struct mem_cgroup_stat *stat = &mem_cont->stat;
  913. int i;
  914. for (i = 0; i < ARRAY_SIZE(stat->cpustat[0].count); i++) {
  915. s64 val;
  916. val = mem_cgroup_read_stat(stat, i);
  917. val *= mem_cgroup_stat_desc[i].unit;
  918. cb->fill(cb, mem_cgroup_stat_desc[i].msg, val);
  919. }
  920. /* showing # of active pages */
  921. {
  922. unsigned long active_anon, inactive_anon;
  923. unsigned long active_file, inactive_file;
  924. unsigned long unevictable;
  925. inactive_anon = mem_cgroup_get_all_zonestat(mem_cont,
  926. LRU_INACTIVE_ANON);
  927. active_anon = mem_cgroup_get_all_zonestat(mem_cont,
  928. LRU_ACTIVE_ANON);
  929. inactive_file = mem_cgroup_get_all_zonestat(mem_cont,
  930. LRU_INACTIVE_FILE);
  931. active_file = mem_cgroup_get_all_zonestat(mem_cont,
  932. LRU_ACTIVE_FILE);
  933. unevictable = mem_cgroup_get_all_zonestat(mem_cont,
  934. LRU_UNEVICTABLE);
  935. cb->fill(cb, "active_anon", (active_anon) * PAGE_SIZE);
  936. cb->fill(cb, "inactive_anon", (inactive_anon) * PAGE_SIZE);
  937. cb->fill(cb, "active_file", (active_file) * PAGE_SIZE);
  938. cb->fill(cb, "inactive_file", (inactive_file) * PAGE_SIZE);
  939. cb->fill(cb, "unevictable", unevictable * PAGE_SIZE);
  940. }
  941. return 0;
  942. }
  943. static struct cftype mem_cgroup_files[] = {
  944. {
  945. .name = "usage_in_bytes",
  946. .private = RES_USAGE,
  947. .read_u64 = mem_cgroup_read,
  948. },
  949. {
  950. .name = "max_usage_in_bytes",
  951. .private = RES_MAX_USAGE,
  952. .trigger = mem_cgroup_reset,
  953. .read_u64 = mem_cgroup_read,
  954. },
  955. {
  956. .name = "limit_in_bytes",
  957. .private = RES_LIMIT,
  958. .write_string = mem_cgroup_write,
  959. .read_u64 = mem_cgroup_read,
  960. },
  961. {
  962. .name = "failcnt",
  963. .private = RES_FAILCNT,
  964. .trigger = mem_cgroup_reset,
  965. .read_u64 = mem_cgroup_read,
  966. },
  967. {
  968. .name = "force_empty",
  969. .trigger = mem_force_empty_write,
  970. },
  971. {
  972. .name = "stat",
  973. .read_map = mem_control_stat_show,
  974. },
  975. };
  976. static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
  977. {
  978. struct mem_cgroup_per_node *pn;
  979. struct mem_cgroup_per_zone *mz;
  980. enum lru_list l;
  981. int zone, tmp = node;
  982. /*
  983. * This routine is called against possible nodes.
  984. * But it's BUG to call kmalloc() against offline node.
  985. *
  986. * TODO: this routine can waste much memory for nodes which will
  987. * never be onlined. It's better to use memory hotplug callback
  988. * function.
  989. */
  990. if (!node_state(node, N_NORMAL_MEMORY))
  991. tmp = -1;
  992. pn = kmalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
  993. if (!pn)
  994. return 1;
  995. mem->info.nodeinfo[node] = pn;
  996. memset(pn, 0, sizeof(*pn));
  997. for (zone = 0; zone < MAX_NR_ZONES; zone++) {
  998. mz = &pn->zoneinfo[zone];
  999. spin_lock_init(&mz->lru_lock);
  1000. for_each_lru(l)
  1001. INIT_LIST_HEAD(&mz->lists[l]);
  1002. }
  1003. return 0;
  1004. }
  1005. static void free_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
  1006. {
  1007. kfree(mem->info.nodeinfo[node]);
  1008. }
  1009. static struct mem_cgroup *mem_cgroup_alloc(void)
  1010. {
  1011. struct mem_cgroup *mem;
  1012. if (sizeof(*mem) < PAGE_SIZE)
  1013. mem = kmalloc(sizeof(*mem), GFP_KERNEL);
  1014. else
  1015. mem = vmalloc(sizeof(*mem));
  1016. if (mem)
  1017. memset(mem, 0, sizeof(*mem));
  1018. return mem;
  1019. }
  1020. static void mem_cgroup_free(struct mem_cgroup *mem)
  1021. {
  1022. if (sizeof(*mem) < PAGE_SIZE)
  1023. kfree(mem);
  1024. else
  1025. vfree(mem);
  1026. }
  1027. static struct cgroup_subsys_state *
  1028. mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
  1029. {
  1030. struct mem_cgroup *mem;
  1031. int node;
  1032. if (unlikely((cont->parent) == NULL)) {
  1033. mem = &init_mem_cgroup;
  1034. } else {
  1035. mem = mem_cgroup_alloc();
  1036. if (!mem)
  1037. return ERR_PTR(-ENOMEM);
  1038. }
  1039. res_counter_init(&mem->res);
  1040. for_each_node_state(node, N_POSSIBLE)
  1041. if (alloc_mem_cgroup_per_zone_info(mem, node))
  1042. goto free_out;
  1043. return &mem->css;
  1044. free_out:
  1045. for_each_node_state(node, N_POSSIBLE)
  1046. free_mem_cgroup_per_zone_info(mem, node);
  1047. if (cont->parent != NULL)
  1048. mem_cgroup_free(mem);
  1049. return ERR_PTR(-ENOMEM);
  1050. }
  1051. static void mem_cgroup_pre_destroy(struct cgroup_subsys *ss,
  1052. struct cgroup *cont)
  1053. {
  1054. struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
  1055. mem_cgroup_force_empty(mem);
  1056. }
  1057. static void mem_cgroup_destroy(struct cgroup_subsys *ss,
  1058. struct cgroup *cont)
  1059. {
  1060. int node;
  1061. struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
  1062. for_each_node_state(node, N_POSSIBLE)
  1063. free_mem_cgroup_per_zone_info(mem, node);
  1064. mem_cgroup_free(mem_cgroup_from_cont(cont));
  1065. }
  1066. static int mem_cgroup_populate(struct cgroup_subsys *ss,
  1067. struct cgroup *cont)
  1068. {
  1069. return cgroup_add_files(cont, ss, mem_cgroup_files,
  1070. ARRAY_SIZE(mem_cgroup_files));
  1071. }
  1072. static void mem_cgroup_move_task(struct cgroup_subsys *ss,
  1073. struct cgroup *cont,
  1074. struct cgroup *old_cont,
  1075. struct task_struct *p)
  1076. {
  1077. struct mm_struct *mm;
  1078. struct mem_cgroup *mem, *old_mem;
  1079. mm = get_task_mm(p);
  1080. if (mm == NULL)
  1081. return;
  1082. mem = mem_cgroup_from_cont(cont);
  1083. old_mem = mem_cgroup_from_cont(old_cont);
  1084. /*
  1085. * Only thread group leaders are allowed to migrate, the mm_struct is
  1086. * in effect owned by the leader
  1087. */
  1088. if (!thread_group_leader(p))
  1089. goto out;
  1090. out:
  1091. mmput(mm);
  1092. }
  1093. struct cgroup_subsys mem_cgroup_subsys = {
  1094. .name = "memory",
  1095. .subsys_id = mem_cgroup_subsys_id,
  1096. .create = mem_cgroup_create,
  1097. .pre_destroy = mem_cgroup_pre_destroy,
  1098. .destroy = mem_cgroup_destroy,
  1099. .populate = mem_cgroup_populate,
  1100. .attach = mem_cgroup_move_task,
  1101. .early_init = 0,
  1102. };