From nobody Fri Dec 19 22:07:26 2025 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22D5D128820 for ; Mon, 3 Jun 2024 12:12:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416770; cv=none; b=Srwxyj5j9t2AXrUmY95L/mamj6Vgie50EONuvSOaYifXL0eZhVyF+HGirqTr0bTDMK/OS2WnGVNRPUsf8MC1z9owxPH6waYD/lHVaZWfq6QnJ2s/OHYC2Xx+Hj7n5UOM+JrUuHHflts+0gzTtaCpy9XC71YfPg4gBQR05EVd30w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416770; c=relaxed/simple; bh=OAIaQ6JZgKz5GOYpBFjTY8RlwKi7yq66Tt48HkB10iM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vF4OIFVyUIC/+sy5C+Gspcg4wzkxx1FvpSEGJj8pe/nqtG8MuL0DmYR8uA3SiSbjD8Xg9dWuQZWn6gWnckLlVFu3P/nhs4U3yctn/L3zM2Tg3lPgieItKebplM0gZ9OYkrYAYFaZynYYs8FsjDORF4uJycpydC8rRwK/9yMn/bY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VtCDz2xwGz1S91k; Mon, 3 Jun 2024 20:08:51 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 55926140109; Mon, 3 Jun 2024 20:12:45 +0800 (CST) Received: from hulk-vt.huawei.com (10.67.174.26) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 3 Jun 2024 20:12:45 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH -next 1/3] mm/hugetlb_cgroup: identify the legacy using cgroup_subsys_on_dfl() Date: Mon, 3 Jun 2024 12:05:04 +0000 Message-ID: <20240603120506.1837322-2-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603120506.1837322-1-xiujianfeng@huawei.com> References: <20240603120506.1837322-1-xiujianfeng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500023.china.huawei.com (7.185.36.114) Content-Type: text/plain; charset="utf-8" Currently the numa_stat file encodes 1 into .private using the micro MEMFILE_PRIVATE() to identify the legacy. Actually, we can use cgroup_subsys_on_dfl() instead. This is helpful to handle .private in the static array in the next patch. Signed-off-by: Xiu Jianfeng --- mm/hugetlb_cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index e20339a346b9..45f94a869776 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -460,7 +460,7 @@ static int hugetlb_cgroup_read_numa_stat(struct seq_fil= e *seq, void *dummy) int nid; struct cftype *cft =3D seq_cft(seq); int idx =3D MEMFILE_IDX(cft->private); - bool legacy =3D MEMFILE_ATTR(cft->private); + bool legacy =3D !cgroup_subsys_on_dfl(hugetlb_cgrp_subsys); struct hugetlb_cgroup *h_cg =3D hugetlb_cgroup_from_css(seq_css(seq)); struct cgroup_subsys_state *css; unsigned long usage; @@ -839,7 +839,7 @@ static void __init __hugetlb_cgroup_file_legacy_init(in= t idx) /* Add the numa stat file */ cft =3D &h->cgroup_files_legacy[8]; snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf); - cft->private =3D MEMFILE_PRIVATE(idx, 1); + cft->private =3D MEMFILE_PRIVATE(idx, 0); cft->seq_show =3D hugetlb_cgroup_read_numa_stat; =20 /* NULL terminate the last cft */ --=20 2.34.1 From nobody Fri Dec 19 22:07:26 2025 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4595B128832 for ; Mon, 3 Jun 2024 12:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416771; cv=none; b=mARmCw56/Pt41r2VujsTw+AmnZwDirBAGNNtqsofjl9NGVU0l/AzmvNsezlt5yxRGbG5CoRVl7RB7PtnzycoIY7UqFKglGlGLWqRVEd2C3xiH5zQEKZPhJIO0mcJF2j4ByxN9fkKF6KSkEGhytZ9ztJWXi6p9w5efVahYsbLowo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416771; c=relaxed/simple; bh=H0kB1Bi2osqi2agRb4AVPOt3pTG+vr9JMCTGVRmxBxI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F1mIglUVK+1fXUMP3WBJf6/InCYg25o8uq5BT7ESN04VPYpN0rVFhjpudsXZHymLfccAvXU/A9bp3zXl62r/o2bTTsY1DX/fSL4nwYqRZBtyndpG8FyTM0diLCLH2Kvr7PHf3fXGB36hdxXxkuUqO6Jrp0xgFrgbYMQ7B/UfwDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VtCF03SF1z1S92S; Mon, 3 Jun 2024 20:08:52 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 65CC0180060; Mon, 3 Jun 2024 20:12:46 +0800 (CST) Received: from hulk-vt.huawei.com (10.67.174.26) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 3 Jun 2024 20:12:46 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH -next 2/3] mm/hugetlb_cgroup: prepare cftypes based on template Date: Mon, 3 Jun 2024 12:05:05 +0000 Message-ID: <20240603120506.1837322-3-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603120506.1837322-1-xiujianfeng@huawei.com> References: <20240603120506.1837322-1-xiujianfeng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500023.china.huawei.com (7.185.36.114) Content-Type: text/plain; charset="utf-8" Unlike other cgroup subsystems, the hugetlb cgroup does not provide a static array of cftype that explicitly displays the properties, handling functions, etc., of each file. Instead, it dynamically creates the attribute of cftypes based on the hstate during the startup procedure. This reduces the readability of the code. To fix this issue, introduce two templates of cftypes, and rebuild the attributes according to the hstate to make it ready to be added to cgroup framework. Signed-off-by: Xiu Jianfeng --- mm/hugetlb_cgroup.c | 157 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 45f94a869776..378f2353443f 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -27,7 +27,16 @@ #define MEMFILE_IDX(val) (((val) >> 16) & 0xffff) #define MEMFILE_ATTR(val) ((val) & 0xffff) =20 +#define MEMFILE_OFFSET(t, m) (((offsetof(t, m) << 16) | sizeof_field(t, m)= )) +#define MEMFILE_OFFSET0(val) (((val) >> 16) & 0xffff) +#define MEMFILE_FIELD_SIZE(val) ((val) & 0xffff) + +#define DFL_TMPL_SIZE ARRAY_SIZE(hugetlb_dfl_tmpl) +#define LEGACY_TMPL_SIZE ARRAY_SIZE(hugetlb_legacy_tmpl) + static struct hugetlb_cgroup *root_h_cgroup __read_mostly; +static struct cftype *dfl_files; +static struct cftype *legacy_files; =20 static inline struct page_counter * __hugetlb_cgroup_counter_from_cgroup(struct hugetlb_cgroup *h_cg, int idx, @@ -702,12 +711,144 @@ static int hugetlb_events_local_show(struct seq_file= *seq, void *v) return __hugetlb_events_show(seq, true); } =20 +static struct cftype hugetlb_dfl_tmpl[] =3D { + { + .name =3D "max", + .private =3D RES_LIMIT, + .seq_show =3D hugetlb_cgroup_read_u64_max, + .write =3D hugetlb_cgroup_write_dfl, + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + { + .name =3D "rsvd.max", + .private =3D RES_RSVD_LIMIT, + .seq_show =3D hugetlb_cgroup_read_u64_max, + .write =3D hugetlb_cgroup_write_dfl, + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + { + .name =3D "current", + .private =3D RES_USAGE, + .seq_show =3D hugetlb_cgroup_read_u64_max, + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + { + .name =3D "rsvd.current", + .private =3D RES_RSVD_USAGE, + .seq_show =3D hugetlb_cgroup_read_u64_max, + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + { + .name =3D "events", + .seq_show =3D hugetlb_events_show, + .file_offset =3D MEMFILE_OFFSET(struct hugetlb_cgroup, events_file[0]), + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + { + .name =3D "events.local", + .seq_show =3D hugetlb_events_local_show, + .file_offset =3D MEMFILE_OFFSET(struct hugetlb_cgroup, events_local_file= [0]), + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + { + .name =3D "numa_stat", + .seq_show =3D hugetlb_cgroup_read_numa_stat, + .flags =3D CFTYPE_NOT_ON_ROOT, + }, + /* don't need terminator here */ +}; + +static struct cftype hugetlb_legacy_tmpl[] =3D { + { + .name =3D "limit_in_bytes", + .private =3D RES_LIMIT, + .read_u64 =3D hugetlb_cgroup_read_u64, + .write =3D hugetlb_cgroup_write_legacy, + }, + { + .name =3D "rsvd.limit_in_bytes", + .private =3D RES_RSVD_LIMIT, + .read_u64 =3D hugetlb_cgroup_read_u64, + .write =3D hugetlb_cgroup_write_legacy, + }, + { + .name =3D "usage_in_bytes", + .private =3D RES_USAGE, + .read_u64 =3D hugetlb_cgroup_read_u64, + }, + { + .name =3D "rsvd.usage_in_bytes", + .private =3D RES_RSVD_USAGE, + .read_u64 =3D hugetlb_cgroup_read_u64, + }, + { + .name =3D "max_usage_in_bytes", + .private =3D RES_MAX_USAGE, + .write =3D hugetlb_cgroup_reset, + .read_u64 =3D hugetlb_cgroup_read_u64, + }, + { + .name =3D "rsvd.max_usage_in_bytes", + .private =3D RES_RSVD_MAX_USAGE, + .write =3D hugetlb_cgroup_reset, + .read_u64 =3D hugetlb_cgroup_read_u64, + }, + { + .name =3D "failcnt", + .private =3D RES_FAILCNT, + .write =3D hugetlb_cgroup_reset, + .read_u64 =3D hugetlb_cgroup_read_u64, + }, + { + .name =3D "rsvd.failcnt", + .private =3D RES_RSVD_FAILCNT, + .write =3D hugetlb_cgroup_reset, + .read_u64 =3D hugetlb_cgroup_read_u64, + }, + { + .name =3D "numa_stat", + .seq_show =3D hugetlb_cgroup_read_numa_stat, + }, + /* don't need terminator here */ +}; + +static void __init +hugetlb_cgroup_cfttypes_init(struct hstate *h, struct cftype *cft, + struct cftype *tmpl, int tmpl_size) +{ + char buf[32]; + int i, idx =3D hstate_index(h); + + /* format the size */ + mem_fmt(buf, sizeof(buf), huge_page_size(h)); + + for (i =3D 0; i < tmpl_size; cft++, tmpl++, i++) { + *cft =3D *tmpl; + /* rebuild the name */ + if (tmpl->name) + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.%s", buf, tmpl->name); + /* rebuild the private */ + if (tmpl->private) + cft->private =3D MEMFILE_PRIVATE(idx, tmpl->private); + /* rebuild the file_offset */ + if (tmpl->file_offset) { + unsigned int offset =3D tmpl->file_offset; + + cft->file_offset =3D MEMFILE_OFFSET0(offset) + + MEMFILE_FIELD_SIZE(offset) * idx; + } + } +} + static void __init __hugetlb_cgroup_file_dfl_init(int idx) { char buf[32]; struct cftype *cft; struct hstate *h =3D &hstates[idx]; =20 + hugetlb_cgroup_cfttypes_init(h, dfl_files + idx * DFL_TMPL_SIZE, + hugetlb_dfl_tmpl, DFL_TMPL_SIZE); + /* format the size */ mem_fmt(buf, sizeof(buf), huge_page_size(h)); =20 @@ -779,6 +920,9 @@ static void __init __hugetlb_cgroup_file_legacy_init(in= t idx) struct cftype *cft; struct hstate *h =3D &hstates[idx]; =20 + hugetlb_cgroup_cfttypes_init(h, legacy_files + idx * LEGACY_TMPL_SIZE, + hugetlb_legacy_tmpl, LEGACY_TMPL_SIZE); + /* format the size */ mem_fmt(buf, sizeof(buf), huge_page_size(h)); =20 @@ -856,10 +1000,23 @@ static void __init __hugetlb_cgroup_file_init(int id= x) __hugetlb_cgroup_file_legacy_init(idx); } =20 +static void __init __hugetlb_cgroup_file_pre_init(void) +{ + int cft_count; + + cft_count =3D hugetlb_max_hstate * DFL_TMPL_SIZE + 1; /* add terminator */ + dfl_files =3D kcalloc(cft_count, sizeof(struct cftype), GFP_KERNEL); + BUG_ON(!dfl_files); + cft_count =3D hugetlb_max_hstate * LEGACY_TMPL_SIZE + 1; /* add terminato= r */ + legacy_files =3D kcalloc(cft_count, sizeof(struct cftype), GFP_KERNEL); + BUG_ON(!legacy_files); +} + void __init hugetlb_cgroup_file_init(void) { struct hstate *h; =20 + __hugetlb_cgroup_file_pre_init(); for_each_hstate(h) __hugetlb_cgroup_file_init(hstate_index(h)); } --=20 2.34.1 From nobody Fri Dec 19 22:07:26 2025 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F301B1292D3 for ; Mon, 3 Jun 2024 12:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416772; cv=none; b=XtNjHvTEQZ5L0Nt7ARRCcIiGP/knaCrIquM7GEEeanx/7OezeJTjZJCQ9kHfbgQIoNl6qWM0XFXrDXS6oOtFEqUC5rIG0hyzHtB3/i3NXs3dp0NGLb7v5ZD1A0/k71luO+1UwVG2yM+3HpGld8LJk3ztBR2Ec3S4BBKvwZxuelA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717416772; c=relaxed/simple; bh=3+yrHg4BbTAhVyeLVG8IYHorFBV3XxzzNtDX/G8hIzA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hlBLemDQsWYRNXclbyck+gs4IzIgd8GkAW9t8Jb8IDwr72AgdBinOx0lHI4P1wWeYNX81qPUfyWl5QPBnJqgILNGvxmQxBblGne8B9ErqHlh23C3+lYAvInJ9ct2pQ9w6QuoanKzB/wKU2QyQTeAhiB8cFOPhQS//qNWw3+fV1g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4VtCFH1fNyz1S67t; Mon, 3 Jun 2024 20:09:07 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 3ED841A016C; Mon, 3 Jun 2024 20:12:47 +0800 (CST) Received: from hulk-vt.huawei.com (10.67.174.26) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 3 Jun 2024 20:12:47 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH -next 3/3] mm/hugetlb_cgroup: switch to the new cftypes Date: Mon, 3 Jun 2024 12:05:06 +0000 Message-ID: <20240603120506.1837322-4-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603120506.1837322-1-xiujianfeng@huawei.com> References: <20240603120506.1837322-1-xiujianfeng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500023.china.huawei.com (7.185.36.114) Content-Type: text/plain; charset="utf-8" The previous patch has already reconstructed the cftype attributes based on the templates and saved them in dfl_cftypes and legacy_cftypes. then remove the old procedure and switch to the new cftypes. Signed-off-by: Xiu Jianfeng --- include/linux/hugetlb.h | 5 -- mm/hugetlb_cgroup.c | 163 +++++----------------------------------- 2 files changed, 17 insertions(+), 151 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 279aca379b95..a951c0d06061 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -686,11 +686,6 @@ struct hstate { unsigned int nr_huge_pages_node[MAX_NUMNODES]; unsigned int free_huge_pages_node[MAX_NUMNODES]; unsigned int surplus_huge_pages_node[MAX_NUMNODES]; -#ifdef CONFIG_CGROUP_HUGETLB - /* cgroup control files */ - struct cftype cgroup_files_dfl[8]; - struct cftype cgroup_files_legacy[10]; -#endif char name[HSTATE_NAME_LEN]; }; =20 diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 378f2353443f..856296d865c6 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -840,164 +840,26 @@ hugetlb_cgroup_cfttypes_init(struct hstate *h, struc= t cftype *cft, } } =20 -static void __init __hugetlb_cgroup_file_dfl_init(int idx) +static void __init __hugetlb_cgroup_file_dfl_init(struct hstate *h) { - char buf[32]; - struct cftype *cft; - struct hstate *h =3D &hstates[idx]; + int idx =3D hstate_index(h); =20 hugetlb_cgroup_cfttypes_init(h, dfl_files + idx * DFL_TMPL_SIZE, hugetlb_dfl_tmpl, DFL_TMPL_SIZE); - - /* format the size */ - mem_fmt(buf, sizeof(buf), huge_page_size(h)); - - /* Add the limit file */ - cft =3D &h->cgroup_files_dfl[0]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_LIMIT); - cft->seq_show =3D hugetlb_cgroup_read_u64_max; - cft->write =3D hugetlb_cgroup_write_dfl; - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* Add the reservation limit file */ - cft =3D &h->cgroup_files_dfl[1]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.max", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_RSVD_LIMIT); - cft->seq_show =3D hugetlb_cgroup_read_u64_max; - cft->write =3D hugetlb_cgroup_write_dfl; - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* Add the current usage file */ - cft =3D &h->cgroup_files_dfl[2]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.current", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_USAGE); - cft->seq_show =3D hugetlb_cgroup_read_u64_max; - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* Add the current reservation usage file */ - cft =3D &h->cgroup_files_dfl[3]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.current", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_RSVD_USAGE); - cft->seq_show =3D hugetlb_cgroup_read_u64_max; - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* Add the events file */ - cft =3D &h->cgroup_files_dfl[4]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.events", buf); - cft->private =3D MEMFILE_PRIVATE(idx, 0); - cft->seq_show =3D hugetlb_events_show; - cft->file_offset =3D offsetof(struct hugetlb_cgroup, events_file[idx]); - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* Add the events.local file */ - cft =3D &h->cgroup_files_dfl[5]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.events.local", buf); - cft->private =3D MEMFILE_PRIVATE(idx, 0); - cft->seq_show =3D hugetlb_events_local_show; - cft->file_offset =3D offsetof(struct hugetlb_cgroup, - events_local_file[idx]); - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* Add the numa stat file */ - cft =3D &h->cgroup_files_dfl[6]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf); - cft->private =3D MEMFILE_PRIVATE(idx, 0); - cft->seq_show =3D hugetlb_cgroup_read_numa_stat; - cft->flags =3D CFTYPE_NOT_ON_ROOT; - - /* NULL terminate the last cft */ - cft =3D &h->cgroup_files_dfl[7]; - memset(cft, 0, sizeof(*cft)); - - WARN_ON(cgroup_add_dfl_cftypes(&hugetlb_cgrp_subsys, - h->cgroup_files_dfl)); } =20 -static void __init __hugetlb_cgroup_file_legacy_init(int idx) +static void __init __hugetlb_cgroup_file_legacy_init(struct hstate *h) { - char buf[32]; - struct cftype *cft; - struct hstate *h =3D &hstates[idx]; + int idx =3D hstate_index(h); =20 hugetlb_cgroup_cfttypes_init(h, legacy_files + idx * LEGACY_TMPL_SIZE, hugetlb_legacy_tmpl, LEGACY_TMPL_SIZE); - - /* format the size */ - mem_fmt(buf, sizeof(buf), huge_page_size(h)); - - /* Add the limit file */ - cft =3D &h->cgroup_files_legacy[0]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.limit_in_bytes", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_LIMIT); - cft->read_u64 =3D hugetlb_cgroup_read_u64; - cft->write =3D hugetlb_cgroup_write_legacy; - - /* Add the reservation limit file */ - cft =3D &h->cgroup_files_legacy[1]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.limit_in_bytes", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_RSVD_LIMIT); - cft->read_u64 =3D hugetlb_cgroup_read_u64; - cft->write =3D hugetlb_cgroup_write_legacy; - - /* Add the usage file */ - cft =3D &h->cgroup_files_legacy[2]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.usage_in_bytes", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_USAGE); - cft->read_u64 =3D hugetlb_cgroup_read_u64; - - /* Add the reservation usage file */ - cft =3D &h->cgroup_files_legacy[3]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.usage_in_bytes", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_RSVD_USAGE); - cft->read_u64 =3D hugetlb_cgroup_read_u64; - - /* Add the MAX usage file */ - cft =3D &h->cgroup_files_legacy[4]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max_usage_in_bytes", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_MAX_USAGE); - cft->write =3D hugetlb_cgroup_reset; - cft->read_u64 =3D hugetlb_cgroup_read_u64; - - /* Add the MAX reservation usage file */ - cft =3D &h->cgroup_files_legacy[5]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.max_usage_in_bytes", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_RSVD_MAX_USAGE); - cft->write =3D hugetlb_cgroup_reset; - cft->read_u64 =3D hugetlb_cgroup_read_u64; - - /* Add the failcntfile */ - cft =3D &h->cgroup_files_legacy[6]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.failcnt", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_FAILCNT); - cft->write =3D hugetlb_cgroup_reset; - cft->read_u64 =3D hugetlb_cgroup_read_u64; - - /* Add the reservation failcntfile */ - cft =3D &h->cgroup_files_legacy[7]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.failcnt", buf); - cft->private =3D MEMFILE_PRIVATE(idx, RES_RSVD_FAILCNT); - cft->write =3D hugetlb_cgroup_reset; - cft->read_u64 =3D hugetlb_cgroup_read_u64; - - /* Add the numa stat file */ - cft =3D &h->cgroup_files_legacy[8]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf); - cft->private =3D MEMFILE_PRIVATE(idx, 0); - cft->seq_show =3D hugetlb_cgroup_read_numa_stat; - - /* NULL terminate the last cft */ - cft =3D &h->cgroup_files_legacy[9]; - memset(cft, 0, sizeof(*cft)); - - WARN_ON(cgroup_add_legacy_cftypes(&hugetlb_cgrp_subsys, - h->cgroup_files_legacy)); } =20 -static void __init __hugetlb_cgroup_file_init(int idx) +static void __init __hugetlb_cgroup_file_init(struct hstate *h) { - __hugetlb_cgroup_file_dfl_init(idx); - __hugetlb_cgroup_file_legacy_init(idx); + __hugetlb_cgroup_file_dfl_init(h); + __hugetlb_cgroup_file_legacy_init(h); } =20 static void __init __hugetlb_cgroup_file_pre_init(void) @@ -1012,13 +874,22 @@ static void __init __hugetlb_cgroup_file_pre_init(vo= id) BUG_ON(!legacy_files); } =20 +static void __init __hugetlb_cgroup_file_post_init(void) +{ + WARN_ON(cgroup_add_dfl_cftypes(&hugetlb_cgrp_subsys, + dfl_files)); + WARN_ON(cgroup_add_legacy_cftypes(&hugetlb_cgrp_subsys, + legacy_files)); +} + void __init hugetlb_cgroup_file_init(void) { struct hstate *h; =20 __hugetlb_cgroup_file_pre_init(); for_each_hstate(h) - __hugetlb_cgroup_file_init(hstate_index(h)); + __hugetlb_cgroup_file_init(h); + __hugetlb_cgroup_file_post_init(); } =20 /* --=20 2.34.1