From: Tal Zussman <tz2294@columbia.edu>
To: Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
Barry Song <baohua@kernel.org>,
Youngjun Park <youngjun.park@lge.com>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Qi Zheng <qi.zheng@linux.dev>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Tal Zussman <tz2294@columbia.edu>
Subject: [PATCH 05/11] mm: memcontrol: constify the mem_cgroup accessors
Date: Wed, 02 Sep 2026 15:27:51 -0400 [thread overview]
Message-ID: <20260902-folio_memcg-const-v1-5-e2c1da22246d@columbia.edu> (raw)
In-Reply-To: <20260902-folio_memcg-const-v1-0-e2c1da22246d@columbia.edu>
mem_cgroup_id(), parent_mem_cgroup(), mem_cgroup_is_root(),
mem_cgroup_is_descendant(), memcg_kmem_id(), and the other memcg
accessors only read from the memcg. Constify them, along with
mem_cgroup_shrink_is_root()'s shrink_control.
mem_cgroup_print_oom_context()'s task stays non-const, as
task_cgroup() takes a non-const task.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
include/linux/memcontrol.h | 41 +++++++++++++++++++++--------------------
mm/memcontrol.c | 3 ++-
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 4b7cc97e45b2..bda969b3e1d9 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -506,7 +506,7 @@ static inline bool PageMemcgKmem(const struct page *page)
return folio_memcg_kmem(page_folio(page));
}
-static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
+static inline bool mem_cgroup_is_root(const struct mem_cgroup *memcg)
{
return (memcg == root_mem_cgroup);
}
@@ -522,7 +522,7 @@ static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
* and do not honour sc->memcg can use this to early-return 0 in per-memcg
* contexts.
*/
-static inline bool mem_cgroup_shrink_is_root(struct shrink_control *sc)
+static inline bool mem_cgroup_shrink_is_root(const struct shrink_control *sc)
{
return !sc->memcg || mem_cgroup_is_root(sc->memcg);
}
@@ -806,7 +806,7 @@ void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);
void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
int (*)(struct task_struct *, void *), void *arg);
-static inline unsigned short mem_cgroup_private_id(struct mem_cgroup *memcg)
+static inline unsigned short mem_cgroup_private_id(const struct mem_cgroup *memcg)
{
if (mem_cgroup_disabled())
return 0;
@@ -815,7 +815,7 @@ static inline unsigned short mem_cgroup_private_id(struct mem_cgroup *memcg)
}
struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id);
-static inline u64 mem_cgroup_id(struct mem_cgroup *memcg)
+static inline u64 mem_cgroup_id(const struct mem_cgroup *memcg)
{
return memcg ? cgroup_id(memcg->css.cgroup) : 0;
}
@@ -844,13 +844,13 @@ static inline struct mem_cgroup *lruvec_memcg(const struct lruvec *lruvec)
*
* Returns the parent memcg, or NULL if this is the root.
*/
-static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
+static inline struct mem_cgroup *parent_mem_cgroup(const struct mem_cgroup *memcg)
{
return mem_cgroup_from_css(memcg->css.parent);
}
-static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg,
- struct mem_cgroup *root)
+static inline bool mem_cgroup_is_descendant(const struct mem_cgroup *memcg,
+ const struct mem_cgroup *root)
{
if (root == memcg)
return true;
@@ -858,7 +858,7 @@ static inline bool mem_cgroup_is_descendant(struct mem_cgroup *memcg,
}
static inline bool mm_match_cgroup(struct mm_struct *mm,
- struct mem_cgroup *memcg)
+ const struct mem_cgroup *memcg)
{
struct mem_cgroup *task_memcg;
bool match = false;
@@ -904,7 +904,7 @@ static inline void mem_cgroup_handle_over_high(gfp_t gfp_mask)
unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg);
-void mem_cgroup_print_oom_context(struct mem_cgroup *memcg,
+void mem_cgroup_print_oom_context(const struct mem_cgroup *memcg,
struct task_struct *p);
void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg);
@@ -1080,12 +1080,12 @@ static inline bool PageMemcgKmem(const struct page *page)
return false;
}
-static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
+static inline bool mem_cgroup_is_root(const struct mem_cgroup *memcg)
{
return true;
}
-static inline bool mem_cgroup_shrink_is_root(struct shrink_control *sc)
+static inline bool mem_cgroup_shrink_is_root(const struct shrink_control *sc)
{
return true;
}
@@ -1187,13 +1187,13 @@ static inline struct lruvec *folio_lruvec(const struct folio *folio)
return &pgdat->__lruvec;
}
-static inline struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
+static inline struct mem_cgroup *parent_mem_cgroup(const struct mem_cgroup *memcg)
{
return NULL;
}
static inline bool mm_match_cgroup(struct mm_struct *mm,
- struct mem_cgroup *memcg)
+ const struct mem_cgroup *memcg)
{
return true;
}
@@ -1287,7 +1287,7 @@ static inline void mem_cgroup_scan_tasks(struct mem_cgroup *memcg,
{
}
-static inline unsigned short mem_cgroup_private_id(struct mem_cgroup *memcg)
+static inline unsigned short mem_cgroup_private_id(const struct mem_cgroup *memcg)
{
return 0;
}
@@ -1299,7 +1299,7 @@ static inline struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)
return NULL;
}
-static inline u64 mem_cgroup_id(struct mem_cgroup *memcg)
+static inline u64 mem_cgroup_id(const struct mem_cgroup *memcg)
{
return 0;
}
@@ -1337,7 +1337,8 @@ static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
}
static inline void
-mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p)
+mem_cgroup_print_oom_context(const struct mem_cgroup *memcg,
+ struct task_struct *p)
{
}
@@ -1773,7 +1774,7 @@ static inline void memcg_kmem_uncharge_page(struct page *page, int order)
* A helper for accessing memcg's kmem_id, used for getting
* corresponding LRU lists.
*/
-static inline int memcg_kmem_id(struct mem_cgroup *memcg)
+static inline int memcg_kmem_id(const struct mem_cgroup *memcg)
{
return memcg ? memcg->kmemcg_id : -1;
}
@@ -1845,7 +1846,7 @@ static inline bool memcg_kmem_online(void)
return false;
}
-static inline int memcg_kmem_id(struct mem_cgroup *memcg)
+static inline int memcg_kmem_id(const struct mem_cgroup *memcg)
{
return -1;
}
@@ -1912,7 +1913,7 @@ static inline bool mem_cgroup_zswap_writeback_enabled(struct mem_cgroup *memcg)
#ifdef CONFIG_MEMCG_V1
bool mem_cgroup_oom_synchronize(bool wait);
-static inline bool task_in_memcg_oom(struct task_struct *p)
+static inline bool task_in_memcg_oom(const struct task_struct *p)
{
return p->memcg_in_oom;
}
@@ -1930,7 +1931,7 @@ static inline void mem_cgroup_exit_user_fault(void)
}
#else /* CONFIG_MEMCG_V1 */
-static inline bool task_in_memcg_oom(struct task_struct *p)
+static inline bool task_in_memcg_oom(const struct task_struct *p)
{
return false;
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e2845f761e37..35f924c9f2a3 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1812,7 +1812,8 @@ static void memory_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
* NOTE: @memcg and @p's mem_cgroup can be different when hierarchy is
* enabled
*/
-void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p)
+void mem_cgroup_print_oom_context(const struct mem_cgroup *memcg,
+ struct task_struct *p)
{
rcu_read_lock();
--
2.39.5
next prev parent reply other threads:[~2026-09-02 19:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 19:27 [PATCH 00/11] mm: memcontrol: constify the read side of the memcg API Tal Zussman
2026-09-02 19:27 ` [PATCH 01/11] mm: memcontrol: take a const folio in folio_memcg() and friends Tal Zussman
2026-09-02 19:27 ` [PATCH 02/11] mm: memcontrol: constify obj_cgroup_memcg() " Tal Zussman
2026-09-02 19:27 ` [PATCH 03/11] mm: memcontrol: constify the lruvec helpers Tal Zussman
2026-09-04 21:35 ` Tal Zussman
2026-09-02 19:27 ` [PATCH 04/11] mm/page_io: take a const folio in bio_associate_blkg_from_folio() Tal Zussman
2026-09-02 19:27 ` Tal Zussman [this message]
2026-09-02 19:27 ` [PATCH 06/11] mm: page_counter: constify page_counter_read() and page_counter_margin() Tal Zussman
2026-09-02 19:27 ` [PATCH 07/11] mm: memcontrol: constify the reclaim protection helpers Tal Zussman
2026-09-02 19:27 ` [PATCH 08/11] mm: memcontrol: constify the memcg and lruvec stat readers Tal Zussman
2026-09-04 21:42 ` Tal Zussman
2026-09-02 19:27 ` [PATCH 09/11] mm: memcontrol: constify the swap accounting helpers Tal Zussman
2026-09-02 19:27 ` [PATCH 10/11] mm: memcontrol: constify mem_cgroup_swappiness() and mem_cgroup_get_max() Tal Zussman
2026-09-02 19:27 ` [PATCH 11/11] mm: memcontrol: constify the zswap and socket pressure helpers Tal Zussman
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=20260902-folio_memcg-const-v1-5-e2c1da22246d@columbia.edu \
--to=tz2294@columbia.edu \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=cgroups@vger.kernel.org \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=youngjun.park@lge.com \
--cc=yuanchu@google.com \
/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