mm/sparse: return right away if sparsemap_buf is null
Subsystems (2)
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
@@ -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
Mike Rapoport
reviewerQuoted 9 lines · Leesoo Ahn
sparse_buffer_fini(..)takes the following actions even though the value ofsparsemap_bufis NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. setsparsemap_bufvariable to NULL (although it is already NULL).These steps are unnecessary if the variable,
sparsemap_bufis 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
Signed-off-by Leesoo Ahn <[email protected]>--- mm/sparse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)mm/sparse.c +6
-2@@ -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.
Quoted 6 lines · Mike Rapoport
Quoted 5 lines · Leesoo Ahn
sparse_buffer_fini(..)takes the following actions even though the value ofsparsemap_bufis NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. setsparsemap_bufvariable to NULL (although it is already NULL).
Quoted 7 lines
Quoted 4 lines
These steps are unnecessary if the variable,
sparsemap_bufis 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
Signed-off-by Leesoo Ahn <[email protected]>--- mm/sparse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)mm/sparse.c +6
-2@@ -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
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 ofsparsemap_bufis NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. setsparsemap_bufvariable to NULL (although it is already NULL).
Quoted 7 lines
Quoted 4 lines
These steps are unnecessary if the variable,
sparsemap_bufis 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
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 ofsparsemap_bufis NULL,
1. calculate size of sparsemap buffer (which is meaningless).
2. setsparsemap_bufvariable to NULL (although it is already NULL).These steps are unnecessary if the variable,
sparsemap_bufis 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