Skip to contentSkip to conversation

alloc_tag: check mem_profiling_support in alloc_tag_init

PATCH Superseded Casey Chen 2 participants 3 messages May 8, 2025 – May 12, 2025

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Casey Chen

author
#0 lore raw

PATCH v2 1/1 alloc_tag: check mem_profiling_support in alloc_tag_init

Allocate module tags and register codetag type only when mem_profiling_support is true. If it is set as false, for example by sysctl.vm.mem_profiling=never, skip them.

---
 lib/alloc_tag.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/alloc_tag.c +10 -8
index 25ecc1334b67..fbf128072c7e 100644
@@ -762,14 +762,16 @@ static int __init alloc_tag_init(void)
 	};
 	int res;
 
-	res = alloc_mod_tags_mem();
-	if (res)
-		return res;
-
-	alloc_tag_cttype = codetag_register_type(&desc);
-	if (IS_ERR(alloc_tag_cttype)) {
-		free_mod_tags_mem();
-		return PTR_ERR(alloc_tag_cttype);
+	if (mem_profiling_support) {
+		res = alloc_mod_tags_mem();
+		if (res)
+			return res;
+
+		alloc_tag_cttype = codetag_register_type(&desc);
+		if (IS_ERR(alloc_tag_cttype)) {
+			free_mod_tags_mem();
+			return PTR_ERR(alloc_tag_cttype);
+		}
 	}
 
 	sysctl_init();
Signature · 1 line
2.49.0
#1 lore raw
Quoted 7 lines · Casey Chen

Allocate module tags and register codetag type only when mem_profiling_support is true. If it is set as false, for example by sysctl.vm.mem_profiling=never, skip them.

Thanks! Looks good to me but let me take a closer look over the weekend to make sure we do not break anything by skipping this allocation.

Quoted 36 lines
---
 lib/alloc_tag.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/alloc_tag.c +10 -9
index 25ecc1334b67..fbf128072c7e 100644
@@ -762,14 +762,16 @@ static int __init alloc_tag_init(void)
        };
        int res;
 
-       res = alloc_mod_tags_mem();
-       if (res)
-               return res;
-
-       alloc_tag_cttype = codetag_register_type(&desc);
-       if (IS_ERR(alloc_tag_cttype)) {
-               free_mod_tags_mem();
-               return PTR_ERR(alloc_tag_cttype);
+       if (mem_profiling_support) {
+               res = alloc_mod_tags_mem();
+               if (res)
+                       return res;
+
+               alloc_tag_cttype = codetag_register_type(&desc);
+               if (IS_ERR(alloc_tag_cttype)) {
+                       free_mod_tags_mem();
+                       return PTR_ERR(alloc_tag_cttype);
+               }
        }
 
        sysctl_init();
--

2.49.0

#2 lore raw
Quoted 7 lines · Suren Baghdasaryan
Quoted 5 lines · Casey Chen

Allocate module tags and register codetag type only when mem_profiling_support is true. If it is set as false, for example by sysctl.vm.mem_profiling=never, skip them.

Quoted 6 lines
Quoted 2 lines

Thanks! Looks good to me but let me take a closer look over the weekend to make sure we do not break anything by skipping this allocation.

I tested the patch and it works as expected. One thing I noticed is the extra mem_profiling_support check inside procfs_init(). Please move procfs_init() call into the "if (mem_profiling_support)" block you added and remove the extra mem_profiling_support check from procfs_init(). Actually, since procfs_init() becomes just one call after the extra check removal, I would suggest just moving the proc_create_seq() into alloc_tag_init() directly and eliminating the procfs_init() function completely.

Quoted 37 lines
Quoted 37 lines
---
 lib/alloc_tag.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
lib/alloc_tag.c +10 -9
index 25ecc1334b67..fbf128072c7e 100644
@@ -762,14 +762,16 @@ static int __init alloc_tag_init(void)
        };
        int res;
 
-       res = alloc_mod_tags_mem();
-       if (res)
-               return res;
-
-       alloc_tag_cttype = codetag_register_type(&desc);
-       if (IS_ERR(alloc_tag_cttype)) {
-               free_mod_tags_mem();
-               return PTR_ERR(alloc_tag_cttype);
+       if (mem_profiling_support) {
+               res = alloc_mod_tags_mem();
+               if (res)
+                       return res;
+
+               alloc_tag_cttype = codetag_register_type(&desc);
+               if (IS_ERR(alloc_tag_cttype)) {
+                       free_mod_tags_mem();
+                       return PTR_ERR(alloc_tag_cttype);
+               }
        }
 
        sysctl_init();
--

2.49.0