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
215215 struct page_counter kmem;
216216 struct page_counter tcpmem;
217217
218− /* Upper bound of normal memory consumption range */
219− unsigned long high;
220−
221218 /* Range enforcement for interrupt charges */
222219 struct work_struct high_work;
223220
include/linux/page_counter.h+8−0
@@ -10,6 +10,7 @@ struct page_counter { · 9 unmodified lines
1010 atomic_long_t usage;
1111 unsigned long min;
1212 unsigned long low;
13+ unsigned long high;
1314 unsigned long max;
1415 struct page_counter *parent;
1516
@@ -55,6 +56,13 @@ bool page_counter_try_charge(struct page_counter *counter, · 39 unmodified lines
5556 void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
5657 void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages);
5758 void page_counter_set_low(struct page_counter *counter, unsigned long nr_pages);
59+
60+static 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+
5866 int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages);
5967 int page_counter_memparse(const char *buf, const char *max,
6068 unsigned long *nr_pages);
mm/memcontrol.c+11−8
@@ -2252,7 +2252,8 @@ static void reclaim_high(struct mem_cgroup *memcg, · 2251 unmodified lines
22522252 gfp_t gfp_mask)
22532253 {
22542254 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))
22562257 continue;
22572258 memcg_memory_event(memcg, MEMCG_HIGH);
22582259 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
23452346
23462347 do {
23472348 overage = calculate_overage(page_counter_read(&memcg->memory),
2348− READ_ONCE(memcg->high));
2349+ READ_ONCE(memcg->memory.high));
23492350 max_overage = max(overage, max_overage);
23502351 } while ((memcg = parent_mem_cgroup(memcg)) &&
23512352 !mem_cgroup_is_root(memcg));
@@ -2604,7 +2605,8 @@ done_restock: · 252 unmodified lines
26042605 * reclaim, the cost of mismatch is negligible.
26052606 */
26062607 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)) {
26082610 /* Don't bother a random interrupted task */
26092611 if (in_interrupt()) {
26102612 schedule_work(&memcg->high_work);
@@ -4347,7 +4349,7 @@ void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, · 1736 unmodified lines
43474349
43484350 while ((parent = parent_mem_cgroup(memcg))) {
43494351 unsigned long ceiling = min(READ_ONCE(memcg->memory.max),
4350− READ_ONCE(memcg->high));
4352+ READ_ONCE(memcg->memory.high));
43514353 unsigned long used = page_counter_read(&memcg->memory);
43524354
43534355 *pheadroom = min(*pheadroom, ceiling - min(ceiling, used));
@@ -5072,7 +5074,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) · 718 unmodified lines
50725074 if (IS_ERR(memcg))
50735075 return ERR_CAST(memcg);
50745076
5075− WRITE_ONCE(memcg->high, PAGE_COUNTER_MAX);
5077+ page_counter_set_high(&memcg->memory, PAGE_COUNTER_MAX);
50765078 memcg->soft_limit = PAGE_COUNTER_MAX;
50775079 if (parent) {
50785080 memcg->swappiness = mem_cgroup_swappiness(parent);
@@ -5225,7 +5227,7 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css) · 146 unmodified lines
52255227 page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX);
52265228 page_counter_set_min(&memcg->memory, 0);
52275229 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);
52295231 memcg->soft_limit = PAGE_COUNTER_MAX;
52305232 memcg_wb_domain_size_changed(memcg);
52315233 }
@@ -6024,7 +6026,8 @@ static ssize_t memory_low_write(struct kernfs_open_file *of, · 792 unmodified lines
60246026
60256027 static int memory_high_show(struct seq_file *m, void *v)
60266028 {
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));
60286031 }
60296032
60306033 static 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
60416044 if (err)
60426045 return err;
60436046
6044− WRITE_ONCE(memcg->high, high);
6047+ page_counter_set_high(&memcg->memory, high);
60456048
60466049 for (;;) {
60476050 unsigned long nr_pages = page_counter_read(&memcg->memory);