* [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem()
@ 2013-11-27 15:46 Vladimir Davydov
2013-11-27 15:46 ` [PATCH] memcg: make memcg_update_cache_sizes() static Vladimir Davydov
2013-11-29 9:45 ` [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Michal Hocko
0 siblings, 2 replies; 5+ messages in thread
From: Vladimir Davydov @ 2013-11-27 15:46 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, cgroups, devel, Johannes Weiner, Michal Hocko,
Balbir Singh, KAMEZAWA Hiroyuki
We should start kmem accounting for a memory cgroup only after both its
kmem limit is set (KMEM_ACCOUNTED_ACTIVE) and related call sites are
patched (KMEM_ACCOUNTED_ACTIVATED). Currently memcg_can_account_kmem()
allows kmem accounting even if only one of the conditions is true.
Fix it.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
mm/memcontrol.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f1a0ae6..40efb9d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2956,7 +2956,8 @@ static DEFINE_MUTEX(set_limit_mutex);
static inline bool memcg_can_account_kmem(struct mem_cgroup *memcg)
{
return !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg) &&
- (memcg->kmem_account_flags & KMEM_ACCOUNTED_MASK);
+ (memcg->kmem_account_flags & KMEM_ACCOUNTED_MASK) ==
+ KMEM_ACCOUNTED_MASK;
}
/*
--
1.7.10.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] memcg: make memcg_update_cache_sizes() static
2013-11-27 15:46 [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Vladimir Davydov
@ 2013-11-27 15:46 ` Vladimir Davydov
2013-11-29 9:45 ` Michal Hocko
2013-11-29 9:45 ` [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Michal Hocko
1 sibling, 1 reply; 5+ messages in thread
From: Vladimir Davydov @ 2013-11-27 15:46 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, cgroups, devel, Johannes Weiner, Michal Hocko,
Balbir Singh, KAMEZAWA Hiroyuki
This function is not used outside of memcontrol.c so make it static.
Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
mm/memcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 40efb9d..b20b915 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3084,7 +3084,7 @@ int memcg_cache_id(struct mem_cgroup *memcg)
* But when we create a new cache, we can call this as well if its parent
* is kmem-limited. That will have to hold set_limit_mutex as well.
*/
-int memcg_update_cache_sizes(struct mem_cgroup *memcg)
+static int memcg_update_cache_sizes(struct mem_cgroup *memcg)
{
int num, ret;
--
1.7.10.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem()
2013-11-27 15:46 [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Vladimir Davydov
2013-11-27 15:46 ` [PATCH] memcg: make memcg_update_cache_sizes() static Vladimir Davydov
@ 2013-11-29 9:45 ` Michal Hocko
2013-11-29 10:09 ` Vladimir Davydov
1 sibling, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2013-11-29 9:45 UTC (permalink / raw)
To: Vladimir Davydov
Cc: linux-kernel, linux-mm, cgroups, devel, Johannes Weiner,
Balbir Singh, KAMEZAWA Hiroyuki
On Wed 27-11-13 19:46:01, Vladimir Davydov wrote:
> We should start kmem accounting for a memory cgroup only after both its
> kmem limit is set (KMEM_ACCOUNTED_ACTIVE) and related call sites are
> patched (KMEM_ACCOUNTED_ACTIVATED).
This should be vice-versa, no? ACTIVE is set after
static_key_slow_inc(&memcg_kmem_enabled_key) AFAICS.
> Currently memcg_can_account_kmem() allows kmem accounting even if only
> one of the conditions is true.
> Fix it.
It would be nice to describe, what is the actual problem here. I assume
this is a charge vs. enable race. Let me try
So we have KMEM_ACCOUNTED_ACTIVATED (set by memcg_update_cache_sizes)
but the static key is not enabled yet (so KMEM_ACCOUNTED_ACTIVE is not
set yet). memcg_can_account_kmem is called from 2 contexts during charge
- memcg_kmem_get_cache via __memcg_kmem_get_cache
- memcg_kmem_newpage_charge via __memcg_kmem_newpage_charge
both of them start by checking memcg_kmem_enabled which is our
static key before memcg_can_account_kmem. This would suggest that
static_key+ACTIVE check memcg_can_account_kmem is sufficient. No?
That being said the proposed change is not incorrect it just doesn't
seem to _fix_ anything. I would much rather see a comprehensive
documentation of the whole enabling workflow. E.g. why do we need
ACTIVATED at all? Nobody seem to care in the code...
> Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.cz>
> Cc: Balbir Singh <bsingharora@gmail.com>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
> mm/memcontrol.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index f1a0ae6..40efb9d 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2956,7 +2956,8 @@ static DEFINE_MUTEX(set_limit_mutex);
> static inline bool memcg_can_account_kmem(struct mem_cgroup *memcg)
> {
> return !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg) &&
> - (memcg->kmem_account_flags & KMEM_ACCOUNTED_MASK);
> + (memcg->kmem_account_flags & KMEM_ACCOUNTED_MASK) ==
> + KMEM_ACCOUNTED_MASK;
> }
>
> /*
> --
> 1.7.10.4
>
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] memcg: make memcg_update_cache_sizes() static
2013-11-27 15:46 ` [PATCH] memcg: make memcg_update_cache_sizes() static Vladimir Davydov
@ 2013-11-29 9:45 ` Michal Hocko
0 siblings, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2013-11-29 9:45 UTC (permalink / raw)
To: Vladimir Davydov
Cc: linux-kernel, linux-mm, cgroups, devel, Johannes Weiner,
Balbir Singh, KAMEZAWA Hiroyuki
On Wed 27-11-13 19:46:02, Vladimir Davydov wrote:
> This function is not used outside of memcontrol.c so make it static.
>
> Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.cz>
> Cc: Balbir Singh <bsingharora@gmail.com>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 40efb9d..b20b915 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3084,7 +3084,7 @@ int memcg_cache_id(struct mem_cgroup *memcg)
> * But when we create a new cache, we can call this as well if its parent
> * is kmem-limited. That will have to hold set_limit_mutex as well.
> */
> -int memcg_update_cache_sizes(struct mem_cgroup *memcg)
> +static int memcg_update_cache_sizes(struct mem_cgroup *memcg)
> {
> int num, ret;
>
> --
> 1.7.10.4
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem()
2013-11-29 9:45 ` [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Michal Hocko
@ 2013-11-29 10:09 ` Vladimir Davydov
0 siblings, 0 replies; 5+ messages in thread
From: Vladimir Davydov @ 2013-11-29 10:09 UTC (permalink / raw)
To: Michal Hocko
Cc: linux-kernel, linux-mm, cgroups, devel, Johannes Weiner,
Balbir Singh, KAMEZAWA Hiroyuki
On 11/29/2013 01:45 PM, Michal Hocko wrote:
> On Wed 27-11-13 19:46:01, Vladimir Davydov wrote:
>> We should start kmem accounting for a memory cgroup only after both its
>> kmem limit is set (KMEM_ACCOUNTED_ACTIVE) and related call sites are
>> patched (KMEM_ACCOUNTED_ACTIVATED).
> This should be vice-versa, no? ACTIVE is set after
> static_key_slow_inc(&memcg_kmem_enabled_key) AFAICS.
>
>> Currently memcg_can_account_kmem() allows kmem accounting even if only
>> one of the conditions is true.
>> Fix it.
> It would be nice to describe, what is the actual problem here. I assume
> this is a charge vs. enable race. Let me try
>
> So we have KMEM_ACCOUNTED_ACTIVATED (set by memcg_update_cache_sizes)
> but the static key is not enabled yet (so KMEM_ACCOUNTED_ACTIVE is not
> set yet). memcg_can_account_kmem is called from 2 contexts during charge
> - memcg_kmem_get_cache via __memcg_kmem_get_cache
> - memcg_kmem_newpage_charge via __memcg_kmem_newpage_charge
>
> both of them start by checking memcg_kmem_enabled which is our
> static key before memcg_can_account_kmem. This would suggest that
> static_key+ACTIVE check memcg_can_account_kmem is sufficient. No?
Yes, I guess you're perfectly right and we don't need the ACTIVATED bit
at all. I'll look at this deeper and send a patch removing it if it
doesn't break something.
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-11-29 10:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-27 15:46 [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Vladimir Davydov
2013-11-27 15:46 ` [PATCH] memcg: make memcg_update_cache_sizes() static Vladimir Davydov
2013-11-29 9:45 ` Michal Hocko
2013-11-29 9:45 ` [PATCH] memcg: fix kmem_account_flags check in memcg_can_account_kmem() Michal Hocko
2013-11-29 10:09 ` Vladimir Davydov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox