简体   繁体   English

gzopen()导致ENOMEM的原因

[英]Causes of gzopen() leading to ENOMEM

I have a program whose total memory footprint is about 100 MiB (VM size, in top, while stopped in gdb ) that's trying to open a new (not-yet-existent) compressed log file using gzopen . 我有一个程序,其总内存占用量约为100 MiB(VM大小,顶部,而在gdb停止),试图使用gzopen打开新的(尚不存在)压缩日志文件。 This fails, with errno set to ENOMEM , despite the fact that the system has 6GB memory completely free (not even holding caches), and lots of space on the filesystem (that would be ENOSPC , I know). 尽管将errno设置为ENOMEM ,但这仍然失败,尽管该系统具有6GB的完全可用内存(甚至不保存缓存),并且在文件系统上有很多空间(我知道这是ENOSPC )。 Are there more obscure issues that could cause this? 是否还有其他可能导致此问题的晦涩问题? Is something in the library incidentally allocating gigabytes upon gigabytes of memory for no good reason? 库中是否有某些东西无缘无故地在GB的内存上分配了GB?

For note, my ulimits are set unlimited. 请注意,我的ulimit设置为无限制。

No, there is nothing in zlib that would allocate more than a MiB or two. 不,zlib中没有什么可以分配超过一两个MiB的。 zlib will only set errno to zero. zlib只会将errno设置为零。 On its own, it never sets errno to ENOMEM. 它自己不会将errno设置为ENOMEM。 The library functions it calls may. 它可能调用的库函数。 What version of zlib are you using? 您正在使用哪个版本的zlib?

Turns out zlib was not returning ENOMEM . 事实证明zlib没有返回ENOMEM It was bailing out because we had passed it a mode argument w+ , which is invalid because it can't read and write a given gzip file at the same time. 它之所以失败,是因为我们给它传递了模式参数w+ ,这是无效的,因为它无法同时读写给定的gzip文件。 The ENOMEM came from what happened to be sitting in errno from previous library/system calls. ENOMEM来自之前的库/系统调用中坐在errno

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM