hugetlb: add a new function get_available_hugepages

on some systems with small RAM, there aren't enough memory
to set as specific hugepages, such as 128 hugepages, it will
fail like this:
 [root@localhost hugemmap]# ./hugemmap01
 hugemmap01    0  TINFO  :  set nr_hugepages to 128
 hugemmap01    1  TBROK  :  nr_hugepages = 55, but expect 128
 hugemmap01    2  TBROK  :  Remaining cases broken
 hugemmap01    0  TINFO  :  set nr_hugepages to 54

we can detect whether the system has the power to get the specific
hugepages through the following commands:

 [root@localhost hugemmap]# echo 128 > /proc/sys/vm/nr_hugepages
 [root@localhost hugemmap]# cat /proc/sys/vm/nr_hugepages
 55

as we know, on this system, there are 55 available hugepages, so we
can set 55 hugepages to continue the case, but to exit the case,
and this is desinged into get_available_hugepages() functions.

Signed-off-by: Zhouping Liu <zliu@redhat.com>
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
17 files changed