diff options
author | Vladimir Davydov <vdavydov@parallels.com> | 2015-04-15 19:13:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-15 19:35:16 -0400 |
commit | adbe427b92d18cf3f801e82e9cd664fbe31cea3c (patch) | |
tree | e1fe1512cd36f2b7a5a978f473be7dc9d05021fa /mm | |
parent | d7e4a2ea51c1b0ac0b2d53f5ab4a2e878b1c4aec (diff) |
memcg: zap mem_cgroup_lookup()
mem_cgroup_lookup() is a wrapper around mem_cgroup_from_id(), which
checks that id != 0 before issuing the function call. Today, there is
no point in this additional check apart from optimization, because there
is no css with id <= 0, so that css_from_id, called by
mem_cgroup_from_id, will return NULL for any id <= 0.
Since mem_cgroup_from_id is only called from mem_cgroup_lookup, let us
zap mem_cgroup_lookup, substituting calls to it with mem_cgroup_from_id
and moving the check if id > 0 to css_from_id.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memcontrol.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c3f09b2dda5f..0a06628470cc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -460,6 +460,12 @@ static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) | |||
460 | return memcg->css.id; | 460 | return memcg->css.id; |
461 | } | 461 | } |
462 | 462 | ||
463 | /* | ||
464 | * A helper function to get mem_cgroup from ID. must be called under | ||
465 | * rcu_read_lock(). The caller is responsible for calling | ||
466 | * css_tryget_online() if the mem_cgroup is used for charging. (dropping | ||
467 | * refcnt from swap can be called against removed memcg.) | ||
468 | */ | ||
463 | static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) | 469 | static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) |
464 | { | 470 | { |
465 | struct cgroup_subsys_state *css; | 471 | struct cgroup_subsys_state *css; |
@@ -2349,20 +2355,6 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) | |||
2349 | } | 2355 | } |
2350 | 2356 | ||
2351 | /* | 2357 | /* |
2352 | * A helper function to get mem_cgroup from ID. must be called under | ||
2353 | * rcu_read_lock(). The caller is responsible for calling | ||
2354 | * css_tryget_online() if the mem_cgroup is used for charging. (dropping | ||
2355 | * refcnt from swap can be called against removed memcg.) | ||
2356 | */ | ||
2357 | static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) | ||
2358 | { | ||
2359 | /* ID 0 is unused ID */ | ||
2360 | if (!id) | ||
2361 | return NULL; | ||
2362 | return mem_cgroup_from_id(id); | ||
2363 | } | ||
2364 | |||
2365 | /* | ||
2366 | * try_get_mem_cgroup_from_page - look up page's memcg association | 2358 | * try_get_mem_cgroup_from_page - look up page's memcg association |
2367 | * @page: the page | 2359 | * @page: the page |
2368 | * | 2360 | * |
@@ -2388,7 +2380,7 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) | |||
2388 | ent.val = page_private(page); | 2380 | ent.val = page_private(page); |
2389 | id = lookup_swap_cgroup_id(ent); | 2381 | id = lookup_swap_cgroup_id(ent); |
2390 | rcu_read_lock(); | 2382 | rcu_read_lock(); |
2391 | memcg = mem_cgroup_lookup(id); | 2383 | memcg = mem_cgroup_from_id(id); |
2392 | if (memcg && !css_tryget_online(&memcg->css)) | 2384 | if (memcg && !css_tryget_online(&memcg->css)) |
2393 | memcg = NULL; | 2385 | memcg = NULL; |
2394 | rcu_read_unlock(); | 2386 | rcu_read_unlock(); |
@@ -5869,7 +5861,7 @@ void mem_cgroup_uncharge_swap(swp_entry_t entry) | |||
5869 | 5861 | ||
5870 | id = swap_cgroup_record(entry, 0); | 5862 | id = swap_cgroup_record(entry, 0); |
5871 | rcu_read_lock(); | 5863 | rcu_read_lock(); |
5872 | memcg = mem_cgroup_lookup(id); | 5864 | memcg = mem_cgroup_from_id(id); |
5873 | if (memcg) { | 5865 | if (memcg) { |
5874 | if (!mem_cgroup_is_root(memcg)) | 5866 | if (!mem_cgroup_is_root(memcg)) |
5875 | page_counter_uncharge(&memcg->memsw, 1); | 5867 | page_counter_uncharge(&memcg->memsw, 1); |