Skip to content

Commit 0c98853

Browse files
jiangliutorvalds
authored andcommitted
mm: concentrate modification of totalram_pages into the mm core
Concentrate code to modify totalram_pages into the mm core, so the arch memory initialized code doesn't need to take care of it. With these changes applied, only following functions from mm core modify global variable totalram_pages: free_bootmem_late(), free_all_bootmem(), free_all_bootmem_node(), adjust_managed_page_count(). With this patch applied, it will be much more easier for us to keep totalram_pages and zone->managed_pages in consistence. Signed-off-by: Jiang Liu <[email protected]> Acked-by: David Howells <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jeremy Fitzhardinge <[email protected]> Cc: Jianguo Wu <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Kamezawa Hiroyuki <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Marek Szyprowski <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michel Lespinasse <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Rusty Russell <[email protected]> Cc: Tang Chen <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Wen Congyang <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yasuaki Ishimatsu <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: Russell King <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3dcc057 commit 0c98853

File tree

36 files changed

+50
-46
lines changed

36 files changed

+50
-46
lines changed

arch/alpha/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void __init
309309
mem_init(void)
310310
{
311311
max_mapnr = num_physpages = max_low_pfn;
312-
totalram_pages += free_all_bootmem();
312+
free_all_bootmem();
313313
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
314314

315315
printk_memory_info();

arch/alpha/mm/numa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void __init mem_init(void)
334334
/*
335335
* This will free up the bootmem, ie, slot 0 memory
336336
*/
337-
totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
337+
free_all_bootmem_node(NODE_DATA(nid));
338338

339339
pfn = NODE_DATA(nid)->node_start_pfn;
340340
for (i = 0; i < node_spanned_pages(nid); i++, pfn++)

arch/arc/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void __init mem_init(void)
111111

112112
high_memory = (void *)(CONFIG_LINUX_LINK_BASE + arc_mem_sz);
113113

114-
totalram_pages = free_all_bootmem();
114+
free_all_bootmem();
115115

116116
/* count all reserved pages [kernel code/data/mem_map..] */
117117
reserved_pages = 0;

arch/arm/mm/init.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ void __init mem_init(void)
596596

597597
/* this will put all unused low memory onto the freelists */
598598
free_unused_memmap(&meminfo);
599-
600-
totalram_pages += free_all_bootmem();
599+
free_all_bootmem();
601600

602601
#ifdef CONFIG_SA1111
603602
/* now that our DMA memory is actually so designated, we can free it */

arch/arm64/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void __init mem_init(void)
284284
free_unused_memmap();
285285
#endif
286286

287-
totalram_pages += free_all_bootmem();
287+
free_all_bootmem();
288288

289289
reserved_pages = free_pages = 0;
290290

arch/avr32/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ void __init mem_init(void)
117117
if (pgdat->node_spanned_pages != 0)
118118
node_pages = free_all_bootmem_node(pgdat);
119119

120-
totalram_pages += node_pages;
121-
122120
for (i = 0; i < node_pages; i++)
123121
if (PageReserved(pgdat->node_mem_map + i))
124122
reservedpages++;

arch/blackfin/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void __init mem_init(void)
104104
printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
105105

106106
/* This will put all low memory onto the freelists. */
107-
totalram_pages = free_all_bootmem();
107+
free_all_bootmem();
108108

109109
reservedpages = 0;
110110
for (tmp = ARCH_PFN_OFFSET; tmp < max_mapnr; tmp++)

arch/c6x/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void __init mem_init(void)
6565
high_memory = (void *)(memory_end & PAGE_MASK);
6666

6767
/* this will put all memory onto the freelists */
68-
totalram_pages = free_all_bootmem();
68+
free_all_bootmem();
6969

7070
codek = (_etext - _stext) >> 10;
7171
datak = (_end - _sdata) >> 10;

arch/cris/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mem_init(void)
3333
max_mapnr = num_physpages = max_low_pfn - min_low_pfn;
3434

3535
/* this will put all memory onto the freelists */
36-
totalram_pages = free_all_bootmem();
36+
free_all_bootmem();
3737

3838
reservedpages = 0;
3939
for (tmp = 0; tmp < max_mapnr; tmp++) {

arch/frv/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void __init mem_init(void)
123123
int codek = 0, datak = 0;
124124

125125
/* this will put all low memory onto the freelists */
126-
totalram_pages = free_all_bootmem();
126+
free_all_bootmem();
127127

128128
#ifdef CONFIG_MMU
129129
for (loop = 0 ; loop < npages ; loop++)

arch/h8300/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void __init mem_init(void)
140140
max_mapnr = num_physpages = MAP_NR(high_memory);
141141

142142
/* this will put all low memory onto the freelists */
143-
totalram_pages = free_all_bootmem();
143+
free_all_bootmem();
144144

145145
codek = (_etext - _stext) >> 10;
146146
datak = (__bss_stop - _sdata) >> 10;

arch/hexagon/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ unsigned long long kmap_generation;
7070
void __init mem_init(void)
7171
{
7272
/* No idea where this is actually declared. Seems to evade LXR. */
73-
totalram_pages += free_all_bootmem();
73+
free_all_bootmem();
7474
num_physpages = bootmem_lastpg-ARCH_PFN_OFFSET;
7575

7676
printk(KERN_INFO "totalram_pages = %ld\n", totalram_pages);

arch/ia64/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ mem_init (void)
622622

623623
for_each_online_pgdat(pgdat)
624624
if (pgdat->bdata->node_bootmem_map)
625-
totalram_pages += free_all_bootmem_node(pgdat);
625+
free_all_bootmem_node(pgdat);
626626

627627
reserved_pages = 0;
628628
efi_memmap_walk(count_reserved_pages, &reserved_pages);

arch/m32r/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void __init mem_init(void)
158158

159159
/* this will put all low memory onto the freelists */
160160
for_each_online_node(nid)
161-
totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
161+
free_all_bootmem_node(NODE_DATA(nid));
162162

163163
reservedpages = reservedpages_count() - hole_pages;
164164
codesize = (unsigned long) &_etext - (unsigned long)&_text;

arch/m68k/mm/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ void __init mem_init(void)
155155
int i;
156156

157157
/* this will put all memory onto the freelists */
158-
totalram_pages = num_physpages = 0;
158+
num_physpages = 0;
159159
for_each_online_pgdat(pgdat) {
160160
num_physpages += pgdat->node_present_pages;
161161

162-
totalram_pages += free_all_bootmem_node(pgdat);
162+
free_all_bootmem_node(pgdat);
163163
for (i = 0; i < pgdat->node_spanned_pages; i++) {
164164
struct page *page = pgdat->node_mem_map + i;
165165
char *addr = page_to_virt(page);

arch/metag/mm/init.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,11 @@ void __init mem_init(void)
393393

394394
for_each_online_node(nid) {
395395
pg_data_t *pgdat = NODE_DATA(nid);
396-
unsigned long node_pages = 0;
397396

398397
num_physpages += pgdat->node_present_pages;
399398

400399
if (pgdat->node_spanned_pages)
401-
node_pages = free_all_bootmem_node(pgdat);
402-
403-
totalram_pages += node_pages;
400+
free_all_bootmem_node(pgdat);
404401
}
405402

406403
pr_info("Memory: %luk/%luk available\n",

arch/microblaze/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void __init mem_init(void)
252252
high_memory = (void *)__va(memory_start + lowmem_size - 1);
253253

254254
/* this will put all memory onto the freelists */
255-
totalram_pages += free_all_bootmem();
255+
free_all_bootmem();
256256

257257
for_each_online_pgdat(pgdat) {
258258
unsigned long i;

arch/mips/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ void __init mem_init(void)
374374
#endif
375375
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
376376

377-
totalram_pages += free_all_bootmem();
377+
free_all_bootmem();
378378
setup_zero_pages(); /* Setup zeroed pages. */
379379

380380
reservedpages = ram = 0;

arch/mips/sgi-ip27/ip27-memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ void __init mem_init(void)
489489
/*
490490
* This will free up the bootmem, ie, slot 0 memory.
491491
*/
492-
totalram_pages += free_all_bootmem_node(NODE_DATA(node));
492+
free_all_bootmem_node(NODE_DATA(node));
493493
}
494494

495495
setup_zero_pages(); /* This comes from node 0 */

arch/mn10300/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void __init mem_init(void)
114114
memset(empty_zero_page, 0, PAGE_SIZE);
115115

116116
/* this will put all low memory onto the freelists */
117-
totalram_pages += free_all_bootmem();
117+
free_all_bootmem();
118118

119119
reservedpages = 0;
120120
for (tmp = 0; tmp < num_physpages; tmp++)

arch/openrisc/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int __init free_pages_init(void)
207207
int reservedpages, pfn;
208208

209209
/* this will put all low memory onto the freelists */
210-
totalram_pages = free_all_bootmem();
210+
free_all_bootmem();
211211

212212
reservedpages = 0;
213213
for (pfn = 0; pfn < max_low_pfn; pfn++) {

arch/parisc/mm/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,13 @@ void __init mem_init(void)
593593

594594
#ifndef CONFIG_DISCONTIGMEM
595595
max_mapnr = page_to_pfn(virt_to_page(high_memory - 1)) + 1;
596-
totalram_pages += free_all_bootmem();
596+
free_all_bootmem();
597597
#else
598598
{
599599
int i;
600600

601601
for (i = 0; i < npmem_ranges; i++)
602-
totalram_pages += free_all_bootmem_node(NODE_DATA(i));
602+
free_all_bootmem_node(NODE_DATA(i));
603603
}
604604
#endif
605605

arch/powerpc/mm/mem.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,12 @@ void __init mem_init(void)
318318
for_each_online_node(nid) {
319319
if (NODE_DATA(nid)->node_spanned_pages != 0) {
320320
printk("freeing bootmem node %d\n", nid);
321-
totalram_pages +=
322-
free_all_bootmem_node(NODE_DATA(nid));
321+
free_all_bootmem_node(NODE_DATA(nid));
323322
}
324323
}
325324
#else
326325
max_mapnr = max_pfn;
327-
totalram_pages += free_all_bootmem();
326+
free_all_bootmem();
328327
#endif
329328
for_each_online_pgdat(pgdat) {
330329
for (i = 0; i < pgdat->node_spanned_pages; i++) {

arch/s390/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void __init mem_init(void)
144144
cmma_init();
145145

146146
/* this will put all low memory onto the freelists */
147-
totalram_pages += free_all_bootmem();
147+
free_all_bootmem();
148148
setup_zero_pages(); /* Setup zeroed pages. */
149149

150150
reservedpages = 0;

arch/score/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void __init mem_init(void)
7979
unsigned long tmp, ram = 0;
8080

8181
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
82-
totalram_pages += free_all_bootmem();
82+
free_all_bootmem();
8383
setup_zero_page(); /* Setup zeroed pages. */
8484
reservedpages = 0;
8585

arch/sh/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void __init mem_init(void)
422422
num_physpages += pgdat->node_present_pages;
423423

424424
if (pgdat->node_spanned_pages)
425-
totalram_pages += free_all_bootmem_node(pgdat);
425+
free_all_bootmem_node(pgdat);
426426

427427

428428
node_high_memory = (void *)__va((pgdat->node_start_pfn +

arch/sparc/mm/init_32.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ void __init mem_init(void)
323323

324324
max_mapnr = last_valid_pfn - pfn_base;
325325
high_memory = __va(max_low_pfn << PAGE_SHIFT);
326-
327-
totalram_pages = free_all_bootmem();
326+
free_all_bootmem();
328327

329328
for (i = 0; sp_banks[i].num_bytes != 0; i++) {
330329
unsigned long start_pfn = sp_banks[i].base_addr >> PAGE_SHIFT;

arch/sparc/mm/init_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ void __init mem_init(void)
20612061
high_memory = __va(last_valid_pfn << PAGE_SHIFT);
20622062

20632063
register_page_bootmem_info();
2064-
totalram_pages = free_all_bootmem();
2064+
free_all_bootmem();
20652065

20662066
/* We subtract one to account for the mem_map_zero page
20672067
* allocated below.

arch/tile/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ void __init mem_init(void)
846846
set_max_mapnr_init();
847847

848848
/* this will put all bootmem onto the freelists */
849-
totalram_pages += free_all_bootmem();
849+
free_all_bootmem();
850850

851851
#ifndef CONFIG_64BIT
852852
/* count all remaining LOWMEM and give all HIGHMEM to page allocator */

arch/um/kernel/mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void __init mem_init(void)
6565
uml_reserved = brk_end;
6666

6767
/* this will put all low memory onto the freelists */
68-
totalram_pages = free_all_bootmem();
68+
free_all_bootmem();
6969
max_low_pfn = totalram_pages;
7070
#ifdef CONFIG_HIGHMEM
7171
setup_highmem(end_iomem, highmem);

arch/unicore32/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void __init mem_init(void)
392392
free_unused_memmap(&meminfo);
393393

394394
/* this will put all unused low memory onto the freelists */
395-
totalram_pages += free_all_bootmem();
395+
free_all_bootmem();
396396

397397
reserved_pages = free_pages = 0;
398398

arch/x86/mm/init_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ void __init mem_init(void)
759759
set_highmem_pages_init();
760760

761761
/* this will put all low memory onto the freelists */
762-
totalram_pages += free_all_bootmem();
762+
free_all_bootmem();
763763

764764
reservedpages = 0;
765765
for (tmp = 0; tmp < max_low_pfn; tmp++)

arch/x86/mm/init_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ void __init mem_init(void)
10541054
register_page_bootmem_info();
10551055

10561056
/* this will put all memory onto the freelists */
1057-
totalram_pages = free_all_bootmem();
1057+
free_all_bootmem();
10581058

10591059
absent_pages = absent_pages_in_range(0, max_pfn);
10601060
reservedpages = max_pfn - totalram_pages - absent_pages;

arch/xtensa/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void __init mem_init(void)
184184
#error HIGHGMEM not implemented in init.c
185185
#endif
186186

187-
totalram_pages += free_all_bootmem();
187+
free_all_bootmem();
188188

189189
reservedpages = ram = 0;
190190
for (tmp = 0; tmp < max_mapnr; tmp++) {

mm/bootmem.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,14 @@ void __init reset_all_zones_managed_pages(void)
271271
*/
272272
unsigned long __init free_all_bootmem_node(pg_data_t *pgdat)
273273
{
274+
unsigned long pages;
275+
274276
register_page_bootmem_info_node(pgdat);
275277
reset_node_managed_pages(pgdat);
276-
return free_all_bootmem_core(pgdat->bdata);
278+
pages = free_all_bootmem_core(pgdat->bdata);
279+
totalram_pages += pages;
280+
281+
return pages;
277282
}
278283

279284
/**
@@ -291,6 +296,8 @@ unsigned long __init free_all_bootmem(void)
291296
list_for_each_entry(bdata, &bdata_list, list)
292297
total_pages += free_all_bootmem_core(bdata);
293298

299+
totalram_pages += total_pages;
300+
294301
return total_pages;
295302
}
296303

mm/nobootmem.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,19 @@ void __init reset_all_zones_managed_pages(void)
165165
*/
166166
unsigned long __init free_all_bootmem(void)
167167
{
168+
unsigned long pages;
169+
168170
reset_all_zones_managed_pages();
169171

170172
/*
171173
* We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id
172174
* because in some case like Node0 doesn't have RAM installed
173175
* low ram will be on Node1
174176
*/
175-
return free_low_memory_core_early();
177+
pages = free_low_memory_core_early();
178+
totalram_pages += pages;
179+
180+
return pages;
176181
}
177182

178183
/**

0 commit comments

Comments
 (0)