diff options
author | Johannes Weiner <hannes@cmpxchg.org> | 2015-11-05 21:50:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-11-05 22:34:48 -0500 |
commit | 6071ca5201066f4b2a61cfb693dd186d6bc6e9f3 (patch) | |
tree | 2ec2fa58fc43986025267568feb96c7b86a2722c | |
parent | f5fc3c5d817435970aa301d066820a9ac12c8120 (diff) |
mm: page_counter: let page_counter_try_charge() return bool
page_counter_try_charge() currently returns 0 on success and -ENOMEM on
failure, which is surprising behavior given the function name.
Make it follow the expected pattern of try_stuff() functions that return a
boolean true to indicate success, or false for failure.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Vladimir Davydov <vdavydov@virtuozzo.com
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/page_counter.h | 6 | ||||
-rw-r--r-- | mm/hugetlb_cgroup.c | 3 | ||||
-rw-r--r-- | mm/memcontrol.c | 11 | ||||
-rw-r--r-- | mm/page_counter.c | 14 |
4 files changed, 17 insertions, 17 deletions
diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h index 17fa4f8de3a6..7e62920a3a94 100644 --- a/include/linux/page_counter.h +++ b/include/linux/page_counter.h | |||
@@ -36,9 +36,9 @@ static inline unsigned long page_counter_read(struct page_counter *counter) | |||
36 | 36 | ||
37 | void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages); | 37 | void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages); |
38 | void page_counter_charge(struct page_counter *counter, unsigned long nr_pages); | 38 | void page_counter_charge(struct page_counter *counter, unsigned long nr_pages); |
39 | int page_counter_try_charge(struct page_counter *counter, | 39 | bool page_counter_try_charge(struct page_counter *counter, |
40 | unsigned long nr_pages, | 40 | unsigned long nr_pages, |
41 | struct page_counter **fail); | 41 | struct page_counter **fail); |
42 | void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages); | 42 | void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages); |
43 | int page_counter_limit(struct page_counter *counter, unsigned long limit); | 43 | int page_counter_limit(struct page_counter *counter, unsigned long limit); |
44 | int page_counter_memparse(const char *buf, const char *max, | 44 | int page_counter_memparse(const char *buf, const char *max, |
diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 6e0057439a46..33d59abe91f1 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c | |||
@@ -186,7 +186,8 @@ again: | |||
186 | } | 186 | } |
187 | rcu_read_unlock(); | 187 | rcu_read_unlock(); |
188 | 188 | ||
189 | ret = page_counter_try_charge(&h_cg->hugepage[idx], nr_pages, &counter); | 189 | if (!page_counter_try_charge(&h_cg->hugepage[idx], nr_pages, &counter)) |
190 | ret = -ENOMEM; | ||
190 | css_put(&h_cg->css); | 191 | css_put(&h_cg->css); |
191 | done: | 192 | done: |
192 | *ptr = h_cg; | 193 | *ptr = h_cg; |
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 59b100fde35f..d47de73d7c36 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -2016,8 +2016,8 @@ retry: | |||
2016 | return 0; | 2016 | return 0; |
2017 | 2017 | ||
2018 | if (!do_swap_account || | 2018 | if (!do_swap_account || |
2019 | !page_counter_try_charge(&memcg->memsw, batch, &counter)) { | 2019 | page_counter_try_charge(&memcg->memsw, batch, &counter)) { |
2020 | if (!page_counter_try_charge(&memcg->memory, batch, &counter)) | 2020 | if (page_counter_try_charge(&memcg->memory, batch, &counter)) |
2021 | goto done_restock; | 2021 | goto done_restock; |
2022 | if (do_swap_account) | 2022 | if (do_swap_account) |
2023 | page_counter_uncharge(&memcg->memsw, batch); | 2023 | page_counter_uncharge(&memcg->memsw, batch); |
@@ -2381,14 +2381,13 @@ int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, | |||
2381 | { | 2381 | { |
2382 | unsigned int nr_pages = 1 << order; | 2382 | unsigned int nr_pages = 1 << order; |
2383 | struct page_counter *counter; | 2383 | struct page_counter *counter; |
2384 | int ret = 0; | 2384 | int ret; |
2385 | 2385 | ||
2386 | if (!memcg_kmem_is_active(memcg)) | 2386 | if (!memcg_kmem_is_active(memcg)) |
2387 | return 0; | 2387 | return 0; |
2388 | 2388 | ||
2389 | ret = page_counter_try_charge(&memcg->kmem, nr_pages, &counter); | 2389 | if (!page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) |
2390 | if (ret) | 2390 | return -ENOMEM; |
2391 | return ret; | ||
2392 | 2391 | ||
2393 | ret = try_charge(memcg, gfp, nr_pages); | 2392 | ret = try_charge(memcg, gfp, nr_pages); |
2394 | if (ret) { | 2393 | if (ret) { |
diff --git a/mm/page_counter.c b/mm/page_counter.c index 11b4beda14ba..7c6a63d2c27f 100644 --- a/mm/page_counter.c +++ b/mm/page_counter.c | |||
@@ -56,12 +56,12 @@ void page_counter_charge(struct page_counter *counter, unsigned long nr_pages) | |||
56 | * @nr_pages: number of pages to charge | 56 | * @nr_pages: number of pages to charge |
57 | * @fail: points first counter to hit its limit, if any | 57 | * @fail: points first counter to hit its limit, if any |
58 | * | 58 | * |
59 | * Returns 0 on success, or -ENOMEM and @fail if the counter or one of | 59 | * Returns %true on success, or %false and @fail if the counter or one |
60 | * its ancestors has hit its configured limit. | 60 | * of its ancestors has hit its configured limit. |
61 | */ | 61 | */ |
62 | int page_counter_try_charge(struct page_counter *counter, | 62 | bool page_counter_try_charge(struct page_counter *counter, |
63 | unsigned long nr_pages, | 63 | unsigned long nr_pages, |
64 | struct page_counter **fail) | 64 | struct page_counter **fail) |
65 | { | 65 | { |
66 | struct page_counter *c; | 66 | struct page_counter *c; |
67 | 67 | ||
@@ -99,13 +99,13 @@ int page_counter_try_charge(struct page_counter *counter, | |||
99 | if (new > c->watermark) | 99 | if (new > c->watermark) |
100 | c->watermark = new; | 100 | c->watermark = new; |
101 | } | 101 | } |
102 | return 0; | 102 | return true; |
103 | 103 | ||
104 | failed: | 104 | failed: |
105 | for (c = counter; c != *fail; c = c->parent) | 105 | for (c = counter; c != *fail; c = c->parent) |
106 | page_counter_cancel(c, nr_pages); | 106 | page_counter_cancel(c, nr_pages); |
107 | 107 | ||
108 | return -ENOMEM; | 108 | return false; |
109 | } | 109 | } |
110 | 110 | ||
111 | /** | 111 | /** |