From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932988AbcHaVKg (ORCPT ); Wed, 31 Aug 2016 17:10:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51223 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753517AbcHaVKe (ORCPT ); Wed, 31 Aug 2016 17:10:34 -0400 Date: Wed, 31 Aug 2016 14:10:33 -0700 From: Andrew Morton To: Anshuman Khandual Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm: Move definition of 'zone_names' array into mmzone.h Message-Id: <20160831141033.8f617b6000bf129bbc40bda7@linux-foundation.org> In-Reply-To: <1472613950-16867-1-git-send-email-khandual@linux.vnet.ibm.com> References: <1472613950-16867-1-git-send-email-khandual@linux.vnet.ibm.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 31 Aug 2016 08:55:49 +0530 Anshuman Khandual 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.