From: "Aneesh Kumar K.V" <aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Konrad Rzeszutek Wilk <konrad-Gq0aWv8utHQdnm+yROfE0A@public.gmane.org>
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org,
dhillf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
mhocko-AlSwsSmVLrQ@public.gmane.org,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH -V7 10/14] hugetlbfs: Add new HugeTLB cgroup
Date: Thu, 31 May 2012 11:13:16 +0530 [thread overview]
Message-ID: <20120531054316.GD24855@skywalker.linux.vnet.ibm.com> (raw)
In-Reply-To: <20120531011953.GE401-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
On Wed, May 30, 2012 at 09:19:54PM -0400, Konrad Rzeszutek Wilk wrote:
> > +static inline bool hugetlb_cgroup_have_usage(struct cgroup *cg)
> > +{
> > + int idx;
> > + struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cg);
> > +
> > + for (idx = 0; idx < HUGE_MAX_HSTATE; idx++) {
> > + if ((res_counter_read_u64(&h_cg->hugepage[idx], RES_USAGE)) > 0)
> > + return 1;
>
> return true;
> > + }
> > + return 0;
>
> And return false here
> > +}
> > +
> > +static struct cgroup_subsys_state *hugetlb_cgroup_create(struct cgroup *cgroup)
> > +{
> > + int idx;
> > + struct cgroup *parent_cgroup;
> > + struct hugetlb_cgroup *h_cgroup, *parent_h_cgroup;
> > +
> > + h_cgroup = kzalloc(sizeof(*h_cgroup), GFP_KERNEL);
> > + if (!h_cgroup)
> > + return ERR_PTR(-ENOMEM);
> > +
>
> No need to check cgroup for NULL?
Other cgroups (memcg) doesn't do that. Can we really get NULL cgroup tere ?
>
> > + parent_cgroup = cgroup->parent;
> > + if (parent_cgroup) {
> > + parent_h_cgroup = hugetlb_cgroup_from_cgroup(parent_cgroup);
> > + for (idx = 0; idx < HUGE_MAX_HSTATE; idx++)
> > + res_counter_init(&h_cgroup->hugepage[idx],
> > + &parent_h_cgroup->hugepage[idx]);
> > + } else {
> > + root_h_cgroup = h_cgroup;
> > + for (idx = 0; idx < HUGE_MAX_HSTATE; idx++)
> > + res_counter_init(&h_cgroup->hugepage[idx], NULL);
> > + }
> > + return &h_cgroup->css;
> > +}
> > +
> > +static int hugetlb_cgroup_move_parent(int idx, struct cgroup *cgroup,
> > + struct page *page)
> > +{
> > + int csize, ret = 0;
> > + struct page_cgroup *pc;
> > + struct res_counter *counter;
> > + struct res_counter *fail_res;
> > + struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cgroup);
> > + struct hugetlb_cgroup *parent = parent_hugetlb_cgroup(cgroup);
> > +
> > + if (!get_page_unless_zero(page))
> > + goto out;
>
> Hmm, so it goes to out, and does return ret. ret is zero. Is
> that correct? Should ret be set to -EBUSY or such?
>
Fixed
> > +
> > + pc = lookup_page_cgroup(page);
>
> What if pc is NULL? Or is it guaranteed that it will
> never happen so?
>
> > + lock_page_cgroup(pc);
> > + if (!PageCgroupUsed(pc) || pc->cgroup != cgroup)
> > + goto err_out;
>
> err is still set to zero. Is that OK? Should it be -EINVAL
> or such?
>
Fixed
> > +
> > + csize = PAGE_SIZE << compound_order(page);
> > + /* If use_hierarchy == 0, we need to charge root */
> > + if (!parent) {
> > + parent = root_h_cgroup;
> > + /* root has no limit */
> > + res_counter_charge_nofail(&parent->hugepage[idx],
> > + csize, &fail_res);
> > + }
> > + counter = &h_cg->hugepage[idx];
> > + res_counter_uncharge_until(counter, counter->parent, csize);
> > +
> > + pc->cgroup = cgroup->parent;
> > +err_out:
> > + unlock_page_cgroup(pc);
> > + put_page(page);
> > +out:
> > + return ret;
> > +}
> > +
> > +/*
> > + * Force the hugetlb cgroup to empty the hugetlb resources by moving them to
> > + * the parent cgroup.
> > + */
> > +static int hugetlb_cgroup_pre_destroy(struct cgroup *cgroup)
> > +{
> > + struct hstate *h;
> > + struct page *page;
> > + int ret = 0, idx = 0;
> > +
> > + do {
> > + if (cgroup_task_count(cgroup) ||
> > + !list_empty(&cgroup->children)) {
> > + ret = -EBUSY;
> > + goto out;
> > + }
> > + /*
> > + * If the task doing the cgroup_rmdir got a signal
> > + * we don't really need to loop till the hugetlb resource
> > + * usage become zero.
>
> Why don't we need to loop? Is somebody else (and if so can you
> say who) doing the deletion?
>
No we just come out without doing the deletion and handle the signal.
> > + */
> > + if (signal_pending(current)) {
> > + ret = -EINTR;
> > + goto out;
> > + }
> > + for_each_hstate(h) {
> > + spin_lock(&hugetlb_lock);
> > + list_for_each_entry(page, &h->hugepage_activelist, lru) {
> > + ret = hugetlb_cgroup_move_parent(idx, cgroup, page);
> > + if (ret) {
> > + spin_unlock(&hugetlb_lock);
> > + goto out;
> > + }
> > + }
> > + spin_unlock(&hugetlb_lock);
> > + idx++;
> > + }
> > + cond_resched();
> > + } while (hugetlb_cgroup_have_usage(cgroup));
> > +out:
> > + return ret;
> > +}
> > +
> > +static void hugetlb_cgroup_destroy(struct cgroup *cgroup)
> > +{
> > + struct hugetlb_cgroup *h_cgroup;
> > +
> > + h_cgroup = hugetlb_cgroup_from_cgroup(cgroup);
> > + kfree(h_cgroup);
> > +}
> > +
> > +int hugetlb_cgroup_charge_page(int idx, unsigned long nr_pages,
> > + struct hugetlb_cgroup **ptr)
> > +{
> > + int ret = 0;
> > + struct res_counter *fail_res;
> > + struct hugetlb_cgroup *h_cg = NULL;
> > + unsigned long csize = nr_pages * PAGE_SIZE;
> > +
> > + if (hugetlb_cgroup_disabled())
> > + goto done;
> > +again:
> > + rcu_read_lock();
> > + h_cg = hugetlb_cgroup_from_task(current);
> > + if (!h_cg)
> > + h_cg = root_h_cgroup;
> > +
> > + if (!css_tryget(&h_cg->css)) {
> > + rcu_read_unlock();
> > + goto again;
>
> You don't want some form of limit on how many times you can
> loop around?
>
you mean fail the allocation after some tries. I am not sure memcg doesn't do that.
> > + }
> > + rcu_read_unlock();
> > +
> > + ret = res_counter_charge(&h_cg->hugepage[idx], csize, &fail_res);
> > + css_put(&h_cg->css);
> > +done:
> > + *ptr = h_cg;
> > + return ret;
> > +}
> > +
>
-aneesh
next prev parent reply other threads:[~2012-05-31 5:43 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-30 14:38 [PATCH -V7 00/14] hugetlb: Add HugeTLB controller to control HugeTLB allocation Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 01/14] hugetlb: rename max_hstate to hugetlb_max_hstate Aneesh Kumar K.V
[not found] ` <1338388739-22919-2-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-05-31 0:48 ` Konrad Rzeszutek Wilk
2012-05-31 5:47 ` Aneesh Kumar K.V
2012-05-31 0:55 ` David Rientjes
2012-05-30 14:38 ` [PATCH -V7 02/14] hugetlbfs: don't use ERR_PTR with VM_FAULT* values Aneesh Kumar K.V
[not found] ` <1338388739-22919-3-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-05-31 0:54 ` Konrad Rzeszutek Wilk
2012-05-31 1:02 ` David Rientjes
2012-05-31 5:45 ` Aneesh Kumar K.V
2012-05-31 6:50 ` David Rientjes
2012-05-30 14:38 ` [PATCH -V7 03/14] hugetlbfs: add an inline helper for finding hstate index Aneesh Kumar K.V
2012-05-31 1:05 ` David Rientjes
2012-05-30 14:38 ` [PATCH -V7 04/14] hugetlb: use mmu_gather instead of a temporary linked list for accumulating pages Aneesh Kumar K.V
[not found] ` <1338388739-22919-5-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-05-31 1:56 ` David Rientjes
2012-05-31 5:35 ` Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 05/14] hugetlb: avoid taking i_mmap_mutex in unmap_single_vma() for hugetlb Aneesh Kumar K.V
[not found] ` <1338388739-22919-6-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-05-31 1:57 ` David Rientjes
2012-05-31 5:25 ` Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 06/14] hugetlb: simplify migrate_huge_page() Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 07/14] mm/page_cgroup: Make page_cgroup point to the cgroup rather than the mem_cgroup Aneesh Kumar K.V
[not found] ` <1338388739-22919-8-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-06-05 1:44 ` Kamezawa Hiroyuki
[not found] ` <4FCD648E.90709-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-06-05 2:53 ` Aneesh Kumar K.V
2012-06-05 3:40 ` Kamezawa Hiroyuki
[not found] ` <4FCD7FBB.1000304-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-06-07 19:05 ` Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 08/14] hugetlbfs: add a list for tracking in-use HugeTLB pages Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 09/14] hugetlbfs: Make some static variables global Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 10/14] hugetlbfs: Add new HugeTLB cgroup Aneesh Kumar K.V
[not found] ` <1338388739-22919-11-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-05-31 1:19 ` Konrad Rzeszutek Wilk
[not found] ` <20120531011953.GE401-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-05-31 5:43 ` Aneesh Kumar K.V [this message]
[not found] ` <20120531054316.GD24855-6yE53ggjAfyuJw1Jpgb2kA4V1jybR7bhVpNB7YpNyf8@public.gmane.org>
2012-05-31 9:43 ` Michal Hocko
2012-05-31 14:01 ` Michal Hocko
2012-05-30 14:38 ` [PATCH -V7 11/14] hugetlbfs: add hugetlb cgroup control files Aneesh Kumar K.V
[not found] ` <1338388739-22919-12-git-send-email-aneesh.kumar-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2012-05-31 1:32 ` Konrad Rzeszutek Wilk
2012-05-31 5:39 ` Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 12/14] hugetlb: add charge/uncharge calls for HugeTLB alloc/free Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 13/14] hugetlb: migrate hugetlb cgroup info from oldpage to new page during migration Aneesh Kumar K.V
2012-05-30 14:38 ` [PATCH -V7 14/14] hugetlb: add HugeTLB controller documentation Aneesh Kumar K.V
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=20120531054316.GD24855@skywalker.linux.vnet.ibm.com \
--to=aneesh.kumar-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dhillf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
--cc=kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org \
--cc=konrad-Gq0aWv8utHQdnm+yROfE0A@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
--cc=rientjes-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).