Skip to contentSkip to conversation

mm/slub: avoid double string traverse in kmem_cache_flags()

PATCH In review Yury Norov 2 participants 3 messages May 1, 2019 – May 14, 2019

Subsystems (2)
lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH 1/1 mm/slub: avoid double string traverse in kmem_cache_flags()

If ',' is not found, kmem_cache_flags() calls strlen() to find the end of line. We can do it in a single pass using strchrnul().

---
 mm/slub.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/slub.c +1 -3
index 4922a0394757..85f90370a293 100644
@@ -1317,9 +1317,7 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
 		char *end, *glob;
 		size_t cmplen;
 
-		end = strchr(iter, ',');
-		if (!end)
-			end = iter + strlen(iter);
+		end = strchrnul(iter, ',');
 
 		glob = strnchr(iter, end - iter, '*');
 		if (glob)
Signature · 1 line
2.17.1
author
#1 lore raw
Quoted 2 lines · Yury Norov

If ',' is not found, kmem_cache_flags() calls strlen() to find the end of line. We can do it in a single pass using strchrnul().

Ping?

Quoted 22 lines
---
 mm/slub.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/slub.c +1 -3
index 4922a0394757..85f90370a293 100644
@@ -1317,9 +1317,7 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
 		char *end, *glob;
 		size_t cmplen;
 
-		end = strchr(iter, ',');
-		if (!end)
-			end = iter + strlen(iter);
+		end = strchrnul(iter, ',');
 
 		glob = strnchr(iter, end - iter, '*');
 		if (glob)
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#2 lore raw
In reply to Yury Norov
Quoted 13 lines · Yury Norov

If ',' is not found, kmem_cache_flags() calls strlen() to find the end of line. We can do it in a single pass using strchrnul().

---
 mm/slub.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/slub.c +0 -0
index 4922a0394757..85f90370a293 100644

mm/slub.c slab_flags_t kmem_cache_flags(unsigned int object_size, · line 1323

Quoted 10 lines
mm/slub.c +1 -3
@@ -1317,9 +1317,7 @@ slab_flags_t kmem_cache_flags(unsigned int object_size,
 		char *end, *glob;
 		size_t cmplen;
 
-		end = strchr(iter, ',');
-		if (!end)
-			end = iter + strlen(iter);
+		end = strchrnul(iter, ',');
 
 		glob = strnchr(iter, end - iter, '*');
 		if (glob)

Fair enough.

Signature · 1 line
Aaron Tomlin