From patchwork Wed Jun 5 07:01:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13686246 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 D5275C25B76 for ; Wed, 5 Jun 2024 07:09:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50EBB6B008C; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49D316B0093; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F94F6B0092; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id F16DA6B008A for ; Wed, 5 Jun 2024 03:09:14 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 79CCB1C10DE for ; Wed, 5 Jun 2024 07:09:14 +0000 (UTC) X-FDA: 82195958628.10.341AF47 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id 48A5980008 for ; Wed, 5 Jun 2024 07:09:10 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=1717571352; 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=ZLm+g6YurgVM/SWhQxLU91h2Iant6voNfOH9F7zZvJc=; b=VseT8rHk4NIckY3z5e2mI3u9eIhYIbPlOY3SfQlB3VOQOkgmKqPSRporUnQgx63xU6P2fG AA6s1iqghyt0tvLU8YybVJvg9S/menHOkYFFZYJwsFWf9klXjC4IOIH4/HsbxmlbE8W+kM U4XGoqPJs55chjGmWVOChtu/xeNIOj8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=1717571352; a=rsa-sha256; cv=none; b=Z1nn7TYxezsc/0YsjlMvua38NiIvflDQQS0CU2ste3VuBR6PK8jTnR4DAa3YepbOf6LvCs EoJf2V5tMFgdzLqXdPIge77wFE85ItYuPv5s2NdHJBe7ATRJ7VmVA6ehxCEqK/5Y9H1MSK cmDW4TcxeNc9PLMqhHdpUJoCFpIwKdw= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VvJPg5KyHzsRVD; Wed, 5 Jun 2024 15:05:11 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 5AAF218007A; Wed, 5 Jun 2024 15:09:08 +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, 5 Jun 2024 15:09:08 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH v2 -next 1/3] mm/hugetlb_cgroup: identify the legacy using cgroup_subsys_on_dfl() Date: Wed, 5 Jun 2024 07:01:31 +0000 Message-ID: <20240605070133.1941677-2-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605070133.1941677-1-xiujianfeng@huawei.com> References: <20240605070133.1941677-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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 48A5980008 X-Stat-Signature: trqroxce38s3qbm1m7xrdsweks3z7iq5 X-HE-Tag: 1717571350-846109 X-HE-Meta: U2FsdGVkX19g/zyzdSiv7qmPYIRxxn/F3vE95ejNwB/5ynR+StUrF5stL6DxinQLWytbEPth2vhsvc/6YTvpdgYePlsFdlpmxk1MFmoMbN8bv9+SF89gaz52CL9sihNgLrYDl8wqW5kYCK4s6abyw9zImrTH7bxBGfhcmrNkNZQ6vCxcnclFprZ5buBGzROtAznwWQv7SjmcfsN76V1HNTHXV/O47RPIK02e4VX0uWH6/dkIJGLO62TOxA6Q8O/8hNZGsEIxxhWWn/Z3svOx462jqXx+ILw6c0fy0n+4bO3SBCxRRmKb6ckSNa16MwLua56KpnQwqRO1M0qR0Dh2gEC6+PdJSEyV5XMpAu44v0o5I6iSNukeUnrWRvDeI7Ci81kZOVqL1iewlm/DnpqTm8ViGjsH5HXAhjPX/fWupBZ+yQhE/6RxodBKrxD5gaGvZT/5+07xmFZW+4jW4YNdTRL5rDajfkpMyqq5JSqbWergUEc5h072/WNGEExCsSqkZ/Y8Byr7Xr5/s45QJr8WTiZdm5viPH2ZhU+V6N25T7F49bAPR9ayMV+KvvR5taR/hKQblEEggzN+FzIE8AJSzPAqa+tdrpxEW5aNRuiM0Juy6m4yyk+r85yN9OdPFctdC/NdsZAR/Vj6dPNggs7lKWrvQsudnYjG+PbH6Zx4gK5Lzs9QLM0bKIc8HWHZK9f3YCzLwgM4AnIE4cCelGJtrTscLkTkdrNkkeSw9jNDnaiN7ePlqZxilTJycNvxC+zsnCPbBTmlHaNVQcHmHXScGdaOhW7jH6MchzOVr2MfeZgnLMT329Smm5WLqOVYSrKIblOR22CXfooX6jCxUiqgedkGZjd4Q2jxQJyitLRgvwLFfMnzAY91nAv9HUX7rvbDbWhnykWoLMIXM0eQHCV35b+dFurWQApXLaU5Sav+hULSg2/Ho0F8iIB5zTjwe0e9TIfykBFJLFhPD2Ggarv l1xs23jS 8rySEbD9XJCrf/3CjJp512xZcsA8C9fJswprf8CmfpWYsXUkxQ2QwnOTMF8zEp+bM0eto+PgT5XFzyHmwm6aI4eotD6767QzGXYyZCLLoAd/1u1y02PqqQbicbPpj3a7sE4oDSTSat53WsM9Z/s+p2iELKVbs2w5CDOZAQXMTXFtg1pEJOktGYkiUPiXtQFOCJeLE 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 of the comming patch. Signed-off-by: Xiu Jianfeng Reviewed-by: Oscar Salvador --- 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 5 07:01:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13686247 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 04DBFC27C52 for ; Wed, 5 Jun 2024 07:09:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 975CA6B0093; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D6806B0092; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BBEC6B0095; Wed, 5 Jun 2024 03:09:15 -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 373AE6B008A for ; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B9D0A121351 for ; Wed, 5 Jun 2024 07:09:14 +0000 (UTC) X-FDA: 82195958628.14.28B8C6C Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf28.hostedemail.com (Postfix) with ESMTP id F3365C0012 for ; Wed, 5 Jun 2024 07:09:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.191 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=1717571352; 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=13n6CPg8A5x7YnqC4PXMCysMGL4xLs7LqXVwnk6N/CU=; b=LCwVuRuO+5wBlbAVTsgZOX8EIFYma50TRjNxrDdAQMCYDi1NXiCdmt6NXFKPjUNpxaMpBF SoA8vRJTm5bdgfvFe0dGAO7WqAj6sUijov549Pih+S2gM/aOPg6Q0nGnCz4kGzB7fz2gLP slK0+9ueI2cipWqgNIxjiaCBpDUoqoQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717571352; a=rsa-sha256; cv=none; b=bNIFeut6nYoAMJWpVm+MT8jDFiOrZtQdrnpElhVqVS7dNV/6op4WkoHihij749KyGYiRaT e0wCHWa/qDwtmp5E6rdYeK3Jv7cPUD5zHPe0UbmCZUZHKN5oA2xdriScICRgkivQvcQAnU gEwWjeYU0QcIgHPQKdvnTryyowEg0EY= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VvJQ001tBz355cs; Wed, 5 Jun 2024 15:05:28 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 16EC11A016C; Wed, 5 Jun 2024 15:09:09 +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, 5 Jun 2024 15:09:08 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH v2 -next 2/3] mm/hugetlb_cgroup: prepare cftypes based on template Date: Wed, 5 Jun 2024 07:01:32 +0000 Message-ID: <20240605070133.1941677-3-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605070133.1941677-1-xiujianfeng@huawei.com> References: <20240605070133.1941677-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: F3365C0012 X-Stat-Signature: usdqbhyh5hwnx14sb6c8j5isrq5fs7eb X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1717571351-572112 X-HE-Meta: U2FsdGVkX1/AMDt5mMyMUUfdwSg99FdieXpb0SUeUbNm5UzJenv+Un2mWpMDXF2+9nh2u4t0SvXjCJdNM7P25AJ9KSIPweftDldNIzoB3udGH8zXSVEBda1kWzSwrOavVGPID3+TK6uMCVmXDYEr7L/p1Joqbff0T9j8cK+9WESi6r6PxLIJXuHCNsQiR239pIiePQdRG+oPRy/oSclGrMGLcJJnaDBpTNfKPVx6aF1O+kngl1Gi4knJ43DAw2Tx3vGa7JydGtChJvgsNQzk2ZX3YpBv35rer7XfLxGlIEjsq8a+HJhc3yR1CLK1R6m9J43vT1lmMmqWg+9aVMilw8iuIabvG5azk/1i1XHLW6GgPGo0kCqG6hNnictvbKggrtW2j5EZkEXEHk5e403y+UcIGAEv2J3wgSeDtt3lffvojG+nA9XnAbCc1zYRs9q00+6n0QfGtwuDwJnlg+j0zgQx/NkxU/nWshXwoyZxpbDtv+SAjOogndRlubLn8wA/mVqNC96sY7Y5jyPzZyYEJ1+vxcAuN+gHsa+s+EmWrMTSErakb6fZ21hjGQCyaWuDYtDbkDSkXJT22L1YIx0uUzNuIQkQOuId1G8TkygVAkH78q5IEtwGVvLc78XiWuMDome3yHM7DFAli52f2MXE/WXtlPJFGWYMd2mHwTB6tuBwCuE6L/Ln9+eujqvRUzMbdmDt4bsrEIRzipNm2SwkzwhrNLio31RrBZdl7C2dEghlf4/Q8vzjEY6nMUGju9trzaqLjNoObhjtQRVupWx6ZEVlWMlnzzA7t12YpMAIfUEVOq7yY87HjmXYfDhcrr39+1L8UtNJriltfazvNDTZlDBpJ+S7VbgzJVXOmrzfwgARf/8s4RqTe8g8EZrMhKEAES2yh6+BOf6wn/Mr1h+vz3h6j2cYtm21wnnBVhD7Evt9/ivx3exrLCyvicW8fiwdcnPm2MMWunZJC1omB4r XqrwOTwV BHaStMc1nqhmbelXxNmggek+z7hlm4ZYaLHwJv4jR5IM2/nEwzBY0uNFpulT3+z1TEyyut2G4SO8C2M4A3sJ3f77whkNQAfpdJi8D4kLnyaM/JGY8tgRFZeL9X1dD3n+NNwjef6c1IUlboQe4j4KyB6XBGLdR5S3q1dDjJDB5lTyt5WkHmMFE5DYcnXyYoJ2PYEn1 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 | 155 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 45f94a869776..56876b61027d 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,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 */ + 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 +918,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 +998,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 5 07:01:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13686248 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 D9332C25B76 for ; Wed, 5 Jun 2024 07:09:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DC286B008A; Wed, 5 Jun 2024 03:09:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15E1E6B0092; Wed, 5 Jun 2024 03:09:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC9B26B0095; Wed, 5 Jun 2024 03:09:15 -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 BFE896B008A for ; Wed, 5 Jun 2024 03:09:15 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 62F47120E9D for ; Wed, 5 Jun 2024 07:09:15 +0000 (UTC) X-FDA: 82195958670.15.6C96995 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf25.hostedemail.com (Postfix) with ESMTP id C06F5A0004 for ; Wed, 5 Jun 2024 07:09:12 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.188 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=1717571353; 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=rMAsczibYIY5qkxlWK8PIOsIyTK1AYE9QgSxyE0XY+8=; b=bCY/1cdx2i/3ae/vzeB0UZA7+Y9F9draaqs+xf55Fvnxj4s2tr62HTaXMENwSt2pTcXgvP syomwKEImgj4E11oeeeL/aQzuxhLk4sLs0R2Slfj0+e6qicQ+5jyHyYyfd1ngA9FDx6NbG FZZaUdKt/r0KiSTsUmAGLwPXBIXRTTM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717571353; a=rsa-sha256; cv=none; b=l6YWIkOTegqLABxv5BL7N/1YX0p5AOgsYtRP9cJt+cqoxoww8iOW+fO/WkYaYtWUaaNQ8Y 71wOPs1wktNFxRId9Av+XZNiw48VSm4CC1+hTDHF60N4DgnJbpFTScN6nxu05L0WJjRVVk iIpR69ELjrcWOuV6Jq6l05RjkRlD/tk= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VvJSd4qyjzcl5F; Wed, 5 Jun 2024 15:07:45 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id B4EFD14022E; Wed, 5 Jun 2024 15:09:09 +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, 5 Jun 2024 15:09:09 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH v2 -next 3/3] mm/hugetlb_cgroup: switch to the new cftypes Date: Wed, 5 Jun 2024 07:01:33 +0000 Message-ID: <20240605070133.1941677-4-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605070133.1941677-1-xiujianfeng@huawei.com> References: <20240605070133.1941677-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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C06F5A0004 X-Stat-Signature: dq3mchwrdpdft9hm4jiqf58o65zgp3i1 X-HE-Tag: 1717571352-923675 X-HE-Meta: U2FsdGVkX1+X/lf/Cao1Sl374x/gFr4iGeLbTY/khGLHzusNZPurt+4NBR9LusjNWtWUhy1nj0UkSIyCwWki9hRkUAYnAzp2SCbTdW/CYPeAlFYOYOSBvpZlrbRrqazXE28Z7U2S04WHswmOfxPzxN8XXpx8lJEJ7lexxumEIw6C1I2kAD0dc5tqrGYD7Adsf2He4DR8kQ3frqu0GuGAKl0qCgbBBJbrqDQk5jjcsDP/O1IIutBlH5mpVF1qshP1xHesWFnWLUcJ01CauZuEfemmcElYf++yEyRfdDXUKMp0AQAf5Lcm0kTvoIMLeG05efyZknAfP43FUCi6nQIuqaGgMxEjbHDos3mZB1elOEZUbhGUGU6uz2slWBFZAWNLTrYWLs1IMYpmL5yWGQEhKo1eWdtsPUuHj7mZfyWEBXiVOcxaC9cYzCj9YlIeqjU/RDMYSWhEguG4P6neJ6jhSprzuJ1P9kT8gSSgSr/+rqXWP4SlvinKOYBemTvEUQSEdxSUo71GryoYlAyZ5kgQJqOV/odsFHzDACrQ1SjyHqvG0CdFDf1Sodpk0GHG9oxOgGR3SIprcXSyUEuzxDuxagLzEUD7/YNbEsNdWXwJ23vXPoK64eWmPF0rmbt/Hk9Rk86KJi5fRLY5O2+tI6wT+upMCG7DxTVldXTGvo7T44DAd0w4R9qC/Mpd24Fv+RV370RwzivF5fQI6ZzGsI3nvAbnNNmiXAvd5jyPCRrMGWxEHZVKxVI9H3uNstcGmXuM8VPIeFK01T0NbTRCvjIfLxCAHoVk1xcB+y8yioJy+bmd60WT627SnIUNC5o+MGxjRE19eU43/ToHieuBg//zfsms7LPOeEys+mKlP/ZlNWTup34unm4OvWE3LR7hIrcpGFzLwAKGGHfWYmJ8Uqc1WTnzDaPDU8kocscDxrAQwElayRyX9yp5w7zIZI+oaPAyAJcCBq1mDPv0UnL9EU9 HwW6TG4q 3/E6u7cyr2HEeItlTN17mQC7lRXkVT/DDN1vL26Dgk75mB4FFNyNQNbIY2qjYioJsSj1nIw40/FmtBBgw6Va/CgNM/WyvO0Xig4nXqwzbB5msjp0grIJrml9H0MHOzx5mcbDnH3c6EscurMEsuJjM4IJXJcZbvAdp1w2O9BEIX/VVOBZp6/NmkdVEL3CDRMf64nTH 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 56876b61027d..11806736ab62 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -838,164 +838,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) @@ -1010,13 +872,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(); } /*