English 中文(简体)
为什么ENOMEM在1TB稀释档案中失败?
原标题:Why does mmap() fail with ENOMEM on a 1TB sparse file?
  • 时间:2010-05-26 03:31:47
  •  标签:
  • c
  • linux
  • mmap

我一直在处理开放式的SSUSE11.2×86_64的大量零件档案。 当我试图用1TB的稀释文档时,它就没有ENOMEM。 我本来会认为,64个轨道地址空间足以在空中绘制地图,但似乎并非如此。 另外,1个GB卷宗的试验效果良好,但2个GB(和任何较大的)卷宗失败。 我猜测,可能有一个地方来拖瓦,但广泛的搜索却无所作为。

这里有一些显示问题的样本代码――任何杂质?

#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
", size);

    char * buffer = (char *)mmap(NULL, (size_t)size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if ( buffer == MAP_FAILED ) {
        perror("mmap");
        exit(1);
    }
    printf("Done mmap - returned 0x0%lx
", (unsigned long)buffer);

    strcpy( buffer, "cafebabe" );
    printf("Wrote to start
");

    strcpy( buffer + (size - 9), "deadbeef" );
    printf("Wrote to end
");

    if ( munmap(buffer, (size_t)size) < 0 ) {
        perror("munmap");
        exit(1);
    }
    close(fd);

    return 0;
}
最佳回答

问题是,每个过程的虚拟记忆限制只设定为1.7GB。 ulimit -v 1610612736 >将其设定为1.5TB,我的微粒接过。 感谢bmargulies,为审判ulimit-a!

问题回答

是否有某种类型的用户配额,限制了用户的记忆量?

我的猜测是,掩体难以分配它需要跟上这一记忆规划的记忆。 我不知道如何把蒸.的网页上封起来(我假设,大多数档案都放在最忙的状态中),但最后可能需要每个记忆页上填写档案。 由于这一档案可能被不止一个过程所耗尽,因此,掩体必须从过程的角度来看保持绘图工作,这将把地图绘制到另一个观点,从而绘制二级储存图(包括装置和地点)。

这将适合您的可用空间,但可能不适于(至少毗连)在体记忆中。

如果有人更多地了解一下Liberin如何做,那么我很有兴趣了解这一情况。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签