Skip to contentSkip to conversation

mm/sparse: return right away if sparsemap_buf is null

PATCH In review Leesoo Ahn 4 participants 5 messages Jul 26, 2024 – Aug 7, 2024

Subsystems (2)
lore
Share & tools
lore

Leesoo Ahn

author
#0 lore raw

PATCH 1/1 mm/sparse: return right away if sparsemap_buf is null

sparse_buffer_fini(..) takes the following actions even though the value of sparsemap_buf is NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. set sparsemap_buf variable to NULL (although it is already NULL).

These steps are unnecessary if the variable, sparsemap_buf is NULL.

Refactor the function to return right away if the variable is NULL. Hence, it doesn't need to take further actions.

---
 mm/sparse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/sparse.c +6 -2
index e4b830091d13..091e4bc2f72c 100644
@@ -469,9 +469,13 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
 
 static void __init sparse_buffer_fini(void)
 {
-	unsigned long size = sparsemap_buf_end - sparsemap_buf;
+	unsigned long size;
 
-	if (sparsemap_buf && size > 0)
+	if (!sparsemap_buf)
+		return;
+
+	size = sparsemap_buf_end - sparsemap_buf;
+	if (size > 0)
 		sparse_buffer_free(size);
 	sparsemap_buf = NULL;
 }
Signature · 1 line
2.34.1
reviewer
#1 lore raw
Quoted 9 lines · Leesoo Ahn

sparse_buffer_fini(..) takes the following actions even though the value of sparsemap_buf is NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. set sparsemap_buf variable to NULL (although it is already NULL).

These steps are unnecessary if the variable, sparsemap_buf is NULL.

Refactor the function to return right away if the variable is NULL. Hence, it doesn't need to take further actions.

sparse_buffer_fini() is called a few times on init so saving a jump (if at all) does not worth the churn.

Quoted 29 lines
---
 mm/sparse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/sparse.c +6 -2
index e4b830091d13..091e4bc2f72c 100644
@@ -469,9 +469,13 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
 
 static void __init sparse_buffer_fini(void)
 {
-	unsigned long size = sparsemap_buf_end - sparsemap_buf;
+	unsigned long size;
 
-	if (sparsemap_buf && size > 0)
+	if (!sparsemap_buf)
+		return;
+
+	size = sparsemap_buf_end - sparsemap_buf;
+	if (size > 0)
 		sparse_buffer_free(size);
 	sparsemap_buf = NULL;
 }
Signature · 1 line
2.34.1
Signature · 2 lines
Sincerely yours,
Mike.
#2 lore raw
Quoted 6 lines · Mike Rapoport
Quoted 5 lines · Leesoo Ahn

sparse_buffer_fini(..) takes the following actions even though the value of sparsemap_buf is NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. set sparsemap_buf variable to NULL (although it is already NULL).

Quoted 7 lines
Quoted 4 lines

These steps are unnecessary if the variable, sparsemap_buf is NULL.

Refactor the function to return right away if the variable is NULL. Hence, it doesn't need to take further actions.

sparse_buffer_fini() is called a few times on init so saving a jump (if at all) does not worth the churn.

Agreed, this is not worth the churn given there could be just a single call instance for sparse_buffer_fini(), either in normal or error path in sparse_init_nid().

Quoted 31 lines
Quoted 30 lines
---
 mm/sparse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/sparse.c +6 -2
index e4b830091d13..091e4bc2f72c 100644
@@ -469,9 +469,13 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
 
 static void __init sparse_buffer_fini(void)
 {
-	unsigned long size = sparsemap_buf_end - sparsemap_buf;
+	unsigned long size;
 
-	if (sparsemap_buf && size > 0)
+	if (!sparsemap_buf)
+		return;
+
+	size = sparsemap_buf_end - sparsemap_buf;
+	if (size > 0)
 		sparse_buffer_free(size);
 	sparsemap_buf = NULL;
 }
Signature · 1 line
2.34.1
author
#3 lore raw
In reply to Mike Rapoport

2024년 7월 28일 (일) 오후 9:43, Mike Rapoport <[email protected]>님이 작성:

Quoted 7 lines · Leesoo Ahn
Quoted 5 lines

sparse_buffer_fini(..) takes the following actions even though the value of sparsemap_buf is NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. set sparsemap_buf variable to NULL (although it is already NULL).

Quoted 7 lines
Quoted 4 lines

These steps are unnecessary if the variable, sparsemap_buf is NULL.

Refactor the function to return right away if the variable is NULL. Hence, it doesn't need to take further actions.

sparse_buffer_fini() is called a few times on init so saving a jump (if at all) does not worth the churn.

Fair enough.

Any related to refactoring codebase will be unlikely to be taken into upstream??

BR,
Leesoo

#4 lore raw
Quoted 13 lines · Leesoo Ahn

2024년 7월 28일 (일) 오후 9:43, Mike Rapoport <[email protected]>님이 작성:

Quoted 12 lines · Leesoo Ahn
Quoted 9 lines

sparse_buffer_fini(..) takes the following actions even though the value of sparsemap_buf is NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. set sparsemap_buf variable to NULL (although it is already NULL).

These steps are unnecessary if the variable, sparsemap_buf is NULL.

Refactor the function to return right away if the variable is NULL. Hence, it doesn't need to take further actions.

Quoted 6 lines
Quoted 2 lines

sparse_buffer_fini() is called a few times on init so saving a jump (if at all) does not worth the churn.

Fair enough.

Any related to refactoring codebase will be unlikely to be taken into upstream??

Any reasonable cleanups or reasonable optimizations are welcome.

Micro-optimizations that effectively add code/LOC, not so much :)

Signature · 3 lines
Cheers,

David / dhildenb