对于hugepages,ftruncate()失败
我的应用程序试图对于hugepages,ftruncate()失败,c,linux,centos7,mmap,huge-pages,C,Linux,Centos7,Mmap,Huge Pages,我的应用程序试图ftruncate()和mmap()-ed 32-33KB,带有2MB的大页面,但退出了 然后我意识到ftruncate()失败了: int fd = open("/mnt/huge2m/test", O_RDWR|O_CREAT, 0666); int rc0 = ftruncate(fd, size); if (0 != rc0) { fprintf(stderr, "Can't ftruncate shared memory segment: %d,
ftruncate()
和mmap()
-ed 32-33KB,带有2MB的大页面,但退出了
然后我意识到ftruncate()
失败了:
int fd = open("/mnt/huge2m/test", O_RDWR|O_CREAT, 0666);
int rc0 = ftruncate(fd, size);
if (0 != rc0) {
fprintf(stderr,
"Can't ftruncate shared memory segment: %d, %lu, errno = %d, err = %s\n",
fd, size, errno, strerror(errno));
exit(1);
}
然后它退出:
Can't ftruncate shared memory segment: 5, 32896, errno = 22, err = Invalid argument
terminate called without an active exception
我在安装HugePageFS的地方选中了/mnt/huge2m
。我确实看到该文件是在那里创建的,但大小为零
然后我检查了我是否还有免费的2MB hugepages:
$ numastat -vm
Per-node system memory usage (in MBs):
Node 0 Node 1 Total
--------------- --------------- ---------------
MemTotal 96936.38 98304.00 195240.38
MemFree 94171.20 95491.38 189662.58
MemUsed 2765.17 2812.62 5577.80
Active 79.84 416.48 496.32
Inactive 136.42 57.93 194.35
Active(anon) 22.71 4.80 27.52
Inactive(anon) 9.20 0.01 9.21
Active(file) 57.13 411.68 468.80
Inactive(file) 127.21 57.92 185.14
Unevictable 0.00 0.00 0.00
Mlocked 0.00 0.00 0.00
Dirty 0.00 0.00 0.00
Writeback 0.00 0.00 0.00
FilePages 193.86 470.31 664.17
Mapped 16.09 1.28 17.37
AnonPages 22.45 4.84 27.29
Shmem 9.52 0.05 9.56
KernelStack 7.42 4.59 12.02
PageTables 2.75 0.32 3.07
NFS_Unstable 0.00 0.00 0.00
Bounce 0.00 0.00 0.00
WritebackTmp 0.00 0.00 0.00
Slab 94.56 47.73 142.30
SReclaimable 34.54 19.01 53.55
SUnreclaim 60.02 28.73 88.75
AnonHugePages 0.00 0.00 0.00
HugePages_Total 80.00 80.00 160.00
HugePages_Free 80.00 12.00 92.00
HugePages_Surp 0.00 0.00 0.00
我还有很多(92MB)
然后,我检查了以下建议的限制:
我的应用程序只能打开<10个文件
我还认为我的用户打开了太多的文件,达到了(硬)限制。如果是这样的话,当我试图打开()文件(hugepage)时,我应该得到-1而不是5(这是一个有效的fd描述符,文件不会在/mnt/huge2m
中创建)
strace
显示不多:
open("/mnt/huge2m/test", O_RDWR|O_CREAT, 0666) = 5
ftruncate(5, 32896) = -1 EINVAL (Invalid argument)
write(2, "Can't ftruncate shared mem segme"..., 82Can't ftruncate shared mem segment: 5, 262272, errno = 22, err = Invalid argument
) = 82
有什么想法吗?大页面归档系统中的文件长度可能只有整数,在您的情况下是2MB的倍数。你不应该为这么少的内存使用巨大的页面。Linux也会在“文件未打开以供写入”上生成EINVAL@IngoLeonhardt是的,我的不好。让我来修复它。@AnttiHaapala我包括了我是如何用读写权限打开文件的。它没有返回-1。有趣的是,常规共享内存页(通常为4K)允许ftruncate()。谢谢如果你不介意的话,这只是一个小问题——你知道如何正确清理mmap ed hugeages(映射到挂载的hugepage fs)吗?即使有时我close()
和mumap()
也能看到那里的文件。谢谢
open("/mnt/huge2m/test", O_RDWR|O_CREAT, 0666) = 5
ftruncate(5, 32896) = -1 EINVAL (Invalid argument)
write(2, "Can't ftruncate shared mem segme"..., 82Can't ftruncate shared mem segment: 5, 262272, errno = 22, err = Invalid argument
) = 82