如何查看Linux系统的内存页大小:
1. getconf PAGESIZE/PAGE_SIZE 返回值单位为Bytes
-
[root@localhost nginx-1.8.0]# getconf PAGESIZE
-
4096
-
[root@localhost nginx-1.8.0]# getconf PAGE_SIZE
-
4096
2. 通过c函数获取
#include
int getpagesize(void);返回值单位为Bytes
-
The function getpagesize() returns the number of bytes in a page, where a "page" is the thing used where it says in the description of mmap(2) that files are mapped in page-sized units.
-
-
The size of the kind of pages that mmap() uses, is found using
-
-
#include <unistd.h>
-
long sz = sysconf(_SC_PAGESIZE);
-
-
(where some systems also allow the synonym _SC_PAGE_SIZE for _SC_PAGESIZE), or
-
-
#include <unistd.h>
-
int sz = getpagesize()
pagesize.c
-
[root@localhost test]# more pagesize.c
-
#include <unistd.h>
-
#include <stdio.h>
-
int main(int argc, char *argv[])
-
{
-
printf("linux page size is %d bytes\n",getpagesize());
-
return 0;
-
}
编译运行:
-
[root@localhost test]# gcc -g pagesize.c -o pagesize -Wall
-
[root@localhost test]# ./pagesize
-
linux page size is 4096 bytes
阅读(7259) | 评论(0) | 转发(0) |