From patchwork Wed Jul 24 20:21:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13741329 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 82DF5C3DA63 for ; Wed, 24 Jul 2024 20:21:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A7636B0096; Wed, 24 Jul 2024 16:21:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 559016B0098; Wed, 24 Jul 2024 16:21:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 384CD6B0099; Wed, 24 Jul 2024 16:21:25 -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 1937B6B0096 for ; Wed, 24 Jul 2024 16:21:25 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CFD46C0B70 for ; Wed, 24 Jul 2024 20:21:24 +0000 (UTC) X-FDA: 82375766088.14.151B9DA Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by imf05.hostedemail.com (Postfix) with ESMTP id 1725A10001A for ; Wed, 24 Jul 2024 20:21:22 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=XFA8jIM6; spf=pass (imf05.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721852459; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RbJVQD3TgI+54uWuq60CTiNA5H84vr1UFlO22URjpZw=; b=kcXwWPifleqK0via4BIgIlvdkIKfPYse0iGFhzqsVE4ZysqUvsyBVYuLub9gRsdGtiX3zY KnuI4o6pSDsXO/xXUXu316QA/QYKu63NCNoWK/3Y1RyBzX7LkhYd96bouzyAicObKlVk4z RKVjpUkjJdieXo9Q5L6AfldM/t4pvRM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=XFA8jIM6; spf=pass (imf05.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721852459; a=rsa-sha256; cv=none; b=aXldekts9dIu82GKGYLz677m4kzj5kZbLA/CS+ac078UBzyPRxX4YjAje0kEHNIlgrmSdA jJ89fTnS45PTp+PYrZ9lj1/mOSsGxy1V9h5LyvAs8flrM+rYbkiVpL4u43QdRIjM/VbZi5 L12SboEGZTB9MYO6a7G3gEBiYw7r2Sg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721852481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RbJVQD3TgI+54uWuq60CTiNA5H84vr1UFlO22URjpZw=; b=XFA8jIM6d6YlZvs65lqN/esSuPBx0o9tFNHsXfxctPo1QVUt3t4LZ/Po0rHiqPuE6VV37t FLQGGNtpnaOtHHfvriDKQk6v8RDs8U8jNlo+8Q13YXXDeXy6z3urqp8AxhnEqTepPWFW6I 1NAO7KX+aLhwM9nZvAWFgp3X3Eu0Tko= From: Roman Gushchin To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Roman Gushchin Subject: [PATCH v2 5/5] mm: memcg: convert enum res_type to mem_counter_type Date: Wed, 24 Jul 2024 20:21:03 +0000 Message-ID: <20240724202103.1210065-6-roman.gushchin@linux.dev> In-Reply-To: <20240724202103.1210065-1-roman.gushchin@linux.dev> References: <20240724202103.1210065-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 1725A10001A X-Stat-Signature: 3xpw4chatjjb8nozf1rtdfddp38g5dri X-Rspam-User: X-HE-Tag: 1721852482-744421 X-HE-Meta: U2FsdGVkX18x1/NXfiZfr5WRougL0nnkA4XID+eibgfumdZpL3Wvg5288ItvntyDuw1cNFCYpKAgeeAqjcwi978EcU5OTZTc/2adTDmIvYyA71YOgSqvWyJfFS2/uWMqNBkzSKcBlbU4Ka2o2tbCexHk/Ev2Ltku/zfXDGdE3JCVx/YxE/muErWgU+GPjlyQHgLnoAVrLJOJxSMbbJCq35cuEZMgDcpydOn6NEoSMS3dFpTPRZicaXUCZ/47y+z18rRT7P28bUHcyn4NbBcpO85V6bLfYwTAelg3JGsYKJhedtgvcjQ7e1wnzD2oVjpB772uPm24EeK9z3sLAXRFWDNdSO03b33bauNhbRBabBas/bUo9FaIHXdRhV6/GsmWiH/U4OY0fI/LWr/h+JnGGZR0g25R3I2koZKe80r/Tf717Z/3gsGNAuD7d1xhqkR3o+qVDRmtQwNUVkQdv+ALShEiqjUpM0JbKf9yxPhpqCfZ0V8ErqU9iXCkoEs+HCyOmZU27oAsvX73q9uUQQjFvG0eqqoNqpkETT7NJB9MI25InnecKfTE/gmZVBJA1HqG8ANxpQs6Kg1KhB4pdeGHzRnZBHpIAJpWndhNXt8WxMj+YGD006Y/Qav1hXEKrkhuHkw+qk5FiuNcDUevkjY8BS9q3b1OL2jVjXE6FZp+DgZBmyuA2T+2EUu/O9rsNW+cDyzdk0aD2IIvWhsaNtfArKcQUB7wS1Bi3ePGk5/9s1veMZL393M5cgrHP9dX5m4lFyreJGVL/hlFjkLu+jNsoLzdWKQLl8Ll3rKfQhXiyheJv/3gybxuB3DdnazgRY1biHb8Dd+aeM7abegtu0xjbQ2tPqZoPwJRu1zMxgnNBNoc7fz8xob6X1tNwNtLOJxtNX0cmjo5XYKiEcc89cVge79IMfmDbL6eWW/IToMujVvbCeBsmEBiIE30mPqNwpe6J74NTRR6prqVD9g8OaG EqoOcYn3 tNNOoYbZJm0e4kMIGsj8X9pgSgwzkDcvtLyNn0Vcb1klQYgkWH1CrDmTWQ2d7LoN6sOwOKn4GNjFS0czwD/ahuReO/HU5TGda9L8bXhIsTAlHrOBjIfrjsOP93yyBQIYTIK/pz/PjHs7i2gLnqHMUkR7N47f+I7oCn3QpSuzWeGPFusbfteYYTM93m+rvYtt9jtfifshrhJvPGJZgJ6qpcvcPMg== 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 res_type enum is listing all types of memory tracked by memory cgroups: generic memory, swap, kernel memory, tcp etc; and it's currently used only for dealing with corresponding sysfs files. To prepare for tracking of various types of memory by a single page_counter structure, a similar enumeration is needed. Instead of introducing a completely new enumeration, let's re-purpose the existing one: rename it into mem_counter_type, change items names to be more meaningful and move to page_counter.h. The latter is needed to have the total number of different memory types available. This change doesn't bring any functional difference, it's a pure refactoring. Signed-off-by: Roman Gushchin Acked-by: Shakeel Butt --- mm/memcontrol-v1.c | 66 +++++++++++++++++++++++----------------------- mm/memcontrol-v1.h | 8 ------ 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index d8bf89c76cc5..05433c0a73dc 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -1497,7 +1497,7 @@ static void mem_cgroup_oom_notify(struct mem_cgroup *memcg) } static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, - struct eventfd_ctx *eventfd, const char *args, enum res_type type) + struct eventfd_ctx *eventfd, const char *args, enum mem_counter_type type) { struct mem_cgroup_thresholds *thresholds; struct mem_cgroup_threshold_ary *new; @@ -1511,10 +1511,10 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, mutex_lock(&memcg->thresholds_lock); - if (type == _MEM) { + if (type == MCT_MEM) { thresholds = &memcg->thresholds; usage = mem_cgroup_usage(memcg, false); - } else if (type == _MEMSWAP) { + } else if (type == MCT_MEMSW) { thresholds = &memcg->memsw_thresholds; usage = mem_cgroup_usage(memcg, true); } else @@ -1522,7 +1522,7 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, /* Check if a threshold crossed before adding a new one */ if (thresholds->primary) - __mem_cgroup_threshold(memcg, type == _MEMSWAP); + __mem_cgroup_threshold(memcg, type == MCT_MEMSW); size = thresholds->primary ? thresholds->primary->size + 1 : 1; @@ -1579,17 +1579,17 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, static int mem_cgroup_usage_register_event(struct mem_cgroup *memcg, struct eventfd_ctx *eventfd, const char *args) { - return __mem_cgroup_usage_register_event(memcg, eventfd, args, _MEM); + return __mem_cgroup_usage_register_event(memcg, eventfd, args, MCT_MEM); } static int memsw_cgroup_usage_register_event(struct mem_cgroup *memcg, struct eventfd_ctx *eventfd, const char *args) { - return __mem_cgroup_usage_register_event(memcg, eventfd, args, _MEMSWAP); + return __mem_cgroup_usage_register_event(memcg, eventfd, args, MCT_MEMSW); } static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, - struct eventfd_ctx *eventfd, enum res_type type) + struct eventfd_ctx *eventfd, enum mem_counter_type type) { struct mem_cgroup_thresholds *thresholds; struct mem_cgroup_threshold_ary *new; @@ -1598,10 +1598,10 @@ static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, mutex_lock(&memcg->thresholds_lock); - if (type == _MEM) { + if (type == MCT_MEM) { thresholds = &memcg->thresholds; usage = mem_cgroup_usage(memcg, false); - } else if (type == _MEMSWAP) { + } else if (type == MCT_MEMSW) { thresholds = &memcg->memsw_thresholds; usage = mem_cgroup_usage(memcg, true); } else @@ -1611,7 +1611,7 @@ static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, goto unlock; /* Check if a threshold crossed before removing */ - __mem_cgroup_threshold(memcg, type == _MEMSWAP); + __mem_cgroup_threshold(memcg, type == MCT_MEMSW); /* Calculate new number of threshold */ size = entries = 0; @@ -1676,13 +1676,13 @@ static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, static void mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, struct eventfd_ctx *eventfd) { - return __mem_cgroup_usage_unregister_event(memcg, eventfd, _MEM); + return __mem_cgroup_usage_unregister_event(memcg, eventfd, MCT_MEM); } static void memsw_cgroup_usage_unregister_event(struct mem_cgroup *memcg, struct eventfd_ctx *eventfd) { - return __mem_cgroup_usage_unregister_event(memcg, eventfd, _MEMSWAP); + return __mem_cgroup_usage_unregister_event(memcg, eventfd, MCT_MEMSW); } static int mem_cgroup_oom_register_event(struct mem_cgroup *memcg, @@ -2414,20 +2414,20 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of, break; } switch (MEMFILE_TYPE(of_cft(of)->private)) { - case _MEM: + case MCT_MEM: ret = mem_cgroup_resize_max(memcg, nr_pages, false); break; - case _MEMSWAP: + case MCT_MEMSW: ret = mem_cgroup_resize_max(memcg, nr_pages, true); break; - case _KMEM: + case MCT_KMEM: pr_warn_once("kmem.limit_in_bytes is deprecated and will be removed. " "Writing any value to this file has no effect. " "Please report your usecase to linux-mm@kvack.org if you " "depend on this functionality.\n"); ret = 0; break; - case _TCP: + case MCT_TCPMEM: ret = memcg_update_tcp_max(memcg, nr_pages); break; } @@ -2738,30 +2738,30 @@ static int mem_cgroup_slab_show(struct seq_file *m, void *p) struct cftype mem_cgroup_legacy_files[] = { { .name = "usage_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_USAGE), + .private = MEMFILE_PRIVATE(MCT_MEM, RES_USAGE), .read_u64 = mem_cgroup_read_u64, }, { .name = "max_usage_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_MAX_USAGE), + .private = MEMFILE_PRIVATE(MCT_MEM, RES_MAX_USAGE), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, { .name = "limit_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_LIMIT), + .private = MEMFILE_PRIVATE(MCT_MEM, RES_LIMIT), .write = mem_cgroup_write, .read_u64 = mem_cgroup_read_u64, }, { .name = "soft_limit_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT), + .private = MEMFILE_PRIVATE(MCT_MEM, RES_SOFT_LIMIT), .write = mem_cgroup_write, .read_u64 = mem_cgroup_read_u64, }, { .name = "failcnt", - .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT), + .private = MEMFILE_PRIVATE(MCT_MEM, RES_FAILCNT), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, @@ -2810,24 +2810,24 @@ struct cftype mem_cgroup_legacy_files[] = { #endif { .name = "kmem.limit_in_bytes", - .private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT), + .private = MEMFILE_PRIVATE(MCT_KMEM, RES_LIMIT), .write = mem_cgroup_write, .read_u64 = mem_cgroup_read_u64, }, { .name = "kmem.usage_in_bytes", - .private = MEMFILE_PRIVATE(_KMEM, RES_USAGE), + .private = MEMFILE_PRIVATE(MCT_KMEM, RES_USAGE), .read_u64 = mem_cgroup_read_u64, }, { .name = "kmem.failcnt", - .private = MEMFILE_PRIVATE(_KMEM, RES_FAILCNT), + .private = MEMFILE_PRIVATE(MCT_KMEM, RES_FAILCNT), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, { .name = "kmem.max_usage_in_bytes", - .private = MEMFILE_PRIVATE(_KMEM, RES_MAX_USAGE), + .private = MEMFILE_PRIVATE(MCT_KMEM, RES_MAX_USAGE), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, @@ -2839,24 +2839,24 @@ struct cftype mem_cgroup_legacy_files[] = { #endif { .name = "kmem.tcp.limit_in_bytes", - .private = MEMFILE_PRIVATE(_TCP, RES_LIMIT), + .private = MEMFILE_PRIVATE(MCT_TCPMEM, RES_LIMIT), .write = mem_cgroup_write, .read_u64 = mem_cgroup_read_u64, }, { .name = "kmem.tcp.usage_in_bytes", - .private = MEMFILE_PRIVATE(_TCP, RES_USAGE), + .private = MEMFILE_PRIVATE(MCT_TCPMEM, RES_USAGE), .read_u64 = mem_cgroup_read_u64, }, { .name = "kmem.tcp.failcnt", - .private = MEMFILE_PRIVATE(_TCP, RES_FAILCNT), + .private = MEMFILE_PRIVATE(MCT_TCPMEM, RES_FAILCNT), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, { .name = "kmem.tcp.max_usage_in_bytes", - .private = MEMFILE_PRIVATE(_TCP, RES_MAX_USAGE), + .private = MEMFILE_PRIVATE(MCT_TCPMEM, RES_MAX_USAGE), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, @@ -2866,24 +2866,24 @@ struct cftype mem_cgroup_legacy_files[] = { struct cftype memsw_files[] = { { .name = "memsw.usage_in_bytes", - .private = MEMFILE_PRIVATE(_MEMSWAP, RES_USAGE), + .private = MEMFILE_PRIVATE(MCT_MEMSW, RES_USAGE), .read_u64 = mem_cgroup_read_u64, }, { .name = "memsw.max_usage_in_bytes", - .private = MEMFILE_PRIVATE(_MEMSWAP, RES_MAX_USAGE), + .private = MEMFILE_PRIVATE(MCT_MEMSW, RES_MAX_USAGE), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, { .name = "memsw.limit_in_bytes", - .private = MEMFILE_PRIVATE(_MEMSWAP, RES_LIMIT), + .private = MEMFILE_PRIVATE(MCT_MEMSW, RES_LIMIT), .write = mem_cgroup_write, .read_u64 = mem_cgroup_read_u64, }, { .name = "memsw.failcnt", - .private = MEMFILE_PRIVATE(_MEMSWAP, RES_FAILCNT), + .private = MEMFILE_PRIVATE(MCT_MEMSW, RES_FAILCNT), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index 9a4d8205aed5..b2795c0493f8 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -87,14 +87,6 @@ void memcg1_cancel_attach(struct cgroup_taskset *tset); void memcg1_move_task(void); void memcg1_css_offline(struct mem_cgroup *memcg); -/* for encoding cft->private value on file */ -enum res_type { - _MEM, - _MEMSWAP, - _KMEM, - _TCP, -}; - bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked); void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked); void memcg1_oom_recover(struct mem_cgroup *memcg);