Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1473005 > unrolled thread

[PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h

Started byAnshuman Khandual <khandual@linux.vnet.ibm.com>
First post2016-08-31 05:30 +0200
Last post2016-09-02 06:30 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h Anshuman Khandual <khandual@linux.vnet.ibm.com> - 2016-08-31 05:30 +0200
    Re: [PATCH 1/2] mm: Move definition of 'zone_names' array into  mmzone.h Andrew Morton <akpm@linux-foundation.org> - 2016-08-31 23:20 +0200
      Re: [PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h Anshuman Khandual <khandual@linux.vnet.ibm.com> - 2016-09-02 06:30 +0200

#1473005 — [PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h

FromAnshuman Khandual <khandual@linux.vnet.ibm.com>
Date2016-08-31 05:30 +0200
Subject[PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h
Message-ID<sc4nZ-5qM-7@gated-at.bofh.it>
zone_names[] is used to identify any zone given it's index which
can be used in many other places. So moving the definition into
include/linux/mmzone.h for broader access.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
---
 include/linux/mmzone.h | 17 +++++++++++++++++
 mm/page_alloc.c        | 17 -----------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index d572b78..01ca3f4 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -341,6 +341,23 @@ enum zone_type {
 
 };
 
+static char * const zone_names[__MAX_NR_ZONES] = {
+#ifdef CONFIG_ZONE_DMA
+	 "DMA",
+#endif
+#ifdef CONFIG_ZONE_DMA32
+	 "DMA32",
+#endif
+	 "Normal",
+#ifdef CONFIG_HIGHMEM
+	 "HighMem",
+#endif
+	 "Movable",
+#ifdef CONFIG_ZONE_DEVICE
+	 "Device",
+#endif
+};
+
 #ifndef __GENERATING_BOUNDS_H
 
 struct zone {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3fbe73a..8e2261c 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -207,23 +207,6 @@ int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1] = {
 
 EXPORT_SYMBOL(totalram_pages);
 
-static char * const zone_names[MAX_NR_ZONES] = {
-#ifdef CONFIG_ZONE_DMA
-	 "DMA",
-#endif
-#ifdef CONFIG_ZONE_DMA32
-	 "DMA32",
-#endif
-	 "Normal",
-#ifdef CONFIG_HIGHMEM
-	 "HighMem",
-#endif
-	 "Movable",
-#ifdef CONFIG_ZONE_DEVICE
-	 "Device",
-#endif
-};
-
 char * const migratetype_names[MIGRATE_TYPES] = {
 	"Unmovable",
 	"Movable",
-- 
1.9.3

[toc] | [next] | [standalone]


#1473886 — Re: [PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h

FromAndrew Morton <akpm@linux-foundation.org>
Date2016-08-31 23:20 +0200
SubjectRe: [PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h
Message-ID<scl5n-7Av-3@gated-at.bofh.it>
In reply to#1473005
On Wed, 31 Aug 2016 08:55:49 +0530 Anshuman Khandual <khandual@linux.vnet.ibm.com> wrote:

> zone_names[] is used to identify any zone given it's index which
> can be used in many other places. So moving the definition into
> include/linux/mmzone.h for broader access.
> 
> ...
>
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -341,6 +341,23 @@ enum zone_type {
>  
>  };
>  
> +static char * const zone_names[__MAX_NR_ZONES] = {
> +#ifdef CONFIG_ZONE_DMA
> +	 "DMA",
> +#endif
> +#ifdef CONFIG_ZONE_DMA32
> +	 "DMA32",
> +#endif
> +	 "Normal",
> +#ifdef CONFIG_HIGHMEM
> +	 "HighMem",
> +#endif
> +	 "Movable",
> +#ifdef CONFIG_ZONE_DEVICE
> +	 "Device",
> +#endif
> +};
> +
>  #ifndef __GENERATING_BOUNDS_H
>  
>  struct zone {
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 3fbe73a..8e2261c 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -207,23 +207,6 @@ int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1] = {
>  
>  EXPORT_SYMBOL(totalram_pages);
>  
> -static char * const zone_names[MAX_NR_ZONES] = {
> -#ifdef CONFIG_ZONE_DMA
> -	 "DMA",
> -#endif
> -#ifdef CONFIG_ZONE_DMA32
> -	 "DMA32",
> -#endif
> -	 "Normal",
> -#ifdef CONFIG_HIGHMEM
> -	 "HighMem",
> -#endif
> -	 "Movable",
> -#ifdef CONFIG_ZONE_DEVICE
> -	 "Device",
> -#endif
> -};
> -
>  char * const migratetype_names[MIGRATE_TYPES] = {
>  	"Unmovable",
>  	"Movable",

This is worrisome.  On some (ancient) compilers, this will produce a
copy of that array into each compilation unit which includes mmzone.h.

On smarter compilers, it will produce a copy of the array in each
compilation unit which *uses* zone_names[].

On even smarter compilers (and linkers!), only one copy of zone_names[]
will exist in vmlinux.

I don't know if gcc is an "even smarter compiler" and I didn't check,
and I didn't check which gcc versions are even smarter.  I'd rather not
have to ;) It is risky.

So, let's just make it non-static and add a declaration into mmzone.h,
please.

[toc] | [prev] | [next] | [standalone]


#1474884

FromAnshuman Khandual <khandual@linux.vnet.ibm.com>
Date2016-09-02 06:30 +0200
Message-ID<scOh4-33O-15@gated-at.bofh.it>
In reply to#1473886
On 09/01/2016 02:40 AM, Andrew Morton wrote:
> On Wed, 31 Aug 2016 08:55:49 +0530 Anshuman Khandual <khandual@linux.vnet.ibm.com> wrote:
> 
>> zone_names[] is used to identify any zone given it's index which
>> can be used in many other places. So moving the definition into
>> include/linux/mmzone.h for broader access.
>>
>> ...
>>
>> --- a/include/linux/mmzone.h
>> +++ b/include/linux/mmzone.h
>> @@ -341,6 +341,23 @@ enum zone_type {
>>  
>>  };
>>  
>> +static char * const zone_names[__MAX_NR_ZONES] = {
>> +#ifdef CONFIG_ZONE_DMA
>> +	 "DMA",
>> +#endif
>> +#ifdef CONFIG_ZONE_DMA32
>> +	 "DMA32",
>> +#endif
>> +	 "Normal",
>> +#ifdef CONFIG_HIGHMEM
>> +	 "HighMem",
>> +#endif
>> +	 "Movable",
>> +#ifdef CONFIG_ZONE_DEVICE
>> +	 "Device",
>> +#endif
>> +};
>> +
>>  #ifndef __GENERATING_BOUNDS_H
>>  
>>  struct zone {
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 3fbe73a..8e2261c 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -207,23 +207,6 @@ int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1] = {
>>  
>>  EXPORT_SYMBOL(totalram_pages);
>>  
>> -static char * const zone_names[MAX_NR_ZONES] = {
>> -#ifdef CONFIG_ZONE_DMA
>> -	 "DMA",
>> -#endif
>> -#ifdef CONFIG_ZONE_DMA32
>> -	 "DMA32",
>> -#endif
>> -	 "Normal",
>> -#ifdef CONFIG_HIGHMEM
>> -	 "HighMem",
>> -#endif
>> -	 "Movable",
>> -#ifdef CONFIG_ZONE_DEVICE
>> -	 "Device",
>> -#endif
>> -};
>> -
>>  char * const migratetype_names[MIGRATE_TYPES] = {
>>  	"Unmovable",
>>  	"Movable",
> 
> This is worrisome.  On some (ancient) compilers, this will produce a
> copy of that array into each compilation unit which includes mmzone.h.
> 
> On smarter compilers, it will produce a copy of the array in each
> compilation unit which *uses* zone_names[].
> 
> On even smarter compilers (and linkers!), only one copy of zone_names[]
> will exist in vmlinux.
> 
> I don't know if gcc is an "even smarter compiler" and I didn't check,
> and I didn't check which gcc versions are even smarter.  I'd rather not
> have to ;) It is risky.
> 
> So, let's just make it non-static and add a declaration into mmzone.h,
> please.
> 

I understand your concern, will change it.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web