aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/Makefile
diff options
context:
space:
mode:
authorPaul Walmsley <paul@pwsan.com>2009-03-12 15:11:43 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2009-03-12 15:25:02 -0400
commite4707dd3e9d0cb57597b6568a5e51fea5d6fca41 (patch)
treec76a6cb54e4f90a8deebf380bf8fe8a5f6eb2750 /sound/soc/codecs/Makefile
parent6dc4a47a0cf423879b505af0e29997fca4088630 (diff)
[ARM] 5422/1: ARM: MMU: add a Non-cacheable Normal executable memory type
This patch adds a Non-cacheable Normal ARM executable memory type, MT_MEMORY_NONCACHED. On OMAP3, this is used for rapid dynamic voltage/frequency scaling in the VDD2 voltage domain. OMAP3's SDRAM controller (SDRC) is in the VDD2 voltage domain, and its clock frequency must change along with voltage. The SDRC clock change code cannot run from SDRAM itself, since SDRAM accesses are paused during the clock change. So the current implementation of the DVFS code executes from OMAP on-chip SRAM, aka "OCM RAM." If the OCM RAM pages are marked as Cacheable, the ARM cache controller will attempt to flush dirty cache lines to the SDRC, so it can fill those lines with OCM RAM instruction code. The problem is that the SDRC is paused during DVFS, and so any SDRAM access causes the ARM MPU subsystem to hang. TI's original solution to this problem was to mark the OCM RAM sections as Strongly Ordered memory, thus preventing caching. This is overkill: since the memory is marked as non-bufferable, OCM RAM writes become needlessly slow. The idea of "Strongly Ordered SRAM" is also conceptually disturbing. Previous LAKML list discussion is here: http://www.spinics.net/lists/arm-kernel/msg54312.html This memory type MT_MEMORY_NONCACHED is used for OCM RAM by a future patch. Cc: Richard Woodruff <r-woodruff2@ti.com> Signed-off-by: Paul Walmsley <paul@pwsan.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'sound/soc/codecs/Makefile')
0 files changed, 0 insertions, 0 deletions
:21 -0400 mm/hugetlb.c must #include <asm/io.h>' href='/cgit/cgit.cgi/litmus-rt.git/commit/mm/hugetlb.c?h=v2.6.34-rc6&id=78a34ae29bf1c9df62a5bd0f0798b6c62a54d520'>78a34ae29bf1
63551ae0feaa

7835e98b2e3c
1da177e4c3f4

396faf0303d2

a5516438959d
e5ff215941d5



53ba51d21d6e

e5ff215941d5


e11bfbfcb08e
e5ff215941d5


396faf0303d2
3935baa9bcda



0bd0f9fb190a
e7c4b0bfd025
968229048437

84afd99b8398









968229048437

























































































































84afd99b8398























968229048437
e7c4b0bfd025
e7c4b0bfd025

a5516438959d

e7c4b0bfd025
a5516438959d

e7c4b0bfd025

84afd99b8398






04f2cbe35699
84afd99b8398
a1e78772d72b








84afd99b8398








a1e78772d72b
e7c4b0bfd025










84afd99b8398


























a1e78772d72b


84afd99b8398

a1e78772d72b


84afd99b8398
a1e78772d72b



84afd99b8398

04f2cbe35699



04f2cbe35699
e7c4b0bfd025


04f2cbe35699




e7c4b0bfd025

a1e78772d72b


a5516438959d

a1e78772d72b
c37f9fb11c97


a1e78772d72b

a5516438959d
84afd99b8398
a1e78772d72b



a5516438959d
a1e78772d72b


04f2cbe35699
a1e78772d72b







7f09ca51e925
a1e78772d72b

7f09ca51e925



a1e78772d72b

a5516438959d

79ac6ba40eb8



a5516438959d
79ac6ba40eb8
281e0e3b34ac
79ac6ba40eb8



9de455b20705
79ac6ba40eb8

a5516438959d
79ac6ba40eb8

a5516438959d
79ac6ba40eb8
9de455b20705
79ac6ba40eb8


a5516438959d
1da177e4c3f4

a5516438959d


1da177e4c3f4

a5516438959d
348e1e04b522




a5516438959d

348e1e04b522

a5516438959d

348e1e04b522





a5516438959d

04f2cbe35699
1da177e4c3f4
31a5c6e4f257
1da177e4c3f4
480eccf9ae10
19770b32609b
396faf0303d2
19770b32609b
dd1a239f6f2d

1da177e4c3f4
a1e78772d72b




7f09ca51e925
a5516438959d
a1e78772d72b

04f2cbe35699
a5516438959d
04f2cbe35699

19770b32609b

54a6eb5c4765

a5516438959d

3abf7afd4068

a5516438959d

04f2cbe35699

a5516438959d
a1e78772d72b
5ab3ee7b1cd5
3abf7afd4068
1da177e4c3f4
52cd3b074050
1da177e4c3f4


a5516438959d
6af2acb66196

a5516438959d



6af2acb66196





7f2e9525ba55
a5516438959d
6af2acb66196

e5ff215941d5










27a85ef1b813

a5516438959d



e5ff215941d5
7893d1d505d5
c79fb75e5a51
27a85ef1b813
c79fb75e5a51
e5df70ab1945
7893d1d505d5
27a85ef1b813


aa888a74977a
a5516438959d


7893d1d505d5
a5516438959d
7893d1d505d5
27a85ef1b813
c79fb75e5a51
9a119c056dc2
27a85ef1b813

7893d1d505d5




a5516438959d
7893d1d505d5











a5516438959d
7893d1d505d5

a5516438959d

7893d1d505d5

a5516438959d

7893d1d505d5







a5516438959d
b7ba30c679ed


a5516438959d

b7ba30c679ed



a5516438959d
1da177e4c3f4
1da177e4c3f4
f96efd585b8d
aa888a74977a


63b4613c3f0d
551883ae8c9c

a5516438959d
1da177e4c3f4
7f2e9525ba55
caff3a2c333e
7b8ee84d8926
7f2e9525ba55
a5516438959d
1da177e4c3f4
63b4613c3f0d



5ced66c901f1




















a5516438959d
63b4613c3f0d





a5516438959d
63b4613c3f0d

a5516438959d
63b4613c3f0d

5ced66c901f1
a5516438959d
63b4613c3f0d
3b1163006332




63b4613c3f0d
1da177e4c3f4

a5516438959d

7893d1d505d5

d1c3fb1f8f29
7893d1d505d5
aa888a74977a


d1c3fb1f8f29























a5516438959d
d1c3fb1f8f29


a5516438959d

d1c3fb1f8f29


551883ae8c9c

a5516438959d
d1c3fb1f8f29
caff3a2c333e




d1c3fb1f8f29
7893d1d505d5
2668db9111bb





d1c3fb1f8f29
7893d1d505d5
d1c3fb1f8f29


a5516438959d

3b1163006332
d1c3fb1f8f29
a5516438959d

3b1163006332
7893d1d505d5
d1c3fb1f8f29
7893d1d505d5



e4e574b767ba



a5516438959d
e4e574b767ba





a5516438959d
ac09b3a15154
a5516438959d
e4e574b767ba
ac09b3a15154
e4e574b767ba







a5516438959d
e4e574b767ba



















a5516438959d

e4e574b767ba






ac09b3a15154


e4e574b767ba

a5516438959d
e4e574b767ba

19fc3f0acde3
e4e574b767ba
19fc3f0acde3

e4e574b767ba
a5516438959d
19fc3f0acde3






af767cbdd78f
2668db9111bb


af767cbdd78f


2668db9111bb
af767cbdd78f
19fc3f0acde3
e4e574b767ba









a5516438959d

e4e574b767ba




11320d17ce4e







ac09b3a15154
a5516438959d
ac09b3a15154
aa888a74977a



a5516438959d
e4e574b767ba
11320d17ce4e
e4e574b767ba



a5516438959d
e4e574b767ba

a5516438959d

e4e574b767ba

a5516438959d




e4e574b767ba
11320d17ce4e
e4e574b767ba



c37f9fb11c97








a5516438959d

c37f9fb11c97




a5516438959d
c37f9fb11c97


84afd99b8398

c37f9fb11c97
84afd99b8398

a5516438959d
84afd99b8398






c37f9fb11c97
a5516438959d

c37f9fb11c97




a5516438959d
c37f9fb11c97
84afd99b8398

a5516438959d
84afd99b8398



c37f9fb11c97


a1e78772d72b
04f2cbe35699
1da177e4c3f4
a5516438959d
348ea204cc23
a1e78772d72b

c37f9fb11c97
a1e78772d72b




c37f9fb11c97

a1e78772d72b
a5516438959d
c37f9fb11c97


a1e78772d72b

1da177e4c3f4

a5516438959d
1da177e4c3f4
b45b5bd65f66
68842c9b9456
a5516438959d
68842c9b9456
a1e78772d72b
68842c9b9456


348ea204cc23
a1e78772d72b

90d8b7e6129e
a5516438959d
c37f9fb11c97
90d8b7e6129e
b45b5bd65f66

53ba51d21d6e
aa888a74977a
















































8faa8b077b2c
1da177e4c3f4

a5516438959d
e5ff215941d5
aa888a74977a



1da177e4c3f4
1da177e4c3f4
8faa8b077b2c
e5ff215941d5






8faa8b077b2c


e5ff215941d5


4abd32dbab20










e5ff215941d5




4abd32dbab20




e5ff215941d5


1da177e4c3f4
a5516438959d
1da177e4c3f4
4415cc8df630

aa888a74977a


1da177e4c3f4

a5516438959d


6b0c880dfefe
1da177e4c3f4


e5ff215941d5
a5516438959d

1da177e4c3f4



a5516438959d
1da177e4c3f4



a5516438959d
e5ff215941d5
1da177e4c3f4
7893d1d505d5
1da177e4c3f4
aa888a74977a


7893d1d505d5



d1c3fb1f8f29





7893d1d505d5
1da177e4c3f4
a5516438959d

7893d1d505d5


a5516438959d
7893d1d505d5





a5516438959d
7893d1d505d5




7893d1d505d5






d1c3fb1f8f29







7893d1d505d5
a5516438959d
6b0c880dfefe
a5516438959d


1da177e4c3f4

a5516438959d
1da177e4c3f4
a5516438959d

7893d1d505d5


a5516438959d
1da177e4c3f4
7893d1d505d5
1da177e4c3f4

a3437870160c
























































































































































0ef89d25d3e3





a3437870160c
e11bfbfcb08e



a3437870160c
e11bfbfcb08e


a3437870160c


aa888a74977a

a3437870160c











8faa8b077b2c

a3437870160c








8faa8b077b2c




a3437870160c

8faa8b077b2c
a3437870160c


e11bfbfcb08e
a3437870160c

8faa8b077b2c
a3437870160c









8faa8b077b2c





a3437870160c


8faa8b077b2c









a3437870160c

e11bfbfcb08e







a3437870160c
8a21346058ad











1da177e4c3f4



e5ff215941d5







1da177e4c3f4
e5ff215941d5



1da177e4c3f4

396faf0303d2












a3d0c6aa1bb3



a5516438959d
e5ff215941d5






a3d0c6aa1bb3
e5ff215941d5






a3d0c6aa1bb3


1da177e4c3f4



a5516438959d
1da177e4c3f4


a43a8c39bbb4
7893d1d505d5
1da177e4c3f4
a5516438959d




1da177e4c3f4



a5516438959d
1da177e4c3f4

a1de09195b29

a5516438959d


1da177e4c3f4

1da177e4c3f4


a5516438959d

1da177e4c3f4
1da177e4c3f4
a5516438959d
fc1b8a73dd71





















a5516438959d
fc1b8a73dd71

a5516438959d

fc1b8a73dd71





a5516438959d
fc1b8a73dd71





84afd99b8398















a1e78772d72b

a5516438959d
84afd99b8398





a5516438959d

84afd99b8398





7251ff78b94c
a5516438959d
7251ff78b94c

84afd99b8398
a1e78772d72b

1da177e4c3f4





d0217ac04ca6
1da177e4c3f4

d0217ac04ca6
1da177e4c3f4


d0217ac04ca6
84afd99b8398
a1e78772d72b
1da177e4c3f4

1e8f889b10d8

63551ae0feaa


1e8f889b10d8
63551ae0feaa


7f2e9525ba55
63551ae0feaa






1e8f889b10d8




7f2e9525ba55

8dab5241d06b
8dab5241d06b
1e8f889b10d8


63551ae0feaa




1c59827d1da9
1e8f889b10d8
a5516438959d

1e8f889b10d8

63551ae0feaa
a5516438959d
c74df32c724a


a5516438959d
63551ae0feaa

c5c99429fa57




c74df32c724a
4647875819aa
7f2e9525ba55
1e8f889b10d8
7f2e9525ba55

1c59827d1da9

1c59827d1da9


c74df32c724a
63551ae0feaa






502717f4e112
04f2cbe35699
63551ae0feaa


c7546f8f03f5
63551ae0feaa

fe1668ae5bf0
a5516438959d


c0a499c2c429




fe1668ae5bf0
63551ae0feaa

a5516438959d

63551ae0feaa
cddb8a5c14aa
508034a32b81
a5516438959d
c7546f8f03f5
4c8872659772
c7546f8f03f5

39dde65c9940


04f2cbe35699




















c7546f8f03f5
7f2e9525ba55
63551ae0feaa
c7546f8f03f5
63551ae0feaa
6649a3863232

fe1668ae5bf0
63551ae0feaa
1da177e4c3f4
508034a32b81
cddb8a5c14aa
fe1668ae5bf0



1da177e4c3f4
63551ae0feaa
502717f4e112
04f2cbe35699
502717f4e112
a137e1cc6d6e


502717f4e112

04f2cbe35699













































1e8f889b10d8
04f2cbe35699

1e8f889b10d8
a5516438959d
1e8f889b10d8
79ac6ba40eb8
04f2cbe35699
1e8f889b10d8


04f2cbe35699
1e8f889b10d8




83c54070ee1a
1e8f889b10d8

04f2cbe35699













1e8f889b10d8
04f2cbe35699
1e8f889b10d8
2fc39cec6a9b
1e8f889b10d8
04f2cbe35699

















2fc39cec6a9b
1e8f889b10d8


9de455b20705
0ed361dec369
1e8f889b10d8

a5516438959d
7f2e9525ba55
1e8f889b10d8
8fe627ec5b7c
1e8f889b10d8






83c54070ee1a
1e8f889b10d8

04f2cbe35699
a5516438959d

04f2cbe35699

e7c4b0bfd025
04f2cbe35699

a5516438959d
04f2cbe35699



a1ed3dda0ad1
1e8f889b10d8
ac9b9c667c2e
a5516438959d
ac9b9c667c2e
e7c4b0bfd025
4c8872659772
4c8872659772

1e8f889b10d8
4c8872659772
04f2cbe35699











4c8872659772
a5516438959d
4c8872659772




6bda666a03f0


a5516438959d
ebed4bfc8da8

04f2cbe35699
2fc39cec6a9b

6bda666a03f0

a5516438959d
0ed361dec369
ac9b9c667c2e
6bda666a03f0

45c682a68a87
6bda666a03f0



6bda666a03f0



45c682a68a87

a5516438959d
45c682a68a87
6bda666a03f0


1e8f889b10d8
57303d80175e






2b26736c88db



57303d80175e
ac9b9c667c2e
a5516438959d
4c8872659772


83c54070ee1a
7f2e9525ba55
4c8872659772

1e8f889b10d8





04f2cbe35699
1e8f889b10d8

ac9b9c667c2e
4c8872659772

ac9b9c667c2e
4c8872659772


2b26736c88db
4c8872659772


ac9b9c667c2e

86e5216f8d8a




1e8f889b10d8
57303d80175e
3935baa9bcda
a5516438959d
86e5216f8d8a
a5516438959d
86e5216f8d8a


3935baa9bcda





7f2e9525ba55

3935baa9bcda
b4d1d99fdd8b
3935baa9bcda
86e5216f8d8a
83c54070ee1a
1e8f889b10d8
57303d80175e








2b26736c88db

b4d1d99fdd8b
2b26736c88db
57303d80175e





1e8f889b10d8

b4d1d99fdd8b





57303d80175e

b4d1d99fdd8b








1e8f889b10d8
57303d80175e





b4d1d99fdd8b
3935baa9bcda
1e8f889b10d8

86e5216f8d8a

ceb868796181








63551ae0feaa

5b23dbe8173c

63551ae0feaa
d5d4b0aa4e14

63551ae0feaa
a5516438959d
63551ae0feaa
1c59827d1da9
63551ae0feaa
4c8872659772

63551ae0feaa
4c8872659772




a5516438959d
63551ae0feaa
7f2e9525ba55

4c8872659772
63551ae0feaa
4c8872659772
5b23dbe8173c
4c8872659772
a89182c76e54
4c8872659772
63551ae0feaa
4c8872659772





a5516438959d
7f2e9525ba55
d5d4b0aa4e14
d6692183ac1d

d5d4b0aa4e14
d6692183ac1d
63551ae0feaa




d5d4b0aa4e14
63551ae0feaa

d5d4b0aa4e14
a5516438959d
d5d4b0aa4e14





63551ae0feaa
1c59827d1da9
63551ae0feaa




8f860591ffb2







a5516438959d
8f860591ffb2



39dde65c9940
8f860591ffb2
a5516438959d
8f860591ffb2


39dde65c9940

7f2e9525ba55
8f860591ffb2


8f860591ffb2


39dde65c9940
8f860591ffb2



a1e78772d72b


e4e574b767ba

a5516438959d
e4e574b767ba
c37f9fb11c97


a1e78772d72b








84afd99b8398



a1e78772d72b
84afd99b8398

04f2cbe35699
a1e78772d72b

e4e574b767ba

8a63011275e1
90d8b7e6129e

a5516438959d
68842c9b9456

a43a8c39bbb4
68842c9b9456
a1e78772d72b

a43a8c39bbb4




a5516438959d
a43a8c39bbb4
45c682a68a87

a5516438959d
45c682a68a87

90d8b7e6129e
a5516438959d
a43a8c39bbb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232








                                

                          
                               
                           
                          
                            
                         
                        
                          
                        
 

                        
                   

                          
                     

                                                              

                                            
 



                                       

                                      


                                                              
                                                    


                                                              
 



                                                                             
 
  

                                                                            









                                                                             

























































































































                                                                            























                                                                          
  
                                                                

                                                         

                                                                          
 

                                                                  

 






                                                                      
                                                                
 








                                                                               








                                                                             
   










                                                                            


























                                                                             


                                            

                                                                          


                 
                                                                              



                                             

                                                                       



                                                                               
                                            


                                                                     




                                                                          

                                                       


                                                              

                                                         
 


                                         

                                                         
                                     
                                                            



                                                                       
                                     


         
                                                          







                                                          
                                                       

                                      



                                                   

 

                                                             



                      
                                            
                               
                                                                    



                                                              
                                                                          

              
                                           

                      
                                                      
                               
                                                                              


         
                                                                  

                                    


                                                          

 
                                                       




                                                  

                                                                          

                                                            

                                                       





                              

                                                           
                                                                         
 
                
                                 
                               
                             
                                                               
                                                                           

                          
 




                                                                            
                                     
                                                                     

                            
                                                                             
                                                                          

                            

                                                                             

                                                                          

                                                                          

                                                            

                                                       

                                           
                                                                    
 
                              
                 
         
                            


                    
                                                                     

              



                                                      





                                                                                        
                                    
                                               

 










                                                 

                                             



                                                                  
                                             
                                    
                                      
 
                                                              
                                  
                                 


                                   
                                                                                


                                                  
                
                                           
         
                                   
                    
                                              

 




                                                                          
                                                           











                                                                          
                                                                  

                                                                     

                                                                           

                                 

                                                         







                                  
                                                                            


                                                     

                                     



                                                                 
                                                                         
 
                          
 


                                  
                                    

                                                                          
                                    
                   
                                                  
                                                               
                                    
                 
                                                 
         



                    




















                                                                   
                                                  





                          
                                        

            
                                                                          

                                
                                               
                                                            
 




                                                        
                   

 

                                                                          

                          
                         
 


                                  























                                                                        
                                                                   


                                           

                                        


                                   

                                                                  
                                                            
 




                                                       
                                 
                   





                                                                            
                                        
                                                             


                                                             

                                                  
                                                     
                

                                        
                                                          
         
                                   



                    



                                                                      
                                                            





                                      
                                                                   
                          
                                            
                         
         







                                      
                                                         



















                                                                              

                                                         






                                                                             


                                                                            

                            
                                    

                
                                                       
                                                                 

                                   
                                     
                                           






                                                                         
                          


                                                                             


                                                                              
                                             
                 
                                         









                                                                             

                                                                        




                               







                                                                        
                                      
                                                
 



                                                    
                                                                 
 
                                                    



                                                          
                                                     

                                 

                                                                          

                                                            




                                                          
                                   
                                                                  



                 








                                                                             

                                                                       




                                                                
                                                                 


                                                                      

                                                             
 

                        
                                                                 






                                                                       
 

                                                                       




                                                                
                                                                 
                                                                          

                                                            
                                                                 



                                                                  


         
                                                               
                                                                          
 
                                           
                          

                                                                
                         




                                                                              

                                                                         
           
                                                  


                                    

                                                             

                                 
                                                                  
                                   
 
                    
                                                           
                            
                                                                 


                                                      
 

                                                        
 
                                             
 
                    

 
                                                                   
















































                                                                              
                                                               

                        
 
                                                 



                                                        
                              
         
                              






                                             


                                                                   


         










                                                       




                                         




                                                                    


         
                     
                                                                  
 

              


                                  

                                            


                                                                    
                                       


                                              
                                                      

                                                                     



                 
                                                                         



      
                                                                           
                                                                              
 
                                     
 


                                         



                                                                   





                                                                        
           
                                 

                                                                           


                              
                                                  





                                                                           
                                               




                                         






                                                                        







                                                                      
           
                                                                               
                                          


                                                         

                              
                                              
         

                                                  


                              
                                       
                                   
                   

 
























































































































































                                                                               





                                                                        
 



                                                               
         


                                                                              


                               

                                  











                                                            

                        








                                                                               




                                                          

                                                                
 


                          
                                                

                           
                                       









                                                                           





                                                                         


                                       









                                                                           

                 







                                                      
 











                                                             



                                                                  







                                              
                                                                         



                                                               

                 












                                                                     



                                                                  
                                           






                                                  
                                                                         






                                                  


                 



                                     
                                           


                                                 
                                                 
                                                 
                                                     




                                                                       



                                                   
                                           

                                                

                                                 


                                                      

 


                                                                               

                                                         
 
 
                                                            





















                                                                              
                                                       

                                 

                                                                      





                                 
                                                                       





                                   















                                                                             

                                                           
                                           





                                                          

                                                                    





                                                                         
                              
                                                         

                                                                            
         

 





                                                                             
                                                                                

              
                 


                                              
                                     
                                   
                                     

  

                                                                         


                    
                       


                                                                              
                                                                            






                                   




                                                                      

                                                                       
                                                      
         


 




                                                                         
                           
                

                                             

                                                                         
 
                                                                    


                                                     
                                                        

                                   




                                                                                
                                                 
                                                                              
                                                             
                                

                                                                            

                                                  


                                                                   
                                                   






                       
                                                                            
                                                                     


                                          
                    

                          
                         


                                             




                                                                        
                             

                                          

                                           
 
                                                            
                                        
                                                             
                                                    
                          

                                 


                                                         




















                                                                            
                                                                 
                                       
                                 
 
                                     

                                             
                                                 
         
                                          
                                         
                                                          



                                                              
 
 
                                                                          
                                                                   
 


                                                           

 













































                                                                                
                                                                        

                                                                      
 
                                           
                                         
                      
                                


                                 
                




                                                                     
                         

         













                                                                            
                                 
                                                                  
 
                               
                                             

















                                                                              
                                          


                                          
                                                         
                                    

                                        
                                                                
                                                         
                               
                                                          






                                                                 
                 

 
                                                               

                                                                          

                                      
                    

                                          
                                                    



                                            
                                                                            
                                                                             
 
                                           
                                  
                    
                           

                                      
                      
 











                                                                               
                                          
                                                    




                                                           


                                            
                                                                        

                                 
                                                        

                                             

                                 
                                                                  
                                        
 

                                                
                                                            



                                                                                



                                                   

                                                  
                                                                   
                                                    


                                        
 






                                                                             



                                                                 
 
                                        
                                                                


                             
                
                                                

                             





                                                                      
                                                                         

         
                                          

                          
                   


                                          
                 


                          

 




                                                                   
                
                                           
                                                         
                                           
 
                                                              


                                    





                                                                            

                                    
                                                                            
                               
         
 
                
 








                                                                             

                                                                 
                                       
                 





                                                                              

                                                                  





                                                            

                                                                        








                                                                                
                                          





                                            
          
                                                   

                   

 








                                                            

                                                                          

                                                                    
 

                                        
                                
                                           
 
                                        
                                                  

                                  
 




                                                                    
                                                                     
 

                                                                
                                
 
                                                          
                                                                   
                                                        
                                                    
                                         
 





                                            
                                                                        
                                                    
          

                                       
                                                     
                 




                                      
                             

                            
                                                       
                                                                      





                                                                             
         
                                          




                            







                                                                           
                                           



                                             
                                                         
                                        
                                                             


                                                    

                                                         
                                                          


                                                                         


                                          
                                                           



                                         


                                                                   

                      
                                               
 


                                                








                                                                              



                                                             
                                

                                                
                                                          

         

                           
 

                                                     
                                          

                                                         
                           
         

                                                                      




                                                                          
                                               
                                                                            

                                  
                                                   

                                    
                                                           
                                               
 
/*
 * Generic hugetlb support.
 * (C) William Irwin, April 2004
 */
#include <linux/gfp.h>
#include <linux/list.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/sysctl.h>
#include <linux/highmem.h>
#include <linux/mmu_notifier.h>
#include <linux/nodemask.h>
#include <linux/pagemap.h>
#include <linux/mempolicy.h>
#include <linux/cpuset.h>
#include <linux/mutex.h>
#include <linux/bootmem.h>
#include <linux/sysfs.h>

#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/io.h>

#include <linux/hugetlb.h>
#include "internal.h"

const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
static gfp_t htlb_alloc_mask = GFP_HIGHUSER;
unsigned long hugepages_treat_as_movable;

static int max_hstate;
unsigned int default_hstate_idx;
struct hstate hstates[HUGE_MAX_HSTATE];

__initdata LIST_HEAD(huge_boot_pages);

/* for command line parsing */
static struct hstate * __initdata parsed_hstate;
static unsigned long __initdata default_hstate_max_huge_pages;
static unsigned long __initdata default_hstate_size;

#define for_each_hstate(h) \
	for ((h) = hstates; (h) < &hstates[max_hstate]; (h)++)

/*
 * Protects updates to hugepage_freelists, nr_huge_pages, and free_huge_pages
 */
static DEFINE_SPINLOCK(hugetlb_lock);

/*
 * Region tracking -- allows tracking of reservations and instantiated pages
 *                    across the pages in a mapping.
 *
 * The region data structures are protected by a combination of the mmap_sem
 * and the hugetlb_instantion_mutex.  To access or modify a region the caller
 * must either hold the mmap_sem for write, or the mmap_sem for read and
 * the hugetlb_instantiation mutex:
 *
 * 	down_write(&mm->mmap_sem);
 * or
 * 	down_read(&mm->mmap_sem);
 * 	mutex_lock(&hugetlb_instantiation_mutex);
 */
struct file_region {
	struct list_head link;
	long from;
	long to;
};

static long region_add(struct list_head *head, long f, long t)
{
	struct file_region *rg, *nrg, *trg;

	/* Locate the region we are either in or before. */
	list_for_each_entry(rg, head, link)
		if (f <= rg->to)
			break;

	/* Round our left edge to the current segment if it encloses us. */
	if (f > rg->from)
		f = rg->from;

	/* Check for and consume any regions we now overlap with. */
	nrg = rg;
	list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
		if (&rg->link == head)
			break;
		if (rg->from > t)
			break;

		/* If this area reaches higher then extend our area to
		 * include it completely.  If this is not the first area
		 * which we intend to reuse, free it. */
		if (rg->to > t)
			t = rg->to;
		if (rg != nrg) {
			list_del(&rg->link);
			kfree(rg);
		}
	}
	nrg->from = f;
	nrg->to = t;
	return 0;
}

static long region_chg(struct list_head *head, long f, long t)
{
	struct file_region *rg, *nrg;
	long chg = 0;

	/* Locate the region we are before or in. */
	list_for_each_entry(rg, head, link)
		if (f <= rg->to)
			break;

	/* If we are below the current region then a new region is required.
	 * Subtle, allocate a new region at the position but make it zero
	 * size such that we can guarantee to record the reservation. */
	if (&rg->link == head || t < rg->from) {
		nrg = kmalloc(sizeof(*nrg), GFP_KERNEL);
		if (!nrg)
			return -ENOMEM;
		nrg->from = f;
		nrg->to   = f;
		INIT_LIST_HEAD(&nrg->link);
		list_add(&nrg->link, rg->link.prev);

		return t - f;
	}

	/* Round our left edge to the current segment if it encloses us. */
	if (f > rg->from)
		f = rg->from;
	chg = t - f;

	/* Check for and consume any regions we now overlap with. */
	list_for_each_entry(rg, rg->link.prev, link) {
		if (&rg->link == head)
			break;
		if (rg->from > t)
			return chg;

		/* We overlap with this area, if it extends futher than
		 * us then we must extend ourselves.  Account for its
		 * existing reservation. */
		if (rg->to > t) {
			chg += rg->to - t;
			t = rg->to;
		}
		chg -= rg->to - rg->from;
	}
	return chg;
}

static long region_truncate(struct list_head *head, long end)
{
	struct file_region *rg, *trg;
	long chg = 0;

	/* Locate the region we are either in or before. */
	list_for_each_entry(rg, head, link)
		if (end <= rg->to)
			break;
	if (&rg->link == head)
		return 0;

	/* If we are in the middle of a region then adjust it. */
	if (end > rg->from) {
		chg = rg->to - end;
		rg->to = end;
		rg = list_entry(rg->link.next, typeof(*rg), link);
	}

	/* Drop any remaining regions. */
	list_for_each_entry_safe(rg, trg, rg->link.prev, link) {
		if (&rg->link == head)
			break;
		chg += rg->to - rg->from;
		list_del(&rg->link);
		kfree(rg);
	}
	return chg;
}

static long region_count(struct list_head *head, long f, long t)
{
	struct file_region *rg;
	long chg = 0;

	/* Locate each segment we overlap with, and count that overlap. */
	list_for_each_entry(rg, head, link) {
		int seg_from;
		int seg_to;

		if (rg->to <= f)
			continue;
		if (rg->from >= t)
			break;

		seg_from = max(rg->from, f);
		seg_to = min(rg->to, t);

		chg += seg_to - seg_from;
	}

	return chg;
}

/*
 * Convert the address within this vma to the page offset within
 * the mapping, in pagecache page units; huge pages here.
 */
static pgoff_t vma_hugecache_offset(struct hstate *h,
			struct vm_area_struct *vma, unsigned long address)
{
	return ((address - vma->vm_start) >> huge_page_shift(h)) +
			(vma->vm_pgoff >> huge_page_order(h));
}

/*
 * Flags for MAP_PRIVATE reservations.  These are stored in the bottom
 * bits of the reservation map pointer, which are always clear due to
 * alignment.
 */
#define HPAGE_RESV_OWNER    (1UL << 0)
#define HPAGE_RESV_UNMAPPED (1UL << 1)
#define HPAGE_RESV_MASK (HPAGE_RESV_OWNER | HPAGE_RESV_UNMAPPED)

/*
 * These helpers are used to track how many pages are reserved for
 * faults in a MAP_PRIVATE mapping. Only the process that called mmap()
 * is guaranteed to have their future faults succeed.
 *
 * With the exception of reset_vma_resv_huge_pages() which is called at fork(),
 * the reserve counters are updated with the hugetlb_lock held. It is safe
 * to reset the VMA at fork() time as it is not in use yet and there is no
 * chance of the global counters getting corrupted as a result of the values.
 *
 * The private mapping reservation is represented in a subtly different
 * manner to a shared mapping.  A shared mapping has a region map associated
 * with the underlying file, this region map represents the backing file
 * pages which have ever had a reservation assigned which this persists even
 * after the page is instantiated.  A private mapping has a region map
 * associated with the original mmap which is attached to all VMAs which
 * reference it, this region map represents those offsets which have consumed
 * reservation ie. where pages have been instantiated.
 */
static unsigned long get_vma_private_data(struct vm_area_struct *vma)
{
	return (unsigned long)vma->vm_private_data;
}

static void set_vma_private_data(struct vm_area_struct *vma,
							unsigned long value)
{
	vma->vm_private_data = (void *)value;
}

struct resv_map {
	struct kref refs;
	struct list_head regions;
};

struct resv_map *resv_map_alloc(void)
{
	struct resv_map *resv_map = kmalloc(sizeof(*resv_map), GFP_KERNEL);
	if (!resv_map)
		return NULL;

	kref_init(&resv_map->refs);
	INIT_LIST_HEAD(&resv_map->regions);

	return resv_map;
}

void resv_map_release(struct kref *ref)
{
	struct resv_map *resv_map = container_of(ref, struct resv_map, refs);

	/* Clear out any active regions before we release the map. */
	region_truncate(&resv_map->regions, 0);
	kfree(resv_map);
}

static struct resv_map *vma_resv_map(struct vm_area_struct *vma)
{
	VM_BUG_ON(!is_vm_hugetlb_page(vma));
	if (!(vma->vm_flags & VM_SHARED))
		return (struct resv_map *)(get_vma_private_data(vma) &
							~HPAGE_RESV_MASK);
	return 0;
}

static void set_vma_resv_map(struct vm_area_struct *vma, struct resv_map *map)
{
	VM_BUG_ON(!is_vm_hugetlb_page(vma));
	VM_BUG_ON(vma->vm_flags & VM_SHARED);

	set_vma_private_data(vma, (get_vma_private_data(vma) &
				HPAGE_RESV_MASK) | (unsigned long)map);
}

static void set_vma_resv_flags(struct vm_area_struct *vma, unsigned long flags)
{
	VM_BUG_ON(!is_vm_hugetlb_page(vma));
	VM_BUG_ON(vma->vm_flags & VM_SHARED);

	set_vma_private_data(vma, get_vma_private_data(vma) | flags);
}

static int is_vma_resv_set(struct vm_area_struct *vma, unsigned long flag)
{
	VM_BUG_ON(!is_vm_hugetlb_page(vma));

	return (get_vma_private_data(vma) & flag) != 0;
}

/* Decrement the reserved pages in the hugepage pool by one */
static void decrement_hugepage_resv_vma(struct hstate *h,
			struct vm_area_struct *vma)
{
	if (vma->vm_flags & VM_NORESERVE)
		return;

	if (vma->vm_flags & VM_SHARED) {
		/* Shared mappings always use reserves */
		h->resv_huge_pages--;
	} else if (is_vma_resv_set(vma, HPAGE_RESV_OWNER)) {
		/*
		 * Only the process that called mmap() has reserves for
		 * private mappings.
		 */
		h->resv_huge_pages--;
	}
}

/* Reset counters to 0 and clear all HPAGE_RESV_* flags */
void reset_vma_resv_huge_pages(struct vm_area_struct *vma)
{
	VM_BUG_ON(!is_vm_hugetlb_page(vma));
	if (!(vma->vm_flags & VM_SHARED))
		vma->vm_private_data = (void *)0;
}

/* Returns true if the VMA has associated reserve pages */
static int vma_has_reserves(struct vm_area_struct *vma)
{
	if (vma->vm_flags & VM_SHARED)
		return 1;
	if (is_vma_resv_set(vma, HPAGE_RESV_OWNER))
		return 1;
	return 0;
}

static void clear_huge_page(struct page *page,
			unsigned long addr, unsigned long sz)
{
	int i;

	might_sleep();
	for (i = 0; i < sz/PAGE_SIZE; i++) {
		cond_resched();
		clear_user_highpage(page + i, addr + i * PAGE_SIZE);
	}
}

static void copy_huge_page(struct page *dst, struct page *src,
			   unsigned long addr, struct vm_area_struct *vma)
{
	int i;
	struct hstate *h = hstate_vma(vma);

	might_sleep();
	for (i = 0; i < pages_per_huge_page(h); i++) {
		cond_resched();
		copy_user_highpage(dst + i, src + i, addr + i*PAGE_SIZE, vma);
	}
}

static void enqueue_huge_page(struct hstate *h, struct page *page)
{
	int nid = page_to_nid(page);
	list_add(&page->lru, &h->hugepage_freelists[nid]);
	h->free_huge_pages++;
	h->free_huge_pages_node[nid]++;
}

static struct page *dequeue_huge_page(struct hstate *h)
{
	int nid;
	struct page *page = NULL;

	for (nid = 0; nid < MAX_NUMNODES; ++nid) {
		if (!list_empty(&h->hugepage_freelists[nid])) {
			page = list_entry(h->hugepage_freelists[nid].next,
					  struct page, lru);
			list_del(&page->lru);
			h->free_huge_pages--;
			h->free_huge_pages_node[nid]--;
			break;
		}
	}
	return page;
}

static struct page *dequeue_huge_page_vma(struct hstate *h,
				struct vm_area_struct *vma,
				unsigned long address, int avoid_reserve)
{
	int nid;
	struct page *page = NULL;
	struct mempolicy *mpol;
	nodemask_t *nodemask;
	struct zonelist *zonelist = huge_zonelist(vma, address,
					htlb_alloc_mask, &mpol, &nodemask);
	struct zone *zone;
	struct zoneref *z;

	/*
	 * A child process with MAP_PRIVATE mappings created by their parent
	 * have no page reserves. This check ensures that reservations are
	 * not "stolen". The child may still get SIGKILLed
	 */
	if (!vma_has_reserves(vma) &&
			h->free_huge_pages - h->resv_huge_pages == 0)
		return NULL;

	/* If reserves cannot be used, ensure enough pages are in the pool */
	if (avoid_reserve && h->free_huge_pages - h->resv_huge_pages == 0)
		return NULL;

	for_each_zone_zonelist_nodemask(zone, z, zonelist,
						MAX_NR_ZONES - 1, nodemask) {
		nid = zone_to_nid(zone);
		if (cpuset_zone_allowed_softwall(zone, htlb_alloc_mask) &&
		    !list_empty(&h->hugepage_freelists[nid])) {
			page = list_entry(h->hugepage_freelists[nid].next,
					  struct page, lru);
			list_del(&page->lru);
			h->free_huge_pages--;
			h->free_huge_pages_node[nid]--;

			if (!avoid_reserve)
				decrement_hugepage_resv_vma(h, vma);

			break;
		}
	}
	mpol_cond_put(mpol);
	return page;
}

static void update_and_free_page(struct hstate *h, struct page *page)
{
	int i;

	h->nr_huge_pages--;
	h->nr_huge_pages_node[page_to_nid(page)]--;
	for (i = 0; i < pages_per_huge_page(h); i++) {
		page[i].flags &= ~(1 << PG_locked | 1 << PG_error | 1 << PG_referenced |
				1 << PG_dirty | 1 << PG_active | 1 << PG_reserved |
				1 << PG_private | 1<< PG_writeback);
	}
	set_compound_page_dtor(page, NULL);
	set_page_refcounted(page);
	arch_release_hugepage(page);
	__free_pages(page, huge_page_order(h));
}

struct hstate *size_to_hstate(unsigned long size)
{
	struct hstate *h;

	for_each_hstate(h) {
		if (huge_page_size(h) == size)
			return h;
	}
	return NULL;
}

static void free_huge_page(struct page *page)
{
	/*
	 * Can't pass hstate in here because it is called from the
	 * compound page destructor.
	 */
	struct hstate *h = page_hstate(page);
	int nid = page_to_nid(page);
	struct address_space *mapping;

	mapping = (struct address_space *) page_private(page);
	set_page_private(page, 0);
	BUG_ON(page_count(page));
	INIT_LIST_HEAD(&page->lru);

	spin_lock(&hugetlb_lock);
	if (h->surplus_huge_pages_node[nid] && huge_page_order(h) < MAX_ORDER) {
		update_and_free_page(h, page);
		h->surplus_huge_pages--;
		h->surplus_huge_pages_node[nid]--;
	} else {
		enqueue_huge_page(h, page);
	}
	spin_unlock(&hugetlb_lock);
	if (mapping)
		hugetlb_put_quota(mapping, 1);
}

/*
 * Increment or decrement surplus_huge_pages.  Keep node-specific counters
 * balanced by operating on them in a round-robin fashion.
 * Returns 1 if an adjustment was made.
 */
static int adjust_pool_surplus(struct hstate *h, int delta)
{
	static int prev_nid;
	int nid = prev_nid;
	int ret = 0;

	VM_BUG_ON(delta != -1 && delta != 1);
	do {
		nid = next_node(nid, node_online_map);
		if (nid == MAX_NUMNODES)
			nid = first_node(node_online_map);

		/* To shrink on this node, there must be a surplus page */
		if (delta < 0 && !h->surplus_huge_pages_node[nid])
			continue;
		/* Surplus cannot exceed the total number of pages */
		if (delta > 0 && h->surplus_huge_pages_node[nid] >=
						h->nr_huge_pages_node[nid])
			continue;

		h->surplus_huge_pages += delta;
		h->surplus_huge_pages_node[nid] += delta;
		ret = 1;
		break;
	} while (nid != prev_nid);

	prev_nid = nid;
	return ret;
}