简体   繁体   English

为什么 Linux msync 返回“无法分配内存”? 是否可以修复此错误代码?

[英]Why is Linux msync is returning “Cannot Allocate memory”? Is it possible to fix this error code?

Good afternoon, We are building a prototype deduper for Centos Linux Release x86_32 and Microsoft Windows.下午好,我们正在为 Centos Linux Release x86_32 和 Microsoft Windows 构建原型重复数据删除器。 One part of the prototype is a MemoryMappedFile program which uses a 1800 element cache.原型的一部分是一个使用 1800 个元素缓存的 MemoryMappedFile 程序。 For Centos Linux 5.5 we call msync to synchronize the file with the memory map.对于 Centos Linux 5.5 我们调用 msync 将文件与 memory Z1D78DC8ED512FE44E51同步文件For the last several weeks, msync has been functioning okay.在过去的几周里,msync 一直运行良好。 Today, msync and perror("msync") are returning "Cannot allocate memory".今天,msync 和 perror("msync") 返回“无法分配内存”。 Why is Centos Linux Version 5.5 x86_32 msync returning "Cannot Allocate memory"?为什么 Centos Linux 版本 5.5 x86_32 msync 返回“无法分配内存”? Is it possible for use to fix the "Cannot Allocate memory" error on Centos Linux 5.5 x86_32.是否可以用于修复 Centos Linux 5.5 x86_32 上的“无法分配内存”错误。 Thank you.谢谢你。 An excerpt of the memory mapped file program code is shown below: memory映射文件程序代码摘录如下所示:

        typedef std::multimap<char *,Range>::const_iterator I;  
    std::pair<I,I> b = mmultimap.equal_range(TmpPrevMapPtr); 
         for (I i=b.first; i != b.second; ++i){ 
    std::deque<Range>::iterator iter;
    iter = std::lower_bound(ranges_type.begin(),ranges_type.end(),i->second);
              if (iter != ranges_type.end() && !(i->second < *iter)){
        sz1 = ranges_type.size();
                        ranges_type.erase(iter);
        sz2 = ranges_type.size();
    }
    }
    erasecount = mmultimap.erase(TmpPrevMapPtr); 
    #if defined(__windows)
    retval = FlushViewOfFile(TmpPrevMapPtr, mappedlength);
    retval =    UnmapViewOfFile(TmpPrevMapPtr);            
    #elif defined(__unix)
         retval = msync(TmpPrevMapPtr,   mappedlength, MS_SYNC);    
    if (retval == -1){                                        
       perror("msync");                                       
         }                                                       
         retval = munmap(TmpPrevMapPtr,  mappedlength);
    if (retval == -1){                    
       perror("munmap");                        
           throw cException(ERR_MEMORYMAPPING,TempFileName);
         }
    #endif

The msync man page states: msync 手册页指出:

 ENOMEM The indicated memory (or part of it) was not mapped.

That's the errno value perror() prints for you.这就是 perror() 为您打印的 errno 值。 So you're somehow trying to msync() memory that you've not mmap()'ed from a file.所以你以某种方式试图 msync() memory 你没有从文件中映射()。

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

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