From: Roman Gushchin <roman.gushchin@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Roman Gushchin <roman.gushchin@linux.dev>
Subject: [PATCH v1 1/9] mm: memcg: move memcg_account_kmem() to memcontrol-v1.c
Date: Fri, 28 Jun 2024 21:03:09 +0000 [thread overview]
Message-ID: <20240628210317.272856-2-roman.gushchin@linux.dev> (raw)
In-Reply-To: <20240628210317.272856-1-roman.gushchin@linux.dev>
memcg_account_kmem() consists of a trivial statistics change via
mod_memcg_state() call and a relatively large memcg1-specific part.
Let's factor out the mod_memcg_state() call and move the rest into
the mm/memcontrol-v1.c file. Also rename memcg_account_kmem()
into memcg1_account_kmem() for consistency.
Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
---
mm/memcontrol-v1.c | 12 ++++++++++++
mm/memcontrol-v1.h | 2 ++
mm/memcontrol.c | 31 ++++++++++---------------------
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 6ac47954eefc..c73a0ff0cc39 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -2913,6 +2913,18 @@ struct cftype memsw_files[] = {
{ }, /* terminate */
};
+#ifdef CONFIG_MEMCG_KMEM
+void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages)
+{
+ if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
+ if (nr_pages > 0)
+ page_counter_charge(&memcg->kmem, nr_pages);
+ else
+ page_counter_uncharge(&memcg->kmem, -nr_pages);
+ }
+}
+#endif /* CONFIG_MEMCG_KMEM */
+
static int __init memcg1_init(void)
{
int node;
diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h
index 64b053d7f131..61620e2b0bf0 100644
--- a/mm/memcontrol-v1.h
+++ b/mm/memcontrol-v1.h
@@ -107,6 +107,7 @@ void memcg1_check_events(struct mem_cgroup *memcg, int nid);
void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s);
+void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages);
extern struct cftype memsw_files[];
extern struct cftype mem_cgroup_legacy_files[];
@@ -125,6 +126,7 @@ static inline void memcg1_check_events(struct mem_cgroup *memcg, int nid) {}
static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {}
+static inline void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) {}
extern struct cftype memsw_files[];
extern struct cftype mem_cgroup_legacy_files[];
#endif /* CONFIG_MEMCG_V1 */
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c251bbe35f4b..802a077e2e2f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1718,7 +1718,6 @@ static DEFINE_MUTEX(percpu_charge_mutex);
static struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock);
static bool obj_stock_flush_required(struct memcg_stock_pcp *stock,
struct mem_cgroup *root_memcg);
-static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages);
#else
static inline struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock)
@@ -1730,9 +1729,6 @@ static bool obj_stock_flush_required(struct memcg_stock_pcp *stock,
{
return false;
}
-static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages)
-{
-}
#endif
/**
@@ -2642,18 +2638,6 @@ struct obj_cgroup *get_obj_cgroup_from_folio(struct folio *folio)
return objcg;
}
-static void memcg_account_kmem(struct mem_cgroup *memcg, int nr_pages)
-{
- mod_memcg_state(memcg, MEMCG_KMEM, nr_pages);
- if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
- if (nr_pages > 0)
- page_counter_charge(&memcg->kmem, nr_pages);
- else
- page_counter_uncharge(&memcg->kmem, -nr_pages);
- }
-}
-
-
/*
* obj_cgroup_uncharge_pages: uncharge a number of kernel pages from a objcg
* @objcg: object cgroup to uncharge
@@ -2666,7 +2650,8 @@ static void obj_cgroup_uncharge_pages(struct obj_cgroup *objcg,
memcg = get_mem_cgroup_from_objcg(objcg);
- memcg_account_kmem(memcg, -nr_pages);
+ mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages);
+ memcg1_account_kmem(memcg, -nr_pages);
refill_stock(memcg, nr_pages);
css_put(&memcg->css);
@@ -2692,7 +2677,8 @@ static int obj_cgroup_charge_pages(struct obj_cgroup *objcg, gfp_t gfp,
if (ret)
goto out;
- memcg_account_kmem(memcg, nr_pages);
+ mod_memcg_state(memcg, MEMCG_KMEM, nr_pages);
+ memcg1_account_kmem(memcg, nr_pages);
out:
css_put(&memcg->css);
@@ -2845,7 +2831,8 @@ static struct obj_cgroup *drain_obj_stock(struct memcg_stock_pcp *stock)
memcg = get_mem_cgroup_from_objcg(old);
- memcg_account_kmem(memcg, -nr_pages);
+ mod_memcg_state(memcg, MEMCG_KMEM, -nr_pages);
+ memcg1_account_kmem(memcg, -nr_pages);
__refill_stock(memcg, nr_pages);
css_put(&memcg->css);
@@ -4806,8 +4793,10 @@ static void uncharge_batch(const struct uncharge_gather *ug)
page_counter_uncharge(&ug->memcg->memory, ug->nr_memory);
if (do_memsw_account())
page_counter_uncharge(&ug->memcg->memsw, ug->nr_memory);
- if (ug->nr_kmem)
- memcg_account_kmem(ug->memcg, -ug->nr_kmem);
+ if (ug->nr_kmem) {
+ mod_memcg_state(ug->memcg, MEMCG_KMEM, -ug->nr_kmem);
+ memcg1_account_kmem(ug->memcg, -ug->nr_kmem);
+ }
memcg1_oom_recover(ug->memcg);
}
--
2.45.2.803.g4e1b14247a-goog
next prev parent reply other threads:[~2024-06-28 21:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 21:03 [PATCH v1 0/9] mm: memcg: put cgroup v1-specific memcg data under CONFIG_MEMCG_V1 Roman Gushchin
2024-06-28 21:03 ` Roman Gushchin [this message]
2024-06-29 0:30 ` [PATCH v1 1/9] mm: memcg: move memcg_account_kmem() to memcontrol-v1.c Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 2/9] mm: memcg: factor out legacy socket memory accounting code Roman Gushchin
2024-06-29 0:39 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 3/9] mm: memcg: guard cgroup v1-specific code in mem_cgroup_print_oom_meminfo() Roman Gushchin
2024-06-29 0:40 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 4/9] mm: memcg: gather memcg1-specific fields initialization in memcg1_memcg_init() Roman Gushchin
2024-06-29 0:43 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 5/9] mm: memcg: guard memcg1-specific fields accesses in mm/memcontrol.c Roman Gushchin
2024-06-29 0:49 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 6/9] mm: memcg: put memcg1-specific struct mem_cgroup's members under CONFIG_MEMCG_V1 Roman Gushchin
2024-06-29 0:48 ` Shakeel Butt
2024-07-04 23:35 ` Andrew Morton
2024-07-05 3:43 ` Shakeel Butt
2024-07-03 15:12 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 7/9] mm: memcg: guard memcg1-specific members of struct mem_cgroup_per_node Roman Gushchin
2024-06-29 0:52 ` Shakeel Butt
2024-07-03 15:13 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 8/9] mm: memcg: put struct task_struct::memcg_in_oom under CONFIG_MEMCG_V1 Roman Gushchin
2024-06-29 0:53 ` Shakeel Butt
2024-06-28 21:03 ` [PATCH v1 9/9] mm: memcg: put struct task_struct::in_user_fault " Roman Gushchin
2024-06-29 0:55 ` Shakeel Butt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240628210317.272856-2-roman.gushchin@linux.dev \
--to=roman.gushchin@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=shakeel.butt@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox