mem: fix allocating all free hugepages
EAL memory init allocates all free hugepages of the whole system,
which seen from sysfs, even when applications do not ask so many.
When there is a limitation on how many hugepages an application can
use (such as cgroup.hugetlb), or hugetlbfs is specified with an
option of size (exceeding the quota of the fs), it just fails to
start even there are enough hugepages allocated.
To fix above issue, this patch:
- Changes the logic to continue memory init to see if hugetlb
requirement of application can be addressed by already allocated
hugepages.
- To make sure each hugepage is allocated successfully, we add a
recover mechanism, which relies on a mem access to fault-in
hugepages, and if it fails with SIGBUS, recover to previously
saved stack environment with siglongjmp().
For the case of CONFIG_RTE_EAL_SINGLE_FILE_SEGMENTS (enabled by
default when compiling IVSHMEM target), it's indispensable to
mapp all free hugepages in the system. Under this case, it fails
to start when allocating fails.
Test example:
a. cgcreate -g hugetlb:/test-subgroup
b. cgset -r hugetlb.1GB.limit_in_bytes=
2147483648 test-subgroup
c. cgexec -g hugetlb:test-subgroup \
./examples/helloworld/build/helloworld -c 0x2 -n 4
Fixes:
af75078fece ("first public release")
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Tested-by: Yulong Pei <yulong.pei@intel.com>
Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>