Skip to content

Commit bbec2e1

Browse files
rgushchintorvalds
authored andcommitted
mm: rename page_counter's count/limit into usage/max
This patch renames struct page_counter fields: count -> usage limit -> max and the corresponding functions: page_counter_limit() -> page_counter_set_max() mem_cgroup_get_limit() -> mem_cgroup_get_max() mem_cgroup_resize_limit() -> mem_cgroup_resize_max() memcg_update_kmem_limit() -> memcg_update_kmem_max() memcg_update_tcp_limit() -> memcg_update_tcp_max() The idea behind this renaming is to have the direct matching between memory cgroup knobs (low, high, max) and page_counters API. This is pure renaming, this patch doesn't bring any functional change. Link: http://lkml.kernel.org/r/20180405185921.4942-1-guro@fb.com Signed-off-by: Roman Gushchin <guro@fb.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1c4bc43 commit bbec2e1

File tree

6 files changed

+82
-82
lines changed

6 files changed

+82
-82
lines changed

include/linux/memcontrol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec,
467467

468468
void mem_cgroup_handle_over_high(void);
469469

470-
unsigned long mem_cgroup_get_limit(struct mem_cgroup *memcg);
470+
unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg);
471471

472472
void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
473473
struct task_struct *p);
@@ -858,7 +858,7 @@ mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,
858858
return 0;
859859
}
860860

861-
static inline unsigned long mem_cgroup_get_limit(struct mem_cgroup *memcg)
861+
static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
862862
{
863863
return 0;
864864
}

include/linux/page_counter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <asm/page.h>
88

99
struct page_counter {
10-
atomic_long_t count;
11-
unsigned long limit;
10+
atomic_long_t usage;
11+
unsigned long max;
1212
struct page_counter *parent;
1313

1414
/* legacy */
@@ -25,14 +25,14 @@ struct page_counter {
2525
static inline void page_counter_init(struct page_counter *counter,
2626
struct page_counter *parent)
2727
{
28-
atomic_long_set(&counter->count, 0);
29-
counter->limit = PAGE_COUNTER_MAX;
28+
atomic_long_set(&counter->usage, 0);
29+
counter->max = PAGE_COUNTER_MAX;
3030
counter->parent = parent;
3131
}
3232

3333
static inline unsigned long page_counter_read(struct page_counter *counter)
3434
{
35-
return atomic_long_read(&counter->count);
35+
return atomic_long_read(&counter->usage);
3636
}
3737

3838
void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages);
@@ -41,7 +41,7 @@ bool page_counter_try_charge(struct page_counter *counter,
4141
unsigned long nr_pages,
4242
struct page_counter **fail);
4343
void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages);
44-
int page_counter_limit(struct page_counter *counter, unsigned long limit);
44+
int page_counter_set_max(struct page_counter *counter, unsigned long nr_pages);
4545
int page_counter_memparse(const char *buf, const char *max,
4646
unsigned long *nr_pages);
4747

mm/hugetlb_cgroup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void hugetlb_cgroup_init(struct hugetlb_cgroup *h_cgroup,
8484

8585
limit = round_down(PAGE_COUNTER_MAX,
8686
1 << huge_page_order(&hstates[idx]));
87-
ret = page_counter_limit(counter, limit);
87+
ret = page_counter_set_max(counter, limit);
8888
VM_BUG_ON(ret);
8989
}
9090
}
@@ -273,7 +273,7 @@ static u64 hugetlb_cgroup_read_u64(struct cgroup_subsys_state *css,
273273
case RES_USAGE:
274274
return (u64)page_counter_read(counter) * PAGE_SIZE;
275275
case RES_LIMIT:
276-
return (u64)counter->limit * PAGE_SIZE;
276+
return (u64)counter->max * PAGE_SIZE;
277277
case RES_MAX_USAGE:
278278
return (u64)counter->watermark * PAGE_SIZE;
279279
case RES_FAILCNT:
@@ -306,7 +306,7 @@ static ssize_t hugetlb_cgroup_write(struct kernfs_open_file *of,
306306
switch (MEMFILE_ATTR(of_cft(of)->private)) {
307307
case RES_LIMIT:
308308
mutex_lock(&hugetlb_limit_mutex);
309-
ret = page_counter_limit(&h_cg->hugepage[idx], nr_pages);
309+
ret = page_counter_set_max(&h_cg->hugepage[idx], nr_pages);
310310
mutex_unlock(&hugetlb_limit_mutex);
311311
break;
312312
default:

mm/memcontrol.c

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,13 @@ static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
10341034
unsigned long limit;
10351035

10361036
count = page_counter_read(&memcg->memory);
1037-
limit = READ_ONCE(memcg->memory.limit);
1037+
limit = READ_ONCE(memcg->memory.max);
10381038
if (count < limit)
10391039
margin = limit - count;
10401040

10411041
if (do_memsw_account()) {
10421042
count = page_counter_read(&memcg->memsw);
1043-
limit = READ_ONCE(memcg->memsw.limit);
1043+
limit = READ_ONCE(memcg->memsw.max);
10441044
if (count <= limit)
10451045
margin = min(margin, limit - count);
10461046
else
@@ -1148,13 +1148,13 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
11481148

11491149
pr_info("memory: usage %llukB, limit %llukB, failcnt %lu\n",
11501150
K((u64)page_counter_read(&memcg->memory)),
1151-
K((u64)memcg->memory.limit), memcg->memory.failcnt);
1151+
K((u64)memcg->memory.max), memcg->memory.failcnt);
11521152
pr_info("memory+swap: usage %llukB, limit %llukB, failcnt %lu\n",
11531153
K((u64)page_counter_read(&memcg->memsw)),
1154-
K((u64)memcg->memsw.limit), memcg->memsw.failcnt);
1154+
K((u64)memcg->memsw.max), memcg->memsw.failcnt);
11551155
pr_info("kmem: usage %llukB, limit %llukB, failcnt %lu\n",
11561156
K((u64)page_counter_read(&memcg->kmem)),
1157-
K((u64)memcg->kmem.limit), memcg->kmem.failcnt);
1157+
K((u64)memcg->kmem.max), memcg->kmem.failcnt);
11581158

11591159
for_each_mem_cgroup_tree(iter, memcg) {
11601160
pr_info("Memory cgroup stats for ");
@@ -1179,21 +1179,21 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p)
11791179
/*
11801180
* Return the memory (and swap, if configured) limit for a memcg.
11811181
*/
1182-
unsigned long mem_cgroup_get_limit(struct mem_cgroup *memcg)
1182+
unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
11831183
{
1184-
unsigned long limit;
1184+
unsigned long max;
11851185

1186-
limit = memcg->memory.limit;
1186+
max = memcg->memory.max;
11871187
if (mem_cgroup_swappiness(memcg)) {
1188-
unsigned long memsw_limit;
1189-
unsigned long swap_limit;
1188+
unsigned long memsw_max;
1189+
unsigned long swap_max;
11901190

1191-
memsw_limit = memcg->memsw.limit;
1192-
swap_limit = memcg->swap.limit;
1193-
swap_limit = min(swap_limit, (unsigned long)total_swap_pages);
1194-
limit = min(limit + swap_limit, memsw_limit);
1191+
memsw_max = memcg->memsw.max;
1192+
swap_max = memcg->swap.max;
1193+
swap_max = min(swap_max, (unsigned long)total_swap_pages);
1194+
max = min(max + swap_max, memsw_max);
11951195
}
1196-
return limit;
1196+
return max;
11971197
}
11981198

11991199
static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
@@ -2444,10 +2444,10 @@ static inline int mem_cgroup_move_swap_account(swp_entry_t entry,
24442444
}
24452445
#endif
24462446

2447-
static DEFINE_MUTEX(memcg_limit_mutex);
2447+
static DEFINE_MUTEX(memcg_max_mutex);
24482448

2449-
static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
2450-
unsigned long limit, bool memsw)
2449+
static int mem_cgroup_resize_max(struct mem_cgroup *memcg,
2450+
unsigned long max, bool memsw)
24512451
{
24522452
bool enlarge = false;
24532453
int ret;
@@ -2460,22 +2460,22 @@ static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
24602460
break;
24612461
}
24622462

2463-
mutex_lock(&memcg_limit_mutex);
2463+
mutex_lock(&memcg_max_mutex);
24642464
/*
24652465
* Make sure that the new limit (memsw or memory limit) doesn't
2466-
* break our basic invariant rule memory.limit <= memsw.limit.
2466+
* break our basic invariant rule memory.max <= memsw.max.
24672467
*/
2468-
limits_invariant = memsw ? limit >= memcg->memory.limit :
2469-
limit <= memcg->memsw.limit;
2468+
limits_invariant = memsw ? max >= memcg->memory.max :
2469+
max <= memcg->memsw.max;
24702470
if (!limits_invariant) {
2471-
mutex_unlock(&memcg_limit_mutex);
2471+
mutex_unlock(&memcg_max_mutex);
24722472
ret = -EINVAL;
24732473
break;
24742474
}
2475-
if (limit > counter->limit)
2475+
if (max > counter->max)
24762476
enlarge = true;
2477-
ret = page_counter_limit(counter, limit);
2478-
mutex_unlock(&memcg_limit_mutex);
2477+
ret = page_counter_set_max(counter, max);
2478+
mutex_unlock(&memcg_max_mutex);
24792479

24802480
if (!ret)
24812481
break;
@@ -2757,7 +2757,7 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
27572757
return (u64)mem_cgroup_usage(memcg, true) * PAGE_SIZE;
27582758
return (u64)page_counter_read(counter) * PAGE_SIZE;
27592759
case RES_LIMIT:
2760-
return (u64)counter->limit * PAGE_SIZE;
2760+
return (u64)counter->max * PAGE_SIZE;
27612761
case RES_MAX_USAGE:
27622762
return (u64)counter->watermark * PAGE_SIZE;
27632763
case RES_FAILCNT:
@@ -2871,24 +2871,24 @@ static void memcg_free_kmem(struct mem_cgroup *memcg)
28712871
}
28722872
#endif /* !CONFIG_SLOB */
28732873

2874-
static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
2875-
unsigned long limit)
2874+
static int memcg_update_kmem_max(struct mem_cgroup *memcg,
2875+
unsigned long max)
28762876
{
28772877
int ret;
28782878

2879-
mutex_lock(&memcg_limit_mutex);
2880-
ret = page_counter_limit(&memcg->kmem, limit);
2881-
mutex_unlock(&memcg_limit_mutex);
2879+
mutex_lock(&memcg_max_mutex);
2880+
ret = page_counter_set_max(&memcg->kmem, max);
2881+
mutex_unlock(&memcg_max_mutex);
28822882
return ret;
28832883
}
28842884

2885-
static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
2885+
static int memcg_update_tcp_max(struct mem_cgroup *memcg, unsigned long max)
28862886
{
28872887
int ret;
28882888

2889-
mutex_lock(&memcg_limit_mutex);
2889+
mutex_lock(&memcg_max_mutex);
28902890

2891-
ret = page_counter_limit(&memcg->tcpmem, limit);
2891+
ret = page_counter_set_max(&memcg->tcpmem, max);
28922892
if (ret)
28932893
goto out;
28942894

@@ -2913,7 +2913,7 @@ static int memcg_update_tcp_limit(struct mem_cgroup *memcg, unsigned long limit)
29132913
memcg->tcpmem_active = true;
29142914
}
29152915
out:
2916-
mutex_unlock(&memcg_limit_mutex);
2916+
mutex_unlock(&memcg_max_mutex);
29172917
return ret;
29182918
}
29192919

@@ -2941,16 +2941,16 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
29412941
}
29422942
switch (MEMFILE_TYPE(of_cft(of)->private)) {
29432943
case _MEM:
2944-
ret = mem_cgroup_resize_limit(memcg, nr_pages, false);
2944+
ret = mem_cgroup_resize_max(memcg, nr_pages, false);
29452945
break;
29462946
case _MEMSWAP:
2947-
ret = mem_cgroup_resize_limit(memcg, nr_pages, true);
2947+
ret = mem_cgroup_resize_max(memcg, nr_pages, true);
29482948
break;
29492949
case _KMEM:
2950-
ret = memcg_update_kmem_limit(memcg, nr_pages);
2950+
ret = memcg_update_kmem_max(memcg, nr_pages);
29512951
break;
29522952
case _TCP:
2953-
ret = memcg_update_tcp_limit(memcg, nr_pages);
2953+
ret = memcg_update_tcp_max(memcg, nr_pages);
29542954
break;
29552955
}
29562956
break;
@@ -3126,8 +3126,8 @@ static int memcg_stat_show(struct seq_file *m, void *v)
31263126
/* Hierarchical information */
31273127
memory = memsw = PAGE_COUNTER_MAX;
31283128
for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) {
3129-
memory = min(memory, mi->memory.limit);
3130-
memsw = min(memsw, mi->memsw.limit);
3129+
memory = min(memory, mi->memory.max);
3130+
memsw = min(memsw, mi->memsw.max);
31313131
}
31323132
seq_printf(m, "hierarchical_memory_limit %llu\n",
31333133
(u64)memory * PAGE_SIZE);
@@ -3626,7 +3626,7 @@ void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages,
36263626
*pheadroom = PAGE_COUNTER_MAX;
36273627

36283628
while ((parent = parent_mem_cgroup(memcg))) {
3629-
unsigned long ceiling = min(memcg->memory.limit, memcg->high);
3629+
unsigned long ceiling = min(memcg->memory.max, memcg->high);
36303630
unsigned long used = page_counter_read(&memcg->memory);
36313631

36323632
*pheadroom = min(*pheadroom, ceiling - min(ceiling, used));
@@ -4319,12 +4319,12 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)
43194319
{
43204320
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
43214321

4322-
page_counter_limit(&memcg->memory, PAGE_COUNTER_MAX);
4323-
page_counter_limit(&memcg->swap, PAGE_COUNTER_MAX);
4324-
page_counter_limit(&memcg->memsw, PAGE_COUNTER_MAX);
4325-
page_counter_limit(&memcg->kmem, PAGE_COUNTER_MAX);
4326-
page_counter_limit(&memcg->tcpmem, PAGE_COUNTER_MAX);
43274322
memcg->low = 0;
4323+
page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX);
4324+
page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX);
4325+
page_counter_set_max(&memcg->memsw, PAGE_COUNTER_MAX);
4326+
page_counter_set_max(&memcg->kmem, PAGE_COUNTER_MAX);
4327+
page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX);
43284328
memcg->high = PAGE_COUNTER_MAX;
43294329
memcg->soft_limit = PAGE_COUNTER_MAX;
43304330
memcg_wb_domain_size_changed(memcg);
@@ -5131,7 +5131,7 @@ static ssize_t memory_high_write(struct kernfs_open_file *of,
51315131
static int memory_max_show(struct seq_file *m, void *v)
51325132
{
51335133
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
5134-
unsigned long max = READ_ONCE(memcg->memory.limit);
5134+
unsigned long max = READ_ONCE(memcg->memory.max);
51355135

51365136
if (max == PAGE_COUNTER_MAX)
51375137
seq_puts(m, "max\n");
@@ -5155,7 +5155,7 @@ static ssize_t memory_max_write(struct kernfs_open_file *of,
51555155
if (err)
51565156
return err;
51575157

5158-
xchg(&memcg->memory.limit, max);
5158+
xchg(&memcg->memory.max, max);
51595159

51605160
for (;;) {
51615161
unsigned long nr_pages = page_counter_read(&memcg->memory);
@@ -6074,7 +6074,7 @@ long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg)
60746074
return nr_swap_pages;
60756075
for (; memcg != root_mem_cgroup; memcg = parent_mem_cgroup(memcg))
60766076
nr_swap_pages = min_t(long, nr_swap_pages,
6077-
READ_ONCE(memcg->swap.limit) -
6077+
READ_ONCE(memcg->swap.max) -
60786078
page_counter_read(&memcg->swap));
60796079
return nr_swap_pages;
60806080
}
@@ -6095,7 +6095,7 @@ bool mem_cgroup_swap_full(struct page *page)
60956095
return false;
60966096

60976097
for (; memcg != root_mem_cgroup; memcg = parent_mem_cgroup(memcg))
6098-
if (page_counter_read(&memcg->swap) * 2 >= memcg->swap.limit)
6098+
if (page_counter_read(&memcg->swap) * 2 >= memcg->swap.max)
60996099
return true;
61006100

61016101
return false;
@@ -6129,7 +6129,7 @@ static u64 swap_current_read(struct cgroup_subsys_state *css,
61296129
static int swap_max_show(struct seq_file *m, void *v)
61306130
{
61316131
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
6132-
unsigned long max = READ_ONCE(memcg->swap.limit);
6132+
unsigned long max = READ_ONCE(memcg->swap.max);
61336133

61346134
if (max == PAGE_COUNTER_MAX)
61356135
seq_puts(m, "max\n");
@@ -6151,9 +6151,9 @@ static ssize_t swap_max_write(struct kernfs_open_file *of,
61516151
if (err)
61526152
return err;
61536153

6154-
mutex_lock(&memcg_limit_mutex);
6155-
err = page_counter_limit(&memcg->swap, max);
6156-
mutex_unlock(&memcg_limit_mutex);
6154+
mutex_lock(&memcg_max_mutex);
6155+
err = page_counter_set_max(&memcg->swap, max);
6156+
mutex_unlock(&memcg_max_mutex);
61576157
if (err)
61586158
return err;
61596159

mm/oom_kill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc)
256256
int nid;
257257

258258
if (is_memcg_oom(oc)) {
259-
oc->totalpages = mem_cgroup_get_limit(oc->memcg) ?: 1;
259+
oc->totalpages = mem_cgroup_get_max(oc->memcg) ?: 1;
260260
return CONSTRAINT_MEMCG;
261261
}
262262

0 commit comments

Comments
 (0)