Skip to contentSkip to conversation

the memset operation on a automatic array variable can be removed by data Initialization

PATCH Denis Cheng 2 participants 2 messages Jun 18, 2007

lore
Share & tools
lore
#0 lore raw
tmp/init.c renamed from x86_64/mm/init.c +1 -2
@@ -406,8 +406,7 @@ void __cpuinit zap_low_mappings(int cpu)
 #ifndef CONFIG_NUMA
 void __init paging_init(void)
 {
-	unsigned long max_zone_pfns[MAX_NR_ZONES];
-	memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
+	unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
 	max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
 	max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
 	max_zone_pfns[ZONE_NORMAL] = end_pfn;
#1 lore raw

tmp/init.c void __cpuinit zap_low_mappings(int cpu) · line 409

Quoted 12 lines · Denis Cheng

Subject: the memset operation on a automatic array variable can be removed by
data Initialization

tmp/init.c renamed from x86_64/mm/init.c +1 -2
@@ -406,8 +406,7 @@ void __cpuinit zap_low_mappings(int cpu)
 #ifndef CONFIG_NUMA
 void __init paging_init(void)
 {
-	unsigned long max_zone_pfns[MAX_NR_ZONES];
-	memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
+	unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };

The cost is the same. "= {0}" is transformed into a bunch of movs, or a rep mov, (At least for x86), so is equivalent to memset (which will get transformed to __builtin_memset anyway). So I wonder what this really buys.

And, you do not even need the zero. Just write

	...[MAX_NR_ZONES] = {};

tmp/init.c void __cpuinit zap_low_mappings(int cpu) · line 412

Quoted 3 lines
tmp/init.c renamed from x86_64/mm/init.c +0 -0
 	max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
 	max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
 	max_zone_pfns[ZONE_NORMAL] = end_pfn;

Jan