From patchwork Wed Jun 12 09:24:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13694700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9669C27C53 for ; Wed, 12 Jun 2024 09:32:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D61756B00A0; Wed, 12 Jun 2024 05:32:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4B7D6B00A2; Wed, 12 Jun 2024 05:32:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9EE86B00A3; Wed, 12 Jun 2024 05:32:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 718166B00A0 for ; Wed, 12 Jun 2024 05:32:03 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 239C41A1254 for ; Wed, 12 Jun 2024 09:32:03 +0000 (UTC) X-FDA: 82221720126.09.040A390 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf27.hostedemail.com (Postfix) with ESMTP id C734540016 for ; Wed, 12 Jun 2024 09:32:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718184721; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+HvMAvryFgbVgtRXqNMEocR+Z+cyn1cMRoVrw6+UdJ0=; b=77Ysh0GChVpZXUe7g41TV8Ed4M5M8z3pqNUwDkOcqaCvbB618/Zr5QC9BIEb1a1RXuP0VD Re6aNRggaYiGv0cgjR49NrQce8SAiCNn11o6CYdrqypwZQTjUUn2O0WpKKI6MTQnxLPCOP VPBT7amcJNiOWnGZOMtKkfWEnHo4zWY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718184721; a=rsa-sha256; cv=none; b=2K7gUMNTNpgNbgmR1+LU+piTIQi4m5fU8ytkMuqWKCBjSVBQhZxNHQFquokbi7pAPy0zZD 2x/lzjgoy++n8hbHP9cb6nPrHxdX/10IZJnM8MTywCQ8ukR9vCZ8FXMDQri9XsEt/bHpE7 C5ibu62nOF/7yqgPI7PKgDMP/XMMzNc= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VzgF13h0Hz1JCj6; Wed, 12 Jun 2024 17:27:49 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 217F318007C; Wed, 12 Jun 2024 17:31:55 +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; Wed, 12 Jun 2024 17:31:54 +0800 From: Xiu Jianfeng To: , CC: , , Subject: [PATCH v3 -next 1/3] mm/hugetlb_cgroup: identify the legacy using cgroup_subsys_on_dfl() Date: Wed, 12 Jun 2024 09:24:07 +0000 Message-ID: <20240612092409.2027592-2-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612092409.2027592-1-xiujianfeng@huawei.com> References: <20240612092409.2027592-1-xiujianfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.26] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500023.china.huawei.com (7.185.36.114) X-Rspamd-Queue-Id: C734540016 X-Stat-Signature: 5akjs4mxaxbcub8ep46ksjhb3mxg8efd X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1718184720-370706 X-HE-Meta: U2FsdGVkX18bnhCZTcUcnX5ato36/tadnHvFKtNpeUstvwyV5UO33enb2b8/Q6IS2hjvhhPMK4vsjbbwNvdma/IKEWfZH1hUtaeU7WksaeUv0kVcrwcpEYYVbkW0vbinXXAXTryMKbQsu9K78cv40m+n1hHOTfr6TwtLaW1S/kHFF/lNIszqXtzso5zydpQj9769dz6bMlNcd4OIq9aV9ptU7ihCisN34wwq+yv6zqok+8Gz+x7F+Rjx3h+I1LVB0EosiGVq5kU2gEFR9whxSpuvrUxvYywBbpxYgcVuKUHt7wnMCYJ0Ap8Eb1uJVnZ/ns6Miu1uFoIH83gW5JS+fCXd3EbMg0aTNC1OZD+YGqflLgBkzinXxzE/CIM7l4l5WQGUVlWedqtNcpbHGzgIlTiu4+t2v6HjNCquY1lPZ+wj4kin+VyajN3lCSTsT/xyqNKjfjPOWZgIgDXry6NmbOK0QYcz0jzqljOVGsKF6M9QXXc5xNz8j7wLh4/e095ZZN0vIPo668VYWlQ3/0UE/vAf68yVe471B04DTXlb3qKptFQGiLDR7Qfll65MeOx2LqoYHh/0r8/eU4Jye9gxZHGYnmrSaPpCcXRyx3e0h3nczTyzQMnz4aW8OA8ENCQ5Ooa/LdqWwtbdve0c2TPiDwVB91V8Nbul2XF07Cq7WZGMRwt+XyKLYcJuy8txJuJGjl+vf9NQtcoIJ6xFqSvvOwyFYl9bJ7Tj6iG6X3wLUv0RveCqcO+3Xp+zPHOpYkzysba3fnSINMrn0ZmfPZ7ernCKaWyiFCFL9daGNOpNlh2Al+qevcKjrBK99PADbt0FF5no7dBIB76v6xZJva6yNjfMaczJ3WHpVUMT6QBlqW6uRmEuiH9eCW5lNoU4gabX/gJqBZsRCT0Ql6Do1G5pU/kPMvC7wBfMYXe5YxFvN0f6rGxYXvIHrspDLNFBWEdBE0iaFEWQldaZ/7SO/HR 9Tsc/W+p JTpF943Pfo0N+8Wo6ZS5fv+MVXU5hTOkTITVKoOcIijSFcTvzXCOLPlQdJ/HMA8c7GSHz2KLK4hDOYndMbKYCBXrg0oWmFPcRXOr6spS/LYLZwuSj5wWn8p2AOjMCYklBrbSVBsQy5nVoZoSe92pradviiMGPfB7m3VoT4cvGM29vyVxgnQ8uDBi+yN+k2iuYxjf2 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 templates in the next patch. Reviewed-by: Oscar Salvador 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_file *seq, void *dummy) int nid; struct cftype *cft = seq_cft(seq); int idx = MEMFILE_IDX(cft->private); - bool legacy = MEMFILE_ATTR(cft->private); + bool legacy = !cgroup_subsys_on_dfl(hugetlb_cgrp_subsys); struct hugetlb_cgroup *h_cg = 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(int idx) /* Add the numa stat file */ cft = &h->cgroup_files_legacy[8]; snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf); - cft->private = MEMFILE_PRIVATE(idx, 1); + cft->private = MEMFILE_PRIVATE(idx, 0); cft->seq_show = hugetlb_cgroup_read_numa_stat; /* NULL terminate the last cft */ From patchwork Wed Jun 12 09:24:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13694698 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5396EC27C53 for ; Wed, 12 Jun 2024 09:32:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA2D16B009D; Wed, 12 Jun 2024 05:32:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9715C6B00A2; Wed, 12 Jun 2024 05:32:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B7106B00A0; Wed, 12 Jun 2024 05:32:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5D8336B009D for ; Wed, 12 Jun 2024 05:32:02 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0D667815E9 for ; Wed, 12 Jun 2024 09:32:02 +0000 (UTC) X-FDA: 82221720084.15.E3A120A Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf28.hostedemail.com (Postfix) with ESMTP id 6B581C001F for ; Wed, 12 Jun 2024 09:31:58 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718184720; a=rsa-sha256; cv=none; b=2E0nfz9OgOxOV3B5Ibitx3ldEyoNKpDgIknM8iPa8PYvVbgs+MXC9W0/2Eyhz0zi8NXA4z yX/qwv/dP0dU8xqA3YcsbwKmAoYzcbYXincoBjpfhVsmMP0qmXs9xjg98rwMyqtAyaRSee gNLCbs2q9qkUon4jUEZCfmYPavV6U6o= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718184720; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yLDVjqKUdhYXt13w2CHRbblonLP3q/2GvJYLU9Xtj74=; b=cMTRcxk+9hNKvOVsxnR3hgsoftYLpa06S+UKQ5PT+c/fVhZ1o3tJf7aa1zzflKxz0KFsgE p6vXEfB784up4AuqfzMNMYLGJJpQnbZry4Q5bvUBSV6inpxUlQqqHzmbuJU+xNQO49jcg5 KqskVInYgHiCIzI5UVLkH6XQiSq9jV4= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VzgHX67B7z1HDNP; Wed, 12 Jun 2024 17:30:00 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id D16DD1400D3; Wed, 12 Jun 2024 17:31:55 +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; Wed, 12 Jun 2024 17:31:55 +0800 From: Xiu Jianfeng To: , CC: , , Subject: [PATCH v3 -next 2/3] mm/hugetlb_cgroup: prepare cftypes based on template Date: Wed, 12 Jun 2024 09:24:08 +0000 Message-ID: <20240612092409.2027592-3-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612092409.2027592-1-xiujianfeng@huawei.com> References: <20240612092409.2027592-1-xiujianfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.26] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500023.china.huawei.com (7.185.36.114) X-Stat-Signature: 9ihsasoz6o8oi5irp84gto85h3fz7ezb X-Rspamd-Queue-Id: 6B581C001F X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1718184718-800030 X-HE-Meta: U2FsdGVkX19vFRpC5oaKhN6MWvOuy8dHqcp6FwYD3HuTXcggsTOM3pXTtAKOB/Wh8GOR2qHIeRG517i4/c1d/Eq2M4zUEA51a8wqP9HlUzB5tnAJW1aMZtdsBWUDSih4yUQe5MKMq9lXrQ6xETYs0UD5bvDomcO//hAKlOMJ1GZnoqbR/Ye/E8+m3bT3fXBdy+Z/GKNFXyeyVUPOhMZaHAcJ3Gd4CxJAsei4ojWHVAIuHiqPXkSPt/C64c+K5FxsEj8is5gWxjDxIZR6VNdXa1i0z2OH9QbGd8degPATD2B2BDg2rlhYtw4Aov5do4YaS/Wv4o9BU95wDk7BqqpO1Lx9pJ9KUrotLy3a0MXJT0yT9aBefLMu06CSLGjvY03ww386JksIGR51MrhkQ9ke/8a76ukJtG1hcvszULjjaf/Pbnfkg79g3odPPO/yR9ufr2PbfqQYsPI/JUv6pj9zGy0w9BB+Okcwx26c6mWb0jemL74N4CLoo5XYCHducTA5ZODUWm/Ujn3hFrZvYHrTVZNMd0NDVBHPmriNBZfugsXRY9w+rJMAW4GbO0joD0plCN/KjEUnX/RlBTNjOXYHCk40YPPiz6LJKqxNheRkGKmINBcp3XMQINYaCE/E/RW4bBv9q2gXk77elv1Cd5wGEd0X1yEH9aUWsvyiiflR3ofQxChjNN1jqq2BSevAFhD7b+dR4KZ6IuLIy47RpSK+Pt/aZsKE9R7K/ZBV/OC4KtuJyECKEEXlvUlP5uKcTqr2OJOFhhejN526Ea5mf5KQjQV491Cx/bs1lynlKV1mQQb3f75gti2Pxkytx87nGm2mZ9tEews8q+LzuGDdHFEs7/SEhlMgPp83oebgBqO/ig146Yt09FHvU7I9y4oN4Cnd5F4acpYFAzwM7HbcBgNFXUWdKbBCLLKc+q5bgXcny8tCSVoXrUrtgaMMr1I7NTjZ8LvyOov7akKH1wlfduX sWJJ55vA EOGNdkbpYn5oytC6KciaFKL/q4qEkZKrRO5ktfOdyws5yr9Z0icMFSdox8spjXKI8e93BTY0EqBz9QRvOGHLBLXa3x45mSrUwC371dYnxv120MDIl9dSJFjY7eCtsCFgKfcdjlB/te2HSjCIDxNOB//cTakDXPiLQ8QNW03/55AcSI4JtFF1/GHuwBtdcubmjhdcr X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 | 156 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 45f94a869776..43aae8f88d5f 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -27,7 +27,17 @@ #define MEMFILE_IDX(val) (((val) >> 16) & 0xffff) #define MEMFILE_ATTR(val) ((val) & 0xffff) +/* Use t->m[0] to encode the offset */ +#define MEMFILE_OFFSET(t, m0) (((offsetof(t, m0) << 16) | sizeof_field(t, m0))) +#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; static inline struct page_counter * __hugetlb_cgroup_counter_from_cgroup(struct hugetlb_cgroup *h_cg, int idx, @@ -702,12 +712,142 @@ static int hugetlb_events_local_show(struct seq_file *seq, void *v) return __hugetlb_events_show(seq, true); } +static struct cftype hugetlb_dfl_tmpl[] = { + { + .name = "max", + .private = RES_LIMIT, + .seq_show = hugetlb_cgroup_read_u64_max, + .write = hugetlb_cgroup_write_dfl, + .flags = CFTYPE_NOT_ON_ROOT, + }, + { + .name = "rsvd.max", + .private = RES_RSVD_LIMIT, + .seq_show = hugetlb_cgroup_read_u64_max, + .write = hugetlb_cgroup_write_dfl, + .flags = CFTYPE_NOT_ON_ROOT, + }, + { + .name = "current", + .private = RES_USAGE, + .seq_show = hugetlb_cgroup_read_u64_max, + .flags = CFTYPE_NOT_ON_ROOT, + }, + { + .name = "rsvd.current", + .private = RES_RSVD_USAGE, + .seq_show = hugetlb_cgroup_read_u64_max, + .flags = CFTYPE_NOT_ON_ROOT, + }, + { + .name = "events", + .seq_show = hugetlb_events_show, + .file_offset = MEMFILE_OFFSET(struct hugetlb_cgroup, events_file[0]), + .flags = CFTYPE_NOT_ON_ROOT, + }, + { + .name = "events.local", + .seq_show = hugetlb_events_local_show, + .file_offset = MEMFILE_OFFSET(struct hugetlb_cgroup, events_local_file[0]), + .flags = CFTYPE_NOT_ON_ROOT, + }, + { + .name = "numa_stat", + .seq_show = hugetlb_cgroup_read_numa_stat, + .flags = CFTYPE_NOT_ON_ROOT, + }, + /* don't need terminator here */ +}; + +static struct cftype hugetlb_legacy_tmpl[] = { + { + .name = "limit_in_bytes", + .private = RES_LIMIT, + .read_u64 = hugetlb_cgroup_read_u64, + .write = hugetlb_cgroup_write_legacy, + }, + { + .name = "rsvd.limit_in_bytes", + .private = RES_RSVD_LIMIT, + .read_u64 = hugetlb_cgroup_read_u64, + .write = hugetlb_cgroup_write_legacy, + }, + { + .name = "usage_in_bytes", + .private = RES_USAGE, + .read_u64 = hugetlb_cgroup_read_u64, + }, + { + .name = "rsvd.usage_in_bytes", + .private = RES_RSVD_USAGE, + .read_u64 = hugetlb_cgroup_read_u64, + }, + { + .name = "max_usage_in_bytes", + .private = RES_MAX_USAGE, + .write = hugetlb_cgroup_reset, + .read_u64 = hugetlb_cgroup_read_u64, + }, + { + .name = "rsvd.max_usage_in_bytes", + .private = RES_RSVD_MAX_USAGE, + .write = hugetlb_cgroup_reset, + .read_u64 = hugetlb_cgroup_read_u64, + }, + { + .name = "failcnt", + .private = RES_FAILCNT, + .write = hugetlb_cgroup_reset, + .read_u64 = hugetlb_cgroup_read_u64, + }, + { + .name = "rsvd.failcnt", + .private = RES_RSVD_FAILCNT, + .write = hugetlb_cgroup_reset, + .read_u64 = hugetlb_cgroup_read_u64, + }, + { + .name = "numa_stat", + .seq_show = 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 = hstate_index(h); + + /* format the size */ + mem_fmt(buf, sizeof(buf), huge_page_size(h)); + + for (i = 0; i < tmpl_size; cft++, tmpl++, i++) { + *cft = *tmpl; + /* rebuild the name */ + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.%s", buf, tmpl->name); + /* rebuild the private */ + cft->private = MEMFILE_PRIVATE(idx, tmpl->private); + /* rebuild the file_offset */ + if (tmpl->file_offset) { + unsigned int offset = tmpl->file_offset; + + cft->file_offset = 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 = &hstates[idx]; + 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)); @@ -779,6 +919,9 @@ static void __init __hugetlb_cgroup_file_legacy_init(int idx) struct cftype *cft; struct hstate *h = &hstates[idx]; + 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)); @@ -856,10 +999,23 @@ static void __init __hugetlb_cgroup_file_init(int idx) __hugetlb_cgroup_file_legacy_init(idx); } +static void __init __hugetlb_cgroup_file_pre_init(void) +{ + int cft_count; + + cft_count = hugetlb_max_hstate * DFL_TMPL_SIZE + 1; /* add terminator */ + dfl_files = kcalloc(cft_count, sizeof(struct cftype), GFP_KERNEL); + BUG_ON(!dfl_files); + cft_count = hugetlb_max_hstate * LEGACY_TMPL_SIZE + 1; /* add terminator */ + legacy_files = kcalloc(cft_count, sizeof(struct cftype), GFP_KERNEL); + BUG_ON(!legacy_files); +} + void __init hugetlb_cgroup_file_init(void) { struct hstate *h; + __hugetlb_cgroup_file_pre_init(); for_each_hstate(h) __hugetlb_cgroup_file_init(hstate_index(h)); } From patchwork Wed Jun 12 09:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13694701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E232C27C77 for ; Wed, 12 Jun 2024 09:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19EFA6B00A2; Wed, 12 Jun 2024 05:32:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 128B16B00A3; Wed, 12 Jun 2024 05:32:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD1D96B00A4; Wed, 12 Jun 2024 05:32:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B081D6B00A2 for ; Wed, 12 Jun 2024 05:32:04 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 656521415D7 for ; Wed, 12 Jun 2024 09:32:04 +0000 (UTC) X-FDA: 82221720168.20.408BC00 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf23.hostedemail.com (Postfix) with ESMTP id BD932140019 for ; Wed, 12 Jun 2024 09:32:01 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718184722; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SYXkCm09J4h5GDSnNec2Lyq/Uf3J8rau1Xg8vMnTV9s=; b=j5icTIe+UeCNo6DSvFY3gp71A30JwL+pmu0ntOltGb+RF5z5Iue/EAnMnzrQT8qXAxQbNp QT+2QqX6x6eh1QgyHIfYVlawDrApHto5zq16njIsWg7j41cFumskn2sgzagilYXYWbjQtB v52cN6DFaqQ/rh9RqFrvYWJKyOzPkOI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718184722; a=rsa-sha256; cv=none; b=Il5sdnX1Dg4dMqgg5Wp2MF9ZMbpo4jPK8ffanzfmvRnEzo5NTxhk5b2ij3Lc911oPLYgFu RXzm4AfY8WgNlPTnEUapA4gcYmfeBItgBUPeBCQqJ0tuwmibLSiWqqIV2/e2bqqYT6287r Wd1VzkB5XJA/+nWuR3xv9OYYHqsbA7c= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VzgF40XBnzxS1q; Wed, 12 Jun 2024 17:27:52 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 71552140443; Wed, 12 Jun 2024 17:31:56 +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; Wed, 12 Jun 2024 17:31:56 +0800 From: Xiu Jianfeng To: , CC: , , Subject: [PATCH v3 -next 3/3] mm/hugetlb_cgroup: switch to the new cftypes Date: Wed, 12 Jun 2024 09:24:09 +0000 Message-ID: <20240612092409.2027592-4-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240612092409.2027592-1-xiujianfeng@huawei.com> References: <20240612092409.2027592-1-xiujianfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.26] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500023.china.huawei.com (7.185.36.114) X-Rspamd-Queue-Id: BD932140019 X-Stat-Signature: q4te6wxrxiw4bo913556ewtgr88bc496 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1718184721-38125 X-HE-Meta: U2FsdGVkX19Au1w+pZ2Dvlz6r2G/ZmAvk7xlgt3Omxu+fiSZ4waTP2YI5IybroCoifbQfMMmF0yMzOnhdT/LFZHTTHinub9N0PJwgdKzFtkczJKGg4DJIkt0NTP0Ycj5Jit+XhgV4DS+sKOVK7s5FazmEMxMUfDLAzWxAKj6IEsljFW6mL+6ld6jDaa9pHNvEK9y98QAUEo7KS0RC2aI1EE3Ax/WaUJu9cpvWuDbdq2iynvU0FxWogGSRis62G3UwkCM7PTLiyGQe5uxDpaC8UHKA1cjTZ0gszdtenmmLZ5gZaTvLqtGgDh5OE63m/ImAlhK5AV9n46svW5QqfMZFgqEIcW5YoO0WJhc3yEIQeqdU5aIQ2BXuprxYrtXa2kze8GPRjUPHUmIFu82eIaGEuLI5VrrLR4koHb4gn1OEJv8SANisILmsNNF/89xpj6llCYbSjmQ9kpZMGHDePqxim9j6h4V1wmueI+NqqG50mEesRzW2wSVJ7RxqHtoiT2IiOZjuf7pJhG7DH4gXxn+ZICCdB1Dog2gJkorCaO9KV3fKTqCr705yrAs1oYj4ixbN7gZviPgOkqG62oFXFc/qf2PuIJEvxOfw23lC+tE4u0Vvdhfafj0kkgRxw9SgQUEe7Q0CDJ83Gx7UvuOJZn1tosBKAWV2Np1YQYD3YXYMpE8FD8cpqy5IiTkKFAoe6lYfm+SPOJkMhKdKJPkSB1CP+yZaeeFC4URJdVZG13Hlf0B0cCYL0rHig5yCVUyht0BGbRJtZ9oyGx1V4mjfkRP3oQNREBohv0pin0HRX5YfpF98azsqLjjHldrL9aBE/nPTkR+x1UBZoRCngSYFZGF9R7ZxM+WfRmyAM9ep8EzOxlMuldA58YdP63Za/Z95RFBE8JdFKgZqN63fldTAFrJCLSvyMRkqmssx7GZFdcL2wxFTop7TcDDslsu/dmQF/mqvWxFjwXzNJWM/Am15T7 VofxXg/K Z3+5Heu+bp/SnyXbfrAZgiviEzJy+zGpBhcQAO43DIBbc/SypyAbvK4TttW+4v08HfvWVtUkE/isFTH/RFsr9Wwy3myCG5IYmPySVsqvHLVSB2BftgwEUlTdDlL6GHnirGg7QFYuHzNKAgk1BPCEQNl8doofDhbklg++U2Yv4Gw4SkH6TFVidYvTHNyU55pqoqx7t X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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]; }; diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 43aae8f88d5f..2b899c4ae968 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -839,164 +839,26 @@ hugetlb_cgroup_cfttypes_init(struct hstate *h, struct cftype *cft, } } -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 = &hstates[idx]; + int idx = hstate_index(h); 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 = &h->cgroup_files_dfl[0]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_LIMIT); - cft->seq_show = hugetlb_cgroup_read_u64_max; - cft->write = hugetlb_cgroup_write_dfl; - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* Add the reservation limit file */ - cft = &h->cgroup_files_dfl[1]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.max", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_RSVD_LIMIT); - cft->seq_show = hugetlb_cgroup_read_u64_max; - cft->write = hugetlb_cgroup_write_dfl; - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* Add the current usage file */ - cft = &h->cgroup_files_dfl[2]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.current", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_USAGE); - cft->seq_show = hugetlb_cgroup_read_u64_max; - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* Add the current reservation usage file */ - cft = &h->cgroup_files_dfl[3]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.current", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_RSVD_USAGE); - cft->seq_show = hugetlb_cgroup_read_u64_max; - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* Add the events file */ - cft = &h->cgroup_files_dfl[4]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.events", buf); - cft->private = MEMFILE_PRIVATE(idx, 0); - cft->seq_show = hugetlb_events_show; - cft->file_offset = offsetof(struct hugetlb_cgroup, events_file[idx]); - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* Add the events.local file */ - cft = &h->cgroup_files_dfl[5]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.events.local", buf); - cft->private = MEMFILE_PRIVATE(idx, 0); - cft->seq_show = hugetlb_events_local_show; - cft->file_offset = offsetof(struct hugetlb_cgroup, - events_local_file[idx]); - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* Add the numa stat file */ - cft = &h->cgroup_files_dfl[6]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf); - cft->private = MEMFILE_PRIVATE(idx, 0); - cft->seq_show = hugetlb_cgroup_read_numa_stat; - cft->flags = CFTYPE_NOT_ON_ROOT; - - /* NULL terminate the last cft */ - cft = &h->cgroup_files_dfl[7]; - memset(cft, 0, sizeof(*cft)); - - WARN_ON(cgroup_add_dfl_cftypes(&hugetlb_cgrp_subsys, - h->cgroup_files_dfl)); } -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 = &hstates[idx]; + int idx = hstate_index(h); 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 = &h->cgroup_files_legacy[0]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.limit_in_bytes", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_LIMIT); - cft->read_u64 = hugetlb_cgroup_read_u64; - cft->write = hugetlb_cgroup_write_legacy; - - /* Add the reservation limit file */ - cft = &h->cgroup_files_legacy[1]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.limit_in_bytes", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_RSVD_LIMIT); - cft->read_u64 = hugetlb_cgroup_read_u64; - cft->write = hugetlb_cgroup_write_legacy; - - /* Add the usage file */ - cft = &h->cgroup_files_legacy[2]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.usage_in_bytes", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_USAGE); - cft->read_u64 = hugetlb_cgroup_read_u64; - - /* Add the reservation usage file */ - cft = &h->cgroup_files_legacy[3]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.usage_in_bytes", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_RSVD_USAGE); - cft->read_u64 = hugetlb_cgroup_read_u64; - - /* Add the MAX usage file */ - cft = &h->cgroup_files_legacy[4]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.max_usage_in_bytes", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_MAX_USAGE); - cft->write = hugetlb_cgroup_reset; - cft->read_u64 = hugetlb_cgroup_read_u64; - - /* Add the MAX reservation usage file */ - cft = &h->cgroup_files_legacy[5]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.max_usage_in_bytes", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_RSVD_MAX_USAGE); - cft->write = hugetlb_cgroup_reset; - cft->read_u64 = hugetlb_cgroup_read_u64; - - /* Add the failcntfile */ - cft = &h->cgroup_files_legacy[6]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.failcnt", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_FAILCNT); - cft->write = hugetlb_cgroup_reset; - cft->read_u64 = hugetlb_cgroup_read_u64; - - /* Add the reservation failcntfile */ - cft = &h->cgroup_files_legacy[7]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.rsvd.failcnt", buf); - cft->private = MEMFILE_PRIVATE(idx, RES_RSVD_FAILCNT); - cft->write = hugetlb_cgroup_reset; - cft->read_u64 = hugetlb_cgroup_read_u64; - - /* Add the numa stat file */ - cft = &h->cgroup_files_legacy[8]; - snprintf(cft->name, MAX_CFTYPE_NAME, "%s.numa_stat", buf); - cft->private = MEMFILE_PRIVATE(idx, 0); - cft->seq_show = hugetlb_cgroup_read_numa_stat; - - /* NULL terminate the last cft */ - cft = &h->cgroup_files_legacy[9]; - memset(cft, 0, sizeof(*cft)); - - WARN_ON(cgroup_add_legacy_cftypes(&hugetlb_cgrp_subsys, - h->cgroup_files_legacy)); } -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); } static void __init __hugetlb_cgroup_file_pre_init(void) @@ -1011,13 +873,22 @@ static void __init __hugetlb_cgroup_file_pre_init(void) BUG_ON(!legacy_files); } +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; __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(); } /*