From: Johannes Weiner <hannes@cmpxchg.org>
To: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] mm: memcontrol: add sanity checks for memcg->id.ref on get/put
Date: Tue, 2 Aug 2016 13:27:36 -0400 [thread overview]
Message-ID: <20160802172736.GC6637@cmpxchg.org> (raw)
In-Reply-To: <32402ace75b459c8523f5b237a62061e1df7a3b5.1470149524.git.vdavydov@virtuozzo.com>
On Tue, Aug 02, 2016 at 06:00:50PM +0300, Vladimir Davydov wrote:
> Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> ---
> mm/memcontrol.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 67109d556a4a..32b2f33865f9 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4033,6 +4033,7 @@ static DEFINE_IDR(mem_cgroup_idr);
>
> static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
> {
> + VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0);
> atomic_add(n, &memcg->id.ref);
> }
>
> @@ -4056,6 +4057,7 @@ static struct mem_cgroup *mem_cgroup_id_get_active(struct mem_cgroup *memcg)
>
> static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n)
> {
> + VM_BUG_ON(atomic_read(&memcg->id.ref) < n);
> if (atomic_sub_and_test(n, &memcg->id.ref)) {
> idr_remove(&mem_cgroup_idr, memcg->id.id);
> memcg->id.id = 0;
> @@ -4176,6 +4178,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
> INIT_LIST_HEAD(&memcg->cgwb_list);
> #endif
> idr_replace(&mem_cgroup_idr, memcg, memcg->id.id);
> + atomic_set(&memcg->id.ref, 1);
> return memcg;
> fail:
> if (memcg->id.id > 0)
> @@ -4245,7 +4248,6 @@ fail:
> static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
> {
> /* Online state pins memcg ID, memcg ID pins CSS */
> - mem_cgroup_id_get(mem_cgroup_from_css(css));
> css_get(css);
> return 0;
This comment and code is no very, very confusing. Can you move the
atomic_set(&memcg->id.ref, 1) down here instead?
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: Johannes Weiner <hannes@cmpxchg.org>
To: Vladimir Davydov <vdavydov@virtuozzo.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] mm: memcontrol: add sanity checks for memcg->id.ref on get/put
Date: Tue, 2 Aug 2016 13:27:36 -0400 [thread overview]
Message-ID: <20160802172736.GC6637@cmpxchg.org> (raw)
In-Reply-To: <32402ace75b459c8523f5b237a62061e1df7a3b5.1470149524.git.vdavydov@virtuozzo.com>
On Tue, Aug 02, 2016 at 06:00:50PM +0300, Vladimir Davydov wrote:
> Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
> ---
> mm/memcontrol.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 67109d556a4a..32b2f33865f9 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4033,6 +4033,7 @@ static DEFINE_IDR(mem_cgroup_idr);
>
> static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n)
> {
> + VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0);
> atomic_add(n, &memcg->id.ref);
> }
>
> @@ -4056,6 +4057,7 @@ static struct mem_cgroup *mem_cgroup_id_get_active(struct mem_cgroup *memcg)
>
> static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n)
> {
> + VM_BUG_ON(atomic_read(&memcg->id.ref) < n);
> if (atomic_sub_and_test(n, &memcg->id.ref)) {
> idr_remove(&mem_cgroup_idr, memcg->id.id);
> memcg->id.id = 0;
> @@ -4176,6 +4178,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
> INIT_LIST_HEAD(&memcg->cgwb_list);
> #endif
> idr_replace(&mem_cgroup_idr, memcg, memcg->id.id);
> + atomic_set(&memcg->id.ref, 1);
> return memcg;
> fail:
> if (memcg->id.id > 0)
> @@ -4245,7 +4248,6 @@ fail:
> static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
> {
> /* Online state pins memcg ID, memcg ID pins CSS */
> - mem_cgroup_id_get(mem_cgroup_from_css(css));
> css_get(css);
> return 0;
This comment and code is no very, very confusing. Can you move the
atomic_set(&memcg->id.ref, 1) down here instead?
next prev parent reply other threads:[~2016-08-02 17:30 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-02 15:00 [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Vladimir Davydov
2016-08-02 15:00 ` Vladimir Davydov
2016-08-02 15:00 ` Vladimir Davydov
2016-08-02 15:00 ` [PATCH v2 2/3] mm: memcontrol: fix memcg id ref counter on swap charge move Vladimir Davydov
2016-08-02 15:00 ` Vladimir Davydov
2016-08-02 15:00 ` Vladimir Davydov
2016-08-02 17:22 ` Johannes Weiner
2016-08-02 17:22 ` Johannes Weiner
2016-08-02 15:00 ` [PATCH v2 3/3] mm: memcontrol: add sanity checks for memcg->id.ref on get/put Vladimir Davydov
2016-08-02 15:00 ` Vladimir Davydov
2016-08-02 16:01 ` Michal Hocko
2016-08-02 16:01 ` Michal Hocko
2016-08-02 17:27 ` Johannes Weiner [this message]
2016-08-02 17:27 ` Johannes Weiner
2016-08-02 16:00 ` [PATCH v2 1/3] mm: memcontrol: fix swap counter leak on swapout from offline cgroup Michal Hocko
2016-08-02 16:00 ` Michal Hocko
2016-08-02 17:33 ` Johannes Weiner
2016-08-02 17:33 ` Johannes Weiner
2016-08-02 20:31 ` Michal Hocko
2016-08-02 20:31 ` Michal Hocko
2016-08-03 10:06 ` Vladimir Davydov
2016-08-03 10:06 ` Vladimir Davydov
2016-08-03 10:06 ` Vladimir Davydov
2016-08-03 9:50 ` Vladimir Davydov
2016-08-03 9:50 ` Vladimir Davydov
2016-08-03 9:50 ` Vladimir Davydov
2016-08-03 11:09 ` Michal Hocko
2016-08-03 11:09 ` Michal Hocko
2016-08-03 11:46 ` Vladimir Davydov
2016-08-03 11:46 ` Vladimir Davydov
2016-08-03 11:46 ` Vladimir Davydov
2016-08-03 12:00 ` Michal Hocko
2016-08-03 12:00 ` Michal Hocko
2016-08-03 14:12 ` Johannes Weiner
2016-08-03 14:12 ` Johannes Weiner
2016-08-03 14:31 ` Vladimir Davydov
2016-08-03 14:31 ` Vladimir Davydov
2016-08-03 14:31 ` Vladimir Davydov
2016-08-02 17:21 ` Johannes Weiner
2016-08-02 17:21 ` Johannes Weiner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160802172736.GC6637@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=vdavydov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.