我一直在使用openSUSE 11.2 x86_64上的大型稀疏文件.当我尝试mmap()1TB稀疏文件时,它会因ENOMEM而失败.我原以为64位地址空间足以映射到太字节,但似乎没有.进一步尝试,1GB文件工作正常,但2GB文件(和更大的文件)失败.我猜测可能有某个地方可以进行调整,但广泛的搜索没有任何结果.
这里有一些显示问题的示例代码 - 任何线索?
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char * filename = argv[1];
int fd;
off_t size = 1UL << 40; // 30 == 1GB, 40 == 1TB
fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
ftruncate(fd, size);
printf("Created %ld byte sparse file\n", size);
char * buffer = (char *)mmap(NULL, (size_t)size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if ( …Run Code Online (Sandbox Code Playgroud)