From: Konrad Rzeszutek Wilk <konrad@darnok.org>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: linux-mm@kvack.org, kamezawa.hiroyu@jp.fujitsu.com,
dhillf@gmail.com, rientjes@google.com, mhocko@suse.cz,
akpm@linux-foundation.org, hannes@cmpxchg.org,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org
Subject: Re: [PATCH -V8 13/16] hugetlb/cgroup: add hugetlb cgroup control files
Date: Sat, 9 Jun 2012 07:19:47 -0400 [thread overview]
Message-ID: <20120609111946.GC16034@localhost.localdomain> (raw)
In-Reply-To: <1339232401-14392-14-git-send-email-aneesh.kumar@linux.vnet.ibm.com>
> const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
> @@ -1916,6 +1917,13 @@ void __init hugetlb_add_hstate(unsigned order)
> h->next_nid_to_free = first_node(node_states[N_HIGH_MEMORY]);
> snprintf(h->name, HSTATE_NAME_LEN, "hugepages-%lukB",
> huge_page_size(h)/1024);
> + /*
> + * Add cgroup control files only if the huge page consists
> + * of more than two normal pages. This is because we use
Not three? I thought the earlier patches said three?
> + * page[2].lru.next for storing cgoup details.
cgoup?
> + */
> + if (order >= 2)
> + hugetlb_cgroup_file_init(hugetlb_max_hstate - 1);
>
> parsed_hstate = h;
> }
> diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c
> index 9458fe3..2a4881d 100644
> --- a/mm/hugetlb_cgroup.c
> +++ b/mm/hugetlb_cgroup.c
> @@ -18,6 +18,11 @@
> #include <linux/hugetlb.h>
> #include <linux/hugetlb_cgroup.h>
>
> +/* lifted from mem control */
And you can also life the comment from mem control explaining
what these defines are good for.
> +#define MEMFILE_PRIVATE(x, val) (((x) << 16) | (val))
> +#define MEMFILE_IDX(val) (((val) >> 16) & 0xffff)
> +#define MEMFILE_ATTR(val) ((val) & 0xffff)
> +
> struct cgroup_subsys hugetlb_subsys __read_mostly;
> struct hugetlb_cgroup *root_h_cgroup __read_mostly;
>
> @@ -269,6 +274,131 @@ void hugetlb_cgroup_uncharge_cgroup(int idx, unsigned long nr_pages,
> return;
> }
>
> +static ssize_t hugetlb_cgroup_read(struct cgroup *cgroup, struct cftype *cft,
> + struct file *file, char __user *buf,
> + size_t nbytes, loff_t *ppos)
> +{
> + u64 val;
> + char str[64];
Why no #define? Wait a minute - didn't I provide a similar comment last
time? So why the reason to stick without the #define's?
> + int idx, name, len;
> + struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cgroup);
> +
> + idx = MEMFILE_IDX(cft->private);
> + name = MEMFILE_ATTR(cft->private);
> +
> + val = res_counter_read_u64(&h_cg->hugepage[idx], name);
> + len = scnprintf(str, sizeof(str), "%llu\n", (unsigned long long)val);
> + return simple_read_from_buffer(buf, nbytes, ppos, str, len);
> +}
> +
> +static int hugetlb_cgroup_write(struct cgroup *cgroup, struct cftype *cft,
> + const char *buffer)
> +{
> + int idx, name, ret;
> + unsigned long long val;
> + struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cgroup);
> +
> + idx = MEMFILE_IDX(cft->private);
> + name = MEMFILE_ATTR(cft->private);
> +
> + switch (name) {
> + case RES_LIMIT:
> + if (hugetlb_cgroup_is_root(h_cg)) {
> + /* Can't set limit on root */
> + ret = -EINVAL;
> + break;
> + }
> + /* This function does all necessary parse...reuse it */
> + ret = res_counter_memparse_write_strategy(buffer, &val);
> + if (ret)
> + break;
> + ret = res_counter_set_limit(&h_cg->hugepage[idx], val);
> + break;
> + default:
> + ret = -EINVAL;
> + break;
> + }
> + return ret;
> +}
> +
> +static int hugetlb_cgroup_reset(struct cgroup *cgroup, unsigned int event)
> +{
> + int idx, name, ret = 0;
> + struct hugetlb_cgroup *h_cg = hugetlb_cgroup_from_cgroup(cgroup);
> +
> + idx = MEMFILE_IDX(event);
> + name = MEMFILE_ATTR(event);
> +
> + switch (name) {
> + case RES_MAX_USAGE:
> + res_counter_reset_max(&h_cg->hugepage[idx]);
> + break;
> + case RES_FAILCNT:
> + res_counter_reset_failcnt(&h_cg->hugepage[idx]);
> + break;
> + default:
> + ret = -EINVAL;
> + break;
> + }
> + return ret;
> +}
> +
> +static char *mem_fmt(char *buf, int size, unsigned long hsize)
> +{
> + if (hsize >= (1UL << 30))
> + snprintf(buf, size, "%luGB", hsize >> 30);
> + else if (hsize >= (1UL << 20))
> + snprintf(buf, size, "%luMB", hsize >> 20);
> + else
> + snprintf(buf, size, "%luKB", hsize >> 10);
> + return buf;
> +}
> +
> +int __init hugetlb_cgroup_file_init(int idx)
> +{
> + char buf[32];
Ditto.
> + struct cftype *cft;
> + struct hstate *h = &hstates[idx];
> +
> + /* format the size */
> + mem_fmt(buf, 32, huge_page_size(h));
Ditto.
> +
> + /* Add the limit file */
> + cft = &h->cgroup_files[0];
Can't this be just:
cfg = &h->cgroup_files;
> + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.limit_in_bytes", buf);
> + cft->private = MEMFILE_PRIVATE(idx, RES_LIMIT);
> + cft->read = hugetlb_cgroup_read;
> + cft->write_string = hugetlb_cgroup_write;
> +
> + /* Add the usage file */
> + cft = &h->cgroup_files[1];
and this be:
cft++;
> + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.usage_in_bytes", buf);
> + cft->private = MEMFILE_PRIVATE(idx, RES_USAGE);
> + cft->read = hugetlb_cgroup_read;
> +
> + /* Add the MAX usage file */
> + cft = &h->cgroup_files[2];
> + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max_usage_in_bytes", buf);
> + cft->private = MEMFILE_PRIVATE(idx, RES_MAX_USAGE);
> + cft->trigger = hugetlb_cgroup_reset;
> + cft->read = hugetlb_cgroup_read;
> +
> + /* Add the failcntfile */
> + cft = &h->cgroup_files[3];
and so for this one.
> + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.failcnt", buf);
> + cft->private = MEMFILE_PRIVATE(idx, RES_FAILCNT);
> + cft->trigger = hugetlb_cgroup_reset;
> + cft->read = hugetlb_cgroup_read;
> +
> + /* NULL terminate the last cft */
> + cft = &h->cgroup_files[4];
and for that one?
> + memset(cft, 0, sizeof(*cft));
> +
> + WARN_ON(cgroup_add_cftypes(&hugetlb_subsys, h->cgroup_files));
> +
> + return 0;
> +}
> +
> struct cgroup_subsys hugetlb_subsys = {
> .name = "hugetlb",
> .create = hugetlb_cgroup_create,
> --
> 1.7.10
>
> --
> 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>
>
--
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>
next prev parent reply other threads:[~2012-06-09 11:19 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-09 8:59 [PATCH -V8 00/16] hugetlb: Add HugeTLB controller to control HugeTLB allocation Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 01/16] hugetlb: rename max_hstate to hugetlb_max_hstate Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 02/16] hugetlb: don't use ERR_PTR with VM_FAULT* values Aneesh Kumar K.V
2012-06-09 11:10 ` Konrad Rzeszutek Wilk
2012-06-09 13:17 ` Aneesh Kumar K.V
2012-06-09 19:28 ` KOSAKI Motohiro
2012-06-10 1:59 ` Hillf Danton
2012-06-09 8:59 ` [PATCH -V8 03/16] hugetlb: add an inline helper for finding hstate index Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 04/16] hugetlb: use mmu_gather instead of a temporary linked list for accumulating pages Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 05/16] hugetlb: avoid taking i_mmap_mutex in unmap_single_vma() for hugetlb Aneesh Kumar K.V
2012-06-09 9:44 ` Johannes Weiner
2012-06-09 13:03 ` Aneesh Kumar K.V
2012-06-09 14:49 ` Johannes Weiner
2012-06-09 8:59 ` [PATCH -V8 06/16] hugetlb: simplify migrate_huge_page() Aneesh Kumar K.V
2012-06-12 7:31 ` Kamezawa Hiroyuki
2012-06-09 8:59 ` [PATCH -V8 07/16] hugetlb: add a list for tracking in-use HugeTLB pages Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 08/16] hugetlb: Make some static variables global Aneesh Kumar K.V
2012-06-12 7:35 ` Kamezawa Hiroyuki
2012-06-09 8:59 ` [PATCH -V8 09/16] mm/hugetlb: Add new HugeTLB cgroup Aneesh Kumar K.V
2012-06-12 7:46 ` Kamezawa Hiroyuki
2012-06-12 9:37 ` Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 10/16] hugetlb/cgroup: Add the cgroup pointer to page lru Aneesh Kumar K.V
2012-06-09 11:14 ` Konrad Rzeszutek Wilk
2012-06-09 17:04 ` Aneesh Kumar K.V
2012-06-11 8:16 ` Michal Hocko
2012-06-11 9:03 ` Aneesh Kumar K.V
2012-06-11 9:16 ` Michal Hocko
2012-06-11 9:33 ` Aneesh Kumar K.V
2012-06-11 8:41 ` Kamezawa Hiroyuki
2012-06-12 7:52 ` Kamezawa Hiroyuki
2012-06-12 9:40 ` Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 11/16] hugetlb/cgroup: Add charge/uncharge routines for hugetlb cgroup Aneesh Kumar K.V
2012-06-11 8:38 ` Michal Hocko
2012-06-11 9:10 ` Michal Hocko
2012-06-11 9:28 ` Aneesh Kumar K.V
2012-06-11 12:59 ` Michal Hocko
2012-06-11 15:35 ` Aneesh Kumar K.V
2012-06-12 8:08 ` Kamezawa Hiroyuki
2012-06-12 10:50 ` Aneesh Kumar K.V
2012-06-13 11:02 ` Kamezawa Hiroyuki
2012-06-09 8:59 ` [PATCH -V8 12/16] hugetlb/cgroup: Add support for cgroup removal Aneesh Kumar K.V
2012-06-11 8:52 ` Michal Hocko
2012-06-11 9:40 ` Aneesh Kumar K.V
2012-06-11 13:14 ` Michal Hocko
2012-06-11 15:34 ` Aneesh Kumar K.V
2012-06-12 8:23 ` Kamezawa Hiroyuki
2012-06-12 10:52 ` Aneesh Kumar K.V
2012-06-09 8:59 ` [PATCH -V8 13/16] hugetlb/cgroup: add hugetlb cgroup control files Aneesh Kumar K.V
2012-06-09 11:19 ` Konrad Rzeszutek Wilk [this message]
2012-06-11 9:02 ` Michal Hocko
2012-06-11 9:43 ` Aneesh Kumar K.V
2012-06-11 13:15 ` Michal Hocko
2012-06-12 8:35 ` Kamezawa Hiroyuki
2012-06-12 10:58 ` Aneesh Kumar K.V
2012-06-13 0:16 ` Kamezawa Hiroyuki
2012-06-09 8:59 ` [PATCH -V8 14/16] hugetlb/cgroup: add charge/uncharge calls for HugeTLB alloc/free Aneesh Kumar K.V
2012-06-09 9:23 ` Johannes Weiner
2012-06-09 13:09 ` Aneesh Kumar K.V
2012-06-09 14:30 ` Johannes Weiner
2012-06-09 15:55 ` Aneesh Kumar K.V
2012-06-11 9:19 ` Michal Hocko
2012-06-11 9:21 ` Michal Hocko
2012-06-11 10:29 ` Aneesh Kumar K.V
2012-06-09 9:00 ` [PATCH -V8 15/16] hugetlb/cgroup: migrate hugetlb cgroup info from oldpage to new page during migration Aneesh Kumar K.V
2012-06-11 9:24 ` Michal Hocko
2012-06-11 10:17 ` Aneesh Kumar K.V
2012-06-12 8:51 ` Kamezawa Hiroyuki
2012-06-12 11:00 ` Aneesh Kumar K.V
2012-06-13 11:15 ` Kamezawa Hiroyuki
2012-06-09 9:00 ` [PATCH -V8 16/16] hugetlb/cgroup: add HugeTLB controller documentation Aneesh Kumar K.V
2012-06-12 8:57 ` Kamezawa Hiroyuki
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=20120609111946.GC16034@localhost.localdomain \
--to=konrad@darnok.org \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=cgroups@vger.kernel.org \
--cc=dhillf@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=rientjes@google.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 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).