[RESEND] mm/sparse: remove duplicated pfn_to_section_nr()
diff mbox series

Message ID 1584345587-16769-1-git-send-email-qiwuchen55@gmail.com
State New
Headers show
Series
  • [RESEND] mm/sparse: remove duplicated pfn_to_section_nr()
Related show

Commit Message

Qiwu Chen March 16, 2020, 7:59 a.m. UTC
From: chenqiwu <chenqiwu@xiaomi.com>

Remove duplicated pfn_to_section_nr() in pfn_valid() and pfn_present()
to increase executing efficiency of code.

Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
 include/linux/mmzone.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Pankaj Gupta March 16, 2020, 8:45 a.m. UTC | #1
> From: chenqiwu <chenqiwu@xiaomi.com>
>
> Remove duplicated pfn_to_section_nr() in pfn_valid() and pfn_present()
> to increase executing efficiency of code.
>
> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> ---
>  include/linux/mmzone.h | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 462f687..35763b5 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1358,10 +1358,11 @@ static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
>  static inline int pfn_valid(unsigned long pfn)
>  {
>         struct mem_section *ms;
> +       unsigned long sec_nr = pfn_to_section_nr(pfn);
>
> -       if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
> +       if (sec_nr >= NR_MEM_SECTIONS)
>                 return 0;
> -       ms = __nr_to_section(pfn_to_section_nr(pfn));
> +       ms = __nr_to_section(sec_nr);
>         if (!valid_section(ms))
>                 return 0;
>         /*
> @@ -1374,9 +1375,11 @@ static inline int pfn_valid(unsigned long pfn)
>
>  static inline int pfn_present(unsigned long pfn)
>  {
> -       if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
> +       unsigned long sec_nr = pfn_to_section_nr(pfn);
> +
> +       if (sec_nr >= NR_MEM_SECTIONS)
>                 return 0;
> -       return present_section(__nr_to_section(pfn_to_section_nr(pfn)));
> +       return present_section(__nr_to_section(sec_nr));
>  }
>
>  static inline unsigned long next_present_section_nr(unsigned long section_nr)
> --

Looks ok.
Acked-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>

> 1.9.1
>
>
Andrew Morton March 21, 2020, 3:04 a.m. UTC | #2
On Mon, 16 Mar 2020 15:59:47 +0800 qiwuchen55@gmail.com wrote:

> From: chenqiwu <chenqiwu@xiaomi.com>
> 
> Remove duplicated pfn_to_section_nr() in pfn_valid() and pfn_present()
> to increase executing efficiency of code.
> 
> ...
>
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1358,10 +1358,11 @@ static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
>  static inline int pfn_valid(unsigned long pfn)
>  {
>  	struct mem_section *ms;
> +	unsigned long sec_nr = pfn_to_section_nr(pfn);
>  
> -	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
> +	if (sec_nr >= NR_MEM_SECTIONS)
>  		return 0;
> -	ms = __nr_to_section(pfn_to_section_nr(pfn));
> +	ms = __nr_to_section(sec_nr);
>  	if (!valid_section(ms))
>  		return 0;
>  	/*
> @@ -1374,9 +1375,11 @@ static inline int pfn_valid(unsigned long pfn)
>  
>  static inline int pfn_present(unsigned long pfn)
>  {
> -	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
> +	unsigned long sec_nr = pfn_to_section_nr(pfn);
> +
> +	if (sec_nr >= NR_MEM_SECTIONS)
>  		return 0;
> -	return present_section(__nr_to_section(pfn_to_section_nr(pfn)));
> +	return present_section(__nr_to_section(sec_nr));
>  }
>  

The compiler already makes this optimization (pfn_to_section_nr() is
very simple).  Generated code appears to be identical.

I guess this patch could be sold as a cleanup, but I don't think it's
worthwhile, really.

Patch
diff mbox series

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 462f687..35763b5 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1358,10 +1358,11 @@  static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
 static inline int pfn_valid(unsigned long pfn)
 {
 	struct mem_section *ms;
+	unsigned long sec_nr = pfn_to_section_nr(pfn);
 
-	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
+	if (sec_nr >= NR_MEM_SECTIONS)
 		return 0;
-	ms = __nr_to_section(pfn_to_section_nr(pfn));
+	ms = __nr_to_section(sec_nr);
 	if (!valid_section(ms))
 		return 0;
 	/*
@@ -1374,9 +1375,11 @@  static inline int pfn_valid(unsigned long pfn)
 
 static inline int pfn_present(unsigned long pfn)
 {
-	if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
+	unsigned long sec_nr = pfn_to_section_nr(pfn);
+
+	if (sec_nr >= NR_MEM_SECTIONS)
 		return 0;
-	return present_section(__nr_to_section(pfn_to_section_nr(pfn)));
+	return present_section(__nr_to_section(sec_nr));
 }
 
 static inline unsigned long next_present_section_nr(unsigned long section_nr)