diff options
author | Johannes Weiner <hannes@cmpxchg.org> | 2016-01-20 18:02:24 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-20 20:09:18 -0500 |
commit | 567e9ab2e614e55feca20e8bcb54b629e9cc1a3b (patch) | |
tree | 4a76642946268e850fdab5b757f9e5bfa2ea07b6 /mm | |
parent | b15aac110a45c52d7f47ab8ee2d68f98044cfe6c (diff) |
mm: memcontrol: give the kmem states more descriptive names
On any given memcg, the kmem accounting feature has three separate
states: not initialized, structures allocated, and actively accounting
slab memory. These are represented through a combination of the
kmem_acct_activated and kmem_acct_active flags, which is confusing.
Convert to a kmem_state enum with the states NONE, ALLOCATED, and
ONLINE. Then rename the functions to modify the state accordingly.
This follows the nomenclature of css object states more closely.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: Vladimir Davydov <vdavydov@virtuozzo.com>
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 | 52 | ||||
-rw-r--r-- | mm/slab_common.c | 4 | ||||
-rw-r--r-- | mm/vmscan.c | 2 |
3 files changed, 28 insertions, 30 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 71dced17b16d..24b6bded13f8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -2378,7 +2378,7 @@ int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, | |||
2378 | struct page_counter *counter; | 2378 | struct page_counter *counter; |
2379 | int ret; | 2379 | int ret; |
2380 | 2380 | ||
2381 | if (!memcg_kmem_is_active(memcg)) | 2381 | if (!memcg_kmem_online(memcg)) |
2382 | return 0; | 2382 | return 0; |
2383 | 2383 | ||
2384 | if (!page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) | 2384 | if (!page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) |
@@ -2861,14 +2861,13 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css, | |||
2861 | } | 2861 | } |
2862 | 2862 | ||
2863 | #ifdef CONFIG_MEMCG_KMEM | 2863 | #ifdef CONFIG_MEMCG_KMEM |
2864 | static int memcg_activate_kmem(struct mem_cgroup *memcg) | 2864 | static int memcg_online_kmem(struct mem_cgroup *memcg) |
2865 | { | 2865 | { |
2866 | int err = 0; | 2866 | int err = 0; |
2867 | int memcg_id; | 2867 | int memcg_id; |
2868 | 2868 | ||
2869 | BUG_ON(memcg->kmemcg_id >= 0); | 2869 | BUG_ON(memcg->kmemcg_id >= 0); |
2870 | BUG_ON(memcg->kmem_acct_activated); | 2870 | BUG_ON(memcg->kmem_state); |
2871 | BUG_ON(memcg->kmem_acct_active); | ||
2872 | 2871 | ||
2873 | /* | 2872 | /* |
2874 | * For simplicity, we won't allow this to be disabled. It also can't | 2873 | * For simplicity, we won't allow this to be disabled. It also can't |
@@ -2898,14 +2897,13 @@ static int memcg_activate_kmem(struct mem_cgroup *memcg) | |||
2898 | 2897 | ||
2899 | static_branch_inc(&memcg_kmem_enabled_key); | 2898 | static_branch_inc(&memcg_kmem_enabled_key); |
2900 | /* | 2899 | /* |
2901 | * A memory cgroup is considered kmem-active as soon as it gets | 2900 | * A memory cgroup is considered kmem-online as soon as it gets |
2902 | * kmemcg_id. Setting the id after enabling static branching will | 2901 | * kmemcg_id. Setting the id after enabling static branching will |
2903 | * guarantee no one starts accounting before all call sites are | 2902 | * guarantee no one starts accounting before all call sites are |
2904 | * patched. | 2903 | * patched. |
2905 | */ | 2904 | */ |
2906 | memcg->kmemcg_id = memcg_id; | 2905 | memcg->kmemcg_id = memcg_id; |
2907 | memcg->kmem_acct_activated = true; | 2906 | memcg->kmem_state = KMEM_ONLINE; |
2908 | memcg->kmem_acct_active = true; | ||
2909 | out: | 2907 | out: |
2910 | return err; | 2908 | return err; |
2911 | } | 2909 | } |
@@ -2917,8 +2915,8 @@ static int memcg_update_kmem_limit(struct mem_cgroup *memcg, | |||
2917 | 2915 | ||
2918 | mutex_lock(&memcg_limit_mutex); | 2916 | mutex_lock(&memcg_limit_mutex); |
2919 | /* Top-level cgroup doesn't propagate from root */ | 2917 | /* Top-level cgroup doesn't propagate from root */ |
2920 | if (!memcg_kmem_is_active(memcg)) { | 2918 | if (!memcg_kmem_online(memcg)) { |
2921 | ret = memcg_activate_kmem(memcg); | 2919 | ret = memcg_online_kmem(memcg); |
2922 | if (ret) | 2920 | if (ret) |
2923 | goto out; | 2921 | goto out; |
2924 | } | 2922 | } |
@@ -2938,11 +2936,12 @@ static int memcg_propagate_kmem(struct mem_cgroup *memcg) | |||
2938 | 2936 | ||
2939 | mutex_lock(&memcg_limit_mutex); | 2937 | mutex_lock(&memcg_limit_mutex); |
2940 | /* | 2938 | /* |
2941 | * If the parent cgroup is not kmem-active now, it cannot be activated | 2939 | * If the parent cgroup is not kmem-online now, it cannot be |
2942 | * after this point, because it has at least one child already. | 2940 | * onlined after this point, because it has at least one child |
2941 | * already. | ||
2943 | */ | 2942 | */ |
2944 | if (memcg_kmem_is_active(parent)) | 2943 | if (memcg_kmem_online(parent)) |
2945 | ret = memcg_activate_kmem(memcg); | 2944 | ret = memcg_online_kmem(memcg); |
2946 | mutex_unlock(&memcg_limit_mutex); | 2945 | mutex_unlock(&memcg_limit_mutex); |
2947 | return ret; | 2946 | return ret; |
2948 | } | 2947 | } |
@@ -3590,22 +3589,21 @@ static int memcg_init_kmem(struct mem_cgroup *memcg) | |||
3590 | return tcp_init_cgroup(memcg); | 3589 | return tcp_init_cgroup(memcg); |
3591 | } | 3590 | } |
3592 | 3591 | ||
3593 | static void memcg_deactivate_kmem(struct mem_cgroup *memcg) | 3592 | static void memcg_offline_kmem(struct mem_cgroup *memcg) |
3594 | { | 3593 | { |
3595 | struct cgroup_subsys_state *css; | 3594 | struct cgroup_subsys_state *css; |
3596 | struct mem_cgroup *parent, *child; | 3595 | struct mem_cgroup *parent, *child; |
3597 | int kmemcg_id; | 3596 | int kmemcg_id; |
3598 | 3597 | ||
3599 | if (!memcg->kmem_acct_active) | 3598 | if (memcg->kmem_state != KMEM_ONLINE) |
3600 | return; | 3599 | return; |
3601 | |||
3602 | /* | 3600 | /* |
3603 | * Clear the 'active' flag before clearing memcg_caches arrays entries. | 3601 | * Clear the online state before clearing memcg_caches array |
3604 | * Since we take the slab_mutex in memcg_deactivate_kmem_caches(), it | 3602 | * entries. The slab_mutex in memcg_deactivate_kmem_caches() |
3605 | * guarantees no cache will be created for this cgroup after we are | 3603 | * guarantees that no cache will be created for this cgroup |
3606 | * done (see memcg_create_kmem_cache()). | 3604 | * after we are done (see memcg_create_kmem_cache()). |
3607 | */ | 3605 | */ |
3608 | memcg->kmem_acct_active = false; | 3606 | memcg->kmem_state = KMEM_ALLOCATED; |
3609 | 3607 | ||
3610 | memcg_deactivate_kmem_caches(memcg); | 3608 | memcg_deactivate_kmem_caches(memcg); |
3611 | 3609 | ||
@@ -3636,9 +3634,9 @@ static void memcg_deactivate_kmem(struct mem_cgroup *memcg) | |||
3636 | memcg_free_cache_id(kmemcg_id); | 3634 | memcg_free_cache_id(kmemcg_id); |
3637 | } | 3635 | } |
3638 | 3636 | ||
3639 | static void memcg_destroy_kmem(struct mem_cgroup *memcg) | 3637 | static void memcg_free_kmem(struct mem_cgroup *memcg) |
3640 | { | 3638 | { |
3641 | if (memcg->kmem_acct_activated) { | 3639 | if (memcg->kmem_state == KMEM_ALLOCATED) { |
3642 | memcg_destroy_kmem_caches(memcg); | 3640 | memcg_destroy_kmem_caches(memcg); |
3643 | static_branch_dec(&memcg_kmem_enabled_key); | 3641 | static_branch_dec(&memcg_kmem_enabled_key); |
3644 | WARN_ON(page_counter_read(&memcg->kmem)); | 3642 | WARN_ON(page_counter_read(&memcg->kmem)); |
@@ -3651,11 +3649,11 @@ static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss) | |||
3651 | return 0; | 3649 | return 0; |
3652 | } | 3650 | } |
3653 | 3651 | ||
3654 | static void memcg_deactivate_kmem(struct mem_cgroup *memcg) | 3652 | static void memcg_offline_kmem(struct mem_cgroup *memcg) |
3655 | { | 3653 | { |
3656 | } | 3654 | } |
3657 | 3655 | ||
3658 | static void memcg_destroy_kmem(struct mem_cgroup *memcg) | 3656 | static void memcg_free_kmem(struct mem_cgroup *memcg) |
3659 | { | 3657 | { |
3660 | } | 3658 | } |
3661 | #endif | 3659 | #endif |
@@ -4308,7 +4306,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) | |||
4308 | 4306 | ||
4309 | vmpressure_cleanup(&memcg->vmpressure); | 4307 | vmpressure_cleanup(&memcg->vmpressure); |
4310 | 4308 | ||
4311 | memcg_deactivate_kmem(memcg); | 4309 | memcg_offline_kmem(memcg); |
4312 | 4310 | ||
4313 | wb_memcg_offline(memcg); | 4311 | wb_memcg_offline(memcg); |
4314 | } | 4312 | } |
@@ -4324,7 +4322,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css) | |||
4324 | { | 4322 | { |
4325 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | 4323 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); |
4326 | 4324 | ||
4327 | memcg_destroy_kmem(memcg); | 4325 | memcg_free_kmem(memcg); |
4328 | #ifdef CONFIG_INET | 4326 | #ifdef CONFIG_INET |
4329 | if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket) | 4327 | if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket) |
4330 | static_branch_dec(&memcg_sockets_enabled_key); | 4328 | static_branch_dec(&memcg_sockets_enabled_key); |
diff --git a/mm/slab_common.c b/mm/slab_common.c index e016178063e1..8c262e6dc33e 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c | |||
@@ -503,10 +503,10 @@ void memcg_create_kmem_cache(struct mem_cgroup *memcg, | |||
503 | mutex_lock(&slab_mutex); | 503 | mutex_lock(&slab_mutex); |
504 | 504 | ||
505 | /* | 505 | /* |
506 | * The memory cgroup could have been deactivated while the cache | 506 | * The memory cgroup could have been offlined while the cache |
507 | * creation work was pending. | 507 | * creation work was pending. |
508 | */ | 508 | */ |
509 | if (!memcg_kmem_is_active(memcg)) | 509 | if (!memcg_kmem_online(memcg)) |
510 | goto out_unlock; | 510 | goto out_unlock; |
511 | 511 | ||
512 | idx = memcg_cache_id(memcg); | 512 | idx = memcg_cache_id(memcg); |
diff --git a/mm/vmscan.c b/mm/vmscan.c index 5ac86956ff9d..05dd182f04fd 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c | |||
@@ -411,7 +411,7 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, | |||
411 | struct shrinker *shrinker; | 411 | struct shrinker *shrinker; |
412 | unsigned long freed = 0; | 412 | unsigned long freed = 0; |
413 | 413 | ||
414 | if (memcg && !memcg_kmem_is_active(memcg)) | 414 | if (memcg && !memcg_kmem_online(memcg)) |
415 | return 0; | 415 | return 0; |
416 | 416 | ||
417 | if (nr_scanned == 0) | 417 | if (nr_scanned == 0) |