From patchwork Fri May 3 20:18:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 13653399 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 98DAFC25B4F for ; Fri, 3 May 2024 20:19:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E41C6B0088; Fri, 3 May 2024 16:18:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 492FE6B0089; Fri, 3 May 2024 16:18:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35A476B008A; Fri, 3 May 2024 16:18:59 -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 16E0B6B0088 for ; Fri, 3 May 2024 16:18:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BD9261C197B for ; Fri, 3 May 2024 20:18:58 +0000 (UTC) X-FDA: 82078198356.29.64A19A8 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf15.hostedemail.com (Postfix) with ESMTP id 9F884A0017 for ; Fri, 3 May 2024 20:18:56 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B2oPjzU9; spf=pass (imf15.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.174 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=1714767536; 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=cTvZ377kNqv2XbQCXUI4tQpUioDWvN7zLM46NIQ/7Hg=; b=bj7Nc0v2sI15S8iVizVQGbYJ4RxHLWV/w19KPdVd6fiX56X+10h8wMtTkDJPuJtYR8gC6v e+bBoDgERJqizmW0lfeXgf75SEOiUpTeruK+oVcYZLCkOZ9B0gFd+goJ9HYK9J309r4vof BvmO474jXYYm/ljf89soO20uxQgyeEY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B2oPjzU9; spf=pass (imf15.hostedemail.com: domain of roman.gushchin@linux.dev designates 95.215.58.174 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=1714767536; a=rsa-sha256; cv=none; b=NxbMVTuvQiYwIJgt86SFI1f0FT39MEyW7/xwmkX4eW/r0TYu5upT4fKn+wj5S/FSsK+EsP 8EK/K8qTyuw1/1d1vkgApFBJO/UCKOoN+hebEWrh6Gmk+UabcGrvIsKuDNmn/xe4Kfdvm1 +TeMaDy6j0Qg7xU4ohMlVoSPdLmw9L0= 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=1714767535; 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=cTvZ377kNqv2XbQCXUI4tQpUioDWvN7zLM46NIQ/7Hg=; b=B2oPjzU9Co7oIA51VgN2Vn9qPMVnYaUG48jUStEsB4ezr6E384yme/8haiVwlKHRFmVHqL eZQCi5M59YnLrGYVSjR5Ni91l+z5cLpSL5UHDrqKZvZvyPunVy+cVr5Ru+d/LA77i8eIhO em00inEpTVP7pZVvy7bF44+S3CMYPHQ= From: Roman Gushchin To: Andrew Morton Cc: Muchun Song , Johannes Weiner , Michal Hocko , Shakeel Butt , Frank van der Linden , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin Subject: [PATCH v1 1/4] mm: memcg: convert enum res_type to mem_counter_type Date: Fri, 3 May 2024 13:18:32 -0700 Message-ID: <20240503201835.2969707-2-roman.gushchin@linux.dev> In-Reply-To: <20240503201835.2969707-1-roman.gushchin@linux.dev> References: <20240503201835.2969707-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 9F884A0017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: s61sw1e64uqoghebiuhai45o9ak7jhu3 X-HE-Tag: 1714767536-107362 X-HE-Meta: U2FsdGVkX1+Kn6gP4HfxrJLVSxl/2IZVTdwCAA8O5JYoDejlAeTia7R5dHOj5wi/t0y3BFgTMj7E+Cmr+FsiibcCHp/s+UOB465iPGh5eukf6NBsFEgMEJaY1YEhVd0Xp5zy5tjV9iK1jxJ6e6/GSQeU5IsUJKKeF/vVzarTa4MQtGqTFM4C5tPUz8gLimjMqtvVqpp9kxB2ivUPa8Pv+gNsIzlFSBKg448ajSabnZBYOrWjNY68pAemVv/S3mUh3F8oDi8EPUqu6sdL/G2GGW3LNRbOaFI+yc0PCcEu/bP30KFsuXVoWM5hW+mK/E8rVRORTxqIInkFVYK9cvk3TpbayMhB+YtZntkBLl7a3Rdh8XkXpdMXvpgVcKYRjERh83q9iHrnU/+pPEMpYgSR3nISCT0KJNv6U2WIqZdlNi+SuPFTM9ta/VqdAQlVY8S1OrYTriVAfzXr4bEPF9x/raURUvvS/jsLsz/UFmMJThJxHhgqd9YCAj4MIIkrLQLtm045+pNv417Bc0ipTor0LIft969yM76Qceow6mbp6VSOpLnA1CoQIcEKDzoDPG/AB4iKazZrDu9pQqyu1Ak50U5C1+FuHg2WG7EZ/Dnm1XN0JyuBZNDkvvZk4Rr2H5XX/yAijfhYOuC4vOpR2IRa9LgEQcD2lRvazTX6Fn/SDrjdjqkl/09zf5Fg3+x0ZtiqnGOnNAjSCQ10LV5SwUb7dJl0qmGDX/bknYU9ich2Rrnl3dCY8oBzNknSwIkzkiyKA92nPTVPQfywhsEWPT0p+b/y2eqIQ/b+usfcNp1bPizQr9bBoZOVQ9pwA18MthGyY7fegwAWmdCxG85RtmH1OTn8ggDhVTQlB3ptKTyVuO8qa1EiApctXcwV0GIzZ4cnl3ZZWP+N45ZOFLLoPp7MOpUbqTcWS/Ojg0K8ynXSt2amghINfpGpGQOYXwGHYJRilS5zO4DFltkRwmaE7Qm 5IlbDK5R jV7P5S+dcM0OVAYOrBCo5f7tDC3cGUoF5aKCXbPdzEJEMlRuFKHErekSjqbypaq1Dus8nzc8MV0lAeHqNJT1l/ruWNzxRXOSvlwctNQ2mj/CJs9PV00HF6sKejJh8UHxPdNkyvZpi3VkcIEjaxgHt5kTWsAcTv27j0149tzr38eyzkD4= 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 --- include/linux/page_counter.h | 8 ++++ mm/memcontrol.c | 91 +++++++++++++++++------------------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h index 8cd858d912c4..2486f98a0c71 100644 --- a/include/linux/page_counter.h +++ b/include/linux/page_counter.h @@ -7,6 +7,14 @@ #include #include +enum mem_counter_type { + MCT_MEMORY, /* cgroup v1 and v2 */ + MCT_SWAP, /* cgroup v2 only */ + MCT_MEMSW = MCT_SWAP, /* cgroup v1 only */ + MCT_KMEM, /* cgroup v1 only */ + MCT_TCPMEM, /* cgroup v1 only */ +}; + struct page_counter { /* * Make sure 'usage' does not share cacheline with any other field. The diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a13d16cde372..894e5b6fe468 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -206,14 +206,6 @@ static struct move_charge_struct { #define MEM_CGROUP_MAX_RECLAIM_LOOPS 100 #define MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS 2 -/* for encoding cft->private value on file */ -enum res_type { - _MEM, - _MEMSWAP, - _KMEM, - _TCP, -}; - #define MEMFILE_PRIVATE(x, val) ((x) << 16 | (val)) #define MEMFILE_TYPE(val) ((val) >> 16 & 0xffff) #define MEMFILE_ATTR(val) ((val) & 0xffff) @@ -4108,16 +4100,16 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css, struct page_counter *counter; switch (MEMFILE_TYPE(cft->private)) { - case _MEM: + case MCT_MEMORY: counter = &memcg->memory; break; - case _MEMSWAP: + case MCT_MEMSW: counter = &memcg->memsw; break; - case _KMEM: + case MCT_KMEM: counter = &memcg->kmem; break; - case _TCP: + case MCT_TCPMEM: counter = &memcg->tcpmem; break; default: @@ -4273,20 +4265,20 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of, break; } switch (MEMFILE_TYPE(of_cft(of)->private)) { - case _MEM: + case MCT_MEMORY: 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; } @@ -4310,16 +4302,16 @@ static ssize_t mem_cgroup_reset(struct kernfs_open_file *of, char *buf, struct page_counter *counter; switch (MEMFILE_TYPE(of_cft(of)->private)) { - case _MEM: + case MCT_MEMORY: counter = &memcg->memory; break; - case _MEMSWAP: + case MCT_MEMSW: counter = &memcg->memsw; break; - case _KMEM: + case MCT_KMEM: counter = &memcg->kmem; break; - case _TCP: + case MCT_TCPMEM: counter = &memcg->tcpmem; break; default: @@ -4706,7 +4698,8 @@ 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; @@ -4720,10 +4713,10 @@ static int __mem_cgroup_usage_register_event(struct mem_cgroup *memcg, mutex_lock(&memcg->thresholds_lock); - if (type == _MEM) { + if (type == MCT_MEMORY) { 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 @@ -4731,7 +4724,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; @@ -4788,17 +4781,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_MEMORY); } 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; @@ -4807,10 +4800,10 @@ static void __mem_cgroup_usage_unregister_event(struct mem_cgroup *memcg, mutex_lock(&memcg->thresholds_lock); - if (type == _MEM) { + if (type == MCT_MEMORY) { 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 @@ -4820,7 +4813,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; @@ -4885,13 +4878,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_MEMORY); } 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, @@ -5426,30 +5419,30 @@ static int memory_stat_show(struct seq_file *m, void *v); static struct cftype mem_cgroup_legacy_files[] = { { .name = "usage_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_USAGE), + .private = MEMFILE_PRIVATE(MCT_MEMORY, RES_USAGE), .read_u64 = mem_cgroup_read_u64, }, { .name = "max_usage_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_MAX_USAGE), + .private = MEMFILE_PRIVATE(MCT_MEMORY, 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_MEMORY, 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_MEMORY, 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_MEMORY, RES_FAILCNT), .write = mem_cgroup_reset, .read_u64 = mem_cgroup_read_u64, }, @@ -5498,24 +5491,24 @@ static 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, }, @@ -5527,24 +5520,24 @@ static 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, }, @@ -8394,24 +8387,24 @@ static struct cftype swap_files[] = { static 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, },