在使用DPDK或者SPDK的时候,需要在进程刚启动的时候使用rte_eal_init初始化Environment Abstract Layer,应用进程会通过这个函数告诉EAL为它映射多大的hugepages,这通常通过ealargs的-m参数来指定,就像下面这样:
char *ealargs[] = {
argv[0], // name
NULL, // core_mask(to be decided)
"-n 4", // number of memory channels per processor socket
"--proc-type=auto", // The type of process instance.
"-m 512",
};
// ....
int rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs);
if (rc < 0)
{
// error handles
}
需要注意的是,此处-m指定的hugepages的大小需要小于系统可用的hugepages大小(系统可用的Hugepages大小可以通过 `cat /proc/meminfo | grep Hugepage`查看。
但是!在系统运行一段时间后,就算是-m指定的hugepages的大小小于系统可用的Hugepages大小,EAL初始化的时候依然会panic掉,输出类似于下面的日志:
EAL: Detected 64 lcore(s)
EAL: Auto-detected process type: PRIMARY
EAL: No free hugepages reported in hugepages-1048