History

mm/memcg: move cgroup high memory limit setting into struct page_counter

High memory limit is currently recorded directly in struct mem_cgroup. We are about to add a high limit for swap, move the field to struct page_counter and add some helpers.

Jakub Kicinski committed 6 years ago

Commit d1663a91 parent ff144e63 files · +19 −11Browse files

Unified · Split

3 files
  1. include/linux/memcontrol.h +0 −3
  2. include/linux/page_counter.h +8 −0
  3. mm/memcontrol.c +11 −8
include/linux/memcontrol.h+0−3
@@ -215,9 +215,6 @@ struct mem_cgroup { · 214 unmodified lines
215 struct page_counter kmem;215 struct page_counter kmem;
216 struct page_counter tcpmem;216 struct page_counter tcpmem;
217 217
218 /* Upper bound of normal memory consumption range */
219 unsigned long high;
220
221 /* Range enforcement for interrupt charges */218 /* Range enforcement for interrupt charges */
222 struct work_struct high_work;219 struct work_struct high_work;
223 220
include/linux/page_counter.h+8−0
@@ -10,6 +10,7 @@ struct page_counter { · 9 unmodified lines
10 atomic_long_t usage;10 atomic_long_t usage;
11 unsigned long min;11 unsigned long min;
12 unsigned long low;12 unsigned long low;
13 unsigned long high;
13 unsigned long max;14 unsigned long max;
14 struct page_counter *parent;15 struct page_counter *parent;
15 16
@@ -55,6 +56,13 @@ bool page_counter_try_charge(struct page_counter *counter, · 39 unmodified lines
55void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);56void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
56void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages);57void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages);
57void page_counter_set_low(struct page_counter *counter, unsigned long nr_pages);58void page_counter_set_low(struct page_counter *counter, unsigned long nr_pages);
59
60static inline void page_counter_set_high(struct page_counter *counter,
61 unsigned long nr_pages)
62{
63 WRITE_ONCE(counter->high, nr_pages);
64}
65
58int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages);66int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages);
59int page_counter_memparse(const char *buf, const char *max,67int page_counter_memparse(const char *buf, const char *max,
60 unsigned long *nr_pages);68 unsigned long *nr_pages);
mm/memcontrol.c+11−8
@@ -2252,7 +2252,8 @@ static void reclaim_high(struct mem_cgroup *memcg, · 2251 unmodified lines
2252 gfp_t gfp_mask)2252 gfp_t gfp_mask)
2253{2253{
2254 do {2254 do {
2255 if (page_counter_read(&memcg->memory) <= READ_ONCE(memcg->high))2255 if (page_counter_read(&memcg->memory) <=
2256 READ_ONCE(memcg->memory.high))
2256 continue;2257 continue;
2257 memcg_memory_event(memcg, MEMCG_HIGH);2258 memcg_memory_event(memcg, MEMCG_HIGH);
2258 try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, true);2259 try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, true);
@@ -2345,7 +2346,7 @@ static u64 mem_find_max_overage(struct mem_cgroup *memcg) · 86 unmodified lines
2345 2346
2346 do {2347 do {
2347 overage = calculate_overage(page_counter_read(&memcg->memory),2348 overage = calculate_overage(page_counter_read(&memcg->memory),
2348 READ_ONCE(memcg->high));2349 READ_ONCE(memcg->memory.high));
2349 max_overage = max(overage, max_overage);2350 max_overage = max(overage, max_overage);
2350 } while ((memcg = parent_mem_cgroup(memcg)) &&2351 } while ((memcg = parent_mem_cgroup(memcg)) &&
2351 !mem_cgroup_is_root(memcg));2352 !mem_cgroup_is_root(memcg));
@@ -2604,7 +2605,8 @@ done_restock: · 252 unmodified lines
2604 * reclaim, the cost of mismatch is negligible.2605 * reclaim, the cost of mismatch is negligible.
2605 */2606 */
2606 do {2607 do {
2607 if (page_counter_read(&memcg->memory) > READ_ONCE(memcg->high)) {2608 if (page_counter_read(&memcg->memory) >
2609 READ_ONCE(memcg->memory.high)) {
2608 /* Don't bother a random interrupted task */2610 /* Don't bother a random interrupted task */
2609 if (in_interrupt()) {2611 if (in_interrupt()) {
2610 schedule_work(&memcg->high_work);2612 schedule_work(&memcg->high_work);
@@ -4347,7 +4349,7 @@ void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, · 1736 unmodified lines
4347 4349
4348 while ((parent = parent_mem_cgroup(memcg))) {4350 while ((parent = parent_mem_cgroup(memcg))) {
4349 unsigned long ceiling = min(READ_ONCE(memcg->memory.max),4351 unsigned long ceiling = min(READ_ONCE(memcg->memory.max),
4350 READ_ONCE(memcg->high));4352 READ_ONCE(memcg->memory.high));
4351 unsigned long used = page_counter_read(&memcg->memory);4353 unsigned long used = page_counter_read(&memcg->memory);
4352 4354
4353 *pheadroom = min(*pheadroom, ceiling - min(ceiling, used));4355 *pheadroom = min(*pheadroom, ceiling - min(ceiling, used));
@@ -5072,7 +5074,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) · 718 unmodified lines
5072 if (IS_ERR(memcg))5074 if (IS_ERR(memcg))
5073 return ERR_CAST(memcg);5075 return ERR_CAST(memcg);
5074 5076
5075 WRITE_ONCE(memcg->high, PAGE_COUNTER_MAX);5077 page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX);
5076 memcg->soft_limit = PAGE_COUNTER_MAX;5078 memcg->soft_limit = PAGE_COUNTER_MAX;
5077 if (parent) {5079 if (parent) {
5078 memcg->swappiness = mem_cgroup_swappiness(parent);5080 memcg->swappiness = mem_cgroup_swappiness(parent);
@@ -5225,7 +5227,7 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css) · 146 unmodified lines
5225 page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX);5227 page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX);
5226 page_counter_set_min(&memcg->memory, 0);5228 page_counter_set_min(&memcg->memory, 0);
5227 page_counter_set_low(&memcg->memory, 0);5229 page_counter_set_low(&memcg->memory, 0);
5228 WRITE_ONCE(memcg->high, PAGE_COUNTER_MAX);5230 page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX);
5229 memcg->soft_limit = PAGE_COUNTER_MAX;5231 memcg->soft_limit = PAGE_COUNTER_MAX;
5230 memcg_wb_domain_size_changed(memcg);5232 memcg_wb_domain_size_changed(memcg);
5231}5233}
@@ -6024,7 +6026,8 @@ static ssize_t memory_low_write(struct kernfs_open_file *of, · 792 unmodified lines
6024 6026
6025static int memory_high_show(struct seq_file *m, void *v)6027static int memory_high_show(struct seq_file *m, void *v)
6026{6028{
6027 return seq_puts_memcg_tunable(m, READ_ONCE(mem_cgroup_from_seq(m)->high));6029 return seq_puts_memcg_tunable(m,
6030 READ_ONCE(mem_cgroup_from_seq(m)->memory.high));
6028}6031}
6029 6032
6030static ssize_t memory_high_write(struct kernfs_open_file *of,6033static ssize_t memory_high_write(struct kernfs_open_file *of,
@@ -6041,7 +6044,7 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, · 10 unmodified lines
6041 if (err)6044 if (err)
6042 return err;6045 return err;
6043 6046
6044 WRITE_ONCE(memcg->high, high);6047 page_counter_set_high(&memcg->memory, high);
6045 6048
6046 for (;;) {6049 for (;;) {
6047 unsigned long nr_pages = page_counter_read(&memcg->memory);6050 unsigned long nr_pages = page_counter_read(&memcg->memory);