Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1 | /* memcontrol.c - Memory Controller |
| 2 | * |
| 3 | * Copyright IBM Corporation, 2007 |
| 4 | * Author Balbir Singh <balbir@linux.vnet.ibm.com> |
| 5 | * |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 6 | * Copyright 2007 OpenVZ SWsoft Inc |
| 7 | * Author: Pavel Emelianov <xemul@openvz.org> |
| 8 | * |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 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 | |
| 20 | #include <linux/res_counter.h> |
| 21 | #include <linux/memcontrol.h> |
| 22 | #include <linux/cgroup.h> |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 23 | #include <linux/mm.h> |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 24 | #include <linux/smp.h> |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 25 | #include <linux/page-flags.h> |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 26 | #include <linux/backing-dev.h> |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 27 | #include <linux/bit_spinlock.h> |
| 28 | #include <linux/rcupdate.h> |
Balbir Singh | b6ac57d | 2008-04-29 01:00:19 -0700 | [diff] [blame] | 29 | #include <linux/slab.h> |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 30 | #include <linux/swap.h> |
| 31 | #include <linux/spinlock.h> |
| 32 | #include <linux/fs.h> |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 33 | #include <linux/seq_file.h> |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 35 | #include <linux/mm_inline.h> |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 36 | #include <linux/page_cgroup.h> |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 37 | |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 38 | #include <asm/uaccess.h> |
| 39 | |
KAMEZAWA Hiroyuki | a181b0e | 2008-07-25 01:47:08 -0700 | [diff] [blame] | 40 | struct cgroup_subsys mem_cgroup_subsys __read_mostly; |
KAMEZAWA Hiroyuki | a181b0e | 2008-07-25 01:47:08 -0700 | [diff] [blame] | 41 | #define MEM_CGROUP_RECLAIM_RETRIES 5 |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 42 | |
| 43 | /* |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 44 | * Statistics for memory cgroup. |
| 45 | */ |
| 46 | enum mem_cgroup_stat_index { |
| 47 | /* |
| 48 | * For MEM_CONTAINER_TYPE_ALL, usage = pagecache + rss. |
| 49 | */ |
| 50 | MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */ |
| 51 | MEM_CGROUP_STAT_RSS, /* # of pages charged as rss */ |
Balaji Rao | 55e462b | 2008-05-01 04:35:12 -0700 | [diff] [blame] | 52 | MEM_CGROUP_STAT_PGPGIN_COUNT, /* # of pages paged in */ |
| 53 | MEM_CGROUP_STAT_PGPGOUT_COUNT, /* # of pages paged out */ |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 54 | |
| 55 | MEM_CGROUP_STAT_NSTATS, |
| 56 | }; |
| 57 | |
| 58 | struct mem_cgroup_stat_cpu { |
| 59 | s64 count[MEM_CGROUP_STAT_NSTATS]; |
| 60 | } ____cacheline_aligned_in_smp; |
| 61 | |
| 62 | struct mem_cgroup_stat { |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 63 | struct mem_cgroup_stat_cpu cpustat[0]; |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /* |
| 67 | * For accounting under irq disable, no need for increment preempt count. |
| 68 | */ |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 69 | static inline void __mem_cgroup_stat_add_safe(struct mem_cgroup_stat_cpu *stat, |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 70 | enum mem_cgroup_stat_index idx, int val) |
| 71 | { |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 72 | stat->count[idx] += val; |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static s64 mem_cgroup_read_stat(struct mem_cgroup_stat *stat, |
| 76 | enum mem_cgroup_stat_index idx) |
| 77 | { |
| 78 | int cpu; |
| 79 | s64 ret = 0; |
| 80 | for_each_possible_cpu(cpu) |
| 81 | ret += stat->cpustat[cpu].count[idx]; |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | /* |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 86 | * per-zone information in memory controller. |
| 87 | */ |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 88 | struct mem_cgroup_per_zone { |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 89 | /* |
| 90 | * spin_lock to protect the per cgroup LRU |
| 91 | */ |
| 92 | spinlock_t lru_lock; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 93 | struct list_head lists[NR_LRU_LISTS]; |
| 94 | unsigned long count[NR_LRU_LISTS]; |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 95 | }; |
| 96 | /* Macro for accessing counter */ |
| 97 | #define MEM_CGROUP_ZSTAT(mz, idx) ((mz)->count[(idx)]) |
| 98 | |
| 99 | struct mem_cgroup_per_node { |
| 100 | struct mem_cgroup_per_zone zoneinfo[MAX_NR_ZONES]; |
| 101 | }; |
| 102 | |
| 103 | struct mem_cgroup_lru_info { |
| 104 | struct mem_cgroup_per_node *nodeinfo[MAX_NUMNODES]; |
| 105 | }; |
| 106 | |
| 107 | /* |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 108 | * The memory controller data structure. The memory controller controls both |
| 109 | * page cache and RSS per cgroup. We would eventually like to provide |
| 110 | * statistics based on the statistics developed by Rik Van Riel for clock-pro, |
| 111 | * to help the administrator determine what knobs to tune. |
| 112 | * |
| 113 | * TODO: Add a water mark for the memory controller. Reclaim will begin when |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 114 | * we hit the water mark. May be even add a low water mark, such that |
| 115 | * no reclaim occurs from a cgroup at it's low water mark, this is |
| 116 | * a feature that will be implemented much later in the future. |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 117 | */ |
| 118 | struct mem_cgroup { |
| 119 | struct cgroup_subsys_state css; |
| 120 | /* |
| 121 | * the counter to account for memory usage |
| 122 | */ |
| 123 | struct res_counter res; |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 124 | /* |
| 125 | * Per cgroup active and inactive list, similar to the |
| 126 | * per zone LRU lists. |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 127 | */ |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 128 | struct mem_cgroup_lru_info info; |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 129 | |
KAMEZAWA Hiroyuki | 6c48a1d | 2008-02-07 00:14:34 -0800 | [diff] [blame] | 130 | int prev_priority; /* for recording reclaim priority */ |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 131 | /* |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 132 | * statistics. This must be placed at the end of memcg. |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 133 | */ |
| 134 | struct mem_cgroup_stat stat; |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 135 | }; |
| 136 | |
KAMEZAWA Hiroyuki | 217bc31 | 2008-02-07 00:14:17 -0800 | [diff] [blame] | 137 | enum charge_type { |
| 138 | MEM_CGROUP_CHARGE_TYPE_CACHE = 0, |
| 139 | MEM_CGROUP_CHARGE_TYPE_MAPPED, |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 140 | MEM_CGROUP_CHARGE_TYPE_SHMEM, /* used by page migration of shmem */ |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 141 | MEM_CGROUP_CHARGE_TYPE_FORCE, /* used by force_empty */ |
| 142 | NR_CHARGE_TYPE, |
| 143 | }; |
| 144 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 145 | /* only for here (for easy reading.) */ |
| 146 | #define PCGF_CACHE (1UL << PCG_CACHE) |
| 147 | #define PCGF_USED (1UL << PCG_USED) |
| 148 | #define PCGF_ACTIVE (1UL << PCG_ACTIVE) |
| 149 | #define PCGF_LOCK (1UL << PCG_LOCK) |
| 150 | #define PCGF_FILE (1UL << PCG_FILE) |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 151 | static const unsigned long |
| 152 | pcg_default_flags[NR_CHARGE_TYPE] = { |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 153 | PCGF_CACHE | PCGF_FILE | PCGF_USED | PCGF_LOCK, /* File Cache */ |
| 154 | PCGF_ACTIVE | PCGF_USED | PCGF_LOCK, /* Anon */ |
| 155 | PCGF_ACTIVE | PCGF_CACHE | PCGF_USED | PCGF_LOCK, /* Shmem */ |
| 156 | 0, /* FORCE */ |
KAMEZAWA Hiroyuki | 217bc31 | 2008-02-07 00:14:17 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 159 | /* |
| 160 | * Always modified under lru lock. Then, not necessary to preempt_disable() |
| 161 | */ |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 162 | static void mem_cgroup_charge_statistics(struct mem_cgroup *mem, |
| 163 | struct page_cgroup *pc, |
| 164 | bool charge) |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 165 | { |
| 166 | int val = (charge)? 1 : -1; |
| 167 | struct mem_cgroup_stat *stat = &mem->stat; |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 168 | struct mem_cgroup_stat_cpu *cpustat; |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 169 | |
Hugh Dickins | 8869b8f | 2008-03-04 14:29:09 -0800 | [diff] [blame] | 170 | VM_BUG_ON(!irqs_disabled()); |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 171 | |
| 172 | cpustat = &stat->cpustat[smp_processor_id()]; |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 173 | if (PageCgroupCache(pc)) |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 174 | __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_CACHE, val); |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 175 | else |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 176 | __mem_cgroup_stat_add_safe(cpustat, MEM_CGROUP_STAT_RSS, val); |
Balaji Rao | 55e462b | 2008-05-01 04:35:12 -0700 | [diff] [blame] | 177 | |
| 178 | if (charge) |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 179 | __mem_cgroup_stat_add_safe(cpustat, |
Balaji Rao | 55e462b | 2008-05-01 04:35:12 -0700 | [diff] [blame] | 180 | MEM_CGROUP_STAT_PGPGIN_COUNT, 1); |
| 181 | else |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 182 | __mem_cgroup_stat_add_safe(cpustat, |
Balaji Rao | 55e462b | 2008-05-01 04:35:12 -0700 | [diff] [blame] | 183 | MEM_CGROUP_STAT_PGPGOUT_COUNT, 1); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 184 | } |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 185 | |
Hugh Dickins | d5b69e3 | 2008-03-04 14:29:10 -0800 | [diff] [blame] | 186 | static struct mem_cgroup_per_zone * |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 187 | mem_cgroup_zoneinfo(struct mem_cgroup *mem, int nid, int zid) |
| 188 | { |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 189 | return &mem->info.nodeinfo[nid]->zoneinfo[zid]; |
| 190 | } |
| 191 | |
Hugh Dickins | d5b69e3 | 2008-03-04 14:29:10 -0800 | [diff] [blame] | 192 | static struct mem_cgroup_per_zone * |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 193 | page_cgroup_zoneinfo(struct page_cgroup *pc) |
| 194 | { |
| 195 | struct mem_cgroup *mem = pc->mem_cgroup; |
| 196 | int nid = page_cgroup_nid(pc); |
| 197 | int zid = page_cgroup_zid(pc); |
| 198 | |
| 199 | return mem_cgroup_zoneinfo(mem, nid, zid); |
| 200 | } |
| 201 | |
| 202 | static unsigned long mem_cgroup_get_all_zonestat(struct mem_cgroup *mem, |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 203 | enum lru_list idx) |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 204 | { |
| 205 | int nid, zid; |
| 206 | struct mem_cgroup_per_zone *mz; |
| 207 | u64 total = 0; |
| 208 | |
| 209 | for_each_online_node(nid) |
| 210 | for (zid = 0; zid < MAX_NR_ZONES; zid++) { |
| 211 | mz = mem_cgroup_zoneinfo(mem, nid, zid); |
| 212 | total += MEM_CGROUP_ZSTAT(mz, idx); |
| 213 | } |
| 214 | return total; |
KAMEZAWA Hiroyuki | d52aa41 | 2008-02-07 00:14:24 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Hugh Dickins | d5b69e3 | 2008-03-04 14:29:10 -0800 | [diff] [blame] | 217 | static struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont) |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 218 | { |
| 219 | return container_of(cgroup_subsys_state(cont, |
| 220 | mem_cgroup_subsys_id), struct mem_cgroup, |
| 221 | css); |
| 222 | } |
| 223 | |
Balbir Singh | cf475ad | 2008-04-29 01:00:16 -0700 | [diff] [blame] | 224 | struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 225 | { |
Balbir Singh | 31a78f2 | 2008-09-28 23:09:31 +0100 | [diff] [blame] | 226 | /* |
| 227 | * mm_update_next_owner() may clear mm->owner to NULL |
| 228 | * if it races with swapoff, page migration, etc. |
| 229 | * So this can be called with p == NULL. |
| 230 | */ |
| 231 | if (unlikely(!p)) |
| 232 | return NULL; |
| 233 | |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 234 | return container_of(task_subsys_state(p, mem_cgroup_subsys_id), |
| 235 | struct mem_cgroup, css); |
| 236 | } |
| 237 | |
KAMEZAWA Hiroyuki | 3eae90c | 2008-04-29 01:00:22 -0700 | [diff] [blame] | 238 | static void __mem_cgroup_remove_list(struct mem_cgroup_per_zone *mz, |
| 239 | struct page_cgroup *pc) |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 240 | { |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 241 | int lru = LRU_BASE; |
| 242 | |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 243 | if (PageCgroupUnevictable(pc)) |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 244 | lru = LRU_UNEVICTABLE; |
| 245 | else { |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 246 | if (PageCgroupActive(pc)) |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 247 | lru += LRU_ACTIVE; |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 248 | if (PageCgroupFile(pc)) |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 249 | lru += LRU_FILE; |
| 250 | } |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 251 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 252 | MEM_CGROUP_ZSTAT(mz, lru) -= 1; |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 253 | |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 254 | mem_cgroup_charge_statistics(pc->mem_cgroup, pc, false); |
KAMEZAWA Hiroyuki | 508b7be | 2008-07-25 01:47:09 -0700 | [diff] [blame] | 255 | list_del(&pc->lru); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 256 | } |
| 257 | |
KAMEZAWA Hiroyuki | 3eae90c | 2008-04-29 01:00:22 -0700 | [diff] [blame] | 258 | static void __mem_cgroup_add_list(struct mem_cgroup_per_zone *mz, |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 259 | struct page_cgroup *pc, bool hot) |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 260 | { |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 261 | int lru = LRU_BASE; |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 262 | |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 263 | if (PageCgroupUnevictable(pc)) |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 264 | lru = LRU_UNEVICTABLE; |
| 265 | else { |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 266 | if (PageCgroupActive(pc)) |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 267 | lru += LRU_ACTIVE; |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 268 | if (PageCgroupFile(pc)) |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 269 | lru += LRU_FILE; |
| 270 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 271 | |
| 272 | MEM_CGROUP_ZSTAT(mz, lru) += 1; |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 273 | if (hot) |
| 274 | list_add(&pc->lru, &mz->lists[lru]); |
| 275 | else |
| 276 | list_add_tail(&pc->lru, &mz->lists[lru]); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 277 | |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 278 | mem_cgroup_charge_statistics(pc->mem_cgroup, pc, true); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 281 | static void __mem_cgroup_move_lists(struct page_cgroup *pc, enum lru_list lru) |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 282 | { |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 283 | struct mem_cgroup_per_zone *mz = page_cgroup_zoneinfo(pc); |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 284 | int active = PageCgroupActive(pc); |
| 285 | int file = PageCgroupFile(pc); |
| 286 | int unevictable = PageCgroupUnevictable(pc); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 287 | enum lru_list from = unevictable ? LRU_UNEVICTABLE : |
| 288 | (LRU_FILE * !!file + !!active); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 289 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 290 | if (lru == from) |
| 291 | return; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 292 | |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 293 | MEM_CGROUP_ZSTAT(mz, from) -= 1; |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 294 | /* |
| 295 | * However this is done under mz->lru_lock, another flags, which |
| 296 | * are not related to LRU, will be modified from out-of-lock. |
| 297 | * We have to use atomic set/clear flags. |
| 298 | */ |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 299 | if (is_unevictable_lru(lru)) { |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 300 | ClearPageCgroupActive(pc); |
| 301 | SetPageCgroupUnevictable(pc); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 302 | } else { |
| 303 | if (is_active_lru(lru)) |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 304 | SetPageCgroupActive(pc); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 305 | else |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 306 | ClearPageCgroupActive(pc); |
| 307 | ClearPageCgroupUnevictable(pc); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 308 | } |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 309 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 310 | MEM_CGROUP_ZSTAT(mz, lru) += 1; |
| 311 | list_move(&pc->lru, &mz->lists[lru]); |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 312 | } |
| 313 | |
David Rientjes | 4c4a221 | 2008-02-07 00:14:06 -0800 | [diff] [blame] | 314 | int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem) |
| 315 | { |
| 316 | int ret; |
| 317 | |
| 318 | task_lock(task); |
Hugh Dickins | bd845e3 | 2008-03-04 14:29:01 -0800 | [diff] [blame] | 319 | ret = task->mm && mm_match_cgroup(task->mm, mem); |
David Rientjes | 4c4a221 | 2008-02-07 00:14:06 -0800 | [diff] [blame] | 320 | task_unlock(task); |
| 321 | return ret; |
| 322 | } |
| 323 | |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 324 | /* |
| 325 | * This routine assumes that the appropriate zone's lru lock is already held |
| 326 | */ |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 327 | void mem_cgroup_move_lists(struct page *page, enum lru_list lru) |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 328 | { |
Hugh Dickins | 427d541 | 2008-03-04 14:29:03 -0800 | [diff] [blame] | 329 | struct page_cgroup *pc; |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 330 | struct mem_cgroup_per_zone *mz; |
| 331 | unsigned long flags; |
| 332 | |
Li Zefan | cede86a | 2008-07-25 01:47:18 -0700 | [diff] [blame] | 333 | if (mem_cgroup_subsys.disabled) |
| 334 | return; |
| 335 | |
Hugh Dickins | 2680eed | 2008-03-04 14:29:13 -0800 | [diff] [blame] | 336 | /* |
| 337 | * We cannot lock_page_cgroup while holding zone's lru_lock, |
| 338 | * because other holders of lock_page_cgroup can be interrupted |
| 339 | * with an attempt to rotate_reclaimable_page. But we cannot |
| 340 | * safely get to page_cgroup without it, so just try_lock it: |
| 341 | * mem_cgroup_isolate_pages allows for page left on wrong list. |
| 342 | */ |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 343 | pc = lookup_page_cgroup(page); |
| 344 | if (!trylock_page_cgroup(pc)) |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 345 | return; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 346 | if (pc && PageCgroupUsed(pc)) { |
Hugh Dickins | 2680eed | 2008-03-04 14:29:13 -0800 | [diff] [blame] | 347 | mz = page_cgroup_zoneinfo(pc); |
Hugh Dickins | 2680eed | 2008-03-04 14:29:13 -0800 | [diff] [blame] | 348 | spin_lock_irqsave(&mz->lru_lock, flags); |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 349 | __mem_cgroup_move_lists(pc, lru); |
Hugh Dickins | 2680eed | 2008-03-04 14:29:13 -0800 | [diff] [blame] | 350 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
Hirokazu Takahashi | 9b3c0a0 | 2008-03-04 14:29:15 -0800 | [diff] [blame] | 351 | } |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 352 | unlock_page_cgroup(pc); |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 353 | } |
| 354 | |
KAMEZAWA Hiroyuki | 58ae83d | 2008-02-07 00:14:32 -0800 | [diff] [blame] | 355 | /* |
| 356 | * Calculate mapped_ratio under memory controller. This will be used in |
| 357 | * vmscan.c for deteremining we have to reclaim mapped pages. |
| 358 | */ |
| 359 | int mem_cgroup_calc_mapped_ratio(struct mem_cgroup *mem) |
| 360 | { |
| 361 | long total, rss; |
| 362 | |
| 363 | /* |
| 364 | * usage is recorded in bytes. But, here, we assume the number of |
| 365 | * physical pages can be represented by "long" on any arch. |
| 366 | */ |
| 367 | total = (long) (mem->res.usage >> PAGE_SHIFT) + 1L; |
| 368 | rss = (long)mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS); |
| 369 | return (int)((rss * 100L) / total); |
| 370 | } |
Hugh Dickins | 8869b8f | 2008-03-04 14:29:09 -0800 | [diff] [blame] | 371 | |
KAMEZAWA Hiroyuki | 5932f36 | 2008-02-07 00:14:33 -0800 | [diff] [blame] | 372 | /* |
KAMEZAWA Hiroyuki | 6c48a1d | 2008-02-07 00:14:34 -0800 | [diff] [blame] | 373 | * prev_priority control...this will be used in memory reclaim path. |
| 374 | */ |
| 375 | int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem) |
| 376 | { |
| 377 | return mem->prev_priority; |
| 378 | } |
| 379 | |
| 380 | void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem, int priority) |
| 381 | { |
| 382 | if (priority < mem->prev_priority) |
| 383 | mem->prev_priority = priority; |
| 384 | } |
| 385 | |
| 386 | void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem, int priority) |
| 387 | { |
| 388 | mem->prev_priority = priority; |
| 389 | } |
| 390 | |
KAMEZAWA Hiroyuki | cc38108 | 2008-02-07 00:14:35 -0800 | [diff] [blame] | 391 | /* |
| 392 | * Calculate # of pages to be scanned in this priority/zone. |
| 393 | * See also vmscan.c |
| 394 | * |
| 395 | * priority starts from "DEF_PRIORITY" and decremented in each loop. |
| 396 | * (see include/linux/mmzone.h) |
| 397 | */ |
| 398 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 399 | long mem_cgroup_calc_reclaim(struct mem_cgroup *mem, struct zone *zone, |
| 400 | int priority, enum lru_list lru) |
KAMEZAWA Hiroyuki | cc38108 | 2008-02-07 00:14:35 -0800 | [diff] [blame] | 401 | { |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 402 | long nr_pages; |
KAMEZAWA Hiroyuki | cc38108 | 2008-02-07 00:14:35 -0800 | [diff] [blame] | 403 | int nid = zone->zone_pgdat->node_id; |
| 404 | int zid = zone_idx(zone); |
| 405 | struct mem_cgroup_per_zone *mz = mem_cgroup_zoneinfo(mem, nid, zid); |
| 406 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 407 | nr_pages = MEM_CGROUP_ZSTAT(mz, lru); |
KAMEZAWA Hiroyuki | cc38108 | 2008-02-07 00:14:35 -0800 | [diff] [blame] | 408 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 409 | return (nr_pages >> priority); |
KAMEZAWA Hiroyuki | cc38108 | 2008-02-07 00:14:35 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 412 | unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, |
| 413 | struct list_head *dst, |
| 414 | unsigned long *scanned, int order, |
| 415 | int mode, struct zone *z, |
| 416 | struct mem_cgroup *mem_cont, |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 417 | int active, int file) |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 418 | { |
| 419 | unsigned long nr_taken = 0; |
| 420 | struct page *page; |
| 421 | unsigned long scan; |
| 422 | LIST_HEAD(pc_list); |
| 423 | struct list_head *src; |
KAMEZAWA Hiroyuki | ff7283f | 2008-02-07 00:14:11 -0800 | [diff] [blame] | 424 | struct page_cgroup *pc, *tmp; |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 425 | int nid = z->zone_pgdat->node_id; |
| 426 | int zid = zone_idx(z); |
| 427 | struct mem_cgroup_per_zone *mz; |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 428 | int lru = LRU_FILE * !!file + !!active; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 429 | |
Balbir Singh | cf475ad | 2008-04-29 01:00:16 -0700 | [diff] [blame] | 430 | BUG_ON(!mem_cont); |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 431 | mz = mem_cgroup_zoneinfo(mem_cont, nid, zid); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 432 | src = &mz->lists[lru]; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 433 | |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 434 | spin_lock(&mz->lru_lock); |
KAMEZAWA Hiroyuki | ff7283f | 2008-02-07 00:14:11 -0800 | [diff] [blame] | 435 | scan = 0; |
| 436 | list_for_each_entry_safe_reverse(pc, tmp, src, lru) { |
Hugh Dickins | 436c6541 | 2008-02-07 00:14:12 -0800 | [diff] [blame] | 437 | if (scan >= nr_to_scan) |
KAMEZAWA Hiroyuki | ff7283f | 2008-02-07 00:14:11 -0800 | [diff] [blame] | 438 | break; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 439 | if (unlikely(!PageCgroupUsed(pc))) |
| 440 | continue; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 441 | page = pc->page; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 442 | |
Hugh Dickins | 436c6541 | 2008-02-07 00:14:12 -0800 | [diff] [blame] | 443 | if (unlikely(!PageLRU(page))) |
KAMEZAWA Hiroyuki | ff7283f | 2008-02-07 00:14:11 -0800 | [diff] [blame] | 444 | continue; |
KAMEZAWA Hiroyuki | ff7283f | 2008-02-07 00:14:11 -0800 | [diff] [blame] | 445 | |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 446 | /* |
| 447 | * TODO: play better with lumpy reclaim, grabbing anything. |
| 448 | */ |
Lee Schermerhorn | 894bc31 | 2008-10-18 20:26:39 -0700 | [diff] [blame] | 449 | if (PageUnevictable(page) || |
| 450 | (PageActive(page) && !active) || |
| 451 | (!PageActive(page) && active)) { |
| 452 | __mem_cgroup_move_lists(pc, page_lru(page)); |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 453 | continue; |
| 454 | } |
| 455 | |
Hugh Dickins | 436c6541 | 2008-02-07 00:14:12 -0800 | [diff] [blame] | 456 | scan++; |
| 457 | list_move(&pc->lru, &pc_list); |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 458 | |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 459 | if (__isolate_lru_page(page, mode, file) == 0) { |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 460 | list_move(&page->lru, dst); |
| 461 | nr_taken++; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | list_splice(&pc_list, src); |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 466 | spin_unlock(&mz->lru_lock); |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 467 | |
| 468 | *scanned = scan; |
| 469 | return nr_taken; |
| 470 | } |
| 471 | |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 472 | /* |
| 473 | * Unlike exported interface, "oom" parameter is added. if oom==true, |
| 474 | * oom-killer can be invoked. |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 475 | */ |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 476 | static int __mem_cgroup_try_charge(struct mm_struct *mm, |
| 477 | gfp_t gfp_mask, struct mem_cgroup **memcg, bool oom) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 478 | { |
| 479 | struct mem_cgroup *mem; |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 480 | int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 481 | /* |
Hugh Dickins | 3be9127 | 2008-02-07 00:14:19 -0800 | [diff] [blame] | 482 | * We always charge the cgroup the mm_struct belongs to. |
| 483 | * The mm_struct's mem_cgroup changes on task migration if the |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 484 | * thread group leader migrates. It's possible that mm is not |
| 485 | * set, if so charge the init_mm (happens for pagecache usage). |
| 486 | */ |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 487 | if (likely(!*memcg)) { |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 488 | rcu_read_lock(); |
| 489 | mem = mem_cgroup_from_task(rcu_dereference(mm->owner)); |
Balbir Singh | 31a78f2 | 2008-09-28 23:09:31 +0100 | [diff] [blame] | 490 | if (unlikely(!mem)) { |
| 491 | rcu_read_unlock(); |
Balbir Singh | 31a78f2 | 2008-09-28 23:09:31 +0100 | [diff] [blame] | 492 | return 0; |
| 493 | } |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 494 | /* |
| 495 | * For every charge from the cgroup, increment reference count |
| 496 | */ |
| 497 | css_get(&mem->css); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 498 | *memcg = mem; |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 499 | rcu_read_unlock(); |
| 500 | } else { |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 501 | mem = *memcg; |
| 502 | css_get(&mem->css); |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 503 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 504 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 505 | |
KAMEZAWA Hiroyuki | addb9ef | 2008-10-18 20:28:10 -0700 | [diff] [blame] | 506 | while (unlikely(res_counter_charge(&mem->res, PAGE_SIZE))) { |
Hugh Dickins | 3be9127 | 2008-02-07 00:14:19 -0800 | [diff] [blame] | 507 | if (!(gfp_mask & __GFP_WAIT)) |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 508 | goto nomem; |
Balbir Singh | e1a1cd5 | 2008-02-07 00:14:02 -0800 | [diff] [blame] | 509 | |
| 510 | if (try_to_free_mem_cgroup_pages(mem, gfp_mask)) |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 511 | continue; |
| 512 | |
| 513 | /* |
Hugh Dickins | 8869b8f | 2008-03-04 14:29:09 -0800 | [diff] [blame] | 514 | * try_to_free_mem_cgroup_pages() might not give us a full |
| 515 | * picture of reclaim. Some pages are reclaimed and might be |
| 516 | * moved to swap cache or just unmapped from the cgroup. |
| 517 | * Check the limit again to see if the reclaim reduced the |
| 518 | * current usage of the cgroup before giving up |
| 519 | */ |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 520 | if (res_counter_check_under_limit(&mem->res)) |
| 521 | continue; |
Hugh Dickins | 3be9127 | 2008-02-07 00:14:19 -0800 | [diff] [blame] | 522 | |
| 523 | if (!nr_retries--) { |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 524 | if (oom) |
| 525 | mem_cgroup_out_of_memory(mem, gfp_mask); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 526 | goto nomem; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 527 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 528 | } |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 529 | return 0; |
| 530 | nomem: |
| 531 | css_put(&mem->css); |
| 532 | return -ENOMEM; |
| 533 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 534 | |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 535 | /** |
| 536 | * mem_cgroup_try_charge - get charge of PAGE_SIZE. |
| 537 | * @mm: an mm_struct which is charged against. (when *memcg is NULL) |
| 538 | * @gfp_mask: gfp_mask for reclaim. |
| 539 | * @memcg: a pointer to memory cgroup which is charged against. |
| 540 | * |
| 541 | * charge against memory cgroup pointed by *memcg. if *memcg == NULL, estimated |
| 542 | * memory cgroup from @mm is got and stored in *memcg. |
| 543 | * |
| 544 | * Returns 0 if success. -ENOMEM at failure. |
| 545 | * This call can invoke OOM-Killer. |
| 546 | */ |
| 547 | |
| 548 | int mem_cgroup_try_charge(struct mm_struct *mm, |
| 549 | gfp_t mask, struct mem_cgroup **memcg) |
| 550 | { |
| 551 | return __mem_cgroup_try_charge(mm, mask, memcg, true); |
| 552 | } |
| 553 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 554 | /* |
| 555 | * commit a charge got by mem_cgroup_try_charge() and makes page_cgroup to be |
| 556 | * USED state. If already USED, uncharge and return. |
| 557 | */ |
| 558 | |
| 559 | static void __mem_cgroup_commit_charge(struct mem_cgroup *mem, |
| 560 | struct page_cgroup *pc, |
| 561 | enum charge_type ctype) |
| 562 | { |
| 563 | struct mem_cgroup_per_zone *mz; |
| 564 | unsigned long flags; |
| 565 | |
| 566 | /* try_charge() can return NULL to *memcg, taking care of it. */ |
| 567 | if (!mem) |
| 568 | return; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 569 | |
| 570 | lock_page_cgroup(pc); |
| 571 | if (unlikely(PageCgroupUsed(pc))) { |
| 572 | unlock_page_cgroup(pc); |
| 573 | res_counter_uncharge(&mem->res, PAGE_SIZE); |
| 574 | css_put(&mem->css); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 575 | return; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 576 | } |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 577 | pc->mem_cgroup = mem; |
KAMEZAWA Hiroyuki | 508b7be | 2008-07-25 01:47:09 -0700 | [diff] [blame] | 578 | /* |
| 579 | * If a page is accounted as a page cache, insert to inactive list. |
| 580 | * If anon, insert to active list. |
| 581 | */ |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 582 | pc->flags = pcg_default_flags[ctype]; |
Hugh Dickins | 3be9127 | 2008-02-07 00:14:19 -0800 | [diff] [blame] | 583 | |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 584 | mz = page_cgroup_zoneinfo(pc); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 585 | |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 586 | spin_lock_irqsave(&mz->lru_lock, flags); |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 587 | __mem_cgroup_add_list(mz, pc, true); |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 588 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 589 | unlock_page_cgroup(pc); |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 590 | } |
| 591 | |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 592 | /** |
| 593 | * mem_cgroup_move_account - move account of the page |
| 594 | * @pc: page_cgroup of the page. |
| 595 | * @from: mem_cgroup which the page is moved from. |
| 596 | * @to: mem_cgroup which the page is moved to. @from != @to. |
| 597 | * |
| 598 | * The caller must confirm following. |
| 599 | * 1. disable irq. |
| 600 | * 2. lru_lock of old mem_cgroup(@from) should be held. |
| 601 | * |
| 602 | * returns 0 at success, |
| 603 | * returns -EBUSY when lock is busy or "pc" is unstable. |
| 604 | * |
| 605 | * This function does "uncharge" from old cgroup but doesn't do "charge" to |
| 606 | * new cgroup. It should be done by a caller. |
| 607 | */ |
| 608 | |
| 609 | static int mem_cgroup_move_account(struct page_cgroup *pc, |
| 610 | struct mem_cgroup *from, struct mem_cgroup *to) |
| 611 | { |
| 612 | struct mem_cgroup_per_zone *from_mz, *to_mz; |
| 613 | int nid, zid; |
| 614 | int ret = -EBUSY; |
| 615 | |
| 616 | VM_BUG_ON(!irqs_disabled()); |
| 617 | VM_BUG_ON(from == to); |
| 618 | |
| 619 | nid = page_cgroup_nid(pc); |
| 620 | zid = page_cgroup_zid(pc); |
| 621 | from_mz = mem_cgroup_zoneinfo(from, nid, zid); |
| 622 | to_mz = mem_cgroup_zoneinfo(to, nid, zid); |
| 623 | |
| 624 | |
| 625 | if (!trylock_page_cgroup(pc)) |
| 626 | return ret; |
| 627 | |
| 628 | if (!PageCgroupUsed(pc)) |
| 629 | goto out; |
| 630 | |
| 631 | if (pc->mem_cgroup != from) |
| 632 | goto out; |
| 633 | |
| 634 | if (spin_trylock(&to_mz->lru_lock)) { |
| 635 | __mem_cgroup_remove_list(from_mz, pc); |
| 636 | css_put(&from->css); |
| 637 | res_counter_uncharge(&from->res, PAGE_SIZE); |
| 638 | pc->mem_cgroup = to; |
| 639 | css_get(&to->css); |
| 640 | __mem_cgroup_add_list(to_mz, pc, false); |
| 641 | ret = 0; |
| 642 | spin_unlock(&to_mz->lru_lock); |
| 643 | } |
| 644 | out: |
| 645 | unlock_page_cgroup(pc); |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | /* |
| 650 | * move charges to its parent. |
| 651 | */ |
| 652 | |
| 653 | static int mem_cgroup_move_parent(struct page_cgroup *pc, |
| 654 | struct mem_cgroup *child, |
| 655 | gfp_t gfp_mask) |
| 656 | { |
| 657 | struct cgroup *cg = child->css.cgroup; |
| 658 | struct cgroup *pcg = cg->parent; |
| 659 | struct mem_cgroup *parent; |
| 660 | struct mem_cgroup_per_zone *mz; |
| 661 | unsigned long flags; |
| 662 | int ret; |
| 663 | |
| 664 | /* Is ROOT ? */ |
| 665 | if (!pcg) |
| 666 | return -EINVAL; |
| 667 | |
| 668 | parent = mem_cgroup_from_cont(pcg); |
| 669 | |
| 670 | ret = __mem_cgroup_try_charge(NULL, gfp_mask, &parent, false); |
| 671 | if (ret) |
| 672 | return ret; |
| 673 | |
| 674 | mz = mem_cgroup_zoneinfo(child, |
| 675 | page_cgroup_nid(pc), page_cgroup_zid(pc)); |
| 676 | |
| 677 | spin_lock_irqsave(&mz->lru_lock, flags); |
| 678 | ret = mem_cgroup_move_account(pc, child, parent); |
| 679 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
| 680 | |
| 681 | /* drop extra refcnt */ |
| 682 | css_put(&parent->css); |
| 683 | /* uncharge if move fails */ |
| 684 | if (ret) |
| 685 | res_counter_uncharge(&parent->res, PAGE_SIZE); |
| 686 | |
| 687 | return ret; |
| 688 | } |
| 689 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 690 | /* |
| 691 | * Charge the memory controller for page usage. |
| 692 | * Return |
| 693 | * 0 if the charge was successful |
| 694 | * < 0 if the cgroup is over its limit |
| 695 | */ |
| 696 | static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm, |
| 697 | gfp_t gfp_mask, enum charge_type ctype, |
| 698 | struct mem_cgroup *memcg) |
| 699 | { |
| 700 | struct mem_cgroup *mem; |
| 701 | struct page_cgroup *pc; |
| 702 | int ret; |
| 703 | |
| 704 | pc = lookup_page_cgroup(page); |
| 705 | /* can happen at boot */ |
| 706 | if (unlikely(!pc)) |
| 707 | return 0; |
| 708 | prefetchw(pc); |
| 709 | |
| 710 | mem = memcg; |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 711 | ret = __mem_cgroup_try_charge(mm, gfp_mask, &mem, true); |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 712 | if (ret) |
| 713 | return ret; |
| 714 | |
| 715 | __mem_cgroup_commit_charge(mem, pc, ctype); |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | int mem_cgroup_newpage_charge(struct page *page, |
| 720 | struct mm_struct *mm, gfp_t gfp_mask) |
KAMEZAWA Hiroyuki | 217bc31 | 2008-02-07 00:14:17 -0800 | [diff] [blame] | 721 | { |
Li Zefan | cede86a | 2008-07-25 01:47:18 -0700 | [diff] [blame] | 722 | if (mem_cgroup_subsys.disabled) |
| 723 | return 0; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 724 | if (PageCompound(page)) |
| 725 | return 0; |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 726 | /* |
| 727 | * If already mapped, we don't have to account. |
| 728 | * If page cache, page->mapping has address_space. |
| 729 | * But page->mapping may have out-of-use anon_vma pointer, |
| 730 | * detecit it by PageAnon() check. newly-mapped-anon's page->mapping |
| 731 | * is NULL. |
| 732 | */ |
| 733 | if (page_mapped(page) || (page->mapping && !PageAnon(page))) |
| 734 | return 0; |
| 735 | if (unlikely(!mm)) |
| 736 | mm = &init_mm; |
KAMEZAWA Hiroyuki | 217bc31 | 2008-02-07 00:14:17 -0800 | [diff] [blame] | 737 | return mem_cgroup_charge_common(page, mm, gfp_mask, |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 738 | MEM_CGROUP_CHARGE_TYPE_MAPPED, NULL); |
KAMEZAWA Hiroyuki | 217bc31 | 2008-02-07 00:14:17 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Balbir Singh | e1a1cd5 | 2008-02-07 00:14:02 -0800 | [diff] [blame] | 741 | int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, |
| 742 | gfp_t gfp_mask) |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 743 | { |
Li Zefan | cede86a | 2008-07-25 01:47:18 -0700 | [diff] [blame] | 744 | if (mem_cgroup_subsys.disabled) |
| 745 | return 0; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 746 | if (PageCompound(page)) |
| 747 | return 0; |
KAMEZAWA Hiroyuki | accf163 | 2008-07-25 01:47:17 -0700 | [diff] [blame] | 748 | /* |
| 749 | * Corner case handling. This is called from add_to_page_cache() |
| 750 | * in usual. But some FS (shmem) precharges this page before calling it |
| 751 | * and call add_to_page_cache() with GFP_NOWAIT. |
| 752 | * |
| 753 | * For GFP_NOWAIT case, the page may be pre-charged before calling |
| 754 | * add_to_page_cache(). (See shmem.c) check it here and avoid to call |
| 755 | * charge twice. (It works but has to pay a bit larger cost.) |
| 756 | */ |
| 757 | if (!(gfp_mask & __GFP_WAIT)) { |
| 758 | struct page_cgroup *pc; |
| 759 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 760 | |
| 761 | pc = lookup_page_cgroup(page); |
| 762 | if (!pc) |
| 763 | return 0; |
| 764 | lock_page_cgroup(pc); |
| 765 | if (PageCgroupUsed(pc)) { |
| 766 | unlock_page_cgroup(pc); |
KAMEZAWA Hiroyuki | accf163 | 2008-07-25 01:47:17 -0700 | [diff] [blame] | 767 | return 0; |
| 768 | } |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 769 | unlock_page_cgroup(pc); |
KAMEZAWA Hiroyuki | accf163 | 2008-07-25 01:47:17 -0700 | [diff] [blame] | 770 | } |
| 771 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 772 | if (unlikely(!mm)) |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 773 | mm = &init_mm; |
KAMEZAWA Hiroyuki | accf163 | 2008-07-25 01:47:17 -0700 | [diff] [blame] | 774 | |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 775 | if (page_is_file_cache(page)) |
| 776 | return mem_cgroup_charge_common(page, mm, gfp_mask, |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 777 | MEM_CGROUP_CHARGE_TYPE_CACHE, NULL); |
KAMEZAWA Hiroyuki | c05555b | 2008-10-18 20:28:11 -0700 | [diff] [blame] | 778 | else |
| 779 | return mem_cgroup_charge_common(page, mm, gfp_mask, |
| 780 | MEM_CGROUP_CHARGE_TYPE_SHMEM, NULL); |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 781 | } |
| 782 | |
KAMEZAWA Hiroyuki | 7a81b88 | 2009-01-07 18:07:48 -0800 | [diff] [blame] | 783 | void mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr) |
| 784 | { |
| 785 | struct page_cgroup *pc; |
| 786 | |
| 787 | if (mem_cgroup_subsys.disabled) |
| 788 | return; |
| 789 | if (!ptr) |
| 790 | return; |
| 791 | pc = lookup_page_cgroup(page); |
| 792 | __mem_cgroup_commit_charge(ptr, pc, MEM_CGROUP_CHARGE_TYPE_MAPPED); |
| 793 | } |
| 794 | |
| 795 | void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *mem) |
| 796 | { |
| 797 | if (mem_cgroup_subsys.disabled) |
| 798 | return; |
| 799 | if (!mem) |
| 800 | return; |
| 801 | res_counter_uncharge(&mem->res, PAGE_SIZE); |
| 802 | css_put(&mem->css); |
| 803 | } |
| 804 | |
| 805 | |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 806 | /* |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 807 | * uncharge if !page_mapped(page) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 808 | */ |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 809 | static void |
| 810 | __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 811 | { |
Hugh Dickins | 8289546 | 2008-03-04 14:29:08 -0800 | [diff] [blame] | 812 | struct page_cgroup *pc; |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 813 | struct mem_cgroup *mem; |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 814 | struct mem_cgroup_per_zone *mz; |
Balbir Singh | 66e1707 | 2008-02-07 00:13:56 -0800 | [diff] [blame] | 815 | unsigned long flags; |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 816 | |
Balbir Singh | 4077960 | 2008-04-04 14:29:59 -0700 | [diff] [blame] | 817 | if (mem_cgroup_subsys.disabled) |
| 818 | return; |
| 819 | |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 820 | /* |
Balbir Singh | 3c541e1 | 2008-02-07 00:14:41 -0800 | [diff] [blame] | 821 | * Check if our page_cgroup is valid |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 822 | */ |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 823 | pc = lookup_page_cgroup(page); |
| 824 | if (unlikely(!pc || !PageCgroupUsed(pc))) |
| 825 | return; |
Balbir Singh | 8a9f3cc | 2008-02-07 00:13:53 -0800 | [diff] [blame] | 826 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 827 | lock_page_cgroup(pc); |
| 828 | if ((ctype == MEM_CGROUP_CHARGE_TYPE_MAPPED && page_mapped(page)) |
| 829 | || !PageCgroupUsed(pc)) { |
| 830 | /* This happens at race in zap_pte_range() and do_swap_page()*/ |
| 831 | unlock_page_cgroup(pc); |
| 832 | return; |
| 833 | } |
| 834 | ClearPageCgroupUsed(pc); |
| 835 | mem = pc->mem_cgroup; |
Hugh Dickins | b9c565d | 2008-03-04 14:29:11 -0800 | [diff] [blame] | 836 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 837 | mz = page_cgroup_zoneinfo(pc); |
| 838 | spin_lock_irqsave(&mz->lru_lock, flags); |
| 839 | __mem_cgroup_remove_list(mz, pc); |
| 840 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 841 | unlock_page_cgroup(pc); |
Hugh Dickins | fb59e9f | 2008-03-04 14:29:16 -0800 | [diff] [blame] | 842 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 843 | res_counter_uncharge(&mem->res, PAGE_SIZE); |
| 844 | css_put(&mem->css); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 845 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 846 | return; |
Balbir Singh | 3c541e1 | 2008-02-07 00:14:41 -0800 | [diff] [blame] | 847 | } |
| 848 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 849 | void mem_cgroup_uncharge_page(struct page *page) |
| 850 | { |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 851 | /* early check. */ |
| 852 | if (page_mapped(page)) |
| 853 | return; |
| 854 | if (page->mapping && !PageAnon(page)) |
| 855 | return; |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 856 | __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_MAPPED); |
| 857 | } |
| 858 | |
| 859 | void mem_cgroup_uncharge_cache_page(struct page *page) |
| 860 | { |
| 861 | VM_BUG_ON(page_mapped(page)); |
KAMEZAWA Hiroyuki | b7abea9 | 2008-10-18 20:28:09 -0700 | [diff] [blame] | 862 | VM_BUG_ON(page->mapping); |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 863 | __mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE); |
| 864 | } |
| 865 | |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 866 | /* |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 867 | * Before starting migration, account PAGE_SIZE to mem_cgroup that the old |
| 868 | * page belongs to. |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 869 | */ |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 870 | int mem_cgroup_prepare_migration(struct page *page, struct mem_cgroup **ptr) |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 871 | { |
| 872 | struct page_cgroup *pc; |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 873 | struct mem_cgroup *mem = NULL; |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 874 | int ret = 0; |
Hugh Dickins | 8869b8f | 2008-03-04 14:29:09 -0800 | [diff] [blame] | 875 | |
Balbir Singh | 4077960 | 2008-04-04 14:29:59 -0700 | [diff] [blame] | 876 | if (mem_cgroup_subsys.disabled) |
| 877 | return 0; |
| 878 | |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 879 | pc = lookup_page_cgroup(page); |
| 880 | lock_page_cgroup(pc); |
| 881 | if (PageCgroupUsed(pc)) { |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 882 | mem = pc->mem_cgroup; |
| 883 | css_get(&mem->css); |
Hugh Dickins | b9c565d | 2008-03-04 14:29:11 -0800 | [diff] [blame] | 884 | } |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 885 | unlock_page_cgroup(pc); |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 886 | |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 887 | if (mem) { |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 888 | ret = mem_cgroup_try_charge(NULL, GFP_HIGHUSER_MOVABLE, &mem); |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 889 | css_put(&mem->css); |
| 890 | } |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 891 | *ptr = mem; |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 892 | return ret; |
| 893 | } |
Hugh Dickins | fb59e9f | 2008-03-04 14:29:16 -0800 | [diff] [blame] | 894 | |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 895 | /* remove redundant charge if migration failed*/ |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 896 | void mem_cgroup_end_migration(struct mem_cgroup *mem, |
| 897 | struct page *oldpage, struct page *newpage) |
KAMEZAWA Hiroyuki | e8589cc | 2008-07-25 01:47:10 -0700 | [diff] [blame] | 898 | { |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 899 | struct page *target, *unused; |
| 900 | struct page_cgroup *pc; |
| 901 | enum charge_type ctype; |
| 902 | |
| 903 | if (!mem) |
| 904 | return; |
| 905 | |
| 906 | /* at migration success, oldpage->mapping is NULL. */ |
| 907 | if (oldpage->mapping) { |
| 908 | target = oldpage; |
| 909 | unused = NULL; |
| 910 | } else { |
| 911 | target = newpage; |
| 912 | unused = oldpage; |
| 913 | } |
| 914 | |
| 915 | if (PageAnon(target)) |
| 916 | ctype = MEM_CGROUP_CHARGE_TYPE_MAPPED; |
| 917 | else if (page_is_file_cache(target)) |
| 918 | ctype = MEM_CGROUP_CHARGE_TYPE_CACHE; |
| 919 | else |
| 920 | ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM; |
| 921 | |
| 922 | /* unused page is not on radix-tree now. */ |
| 923 | if (unused && ctype != MEM_CGROUP_CHARGE_TYPE_MAPPED) |
| 924 | __mem_cgroup_uncharge_common(unused, ctype); |
| 925 | |
| 926 | pc = lookup_page_cgroup(target); |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 927 | /* |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 928 | * __mem_cgroup_commit_charge() check PCG_USED bit of page_cgroup. |
| 929 | * So, double-counting is effectively avoided. |
KAMEZAWA Hiroyuki | 69029cd | 2008-07-25 01:47:14 -0700 | [diff] [blame] | 930 | */ |
KAMEZAWA Hiroyuki | 01b1ae6 | 2009-01-07 18:07:50 -0800 | [diff] [blame] | 931 | __mem_cgroup_commit_charge(mem, pc, ctype); |
| 932 | |
| 933 | /* |
| 934 | * Both of oldpage and newpage are still under lock_page(). |
| 935 | * Then, we don't have to care about race in radix-tree. |
| 936 | * But we have to be careful that this page is unmapped or not. |
| 937 | * |
| 938 | * There is a case for !page_mapped(). At the start of |
| 939 | * migration, oldpage was mapped. But now, it's zapped. |
| 940 | * But we know *target* page is not freed/reused under us. |
| 941 | * mem_cgroup_uncharge_page() does all necessary checks. |
| 942 | */ |
| 943 | if (ctype == MEM_CGROUP_CHARGE_TYPE_MAPPED) |
| 944 | mem_cgroup_uncharge_page(target); |
KAMEZAWA Hiroyuki | ae41be3 | 2008-02-07 00:14:10 -0800 | [diff] [blame] | 945 | } |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 946 | |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 947 | /* |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 948 | * A call to try to shrink memory usage under specified resource controller. |
| 949 | * This is typically used for page reclaiming for shmem for reducing side |
| 950 | * effect of page allocation from shmem, which is used by some mem_cgroup. |
| 951 | */ |
| 952 | int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask) |
| 953 | { |
| 954 | struct mem_cgroup *mem; |
| 955 | int progress = 0; |
| 956 | int retry = MEM_CGROUP_RECLAIM_RETRIES; |
| 957 | |
Li Zefan | cede86a | 2008-07-25 01:47:18 -0700 | [diff] [blame] | 958 | if (mem_cgroup_subsys.disabled) |
| 959 | return 0; |
Hugh Dickins | 9623e07 | 2008-08-12 15:08:41 -0700 | [diff] [blame] | 960 | if (!mm) |
| 961 | return 0; |
Li Zefan | cede86a | 2008-07-25 01:47:18 -0700 | [diff] [blame] | 962 | |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 963 | rcu_read_lock(); |
| 964 | mem = mem_cgroup_from_task(rcu_dereference(mm->owner)); |
Balbir Singh | 31a78f2 | 2008-09-28 23:09:31 +0100 | [diff] [blame] | 965 | if (unlikely(!mem)) { |
| 966 | rcu_read_unlock(); |
| 967 | return 0; |
| 968 | } |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 969 | css_get(&mem->css); |
| 970 | rcu_read_unlock(); |
| 971 | |
| 972 | do { |
| 973 | progress = try_to_free_mem_cgroup_pages(mem, gfp_mask); |
Daisuke Nishimura | a10cebf | 2008-09-22 13:57:52 -0700 | [diff] [blame] | 974 | progress += res_counter_check_under_limit(&mem->res); |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 975 | } while (!progress && --retry); |
| 976 | |
| 977 | css_put(&mem->css); |
| 978 | if (!retry) |
| 979 | return -ENOMEM; |
| 980 | return 0; |
| 981 | } |
| 982 | |
KOSAKI Motohiro | d38d2a7 | 2009-01-06 14:39:44 -0800 | [diff] [blame] | 983 | static int mem_cgroup_resize_limit(struct mem_cgroup *memcg, |
| 984 | unsigned long long val) |
KAMEZAWA Hiroyuki | 628f423 | 2008-07-25 01:47:20 -0700 | [diff] [blame] | 985 | { |
| 986 | |
| 987 | int retry_count = MEM_CGROUP_RECLAIM_RETRIES; |
| 988 | int progress; |
| 989 | int ret = 0; |
| 990 | |
| 991 | while (res_counter_set_limit(&memcg->res, val)) { |
| 992 | if (signal_pending(current)) { |
| 993 | ret = -EINTR; |
| 994 | break; |
| 995 | } |
| 996 | if (!retry_count) { |
| 997 | ret = -EBUSY; |
| 998 | break; |
| 999 | } |
KAMEZAWA Hiroyuki | bced052 | 2009-01-07 18:07:49 -0800 | [diff] [blame] | 1000 | progress = try_to_free_mem_cgroup_pages(memcg, |
| 1001 | GFP_HIGHUSER_MOVABLE); |
KAMEZAWA Hiroyuki | 628f423 | 2008-07-25 01:47:20 -0700 | [diff] [blame] | 1002 | if (!progress) |
| 1003 | retry_count--; |
| 1004 | } |
| 1005 | return ret; |
| 1006 | } |
| 1007 | |
| 1008 | |
KAMEZAWA Hiroyuki | c9b0ed5 | 2008-07-25 01:47:15 -0700 | [diff] [blame] | 1009 | /* |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1010 | * This routine traverse page_cgroup in given list and drop them all. |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1011 | * *And* this routine doesn't reclaim page itself, just removes page_cgroup. |
| 1012 | */ |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1013 | static int mem_cgroup_force_empty_list(struct mem_cgroup *mem, |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 1014 | struct mem_cgroup_per_zone *mz, |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 1015 | enum lru_list lru) |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1016 | { |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1017 | struct page_cgroup *pc, *busy; |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1018 | unsigned long flags; |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1019 | unsigned long loop; |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 1020 | struct list_head *list; |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1021 | int ret = 0; |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 1022 | |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 1023 | list = &mz->lists[lru]; |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1024 | |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1025 | loop = MEM_CGROUP_ZSTAT(mz, lru); |
| 1026 | /* give some margin against EBUSY etc...*/ |
| 1027 | loop += 256; |
| 1028 | busy = NULL; |
| 1029 | while (loop--) { |
| 1030 | ret = 0; |
| 1031 | spin_lock_irqsave(&mz->lru_lock, flags); |
| 1032 | if (list_empty(list)) { |
| 1033 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 1034 | break; |
| 1035 | } |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1036 | pc = list_entry(list->prev, struct page_cgroup, lru); |
| 1037 | if (busy == pc) { |
| 1038 | list_move(&pc->lru, list); |
| 1039 | busy = 0; |
| 1040 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
| 1041 | continue; |
| 1042 | } |
| 1043 | spin_unlock_irqrestore(&mz->lru_lock, flags); |
| 1044 | |
| 1045 | ret = mem_cgroup_move_parent(pc, mem, GFP_HIGHUSER_MOVABLE); |
| 1046 | if (ret == -ENOMEM) |
| 1047 | break; |
| 1048 | |
| 1049 | if (ret == -EBUSY || ret == -EINVAL) { |
| 1050 | /* found lock contention or "pc" is obsolete. */ |
| 1051 | busy = pc; |
| 1052 | cond_resched(); |
| 1053 | } else |
| 1054 | busy = NULL; |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1055 | } |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1056 | if (!ret && !list_empty(list)) |
| 1057 | return -EBUSY; |
| 1058 | return ret; |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /* |
| 1062 | * make mem_cgroup's charge to be 0 if there is no task. |
| 1063 | * This enables deleting this mem_cgroup. |
| 1064 | */ |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1065 | static int mem_cgroup_force_empty(struct mem_cgroup *mem, bool free_all) |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1066 | { |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1067 | int ret; |
| 1068 | int node, zid, shrink; |
| 1069 | int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1070 | struct cgroup *cgrp = mem->css.cgroup; |
Hugh Dickins | 8869b8f | 2008-03-04 14:29:09 -0800 | [diff] [blame] | 1071 | |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1072 | css_get(&mem->css); |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1073 | |
| 1074 | shrink = 0; |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1075 | /* should free all ? */ |
| 1076 | if (free_all) |
| 1077 | goto try_to_free; |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1078 | move_account: |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1079 | while (mem->res.usage > 0) { |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1080 | ret = -EBUSY; |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1081 | if (cgroup_task_count(cgrp) || !list_empty(&cgrp->children)) |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1082 | goto out; |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1083 | ret = -EINTR; |
| 1084 | if (signal_pending(current)) |
| 1085 | goto out; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 1086 | /* This is for making all *used* pages to be on LRU. */ |
| 1087 | lru_add_drain_all(); |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1088 | ret = 0; |
| 1089 | for_each_node_state(node, N_POSSIBLE) { |
| 1090 | for (zid = 0; !ret && zid < MAX_NR_ZONES; zid++) { |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1091 | struct mem_cgroup_per_zone *mz; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 1092 | enum lru_list l; |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1093 | mz = mem_cgroup_zoneinfo(mem, node, zid); |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1094 | for_each_lru(l) { |
| 1095 | ret = mem_cgroup_force_empty_list(mem, |
| 1096 | mz, l); |
| 1097 | if (ret) |
| 1098 | break; |
| 1099 | } |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1100 | } |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1101 | if (ret) |
| 1102 | break; |
| 1103 | } |
| 1104 | /* it seems parent cgroup doesn't have enough mem */ |
| 1105 | if (ret == -ENOMEM) |
| 1106 | goto try_to_free; |
KAMEZAWA Hiroyuki | 52d4b9a | 2008-10-18 20:28:16 -0700 | [diff] [blame] | 1107 | cond_resched(); |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1108 | } |
| 1109 | ret = 0; |
| 1110 | out: |
| 1111 | css_put(&mem->css); |
| 1112 | return ret; |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1113 | |
| 1114 | try_to_free: |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1115 | /* returns EBUSY if there is a task or if we come here twice. */ |
| 1116 | if (cgroup_task_count(cgrp) || !list_empty(&cgrp->children) || shrink) { |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1117 | ret = -EBUSY; |
| 1118 | goto out; |
| 1119 | } |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1120 | /* we call try-to-free pages for make this cgroup empty */ |
| 1121 | lru_add_drain_all(); |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1122 | /* try to free all pages in this cgroup */ |
| 1123 | shrink = 1; |
| 1124 | while (nr_retries && mem->res.usage > 0) { |
| 1125 | int progress; |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1126 | |
| 1127 | if (signal_pending(current)) { |
| 1128 | ret = -EINTR; |
| 1129 | goto out; |
| 1130 | } |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1131 | progress = try_to_free_mem_cgroup_pages(mem, |
| 1132 | GFP_HIGHUSER_MOVABLE); |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1133 | if (!progress) { |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1134 | nr_retries--; |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1135 | /* maybe some writeback is necessary */ |
| 1136 | congestion_wait(WRITE, HZ/10); |
| 1137 | } |
KAMEZAWA Hiroyuki | f817ed4 | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1138 | |
| 1139 | } |
| 1140 | /* try move_account...there may be some *locked* pages. */ |
| 1141 | if (mem->res.usage) |
| 1142 | goto move_account; |
| 1143 | ret = 0; |
| 1144 | goto out; |
KAMEZAWA Hiroyuki | cc84758 | 2008-02-07 00:14:16 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1147 | int mem_cgroup_force_empty_write(struct cgroup *cont, unsigned int event) |
| 1148 | { |
| 1149 | return mem_cgroup_force_empty(mem_cgroup_from_cont(cont), true); |
| 1150 | } |
| 1151 | |
| 1152 | |
Paul Menage | 2c3daa7 | 2008-04-29 00:59:58 -0700 | [diff] [blame] | 1153 | static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft) |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1154 | { |
Paul Menage | 2c3daa7 | 2008-04-29 00:59:58 -0700 | [diff] [blame] | 1155 | return res_counter_read_u64(&mem_cgroup_from_cont(cont)->res, |
| 1156 | cft->private); |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1157 | } |
KAMEZAWA Hiroyuki | 628f423 | 2008-07-25 01:47:20 -0700 | [diff] [blame] | 1158 | /* |
| 1159 | * The user of this function is... |
| 1160 | * RES_LIMIT. |
| 1161 | */ |
Paul Menage | 856c13a | 2008-07-25 01:47:04 -0700 | [diff] [blame] | 1162 | static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, |
| 1163 | const char *buffer) |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1164 | { |
KAMEZAWA Hiroyuki | 628f423 | 2008-07-25 01:47:20 -0700 | [diff] [blame] | 1165 | struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); |
| 1166 | unsigned long long val; |
| 1167 | int ret; |
| 1168 | |
| 1169 | switch (cft->private) { |
| 1170 | case RES_LIMIT: |
| 1171 | /* This function does all necessary parse...reuse it */ |
| 1172 | ret = res_counter_memparse_write_strategy(buffer, &val); |
| 1173 | if (!ret) |
| 1174 | ret = mem_cgroup_resize_limit(memcg, val); |
| 1175 | break; |
| 1176 | default: |
| 1177 | ret = -EINVAL; /* should be BUG() ? */ |
| 1178 | break; |
| 1179 | } |
| 1180 | return ret; |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1181 | } |
| 1182 | |
Pavel Emelyanov | 29f2a4d | 2008-04-29 01:00:21 -0700 | [diff] [blame] | 1183 | static int mem_cgroup_reset(struct cgroup *cont, unsigned int event) |
Pavel Emelyanov | c84872e | 2008-04-29 01:00:17 -0700 | [diff] [blame] | 1184 | { |
| 1185 | struct mem_cgroup *mem; |
| 1186 | |
| 1187 | mem = mem_cgroup_from_cont(cont); |
Pavel Emelyanov | 29f2a4d | 2008-04-29 01:00:21 -0700 | [diff] [blame] | 1188 | switch (event) { |
| 1189 | case RES_MAX_USAGE: |
| 1190 | res_counter_reset_max(&mem->res); |
| 1191 | break; |
| 1192 | case RES_FAILCNT: |
| 1193 | res_counter_reset_failcnt(&mem->res); |
| 1194 | break; |
| 1195 | } |
Pavel Emelyanov | 85cc59d | 2008-04-29 01:00:20 -0700 | [diff] [blame] | 1196 | return 0; |
Pavel Emelyanov | c84872e | 2008-04-29 01:00:17 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1199 | static const struct mem_cgroup_stat_desc { |
| 1200 | const char *msg; |
| 1201 | u64 unit; |
| 1202 | } mem_cgroup_stat_desc[] = { |
| 1203 | [MEM_CGROUP_STAT_CACHE] = { "cache", PAGE_SIZE, }, |
| 1204 | [MEM_CGROUP_STAT_RSS] = { "rss", PAGE_SIZE, }, |
Balaji Rao | 55e462b | 2008-05-01 04:35:12 -0700 | [diff] [blame] | 1205 | [MEM_CGROUP_STAT_PGPGIN_COUNT] = {"pgpgin", 1, }, |
| 1206 | [MEM_CGROUP_STAT_PGPGOUT_COUNT] = {"pgpgout", 1, }, |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1207 | }; |
| 1208 | |
Paul Menage | c64745c | 2008-04-29 01:00:02 -0700 | [diff] [blame] | 1209 | static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft, |
| 1210 | struct cgroup_map_cb *cb) |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1211 | { |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1212 | struct mem_cgroup *mem_cont = mem_cgroup_from_cont(cont); |
| 1213 | struct mem_cgroup_stat *stat = &mem_cont->stat; |
| 1214 | int i; |
| 1215 | |
| 1216 | for (i = 0; i < ARRAY_SIZE(stat->cpustat[0].count); i++) { |
| 1217 | s64 val; |
| 1218 | |
| 1219 | val = mem_cgroup_read_stat(stat, i); |
| 1220 | val *= mem_cgroup_stat_desc[i].unit; |
Paul Menage | c64745c | 2008-04-29 01:00:02 -0700 | [diff] [blame] | 1221 | cb->fill(cb, mem_cgroup_stat_desc[i].msg, val); |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1222 | } |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1223 | /* showing # of active pages */ |
| 1224 | { |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 1225 | unsigned long active_anon, inactive_anon; |
| 1226 | unsigned long active_file, inactive_file; |
Lee Schermerhorn | 7b85412 | 2008-10-18 20:26:40 -0700 | [diff] [blame] | 1227 | unsigned long unevictable; |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1228 | |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 1229 | inactive_anon = mem_cgroup_get_all_zonestat(mem_cont, |
| 1230 | LRU_INACTIVE_ANON); |
| 1231 | active_anon = mem_cgroup_get_all_zonestat(mem_cont, |
| 1232 | LRU_ACTIVE_ANON); |
| 1233 | inactive_file = mem_cgroup_get_all_zonestat(mem_cont, |
| 1234 | LRU_INACTIVE_FILE); |
| 1235 | active_file = mem_cgroup_get_all_zonestat(mem_cont, |
| 1236 | LRU_ACTIVE_FILE); |
Lee Schermerhorn | 7b85412 | 2008-10-18 20:26:40 -0700 | [diff] [blame] | 1237 | unevictable = mem_cgroup_get_all_zonestat(mem_cont, |
| 1238 | LRU_UNEVICTABLE); |
| 1239 | |
Rik van Riel | 4f98a2f | 2008-10-18 20:26:32 -0700 | [diff] [blame] | 1240 | cb->fill(cb, "active_anon", (active_anon) * PAGE_SIZE); |
| 1241 | cb->fill(cb, "inactive_anon", (inactive_anon) * PAGE_SIZE); |
| 1242 | cb->fill(cb, "active_file", (active_file) * PAGE_SIZE); |
| 1243 | cb->fill(cb, "inactive_file", (inactive_file) * PAGE_SIZE); |
Lee Schermerhorn | 7b85412 | 2008-10-18 20:26:40 -0700 | [diff] [blame] | 1244 | cb->fill(cb, "unevictable", unevictable * PAGE_SIZE); |
| 1245 | |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1246 | } |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1247 | return 0; |
| 1248 | } |
| 1249 | |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1250 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1251 | static struct cftype mem_cgroup_files[] = { |
| 1252 | { |
Balbir Singh | 0eea103 | 2008-02-07 00:13:57 -0800 | [diff] [blame] | 1253 | .name = "usage_in_bytes", |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1254 | .private = RES_USAGE, |
Paul Menage | 2c3daa7 | 2008-04-29 00:59:58 -0700 | [diff] [blame] | 1255 | .read_u64 = mem_cgroup_read, |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1256 | }, |
| 1257 | { |
Pavel Emelyanov | c84872e | 2008-04-29 01:00:17 -0700 | [diff] [blame] | 1258 | .name = "max_usage_in_bytes", |
| 1259 | .private = RES_MAX_USAGE, |
Pavel Emelyanov | 29f2a4d | 2008-04-29 01:00:21 -0700 | [diff] [blame] | 1260 | .trigger = mem_cgroup_reset, |
Pavel Emelyanov | c84872e | 2008-04-29 01:00:17 -0700 | [diff] [blame] | 1261 | .read_u64 = mem_cgroup_read, |
| 1262 | }, |
| 1263 | { |
Balbir Singh | 0eea103 | 2008-02-07 00:13:57 -0800 | [diff] [blame] | 1264 | .name = "limit_in_bytes", |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1265 | .private = RES_LIMIT, |
Paul Menage | 856c13a | 2008-07-25 01:47:04 -0700 | [diff] [blame] | 1266 | .write_string = mem_cgroup_write, |
Paul Menage | 2c3daa7 | 2008-04-29 00:59:58 -0700 | [diff] [blame] | 1267 | .read_u64 = mem_cgroup_read, |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1268 | }, |
| 1269 | { |
| 1270 | .name = "failcnt", |
| 1271 | .private = RES_FAILCNT, |
Pavel Emelyanov | 29f2a4d | 2008-04-29 01:00:21 -0700 | [diff] [blame] | 1272 | .trigger = mem_cgroup_reset, |
Paul Menage | 2c3daa7 | 2008-04-29 00:59:58 -0700 | [diff] [blame] | 1273 | .read_u64 = mem_cgroup_read, |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1274 | }, |
Balbir Singh | 8697d33 | 2008-02-07 00:13:59 -0800 | [diff] [blame] | 1275 | { |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1276 | .name = "stat", |
Paul Menage | c64745c | 2008-04-29 01:00:02 -0700 | [diff] [blame] | 1277 | .read_map = mem_control_stat_show, |
KAMEZAWA Hiroyuki | d2ceb9b | 2008-02-07 00:14:25 -0800 | [diff] [blame] | 1278 | }, |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1279 | { |
| 1280 | .name = "force_empty", |
| 1281 | .trigger = mem_cgroup_force_empty_write, |
| 1282 | }, |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1283 | }; |
| 1284 | |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1285 | static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node) |
| 1286 | { |
| 1287 | struct mem_cgroup_per_node *pn; |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1288 | struct mem_cgroup_per_zone *mz; |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 1289 | enum lru_list l; |
KAMEZAWA Hiroyuki | 41e3355 | 2008-04-08 17:41:54 -0700 | [diff] [blame] | 1290 | int zone, tmp = node; |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1291 | /* |
| 1292 | * This routine is called against possible nodes. |
| 1293 | * But it's BUG to call kmalloc() against offline node. |
| 1294 | * |
| 1295 | * TODO: this routine can waste much memory for nodes which will |
| 1296 | * never be onlined. It's better to use memory hotplug callback |
| 1297 | * function. |
| 1298 | */ |
KAMEZAWA Hiroyuki | 41e3355 | 2008-04-08 17:41:54 -0700 | [diff] [blame] | 1299 | if (!node_state(node, N_NORMAL_MEMORY)) |
| 1300 | tmp = -1; |
| 1301 | pn = kmalloc_node(sizeof(*pn), GFP_KERNEL, tmp); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1302 | if (!pn) |
| 1303 | return 1; |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1304 | |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1305 | mem->info.nodeinfo[node] = pn; |
| 1306 | memset(pn, 0, sizeof(*pn)); |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1307 | |
| 1308 | for (zone = 0; zone < MAX_NR_ZONES; zone++) { |
| 1309 | mz = &pn->zoneinfo[zone]; |
KAMEZAWA Hiroyuki | 072c56c1 | 2008-02-07 00:14:39 -0800 | [diff] [blame] | 1310 | spin_lock_init(&mz->lru_lock); |
Christoph Lameter | b69408e | 2008-10-18 20:26:14 -0700 | [diff] [blame] | 1311 | for_each_lru(l) |
| 1312 | INIT_LIST_HEAD(&mz->lists[l]); |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1313 | } |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1314 | return 0; |
| 1315 | } |
| 1316 | |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1317 | static void free_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node) |
| 1318 | { |
| 1319 | kfree(mem->info.nodeinfo[node]); |
| 1320 | } |
| 1321 | |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1322 | static int mem_cgroup_size(void) |
| 1323 | { |
| 1324 | int cpustat_size = nr_cpu_ids * sizeof(struct mem_cgroup_stat_cpu); |
| 1325 | return sizeof(struct mem_cgroup) + cpustat_size; |
| 1326 | } |
| 1327 | |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1328 | static struct mem_cgroup *mem_cgroup_alloc(void) |
| 1329 | { |
| 1330 | struct mem_cgroup *mem; |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1331 | int size = mem_cgroup_size(); |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1332 | |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1333 | if (size < PAGE_SIZE) |
| 1334 | mem = kmalloc(size, GFP_KERNEL); |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1335 | else |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1336 | mem = vmalloc(size); |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1337 | |
| 1338 | if (mem) |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1339 | memset(mem, 0, size); |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1340 | return mem; |
| 1341 | } |
| 1342 | |
| 1343 | static void mem_cgroup_free(struct mem_cgroup *mem) |
| 1344 | { |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1345 | if (mem_cgroup_size() < PAGE_SIZE) |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1346 | kfree(mem); |
| 1347 | else |
| 1348 | vfree(mem); |
| 1349 | } |
| 1350 | |
| 1351 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1352 | static struct cgroup_subsys_state * |
| 1353 | mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) |
| 1354 | { |
| 1355 | struct mem_cgroup *mem; |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1356 | int node; |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1357 | |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1358 | mem = mem_cgroup_alloc(); |
| 1359 | if (!mem) |
| 1360 | return ERR_PTR(-ENOMEM); |
Pavel Emelianov | 78fb746 | 2008-02-07 00:13:51 -0800 | [diff] [blame] | 1361 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1362 | res_counter_init(&mem->res); |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1363 | |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1364 | for_each_node_state(node, N_POSSIBLE) |
| 1365 | if (alloc_mem_cgroup_per_zone_info(mem, node)) |
| 1366 | goto free_out; |
| 1367 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1368 | return &mem->css; |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1369 | free_out: |
| 1370 | for_each_node_state(node, N_POSSIBLE) |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1371 | free_mem_cgroup_per_zone_info(mem, node); |
Jan Blunck | c8dad2b | 2009-01-07 18:07:53 -0800 | [diff] [blame] | 1372 | mem_cgroup_free(mem); |
Li Zefan | 2dda81c | 2008-02-23 15:24:14 -0800 | [diff] [blame] | 1373 | return ERR_PTR(-ENOMEM); |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
KAMEZAWA Hiroyuki | df878fb | 2008-02-07 00:14:28 -0800 | [diff] [blame] | 1376 | static void mem_cgroup_pre_destroy(struct cgroup_subsys *ss, |
| 1377 | struct cgroup *cont) |
| 1378 | { |
| 1379 | struct mem_cgroup *mem = mem_cgroup_from_cont(cont); |
KAMEZAWA Hiroyuki | c1e862c | 2009-01-07 18:07:55 -0800 | [diff] [blame^] | 1380 | mem_cgroup_force_empty(mem, false); |
KAMEZAWA Hiroyuki | df878fb | 2008-02-07 00:14:28 -0800 | [diff] [blame] | 1381 | } |
| 1382 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1383 | static void mem_cgroup_destroy(struct cgroup_subsys *ss, |
| 1384 | struct cgroup *cont) |
| 1385 | { |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1386 | int node; |
| 1387 | struct mem_cgroup *mem = mem_cgroup_from_cont(cont); |
| 1388 | |
| 1389 | for_each_node_state(node, N_POSSIBLE) |
KAMEZAWA Hiroyuki | 1ecaab2 | 2008-02-07 00:14:38 -0800 | [diff] [blame] | 1390 | free_mem_cgroup_per_zone_info(mem, node); |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1391 | |
KAMEZAWA Hiroyuki | 3332794 | 2008-04-29 01:00:24 -0700 | [diff] [blame] | 1392 | mem_cgroup_free(mem_cgroup_from_cont(cont)); |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static int mem_cgroup_populate(struct cgroup_subsys *ss, |
| 1396 | struct cgroup *cont) |
| 1397 | { |
| 1398 | return cgroup_add_files(cont, ss, mem_cgroup_files, |
| 1399 | ARRAY_SIZE(mem_cgroup_files)); |
| 1400 | } |
| 1401 | |
Balbir Singh | 67e465a | 2008-02-07 00:13:54 -0800 | [diff] [blame] | 1402 | static void mem_cgroup_move_task(struct cgroup_subsys *ss, |
| 1403 | struct cgroup *cont, |
| 1404 | struct cgroup *old_cont, |
| 1405 | struct task_struct *p) |
| 1406 | { |
| 1407 | struct mm_struct *mm; |
| 1408 | struct mem_cgroup *mem, *old_mem; |
| 1409 | |
| 1410 | mm = get_task_mm(p); |
| 1411 | if (mm == NULL) |
| 1412 | return; |
| 1413 | |
| 1414 | mem = mem_cgroup_from_cont(cont); |
| 1415 | old_mem = mem_cgroup_from_cont(old_cont); |
| 1416 | |
Balbir Singh | 67e465a | 2008-02-07 00:13:54 -0800 | [diff] [blame] | 1417 | /* |
| 1418 | * Only thread group leaders are allowed to migrate, the mm_struct is |
| 1419 | * in effect owned by the leader |
| 1420 | */ |
Pavel Emelyanov | 52ea27e | 2008-03-19 17:00:45 -0700 | [diff] [blame] | 1421 | if (!thread_group_leader(p)) |
Balbir Singh | 67e465a | 2008-02-07 00:13:54 -0800 | [diff] [blame] | 1422 | goto out; |
| 1423 | |
Balbir Singh | 67e465a | 2008-02-07 00:13:54 -0800 | [diff] [blame] | 1424 | out: |
| 1425 | mmput(mm); |
Balbir Singh | 67e465a | 2008-02-07 00:13:54 -0800 | [diff] [blame] | 1426 | } |
| 1427 | |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1428 | struct cgroup_subsys mem_cgroup_subsys = { |
| 1429 | .name = "memory", |
| 1430 | .subsys_id = mem_cgroup_subsys_id, |
| 1431 | .create = mem_cgroup_create, |
KAMEZAWA Hiroyuki | df878fb | 2008-02-07 00:14:28 -0800 | [diff] [blame] | 1432 | .pre_destroy = mem_cgroup_pre_destroy, |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1433 | .destroy = mem_cgroup_destroy, |
| 1434 | .populate = mem_cgroup_populate, |
Balbir Singh | 67e465a | 2008-02-07 00:13:54 -0800 | [diff] [blame] | 1435 | .attach = mem_cgroup_move_task, |
KAMEZAWA Hiroyuki | 6d12e2d | 2008-02-07 00:14:31 -0800 | [diff] [blame] | 1436 | .early_init = 0, |
Balbir Singh | 8cdea7c | 2008-02-07 00:13:50 -0800 | [diff] [blame] | 1437 | }; |