如何获得巨大页面尺寸的价值? [英] How to get the value of huge page size?
本文介绍了如何获得巨大页面尺寸的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望直接从C代码中获取巨大页面大小的值,而无需运行bash命令.
I am looking to get the value of huge page size directly from my C code without to run a bash command.
我可以通过bash做到这一点
From bash i can do this
grep pse /proc/cpuinfo > /dev/null && echo '2M huge page size are supported'
grep pdpe1gb /proc/cpuinfo> /dev/null && echo '1G huge page size are supported'
其次,如何使用具有1G巨大页面大小的mmap?
Secondly how to use mmap with 1G huge page size ?
谢谢
更新
代码段
#include <stdio.h>
#include <limits.h>
#include <hugetlbfs.h>
int main(void){
long result1 = gethugepagesize();
printf( "%d\n", result1 );
long result2 = gethugepagesizes( NULL, 0);
printf( "%d\n", result2 );
long result3 = getpagesizes( NULL, 0);
printf( "%d\n", result3 );
printf("%d\n", PF_LINUX_HUGETLB);
return 0;
}
输出
2097152
1
2
1048576
这里gethugepagesize返回2 Mb 1Gb的大页面怎么办?
here gethugepagesize return 2 Mb what about 1Gb huge page ?
推荐答案
尝试一下.
#include <hugetlbfs.h>
int getpagesizes(long pagesizes[], int n_elem);
这篇关于如何获得巨大页面尺寸的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文