memcg: separate private and public ID namespaces
Subsystems (7)
Shakeel Butt
maintainercover memcg: separate private and public ID namespaces
The memory cgroup subsystem maintains a private ID infrastructure that is decoupled from the cgroup IDs. This private ID system exists because some kernel objects (like swap entries and shadow entries in the workingset code) can outlive the cgroup they were associated with. The motivation is best described in commit 73f576c04b941 ("mm:
memcontrol: fix cgroup creation failure after many small jobs").
Unfortunately, some in-kernel users (DAMON, LRU gen debugfs interface, shrinker debugfs) started exposing these private IDs to userspace. This is problematic because:
1. The private IDs are internal implementation details that could change
2. Userspace already has access to cgroup IDs through the cgroup filesystem
3. Using different ID namespaces in different interfaces is confusing
This series cleans up the memcg ID infrastructure by:
1. Explicitly marking the private ID APIs with "private" in their names to make it clear they are for internal use only (swap/workingset)
2. Making the public cgroup ID APIs (mem_cgroup_id/mem_cgroup_get_from_id) unconditionally available
3. Converting DAMON, LRU gen, and shrinker debugfs interfaces to use the public cgroup IDs instead of the private IDs
4. Removing the now-unused wrapper functions and renaming the public APIs for clarity
After this series:
- mem_cgroup_private_id() / mem_cgroup_from_private_id() are used for internal kernel objects that outlive their cgroup (swap, workingset)
- mem_cgroup_id() / mem_cgroup_get_from_id() return the public cgroup ID (from cgroup_id()) for use in userspace-facing interfaces
Note: please apply this series after the patch at
https://lore.kernel.org/[email protected]/
Shakeel Butt (8):
memcg: introduce private id API for in-kernel users
memcg: expose mem_cgroup_ino() and mem_cgroup_get_from_ino()
unconditionally
memcg: mem_cgroup_get_from_ino() returns NULL on error
memcg: use cgroup_id() instead of cgroup_ino() for memcg ID mm/damon: use cgroup ID instead of private memcg ID mm/vmscan: use cgroup ID instead of private memcg ID in lru_gen
interface
memcg: remove unused mem_cgroup_id() and mem_cgroup_from_id()
memcg: rename mem_cgroup_ino() to mem_cgroup_id()
include/linux/damon.h | 4 +-- include/linux/memcontrol.h | 26 +++++++---------- mm/damon/core.c | 7 ++--- mm/damon/sysfs-schemes.c | 6 ++-- mm/list_lru.c | 2 +- mm/memcontrol-v1.c | 6 ++-- mm/memcontrol-v1.h | 4 +-- mm/memcontrol.c | 60 ++++++++++++++++++-------------------- mm/shrinker_debug.c | 13 +++++---- mm/vmscan.c | 17 ++++------- mm/workingset.c | 8 ++--- 11 files changed, 68 insertions(+), 85 deletions(-)
--
2.47.3
Shakeel Butt
maintainerPATCH 1/8 memcg: introduce private id API for in-kernel users
The memory cgroup maintains a private ID infrastructure decoupled from the cgroup IDs for swapout records and shadow entries. The main motivation of this private ID infra is best described in the commit 73f576c04b941 ("mm: memcontrol: fix cgroup creation failure after many small jobs").
Unfortunetely some users have started exposing these private IDs to the userspace where they should have used the cgroup IDs which are already exposed to the userspace. Let's rename the memcg ID APIs to explicitly mark them private.
No functional change is intended.
--- include/linux/memcontrol.h | 24 ++++++++++++++--- mm/list_lru.c | 2 +- mm/memcontrol-v1.c | 6 ++--- mm/memcontrol-v1.h | 4 +-- mm/memcontrol.c | 55 +++++++++++++++++++++----------------- mm/workingset.c | 8 +++--- 6 files changed, 61 insertions(+), 38 deletions(-)
include/linux/memcontrol.h +21 -3
@@ -65,7 +65,7 @@ struct mem_cgroup_reclaim_cookie {#define MEM_CGROUP_ID_SHIFT 16 -struct mem_cgroup_id { +struct mem_cgroup_private_id {int id;refcount_t ref; };
@@ -191,7 +191,7 @@ struct mem_cgroup {struct cgroup_subsys_state css;/* Private memcg ID. Used to ID objects that outlive the cgroup */ -struct mem_cgroup_id id; +struct mem_cgroup_private_id id;/* Accounted resources */ struct page_counter memory;/* Both v1 & v2 */
@@ -821,13 +821,19 @@ 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_id (struct mem_cgroup *memcg) +static inline unsigned short mem_cgroup_private_id (struct mem_cgroup *memcg) {if (mem_cgroup_disabled ())return 0 ;return memcg->id.id; } +struct mem_cgroup *mem_cgroup_from_private_id (unsigned short id); + +static inline unsigned short mem_cgroup_id (struct mem_cgroup *memcg) +{ +return mem_cgroup_private_id (memcg); +}struct mem_cgroup *mem_cgroup_from_id (unsigned short id);#ifdef CONFIG_SHRINKER_DEBUG
@@ -1290,6 +1296,18 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id)return NULL ; } +static inline unsigned short mem_cgroup_private_id (struct mem_cgroup *memcg) +{ +return 0 ; +} + +static inline struct mem_cgroup *mem_cgroup_from_private_id (unsigned short id) +{ +WARN_ON_ONCE (id); +/* XXX: This should always return root_mem_cgroup */ +return NULL ; +} +#ifdef CONFIG_SHRINKER_DEBUG static inline unsigned long mem_cgroup_ino (struct mem_cgroup *memcg) {
mm/list_lru.c +1 -1
@@ -369,7 +369,7 @@ unsigned long list_lru_walk_node(struct list_lru *lru, int nid,xa_for_each (&lru->xa, index, mlru) {rcu_read_lock (); - memcg =mem_cgroup_from_id (index); + memcg =mem_cgroup_from_private_id (index);if (!mem_cgroup_tryget (memcg)) {rcu_read_unlock ();continue ;
mm/memcontrol-v1.c +3 -3
@@ -635,14 +635,14 @@ void memcg1_swapout(struct folio *folio, swp_entry_t entry)* have an ID allocated to it anymore, charge the closest online * ancestor for the swap instead and transfer the memory+swap charge. */ - swap_memcg =mem_cgroup_id_get_online (memcg); + swap_memcg =mem_cgroup_private_id_get_online (memcg); nr_entries =folio_nr_pages (folio);/* Get references for the tail pages, too */ if (nr_entries >1 ) -mem_cgroup_id_get_many (swap_memcg, nr_entries -1 ); +mem_cgroup_private_id_get_many (swap_memcg, nr_entries -1 );mod_memcg_state (swap_memcg,MEMCG_SWAP , nr_entries); -swap_cgroup_record (folio,mem_cgroup_id (swap_memcg), entry); +swap_cgroup_record (folio,mem_cgroup_private_id (swap_memcg), entry);folio_unqueue_deferred_split (folio); folio->memcg_data =0 ;
mm/memcontrol-v1.h +2 -2
@@ -28,8 +28,8 @@ unsigned long memcg_events(struct mem_cgroup *memcg, int event);unsigned long memcg_page_state_output (struct mem_cgroup *memcg,int item);int memory_stat_show (struct seq_file *m,void *v); -void mem_cgroup_id_get_many (struct mem_cgroup *memcg,unsigned int n); -struct mem_cgroup *mem_cgroup_id_get_online (struct mem_cgroup *memcg); +void mem_cgroup_private_id_get_many (struct mem_cgroup *memcg,unsigned int n); +struct mem_cgroup *mem_cgroup_private_id_get_online (struct mem_cgroup *memcg);/* Cgroup v1-specific declarations */ #ifdef CONFIG_MEMCG_V1
mm/memcontrol.c +30 -25
167 lines not on this page · raw message
mm/workingset.c +4 -4
@@ -254,7 +254,7 @@ static void *lru_gen_eviction(struct folio *folio) hist =lru_hist_from_seq (min_seq);atomic_long_add (delta, &lrugen->evicted[hist][type][tier]); -return pack_shadow (mem_cgroup_id (memcg), pgdat, token, workingset); +return pack_shadow (mem_cgroup_private_id (memcg), pgdat, token, workingset); }/*
@@ -271,7 +271,7 @@ static bool lru_gen_test_recent(void *shadow, struct lruvec **lruvec,unpack_shadow (shadow, &memcg_id, &pgdat, token, workingset); - memcg =mem_cgroup_from_id (memcg_id); + memcg =mem_cgroup_from_private_id (memcg_id); *lruvec =mem_cgroup_lruvec (memcg, pgdat); max_seq =READ_ONCE ((*lruvec)->lrugen.max_seq);
@@ -395,7 +395,7 @@ void *workingset_eviction(struct folio *folio, struct mem_cgroup *target_memcg) lruvec =mem_cgroup_lruvec (target_memcg, pgdat);/* XXX: target_memcg can be NULL, go through lruvec */ - memcgid =mem_cgroup_id (lruvec_memcg (lruvec)); + memcgid =mem_cgroup_private_id (lruvec_memcg (lruvec)); eviction =atomic_long_read (&lruvec->nonresident_age); eviction >>= bucket_order;workingset_age_nonresident (lruvec,folio_nr_pages (folio));
@@ -456,7 +456,7 @@ bool workingset_test_recent(void *shadow, bool file, bool *workingset,* would be better if the root_mem_cgroup existed in all * configurations instead. */ - eviction_memcg =mem_cgroup_from_id (memcgid); + eviction_memcg =mem_cgroup_from_private_id (memcgid);if (!mem_cgroup_tryget (eviction_memcg)) eviction_memcg =NULL ;rcu_read_unlock ();
Signature · 1 line
2.47.3
Shakeel Butt
maintainerPATCH 2/8 memcg: expose mem_cgroup_ino() and mem_cgroup_get_from_ino() unconditionally
In reply to Shakeel ButtRemove the CONFIG_SHRINKER_DEBUG guards around mem_cgroup_ino() and mem_cgroup_get_from_ino(). These APIs provide a way to get a memcg's cgroup inode number and to look up a memcg from an inode number respectively.
Making these functions unconditionally available allows other in-kernel users to leverage them without requiring CONFIG_SHRINKER_DEBUG to be enabled.
No functional change for existing users.
--- include/linux/memcontrol.h | 4 ---- mm/memcontrol.c | 2 -- 2 files changed, 6 deletions(-)
include/linux/memcontrol.h +0 -4
@@ -836,14 +836,12 @@ static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) }struct mem_cgroup *mem_cgroup_from_id (unsigned short id); -#ifdef CONFIG_SHRINKER_DEBUG static inline unsigned long mem_cgroup_ino (struct mem_cgroup *memcg) {return memcg ?cgroup_ino (memcg->css.cgroup) :0 ; }struct mem_cgroup *mem_cgroup_get_from_ino (unsigned long ino); -#endif static inline struct mem_cgroup *mem_cgroup_from_seq (struct seq_file *m) {
@@ -1308,7 +1306,6 @@ static inline struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return NULL ; } -#ifdef CONFIG_SHRINKER_DEBUG static inline unsigned long mem_cgroup_ino (struct mem_cgroup *memcg) {return 0 ;
@@ -1318,7 +1315,6 @@ static inline struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) {return NULL ; } -#endif static inline struct mem_cgroup *mem_cgroup_from_seq (struct seq_file *m) {
mm/memcontrol.c +0 -2
@@ -3620,7 +3620,6 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)return mem_cgroup_from_private_id (id); } -#ifdef CONFIG_SHRINKER_DEBUG struct mem_cgroup *mem_cgroup_get_from_ino (unsigned long ino) {struct cgroup *cgrp;
@@ -3641,7 +3640,6 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino)return memcg; } -#endif static void free_mem_cgroup_per_node_info (struct mem_cgroup_per_node *pn) {
Signature · 1 line
2.47.3
Shakeel Butt
maintainerPATCH 3/8 memcg: mem_cgroup_get_from_ino() returns NULL on error
In reply to Shakeel ButtChange mem_cgroup_get_from_ino() to return NULL on error instead of ERR_PTR values. This simplifies the API: NULL indicates failure, and a valid pointer indicates success with a CSS reference held that the caller must release via mem_cgroup_put().
--- mm/memcontrol.c | 6 ++---- mm/shrinker_debug.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
mm/memcontrol.c +2 -4
@@ -3624,17 +3624,15 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) {struct cgroup *cgrp;struct cgroup_subsys_state *css; -struct mem_cgroup *memcg; +struct mem_cgroup *memcg =NULL ; cgrp =cgroup_get_from_id (ino);if (IS_ERR (cgrp)) -return ERR_CAST (cgrp); +return NULL ; css =cgroup_get_e_css (cgrp, &memory_cgrp_subsys);if (css) memcg = container_of(css, struct mem_cgroup, css); -else - memcg =ERR_PTR (-ENOENT );cgroup_put (cgrp);
mm/shrinker_debug.c +1 -1
@@ -130,7 +130,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,if (shrinker->flags &SHRINKER_MEMCG_AWARE ) { memcg =mem_cgroup_get_from_ino (ino); -if (!memcg ||IS_ERR (memcg)) +if (!memcg)return -ENOENT ;if (!mem_cgroup_online (memcg)) {
Signature · 1 line
2.47.3
Shakeel Butt
maintainerPATCH 4/8 memcg: use cgroup_id() instead of cgroup_ino() for memcg ID
In reply to Shakeel ButtSwitch mem_cgroup_ino() from using cgroup_ino() to cgroup_id(). The cgroup_ino() returns the kernfs inode number while cgroup_id() returns the kernfs node ID. For 64-bit systems, they are the same. Also cgroup_get_from_id() expects 64-bit node ID which is called by mem_cgroup_get_from_ino().
Change the type from unsigned long to u64 to match cgroup_id()'s return type, and update the format specifiers accordingly.
Note that the names mem_cgroup_ino() and mem_cgroup_get_from_ino() are now misnomers since they deal with cgroup IDs rather than inode numbers. A follow-up patch will rename them.
--- include/linux/memcontrol.h | 10 +++++----- mm/memcontrol.c | 2 +- mm/shrinker_debug.c | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-)
include/linux/memcontrol.h +5 -5
@@ -836,12 +836,12 @@ static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) }struct mem_cgroup *mem_cgroup_from_id (unsigned short id); -static inline unsigned long mem_cgroup_ino (struct mem_cgroup *memcg) +static inline u64 mem_cgroup_ino (struct mem_cgroup *memcg) { -return memcg ?cgroup_ino (memcg->css.cgroup) :0 ; +return memcg ?cgroup_id (memcg->css.cgroup) :0 ; } -struct mem_cgroup *mem_cgroup_get_from_ino (unsigned long ino); +struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino);static inline struct mem_cgroup *mem_cgroup_from_seq (struct seq_file *m) {
@@ -1306,12 +1306,12 @@ static inline struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return NULL ; } -static inline unsigned long mem_cgroup_ino (struct mem_cgroup *memcg) +static inline u64 mem_cgroup_ino (struct mem_cgroup *memcg) {return 0 ; } -static inline struct mem_cgroup *mem_cgroup_get_from_ino (unsigned long ino) +static inline struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) {return NULL ; }
mm/memcontrol.c +1 -1
@@ -3620,7 +3620,7 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id)return mem_cgroup_from_private_id (id); } -struct mem_cgroup *mem_cgroup_get_from_ino (unsigned long ino) +struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) {struct cgroup *cgrp;struct cgroup_subsys_state *css;
mm/shrinker_debug.c +4 -3
@@ -70,7 +70,7 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) memcg_aware ? memcg :NULL , count_per_node);if (total) { -seq_printf (m,"%lu" ,mem_cgroup_ino (memcg)); +seq_printf (m,"%llu" ,mem_cgroup_ino (memcg));for_each_node (nid)seq_printf (m," %lu" , count_per_node[nid]);seq_putc (m,'\n' );
@@ -106,7 +106,8 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, size_t size, loff_t *pos) { struct shrinker *shrinker = file->private_data; -unsigned long nr_to_scan =0 , ino, read_len; +unsigned long nr_to_scan =0 , read_len; +u64 ino;struct shrink_control sc = { .gfp_mask =GFP_KERNEL , };
@@ -119,7 +120,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,return -EFAULT ; kbuf[read_len] ='\0' ; -if (sscanf (kbuf,"%lu %d %lu" , &ino, &nid, &nr_to_scan) !=3 ) +if (sscanf (kbuf,"%llu %d %lu" , &ino, &nid, &nr_to_scan) !=3 )return -EINVAL ;if (nid <0 || nid >= nr_node_ids)
Signature · 1 line
2.47.3
Shakeel Butt
maintainerPATCH 5/8 mm/damon: use cgroup ID instead of private memcg ID
In reply to Shakeel ButtDAMON was using the internal private memcg ID which is meant for tracking kernel objects that outlive their cgroup. Switch to using the public cgroup ID instead.
--- include/linux/damon.h | 4 ++-- mm/damon/core.c | 7 ++----- mm/damon/ops-common.c | 2 +- mm/damon/sysfs-schemes.c | 8 ++++---- 4 files changed, 9 insertions(+), 12 deletions(-)
include/linux/damon.h +2 -2
@@ -203,7 +203,7 @@ struct damos_quota_goal {u64 last_psi_total;struct {int nid; -unsigned short memcg_id; +u64 memcg_id; }; };struct list_head list;
@@ -419,7 +419,7 @@ struct damos_filter {bool matching;bool allow;union { -unsigned short memcg_id; +u64 memcg_id;struct damon_addr_range addr_range;int target_idx;struct damon_size_range sz_range;
mm/damon/core.c +2 -5
@@ -2065,16 +2065,13 @@ static unsigned long damos_get_node_memcg_used_bp(unsigned long used_pages, numerator;struct sysinfo i; -rcu_read_lock (); - memcg =mem_cgroup_from_id (goal->memcg_id); -if (!memcg || !mem_cgroup_tryget (memcg)) { -rcu_read_unlock (); + memcg =mem_cgroup_get_from_ino (goal->memcg_id); +if (!memcg) {if (goal->metric ==DAMOS_QUOTA_NODE_MEMCG_USED_BP )return 0 ;else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */ return 10000 ; } -rcu_read_unlock ();mem_cgroup_flush_stats (memcg); lruvec =mem_cgroup_lruvec (memcg,NODE_DATA (goal->nid));
mm/damon/ops-common.c +1 -1
@@ -274,7 +274,7 @@ bool damos_folio_filter_match(struct damos_filter *filter, struct folio *folio)if (!memcg) matched = false;else - matched = filter->memcg_id ==mem_cgroup_id (memcg); + matched = filter->memcg_id ==mem_cgroup_ino (memcg);rcu_read_unlock ();break ;case DAMOS_FILTER_TYPE_YOUNG :
mm/damon/sysfs-schemes.c +4 -4
@@ -2492,7 +2492,7 @@ static bool damon_sysfs_memcg_path_eq(struct mem_cgroup *memcg,return false; } -static int damon_sysfs_memcg_path_to_id (char *memcg_path,unsigned short *id) +static int damon_sysfs_memcg_path_to_id (char *memcg_path,u64 *id) {struct mem_cgroup *memcg;char *path;
@@ -2507,11 +2507,11 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)for (memcg =mem_cgroup_iter (NULL ,NULL ,NULL ); memcg; memcg =mem_cgroup_iter (NULL , memcg,NULL )) { -/* skip removed memcg */ -if (!mem_cgroup_id (memcg)) +/* skip offlined memcg */ +if (!mem_cgroup_online (memcg))continue ;if (damon_sysfs_memcg_path_eq (memcg, path, memcg_path)) { - *id =mem_cgroup_id (memcg); + *id =mem_cgroup_ino (memcg); found = true;break ; }
Signature · 1 line
2.47.3
Re: [PATCH 5/8] mm/damon: use cgroup ID instead of private memcg ID
Quoted 3 lines · On Thu, 25 Dec 2025 15:21:13 -0800 Shakeel Butt <[email protected]> wrote:
DAMON was using the internal private memcg ID which is meant for tracking kernel objects that outlive their cgroup. Switch to using the public cgroup ID instead.
Thank you for catching and fixing this!
Quoted 2 lines
Signed-off-by Shakeel Butt <[email protected]>
Thanks,
SJ
[...]
Shakeel Butt
maintainerPATCH 6/8 mm/vmscan: use cgroup ID instead of private memcg ID in lru_gen interface
In reply to Shakeel ButtThe LRU gen debugfs interface was using the internal private memcg ID which is meant for tracking kernel objects that outlive their cgroup. Switch to using the public cgroup ID instead.
--- mm/vmscan.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
mm/vmscan.c +6 -13
@@ -5426,7 +5426,7 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)if (memcg)cgroup_path (memcg->css.cgroup, m->private,PATH_MAX );#endif -seq_printf (m,"memcg %5hu %s\n" ,mem_cgroup_id (memcg), path); +seq_printf (m,"memcg %llu %s\n" ,mem_cgroup_ino (memcg), path); }seq_printf (m," node %5d\n" , nid);
@@ -5511,7 +5511,7 @@ static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_coreturn -EINTR ; } -static int run_cmd (char cmd,int memcg_id,int nid,unsigned long seq, +static int run_cmd (char cmd,u64 memcg_id,int nid,unsigned long seq,struct scan_control *sc,int swappiness,unsigned long opt) {struct lruvec *lruvec;
@@ -5522,19 +5522,12 @@ static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq,return -EINVAL ;if (!mem_cgroup_disabled ()) { -rcu_read_lock (); - - memcg =mem_cgroup_from_id (memcg_id); -if (!mem_cgroup_tryget (memcg)) - memcg =NULL ; - -rcu_read_unlock (); - + memcg =mem_cgroup_get_from_ino (memcg_id);if (!memcg)return -EINVAL ; } -if (memcg_id !=mem_cgroup_id (memcg)) +if (memcg_id !=mem_cgroup_ino (memcg)) goto done; sc->target_mem_cgroup = memcg;
@@ -5601,7 +5594,7 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src,int n;int end;char cmd, swap_string[5 ]; -unsigned int memcg_id; +u64 memcg_id;unsigned int nid;unsigned long seq;unsigned int swappiness;
@@ -5611,7 +5604,7 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src,if (!*cur)continue ; - n =sscanf (cur,"%c %u %u %lu %n %4s %n %lu %n" , &cmd, &memcg_id, &nid, + n =sscanf (cur,"%c %llu %u %lu %n %4s %n %lu %n" , &cmd, &memcg_id, &nid, &seq, &end, swap_string, &end, &opt, &end);if (n <4 || cur[end]) { err = -EINVAL ;
Signature · 1 line
2.47.3
Shakeel Butt
maintainerPATCH 7/8 memcg: remove unused mem_cgroup_id() and mem_cgroup_from_id()
In reply to Shakeel ButtNow that all callers have been converted to use either:
- The private ID APIs (mem_cgroup_private_id/mem_cgroup_from_private_id) for internal kernel objects that outlive their cgroup
- The public cgroup ID APIs (mem_cgroup_ino/mem_cgroup_get_from_ino) for external interfaces
Remove the unused wrapper functions mem_cgroup_id() and mem_cgroup_from_id() along with their !CONFIG_MEMCG stubs.
--- include/linux/memcontrol.h | 18 ------------------ mm/memcontrol.c | 5 ----- 2 files changed, 23 deletions(-)
include/linux/memcontrol.h +0 -18
@@ -830,12 +830,6 @@ 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 unsigned short mem_cgroup_id (struct mem_cgroup *memcg) -{ -return mem_cgroup_private_id (memcg); -} -struct mem_cgroup *mem_cgroup_from_id (unsigned short id); -static inline u64 mem_cgroup_ino (struct mem_cgroup *memcg) {return memcg ?cgroup_id (memcg->css.cgroup) :0 ;
@@ -1282,18 +1276,6 @@ static inline void mem_cgroup_scan_tasks(struct mem_cgroup *memcg, { } -static inline unsigned short mem_cgroup_id (struct mem_cgroup *memcg) -{ -return 0 ; -} - -static inline struct mem_cgroup *mem_cgroup_from_id (unsigned short id) -{ -WARN_ON_ONCE (id); -/* XXX: This should always return root_mem_cgroup */ -return NULL ; -} -static inline unsigned short mem_cgroup_private_id (struct mem_cgroup *memcg) {return 0 ;
mm/memcontrol.c +0 -5
@@ -3615,11 +3615,6 @@ struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return xa_load (&mem_cgroup_private_ids, id); } -struct mem_cgroup *mem_cgroup_from_id (unsigned short id) -{ -return mem_cgroup_from_private_id (id); -} -struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) {struct cgroup *cgrp;
Signature · 1 line
2.47.3
Shakeel Butt
maintainerPATCH 8/8 memcg: rename mem_cgroup_ino() to mem_cgroup_id()
In reply to Shakeel ButtRename mem_cgroup_ino() to mem_cgroup_id() and mem_cgroup_get_from_ino() to mem_cgroup_get_from_id(). These functions now use cgroup IDs (from cgroup_id()) rather than inode numbers, so the names should reflect that.
--- include/linux/memcontrol.h | 8 ++++---- mm/damon/core.c | 2 +- mm/damon/ops-common.c | 2 +- mm/damon/sysfs-schemes.c | 2 +- mm/memcontrol.c | 2 +- mm/shrinker_debug.c | 10 +++++----- mm/vmscan.c | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-)
include/linux/memcontrol.h +4 -4
@@ -830,12 +830,12 @@ 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_ino (struct mem_cgroup *memcg) +static inline u64 mem_cgroup_id (struct mem_cgroup *memcg) {return memcg ?cgroup_id (memcg->css.cgroup) :0 ; } -struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino); +struct mem_cgroup *mem_cgroup_get_from_id (u64 ino);static inline struct mem_cgroup *mem_cgroup_from_seq (struct seq_file *m) {
@@ -1288,12 +1288,12 @@ static inline struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return NULL ; } -static inline u64 mem_cgroup_ino (struct mem_cgroup *memcg) +static inline u64 mem_cgroup_id (struct mem_cgroup *memcg) {return 0 ; } -static inline struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) +static inline struct mem_cgroup *mem_cgroup_get_from_id (u64 ino) {return NULL ; }
mm/damon/core.c +1 -1
@@ -2065,7 +2065,7 @@ static unsigned long damos_get_node_memcg_used_bp(unsigned long used_pages, numerator;struct sysinfo i; - memcg =mem_cgroup_get_from_ino (goal->memcg_id); + memcg =mem_cgroup_get_from_id (goal->memcg_id);if (!memcg) {if (goal->metric ==DAMOS_QUOTA_NODE_MEMCG_USED_BP )return 0 ;
mm/damon/ops-common.c +1 -1
@@ -274,7 +274,7 @@ bool damos_folio_filter_match(struct damos_filter *filter, struct folio *folio)if (!memcg) matched = false;else - matched = filter->memcg_id ==mem_cgroup_ino (memcg); + matched = filter->memcg_id ==mem_cgroup_id (memcg);rcu_read_unlock ();break ;case DAMOS_FILTER_TYPE_YOUNG :
mm/damon/sysfs-schemes.c +1 -1
@@ -2511,7 +2511,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, u64 *id)if (!mem_cgroup_online (memcg))continue ;if (damon_sysfs_memcg_path_eq (memcg, path, memcg_path)) { - *id =mem_cgroup_ino (memcg); + *id =mem_cgroup_id (memcg); found = true;break ; }
mm/memcontrol.c +1 -1
@@ -3615,7 +3615,7 @@ struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return xa_load (&mem_cgroup_private_ids, id); } -struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) +struct mem_cgroup *mem_cgroup_get_from_id (u64 ino) {struct cgroup *cgrp;struct cgroup_subsys_state *css;
mm/shrinker_debug.c +5 -5
@@ -70,7 +70,7 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) memcg_aware ? memcg :NULL , count_per_node);if (total) { -seq_printf (m,"%llu" ,mem_cgroup_ino (memcg)); +seq_printf (m,"%llu" ,mem_cgroup_id (memcg));for_each_node (nid)seq_printf (m," %lu" , count_per_node[nid]);seq_putc (m,'\n' );
@@ -107,7 +107,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, {struct shrinker *shrinker = file->private_data;unsigned long nr_to_scan =0 , read_len; -u64 ino; +u64 id;struct shrink_control sc = { .gfp_mask =GFP_KERNEL , };
@@ -120,7 +120,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,return -EFAULT ; kbuf[read_len] ='\0' ; -if (sscanf (kbuf,"%llu %d %lu" , &ino, &nid, &nr_to_scan) !=3 ) +if (sscanf (kbuf,"%llu %d %lu" , &id, &nid, &nr_to_scan) !=3 )return -EINVAL ;if (nid <0 || nid >= nr_node_ids)
@@ -130,7 +130,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,return size;if (shrinker->flags &SHRINKER_MEMCG_AWARE ) { - memcg =mem_cgroup_get_from_ino (ino); + memcg =mem_cgroup_get_from_id (id);if (!memcg)return -ENOENT ;
@@ -138,7 +138,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,mem_cgroup_put (memcg);return -ENOENT ; } - }else if (ino !=0 ) { + }else if (id !=0 ) {return -EINVAL ; }
mm/vmscan.c +3 -3
@@ -5426,7 +5426,7 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)if (memcg)cgroup_path (memcg->css.cgroup, m->private,PATH_MAX );#endif -seq_printf (m,"memcg %llu %s\n" ,mem_cgroup_ino (memcg), path); +seq_printf (m,"memcg %llu %s\n" ,mem_cgroup_id (memcg), path); }seq_printf (m," node %5d\n" , nid);
@@ -5522,12 +5522,12 @@ static int run_cmd(char cmd, u64 memcg_id, int nid, unsigned long seq,return -EINVAL ;if (!mem_cgroup_disabled ()) { - memcg =mem_cgroup_get_from_ino (memcg_id); + memcg =mem_cgroup_get_from_id (memcg_id);if (!memcg)return -EINVAL ; } -if (memcg_id !=mem_cgroup_ino (memcg)) +if (memcg_id !=mem_cgroup_id (memcg)) goto done; sc->target_mem_cgroup = memcg;
Signature · 1 line
2.47.3
kernel test robot
build botRe: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id()
kernel test robot noticed the following build warnings:
Hi Shakeel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on sj/damon/next]
[cannot apply to akpm-mm/mm-everything tj-cgroup/for-next linus/master v6.19-rc2 next-20251219] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shakeel-Butt/memcg-introduce-private-id-API-for-in-kernel-users/20251226-072954 base: https://git.kernel.org/pub/scm/linux/kernel/git/sj/linux.git damon/next patch link: https://lore.kernel.org/r/20251225232116.294540-9-shakeel.butt%40linux.dev patch subject: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id() config: arm64-randconfig-001-20251226 (https://download.01.org/0day-ci/archive/20251226/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251226/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> mm/damon/sysfs.c:2704:33: warning: format specifies type 'unsigned int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
2704 | pr_info("id: %u, path: %s\n", mem_cgroup_id(memcg), path);
| ~~ ^~~~~~~~~~~~~~~~~~~~
| %llu
include/linux/printk.h:585:34: note: expanded from macro 'pr_info'
585 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
| ~~~ ^~~~~~~~~~~
include/linux/printk.h:512:60: note: expanded from macro 'printk'
512 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ~~~ ^~~~~~~~~~~
include/linux/printk.h:484:19: note: expanded from macro 'printk_index_wrap'
484 | _p_func(_fmt, ##__VA_ARGS__); \
| ~~~~ ^~~~~~~~~~~1 warning generated.
vim +2704 mm/damon/sysfs.c
c951cd3b89010c SeongJae Park 2022-03-22 2690
a25dadf8af8ddc SeongJae Park 2022-11-18 2691 static ssize_t debug_show(struct kobject *kobj,
a25dadf8af8ddc SeongJae Park 2022-11-18 2692 struct kobj_attribute *attr, char *buf)
a25dadf8af8ddc SeongJae Park 2022-11-18 2693 {
a25dadf8af8ddc SeongJae Park 2022-11-18 2694 #ifdef CONFIG_MEMCG
a25dadf8af8ddc SeongJae Park 2022-11-18 2695 struct mem_cgroup *memcg;
a25dadf8af8ddc SeongJae Park 2022-11-18 2696 char *path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL);
a25dadf8af8ddc SeongJae Park 2022-11-18 2697
a25dadf8af8ddc SeongJae Park 2022-11-18 2698 if (!path)
a25dadf8af8ddc SeongJae Park 2022-11-18 2699 return -ENOMEM;
a25dadf8af8ddc SeongJae Park 2022-11-18 2700
a25dadf8af8ddc SeongJae Park 2022-11-18 2701 for (memcg = mem_cgroup_iter(NULL, NULL, NULL); memcg; memcg =
a25dadf8af8ddc SeongJae Park 2022-11-18 2702 mem_cgroup_iter(NULL, memcg, NULL)) {
a25dadf8af8ddc SeongJae Park 2022-11-18 2703 cgroup_path(memcg->css.cgroup, path, PATH_MAX);
a25dadf8af8ddc SeongJae Park 2022-11-18 @2704 pr_info("id: %u, path: %s\n", mem_cgroup_id(memcg), path);
a25dadf8af8ddc SeongJae Park 2022-11-18 2705 }
a25dadf8af8ddc SeongJae Park 2022-11-18 2706
a25dadf8af8ddc SeongJae Park 2022-11-18 2707 kfree(path);
a25dadf8af8ddc SeongJae Park 2022-11-18 2708 #endif
a25dadf8af8ddc SeongJae Park 2022-11-18 2709
a25dadf8af8ddc SeongJae Park 2022-11-18 2710 return 0;
a25dadf8af8ddc SeongJae Park 2022-11-18 2711 }
a25dadf8af8ddc SeongJae Park 2022-11-18 2712 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
SeongJae Park
maintainerRe: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id()
Quoted 4 lines · On Fri, 26 Dec 2025 20:31:38 +0800 kernel test robot <[email protected]> wrote:
Hi Shakeel,
kernel test robot noticed the following build warnings:
Quoted 8 lines
[auto build test WARNING on sj/damon/next]
[cannot apply to akpm-mm/mm-everything tj-cgroup/for-next linus/master v6.19-rc2 next-20251219] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Shakeel-Butt/memcg-introduce-private-id-API-for-in-kernel-users/20251226-072954 base: https://git.kernel.org/pub/scm/linux/kernel/git/sj/linux.git damon/next
damon/next tree contains some debugging-purpose only changes that not aim to be upstreamed.
Quoted 11 lines
patch link: https://lore.kernel.org/r/20251225232116.294540-9-shakeel.butt%40linux.dev
patch subject: [PATCH 8/8] memcg: renamemem_cgroup_ino()tomem_cgroup_id()
config: arm64-randconfig-001-20251226 (https://download.01.org/0day-ci/archive/20251226/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251226/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 6 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
mm/damon/sysfs.c:2704:33: warning: format specifies type 'unsigned int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]2704 | pr_info("id: %u, path: %s\n", mem_cgroup_id(memcg), path); | ~~ ^~~~~~~~~~~~~~~~~~~~ | %llu
And this issue happens due to a damon/next chage that made for only debugging and thus not aiming to be upstreamed. Hence, no action from Shakeel is needed.
I will resolve this issue after this patch is added to damon/next.
Thanks,
SJ
[...]
SeongJae Park
maintainerRe: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id()
Quoted 17 lines · On Sat, 27 Dec 2025 14:12:05 -0800 SeongJae Park <[email protected]> wrote:
Quoted 4 lines · On Fri, 26 Dec 2025 20:31:38 +0800 kernel test robot <[email protected]> wrote:
Hi Shakeel,
kernel test robot noticed the following build warnings:
Quoted 8 lines
[auto build test WARNING on sj/damon/next]
[cannot apply to akpm-mm/mm-everything tj-cgroup/for-next linus/master v6.19-rc2 next-20251219] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Shakeel-Butt/memcg-introduce-private-id-API-for-in-kernel-users/20251226-072954 base: https://git.kernel.org/pub/scm/linux/kernel/git/sj/linux.git damon/nextdamon/next tree contains some debugging-purpose only changes that not aim to be upstreamed.
[...]
Quoted 4 lines
And this issue happens due to a damon/next chage that made for only debugging and thus not aiming to be upstreamed. Hence, no action from Shakeel is needed.
I will resolve this issue after this patch is added to damon/next.
FWIW, I ended up removing the debugging-only-purpose commit from damon/next. So hopefully it will not cause any noise.
Thanks,
SJ
[...]
kernel test robot
build botRe: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id()
In reply to Shakeel Buttkernel test robot noticed the following build warnings:
Hi Shakeel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on sj/damon/next]
[cannot apply to akpm-mm/mm-everything tj-cgroup/for-next linus/master v6.19-rc2 next-20251219] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shakeel-Butt/memcg-introduce-private-id-API-for-in-kernel-users/20251226-072954 base: https://git.kernel.org/pub/scm/linux/kernel/git/sj/linux.git damon/next patch link: https://lore.kernel.org/r/20251225232116.294540-9-shakeel.butt%40linux.dev patch subject: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id() config: openrisc-allmodconfig (https://download.01.org/0day-ci/archive/20251226/[email protected]/config) compiler: or1k-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251226/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/asm-generic/bug.h:31,
from arch/openrisc/include/asm/bug.h:5, from include/linux/bug.h:5,
from include/linux/thread_info.h:13,
from include/asm-generic/current.h:6,
from ./arch/openrisc/include/generated/asm/current.h:1, from include/linux/sched.h:12,
from include/linux/rcupdate.h:27,
from include/linux/rculist.h:11,
from include/linux/pid.h:6,
from mm/damon/sysfs.c:8:
mm/damon/sysfs.c: In function 'debug_show':
>> include/linux/kern_levels.h:5:25: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:484:25: note: in definition of macro 'printk_index_wrap'
484 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:585:9: note: in expansion of macro 'printk'
585 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:14:25: note: in expansion of macro 'KERN_SOH'
14 | #define KERN_INFO KERN_SOH "6" /* informational */
| ^~~~~~~~
include/linux/printk.h:585:16: note: in expansion of macro 'KERN_INFO'
585 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~
mm/damon/sysfs.c:2704:17: note: in expansion of macro 'pr_info'
2704 | pr_info("id: %u, path: %s\n", mem_cgroup_id(memcg), path);
| ^~~~~~~vim +5 include/linux/kern_levels.h
314ba3520e513a Joe Perches 2012-07-30 404d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'04d2c8c83d0e3a Joe Perches 2012-07-30 7
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id()
In reply to Shakeel ButtQuoted 5 lines · On Thu, 25 Dec 2025 15:21:16 -0800 Shakeel Butt <[email protected]> wrote:
Rename
mem_cgroup_ino()tomem_cgroup_id()andmem_cgroup_get_from_ino()tomem_cgroup_get_from_id(). These functions now use cgroup IDs (fromcgroup_id()) rather than inode numbers, so the names should reflect that.Signed-off-by Shakeel Butt <[email protected]>
I left trivial comments below. Because those are only trivial,
Quoted 14 lines
--- include/linux/memcontrol.h | 8 ++++---- mm/damon/core.c | 2 +- mm/damon/ops-common.c | 2 +- mm/damon/sysfs-schemes.c | 2 +- mm/memcontrol.c | 2 +- mm/shrinker_debug.c | 10 +++++----- mm/vmscan.c | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-)include/linux/memcontrol.h +0
-0
[...]
include/linux/memcontrol.h static inline unsigned short mem_cgroup_private_id(struct mem_cgroup *memcg) · line 838
Quoted 2 lines
include/linux/memcontrol.h +1
-1-struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino); +struct mem_cgroup *mem_cgroup_get_from_id (u64 ino);
Nit. How about renaming the argument from 'ino' to 'id'?
[...]
include/linux/memcontrol.h static inline struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id) · line 1296
Quoted 2 lines
include/linux/memcontrol.h +1
-1-static inline struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) +static inline struct mem_cgroup *mem_cgroup_get_from_id (u64 ino)
Ditto.
[...]
mm/memcontrol.c struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id) · line 3618
Quoted 8 lines
mm/memcontrol.c +1
-1@@ -3615,7 +3615,7 @@ struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return xa_load (&mem_cgroup_private_ids, id); } -struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) +struct mem_cgroup *mem_cgroup_get_from_id (u64 ino)
Ditto.
Thanks,
SJ
[...]
Shakeel Butt
maintainerRe: [PATCH 8/8] memcg: rename mem_cgroup_ino() to mem_cgroup_id()
Quoted 1 line · SeongJae Park
On Thu, 25 Dec 2025 15:21:16 -0800 Shakeel Butt <[email protected]> wrote:
[...]
Quoted 23 lines
Quoted 4 lines
include/linux/memcontrol.h +0
-0[...]
include/linux/memcontrol.h
Quoted 2 lines
include/linux/memcontrol.h +1
-1-struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino); +struct mem_cgroup *mem_cgroup_get_from_id (u64 ino);Nit. How about renaming the argument from 'ino' to 'id'?
[...]
include/linux/memcontrol.h
Quoted 2 lines
include/linux/memcontrol.h +1
-1-static inline struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) +static inline struct mem_cgroup *mem_cgroup_get_from_id (u64 ino)Ditto.
[...]
Quoted 6 lines
mm/memcontrol.c +0
-0@@ -3615,7 +3615,7 @@ struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return xa_load (&mem_cgroup_private_ids, id); }
Quoted 5 lines
mm/memcontrol.c struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id) · line 3618
Quoted 2 lines
mm/memcontrol.c +1
-1-struct mem_cgroup *mem_cgroup_get_from_ino (u64 ino) +struct mem_cgroup *mem_cgroup_get_from_id (u64 ino)Ditto.
Thanks a lot SJ for the review and suggestions.
Andrew, can you please squash the following fix into the series?
From 7bf26690649ab9c555d17a2acb7215e768232d13 Mon Sep 17 00:00:00 2001
From: Shakeel Butt <[email protected]>
Date: Mon, 12 Jan 2026 13:34:27 -0800
Subject: [PATCH] memcg: replace ino with id
--- include/linux/memcontrol.h | 4 ++-- mm/memcontrol.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/memcontrol.h +2 -2
@@ -835,7 +835,7 @@ static inline u64 mem_cgroup_id(struct mem_cgroup *memcg)return memcg ?cgroup_id (memcg->css.cgroup) :0 ; } -struct mem_cgroup *mem_cgroup_get_from_id (u64 ino); +struct mem_cgroup *mem_cgroup_get_from_id (u64 id);static inline struct mem_cgroup *mem_cgroup_from_seq (struct seq_file *m) {
@@ -1293,7 +1293,7 @@ static inline u64 mem_cgroup_id(struct mem_cgroup *memcg)return 0 ; } -static inline struct mem_cgroup *mem_cgroup_get_from_id (u64 ino) +static inline struct mem_cgroup *mem_cgroup_get_from_id (u64 id) {return NULL ; }
mm/memcontrol.c +1 -1
@@ -3615,7 +3615,7 @@ struct mem_cgroup *mem_cgroup_from_private_id(unsigned short id)return xa_load (&mem_cgroup_private_ids, id); } -struct mem_cgroup *mem_cgroup_get_from_id (u64 ino) +struct mem_cgroup *mem_cgroup_get_from_id (u64 id) {struct cgroup *cgrp;struct cgroup_subsys_state *css;
Signature · 1 line
2.47.3
SeongJae Park
maintainerQuoted 9 lines · On Thu, 25 Dec 2025 15:21:08 -0800 Shakeel Butt <[email protected]> wrote:
The memory cgroup subsystem maintains a private ID infrastructure that is decoupled from the cgroup IDs. This private ID system exists because some kernel objects (like swap entries and shadow entries in the workingset code) can outlive the cgroup they were associated with. The motivation is best described in commit
73f576c04b941("mm:
memcontrol: fix cgroup creation failure after many small jobs").Unfortunately, some in-kernel users (DAMON, LRU gen debugfs interface, shrinker debugfs) started exposing these private IDs to userspace.
Technically speaking, DAMON is not exposing the private IDs to userspace. It does use the ids to specify the memory cgroups in kernel space. But, when it communicates with the user space, it uses the paths of the cgroups, not the ids.
Quoted 6 lines
This is problematic because:
1. The private IDs are internal implementation details that could change
2. Userspace already has access to cgroup IDs through the cgroup filesystem
3. Using different ID namespaces in different interfaces is confusing
Though DAMON is not exposing the IDs to the userspace, I agree it is better to use public id, mainly because DAMON doesn't really care about the cgroup-outlive objects. Also, it would allow easier change of the implementation details and make more consistent kernel-space API usages.
Thanks,
SJ
[...]
Quoted 30 lines · Shakeel Butt
The memory cgroup subsystem maintains a private ID infrastructure that is decoupled from the cgroup IDs. This private ID system exists because some kernel objects (like swap entries and shadow entries in the workingset code) can outlive the cgroup they were associated with. The motivation is best described in commit
73f576c04b941("mm:
memcontrol: fix cgroup creation failure after many small jobs").Unfortunately, some in-kernel users (DAMON, LRU gen debugfs interface, shrinker debugfs) started exposing these private IDs to userspace. This is problematic because:
1. The private IDs are internal implementation details that could change
2. Userspace already has access to cgroup IDs through the cgroup filesystem
3. Using different ID namespaces in different interfaces is confusingThis series cleans up the memcg ID infrastructure by:
1. Explicitly marking the private ID APIs with "private" in their names to make it clear they are for internal use only (swap/workingset)
2. Making the public cgroup ID APIs (mem_cgroup_id/mem_cgroup_get_from_id) unconditionally available
3. Converting DAMON, LRU gen, and shrinker debugfs interfaces to use the public cgroup IDs instead of the private IDs
4. Removing the now-unused wrapper functions and renaming the public APIs for clarity
Quoted 8 lines
After this series:
-mem_cgroup_private_id()/mem_cgroup_from_private_id()are used for internal kernel objects that outlive their cgroup (swap, workingset)
-mem_cgroup_id()/mem_cgroup_get_from_id()return the public cgroup ID (fromcgroup_id()) for use in userspace-facing interfacesNote: please apply this series after the patch at
https://lore.kernel.org/[email protected]/
Makes sense to me. Originally I was not supper happy about the private interface as this should be really private to memcg proper but then I have noticed the lru code needs this outside and dealing with that would be quite messy so an explicit name is probably better in the end.
Feel free to add
Thanks!
Quoted 28 lines
Shakeel Butt (8):
memcg: introduce private id API for in-kernel users
memcg: exposemem_cgroup_ino()andmem_cgroup_get_from_ino()
unconditionally
memcg:mem_cgroup_get_from_ino()returns NULL on error
memcg: usecgroup_id()instead ofcgroup_ino()for memcg ID mm/damon: use cgroup ID instead of private memcg ID mm/vmscan: use cgroup ID instead of private memcg ID inlru_gen
interface
memcg: remove unusedmem_cgroup_id()andmem_cgroup_from_id()
memcg: renamemem_cgroup_ino()tomem_cgroup_id()include/linux/damon.h | 4 +-- include/linux/memcontrol.h | 26 +++++++---------- mm/damon/core.c | 7 ++--- mm/damon/sysfs-schemes.c | 6 ++-- mm/list_lru.c | 2 +- mm/memcontrol-v1.c | 6 ++-- mm/memcontrol-v1.h | 4 +-- mm/memcontrol.c | 60 ++++++++++++++++++-------------------- mm/shrinker_debug.c | 13 +++++---- mm/vmscan.c | 17 ++++------- mm/workingset.c | 8 ++--- 11 files changed, 68 insertions(+), 85 deletions(-)--
2.47.3
Signature · 2 lines
Michal Hocko SUSE Labs
Andrew Morton
maintainerQuoted 2 lines · On Tue, 6 Jan 2026 11:25:59 +0100 Michal Hocko <[email protected]> wrote:
Quoted 2 lines
Note: please apply this series after the patch at
https://lore.kernel.org/[email protected]/
OK, that's in mm-hotfixes-unstable.
Quoted 7 lines
Makes sense to me. Originally I was not supper happy about the private interface as this should be really private to memcg proper but then I have noticed the lru code needs this outside and dealing with that would be quite messy so an explicit name is probably better in the end.
Feel free to add
Acked-by Michal Hocko <[email protected]>
Great, thanks, I'll add it. The series in somewhat old (Dec 25) but nothing seems to have changed.