This post shows the interaction between hugetlbfs and huge pages by an example program. All the results are based on linux 3.10.0-514.55.4.el7.x86_64.
Setup
1 2 |
|
This creates a hugetlbfs with maximum of 10 huge pages.
Example Program
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 |
|
The output of running this program is:
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 |
|
Observations
- Just setting the file size won’t allocate/reserve any huge pages. It only affects the logical file size not the physical one.
mmap
only reserves the huge pages.- Populating the page table or accessing a page actually allocates the huge pages.
HugePages_Free
includesHugePages_Rsvd
so the number of free-to-use huge pages is actuallyHugePages_Free
minusHugePages_Rsvd
.