From patchwork Mon Jun 3 12:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13683727 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 C6F41C25B75 for ; Mon, 3 Jun 2024 12:12:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51F826B0095; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D0786B0096; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3705F6B0099; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1BFF06B0096 for ; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BD7DE80DE7 for ; Mon, 3 Jun 2024 12:12:51 +0000 (UTC) X-FDA: 82189466142.06.BF50E95 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf14.hostedemail.com (Postfix) with ESMTP id 805CA100014 for ; Mon, 3 Jun 2024 12:12:49 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.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=1717416770; 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=70EliohaERBf7VAU1Ekt+wf6hOHMooOBNdpsZ2TcaMg=; b=l37biMasVbW6WlE/pMP2ZkV+deFTeGywPDX9P3JDIAN/u4XOXPG2tZjkF8HFClILzS0mEC JCim0ZCmV74A4gGuz7rlJ7xoamFks7oqt+V2ja2jb5ScZfTq4mcKnCGXpkXkudOsAJcbvR Pvu27k258C0an/D2EXoj0sAai4K3Z5Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717416770; a=rsa-sha256; cv=none; b=LHTfLsW+k0BsK5Ea+5wXBeIxU4gD4vWwyj6ckOx41Ijc2Vfwk0VWRoS6cFDzG5p9NVrR7p 7fk9f/gqjazQlOS2uM4W+3kLJyL0UewwgFskumaCoOOH6b6BbkyXh//GQjJ68uBEM/dQ4F djvo9Z5JryyXA4xcJFLFw71IG08pwlg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=xiujianfeng@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> 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: zn784g6urgfsjkedwffcwd99gtndmkfz X-Rspamd-Queue-Id: 805CA100014 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1717416769-848734 X-HE-Meta: U2FsdGVkX1+K1Kla6+niA2tbnb09vKp+EZ84nem/2vO1SCrUUoXmpnb8Je3GAQ8tkLINrLqr0sVZHtC2SduwrXiOY6jhBadIiEXIA7D6IjghQV6vNRUzfiYh2wzDSW8F3Gw1A8+44+6VREx0BSxgGgiX3JHdM2pbqExNcGwJoaVObetVGpte76nevtUSBVvhid6NyWdX8wPXV37OZM2yLWBsne//tCGd5vfRvwFMAeIA1o8RVI5gNnDRWckkB2k30Rpnn0qwnJsU2L3082jTRcBRwGgCGyMRTvp9vUJwjZYPuqRSuovgdt8mX8pDpEXiTEr1N0+QJ8DtYwXlXLbAmqsUWzKPkG7jHkXOV/xtaOVLUTWsXKqLWW6UYynT7tbsukBhXMU07ebqZ+JG5Q57zdHYMAJROfrvqqCA5emFAnmhcFOCVOvmv3N4K6fvDuqMCySF1TdP9t1RieGXkxyxjbMxqv28TNVRf/R+3tWX1yPVZICt2PQ67Ymd3cCUDOsLNN8crzg31CB9eU8HSYuLzBzsb+CxsqkYnDXCoXqUwpJXPN0Us4FPKVWgZHo4nGgB8tYL6JZcQVD+jNzu4qUOQbh3oVONxOJNEkUic01TUAlpUB6p2IvD2qZmELliEd0mov9AZptMxCKRcQmgtpiaaArVlgJWyCjmJmpN4uth4cn0Ccpx3a+VM9wYvH2P4NqhdPNpvr0GKWU4uyDq+39pBNDP8wA0Hil5Uikr65GclUEU+Q8+oaRJCwnR6SdmLBqHjsEyIyZZjeHMLUdzq4B2H5YSPeoiYGY+TS0YJQj1AbMwY4jO8gCAw5utoP9k93IBEHnUmJexkYxovMQIZHd5kFWkxXP6TjT5LqmL6gu0SE1qhPxjyNrHZIUIck4Z6DTiD7kqdT9t16pNe8t2nOApHqwE55IArQ/yRnc8G4oKTBPPAg5ecW9s3n7As08iU2cLOOirE6/rF4WHEZcIKIE V7y2ErZ3 UVziKY8RFBrLCnH62RKIQzrLtNMfFObfJKflmekxAIoFHXliSQKQg8YVvKauzvp3rU9mj4d6L89+KaGzOcY9B1tdOvdq7q+aPSuU8Up2EipR/TdPrmxLAedc7e3LMpcbED+6xp0v6ufO3ZRoHBGAdfyUR3W0pYnPYUNLv/s4bRGD/3MR/hSZGxuXj7qvjwYdw4kmk 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: 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_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 Mon Jun 3 12:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13683728 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 CD620C25B76 for ; Mon, 3 Jun 2024 12:12:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 770816B0096; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F7116B009A; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 431F56B0098; Mon, 3 Jun 2024 08:12:52 -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 21C8F6B0095 for ; Mon, 3 Jun 2024 08:12:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C42F5A2523 for ; Mon, 3 Jun 2024 12:12:51 +0000 (UTC) X-FDA: 82189466142.02.2EDC4B9 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf15.hostedemail.com (Postfix) with ESMTP id 4A9CFA0003 for ; Mon, 3 Jun 2024 12:12:48 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1717416770; 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=CaVTNr4vMZ0wmkOABc7zKPlT7Xkb2fm4ZEmPQrQor48=; b=z9pd277FouivJjPsQgg39lMn1xcalEeTZb8GRi5ITT+xeO2i5kM/Jt7N2e5QxEIA7Xo2/J c/7pNZpwqQWBA7pERwg6FFUV2HAd1wQv+oJZlvdI4I+FHDfGBanjv7tBqPURW3Ea35J5Gk TSwFOMPWZXG6s277wUQg//mw5VeKB2s= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1717416770; a=rsa-sha256; cv=none; b=n9Q9AHOV0oRESLY/AIEj9EC9JsZofra53P5qOdFyK/2i+W0YMzawEG9hpecWAdfm1rsS5/ 1Yr0wqnGCPGdsDuxhmyHznx5b0eFmEihEinQM6mtpffHs2GF/AviRVk5MJtEVzm95PnyAy lF2oNCvvvikiWOen0W2W4Tc0e1FAbGo= 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> 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-Server: rspam05 X-Rspamd-Queue-Id: 4A9CFA0003 X-Stat-Signature: 688f4whh7gxdy1m5nbs7y4kw4wy97483 X-Rspam-User: X-HE-Tag: 1717416768-530302 X-HE-Meta: U2FsdGVkX1+tHpG9qpusXFrV867mfqvP1qf99GfkMuio7jf2UozCoS6KZvsk94mdVbyFQT7lL5JPmCWHIsZ0P6J0SJxaiYN8h2YMbctA4omL3vNhcCDQKEtv/Z8MT1pSlZrcWDqS5mt6lCFBvjU4LIEejc6QJNuAW8ti8qKdmnxyQ7bjOZSrjnOL/4vxy/UfZbdYCjQkzml2fS19p/QT8aZwJRptBrgNmQ2rPy5auXU/+EY5I3D3AVWD+JEP9b0ohylrTK90HsjV2/a80TkxYzkdqRRPSipfsgQVD72dou+ZH1egR5mIyk1JoM2wnXYs0nueYZhkP4FiU46In/XslLS7Au1/twPSp9Qy5AXfp6/46JcmksAlE/9NSicf/srlrEVEi4/h+/iDDyiCm+WpeFsnvmx9hEVf7CHfq7iPkyxXINbo5kHQd3uUIkhwg9EKRtJl/zHAyH8YFK2l2DLRARt9Q5KuVqCOryX/iOXleRiqowpVNX+F2O0sqj/f841AiXxeAyNl5ehDyuZS3T6M2bHYUYZiDiMgksuRPiU4Tph8RsblaxNCPFiLY5JvqQz9dEL3N6g8hvkbc5DveGt/SbzMexuRi9nCPBSTZ2naFQhpOyFaZaPsILSfdDQwX96QrIpOI2YIFRTkX5jfoqJT9bH1npnHyjmta6GyxtFIREVzmYTe8iOr+1z52LeELf6ooXtf/mci3wG6H4XLDfOh26mnVAqqKA57vIVvks0nk48uhNlzwIBAaLihPCNKXUaJEcZLgoj2txihPpRmA239mFhWCtwlZYxSuEhiXxPkfmWd4MfvRwwGf96Op3aHt6lM66J5rT98UxiKG9DxIzb6DXH1oOs5/Jrvm8uHKoxK7WDIK6+A33IiwN7lgNZskFWByU5lv5RSprwQn4XoZCkhhCVJCpaSSQ15RntfUll3sDoBaWw7RiCBNTY2N6ygPC7HuTaDr824tFKx8/lsYU0 uW/P9ZxQ zoRcJiDrKZ9K75WyWjbclQE4vQqKBujFqjptv06cfVLt/GNTs20rGO2F1tI9EyQKEvs357Rvj+KNlG/8xgitxSYnVlI5LliXN1lnQkY5S2JXMZTBJq64tHNLEkcu/kHMmYbYgRuqytFUv3mzVnBB28G2WW8Es9l2VJJ2AH66q0fzQ8FCZpCdbMYQOdLG1OhvrbH7n 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 | 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) +#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; 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); } +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 */ + if (tmpl->name) + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.%s", buf, tmpl->name); + /* rebuild the private */ + if (tmpl->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 +920,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 +1000,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 Mon Jun 3 12:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13683729 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 F22E6C25B75 for ; Mon, 3 Jun 2024 12:12:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 940736B0098; Mon, 3 Jun 2024 08:12:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C9AA6B009A; Mon, 3 Jun 2024 08:12:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78F016B009B; Mon, 3 Jun 2024 08:12:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5AFB36B0098 for ; Mon, 3 Jun 2024 08:12:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 226F9A08D8 for ; Mon, 3 Jun 2024 12:12:53 +0000 (UTC) X-FDA: 82189466226.01.9CA5D0D Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf29.hostedemail.com (Postfix) with ESMTP id 98F1412000E for ; Mon, 3 Jun 2024 12:12:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.35 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=1717416771; 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=WoT26sPqmQVqcYQIthu+ymf8knmPQjXzuM04mNd+vK4=; b=lMz3RaIG8qs7t7f7+njzuaiDi2T2CM0zA8oLb937Wxak2ZddLgC7362bC5bkSPwe51qnPT 4d7QrFJnbHA1ldRQppNilRjz1wj7yzBGONIo4LZpwoK9aWjUyC/1Zp3i30eshiTODg6vFV 7GqnTvwvAtyGOQ7jVLPcgiOGwdSiccI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717416771; a=rsa-sha256; cv=none; b=OkuHC7MOlSxjJHDofswQze++uUn1vzQkyRYY+ETwCoXkMQN9MFkdpK1A/AY4sHichJodUN gCRqobqg9uqXdOYNXcPXJYsgjOTAFdQ0eEbYTDz1hLnf3qlOnTsumgsZu5LihDOC9FAaPf c8Kd1E2u1TrZ8gltugI7GBMHKnv9w9M= 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> 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: 98F1412000E X-Stat-Signature: hpb5536grttm3uuufgj7kjjx1k19m4w8 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1717416770-582529 X-HE-Meta: U2FsdGVkX1+IgAGbjkOrUOJ7rlS72rs34W91L4LxJ5nmg9WzQ/TqEHNJkX7Td0ypro7CcS8LK0nQbIbtF86IW+PJRSuY0hQlsw/1yjCcoKIq3fcrvSIMOvoYI97Z8LHBM4ArIRBWDKCMEqlTayYg9zGIQYvS5TeOpZR4uzFXFJRw2gmnShgnLSE14/Qekh+LEqeHPw48uKQp7jK1NX5udIwpQuNaaBObccTHaJa/wnuJipTSaImXNkmSnggOzOAeyxMUnEZVQ+F24TxliIqtG3D+61PBCoLCW81opm5PZPL8ZZJ929GD/0Oqqf1XGGqY4eYV2DwXUVs5rkb1+eRZV1vEzdkkE4eY+ZJasL2JGmC2AmDLxxKmrprG01jMXNjVAJVAqckq6db7Y5gGmWpBc7mcf4JR2zLgXK/MtQtiJVgeoZe4/2wLFw3USTIuUzTOH7TRcE9ZyosHzDS7Ts2PRAdINIyEcBXWwb58Tph1B2fG7iwjeO3fk1OlO2QaLfuTZn6m/qZliIn+Q6829czmzkxR301yQ8drs2Kdbz/EiLDzNJqHH1dIFwigr5Ll9scqt3qzIeMeRqnvUukgI/JOMmro9arckdY3W+3TP98mSYejSFeXW+9R0c3sWX2vs0zQasnOZijChBd6DNF7Hn+hIQVDXcVmK15V4xIzTTt26i+pbeomiUInnD6fLPipMqb5gc4AAJYJB+LZZiH6/MaI46rW52kAmm2Aa4+csOiju+uyw21t1MWkv+sm6z+HiXHkZ33hjjW/H3cPFxAP8ci4e8r7qlafDeqAnCpyUAQtle3KbnweCRvt9Br38FIuOZnrNgldFlR3Q00eXJw/QlWb2BzhnhWi0U67rqRt1YqyerWhVg+rIM9hb2eeFVO40pe41MdGVXQQo1B6HH5l+ApcnJ89F22nC9xDsbqe8ijO/ymH7/GJUgjB1HI+jiNZP8Tk0xfl2vtJYEFl9qHX15D z++988dR +ymo3zYf18RgjyIbyjaLIi9M3brDpEUlkLsBOqjRKaiTx4iVHNpBNgqN2UGGgze2H0RN2iItRTOS0dIuGo21cKjn9Y3K0rfnDsGZRmbzW/hClV0O9BC28gnqJjttO5OQiVyOcS5hXDWTkYzfw/UDN4H3wa6ZNUFz434I0kFW+eWHh04ZGWEasz4FQsH+VVJAqQeEI 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 378f2353443f..856296d865c6 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -840,164 +840,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) @@ -1012,13 +874,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(); } /*