From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, kamezawa.hiroyu@jp.fujitsu.com,
mhocko@suse.cz, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hugetlb/cgroup: Simplify pre_destroy callback
Date: Thu, 19 Jul 2012 08:25:06 +0530 [thread overview]
Message-ID: <87hat4794l.fsf@skywalker.in.ibm.com> (raw)
In-Reply-To: <20120718142628.76bf78b3.akpm@linux-foundation.org>
Andrew Morton <akpm@linux-foundation.org> writes:
> On Wed, 18 Jul 2012 11:04:09 +0530
> "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
>
>> From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
>>
>> Since we cannot fail in hugetlb_cgroup_move_parent, we don't really
>> need to check whether cgroup have any change left after that. Also skip
>> those hstates for which we don't have any charge in this cgroup.
>>
>> ...
>>
>> + for_each_hstate(h) {
>> + /*
>> + * if we don't have any charge, skip this hstate
>> + */
>> + idx = hstate_index(h);
>> + if (res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE) == 0)
>> + continue;
>> + spin_lock(&hugetlb_lock);
>> + list_for_each_entry(page, &h->hugepage_activelist, lru)
>> + hugetlb_cgroup_move_parent(idx, cgroup, page);
>> + spin_unlock(&hugetlb_lock);
>> + VM_BUG_ON(res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE));
>> + }
>> out:
>> return ret;
>> }
>
> This looks fishy.
>
> We test RES_USAGE before taking hugetlb_lock. What prevents some other
> thread from increasing RES_USAGE after that test?
>
> After walking the list we test RES_USAGE after dropping hugetlb_lock.
> What prevents another thread from incrementing RES_USAGE before that
> test, triggering the BUG?
IIUC core cgroup will prevent a new task getting added to the cgroup
when we are in pre_destroy. Since we already check that the cgroup doesn't
have any task, the RES_USAGE cannot increase in pre_destroy.
-aneesh
--
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: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, kamezawa.hiroyu@jp.fujitsu.com,
mhocko@suse.cz, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hugetlb/cgroup: Simplify pre_destroy callback
Date: Thu, 19 Jul 2012 08:25:06 +0530 [thread overview]
Message-ID: <87hat4794l.fsf@skywalker.in.ibm.com> (raw)
In-Reply-To: <20120718142628.76bf78b3.akpm@linux-foundation.org>
Andrew Morton <akpm@linux-foundation.org> writes:
> On Wed, 18 Jul 2012 11:04:09 +0530
> "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
>
>> From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
>>
>> Since we cannot fail in hugetlb_cgroup_move_parent, we don't really
>> need to check whether cgroup have any change left after that. Also skip
>> those hstates for which we don't have any charge in this cgroup.
>>
>> ...
>>
>> + for_each_hstate(h) {
>> + /*
>> + * if we don't have any charge, skip this hstate
>> + */
>> + idx = hstate_index(h);
>> + if (res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE) == 0)
>> + continue;
>> + spin_lock(&hugetlb_lock);
>> + list_for_each_entry(page, &h->hugepage_activelist, lru)
>> + hugetlb_cgroup_move_parent(idx, cgroup, page);
>> + spin_unlock(&hugetlb_lock);
>> + VM_BUG_ON(res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE));
>> + }
>> out:
>> return ret;
>> }
>
> This looks fishy.
>
> We test RES_USAGE before taking hugetlb_lock. What prevents some other
> thread from increasing RES_USAGE after that test?
>
> After walking the list we test RES_USAGE after dropping hugetlb_lock.
> What prevents another thread from incrementing RES_USAGE before that
> test, triggering the BUG?
IIUC core cgroup will prevent a new task getting added to the cgroup
when we are in pre_destroy. Since we already check that the cgroup doesn't
have any task, the RES_USAGE cannot increase in pre_destroy.
-aneesh
next prev parent reply other threads:[~2012-07-19 2:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 5:34 [PATCH] hugetlb/cgroup: Simplify pre_destroy callback Aneesh Kumar K.V
2012-07-18 5:34 ` Aneesh Kumar K.V
2012-07-18 7:24 ` Wanpeng Li
2012-07-18 7:24 ` Wanpeng Li
2012-07-18 21:26 ` Andrew Morton
2012-07-18 21:26 ` Andrew Morton
2012-07-19 2:55 ` Aneesh Kumar K.V [this message]
2012-07-19 2:55 ` Aneesh Kumar K.V
2012-07-19 6:59 ` Li Zefan
2012-07-19 6:59 ` Li Zefan
2012-07-19 9:41 ` Aneesh Kumar K.V
2012-07-19 9:41 ` Aneesh Kumar K.V
2012-07-19 10:25 ` Kamezawa Hiroyuki
2012-07-19 10:25 ` Kamezawa Hiroyuki
2012-07-19 11:26 ` Aneesh Kumar K.V
2012-07-19 11:26 ` Aneesh Kumar K.V
2012-07-19 11:42 ` Michal Hocko
2012-07-19 11:42 ` Michal Hocko
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=87hat4794l.fsf@skywalker.in.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
/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.