Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Unexpected behavior of mmap64() on QNX: (1 Item)
   
Unexpected behavior of mmap64() on QNX  
Hi,

I'm facing a problem with the usage of mmap() API.

As part of a database validation i'm using a disk file as shared memory through memory mapping. This disk file is memory
 mapped to process address space to store the database page indexes.

Memory mapping of physical file happens in regions of 32k using the API mmap64(). When i map the first 32k region with 
offset 0, it is mapping correctly(32k region is initialized with zeros). But in the subsequent calls to map the next 32k
 regions it is giving problem. Even though i pass a valid offset (multiple of 32k), it is initializing the previous 
regions with zeros, whereas it was supposed to initialize only the new region. 
This is causing issues while using the shared memory, as the mmapped locations having updated data(page numbers) are 
overwritten with zeros. As a result the database is getting corrupted.

________________________________________________________________________________________________
void * mmap64( void * addr,
               size_t len,
               int prot,
               int flags,
               int fildes,
               off64_t off );

Extra Info with the API:

MAP_NOINIT 
When specified, the POSIX requirement that the memory be zeroed is relaxed. The 
physical memory being used for this allocation must have been previously freed 
with UNMAP_INIT_OPTIONAL for this flag to have any effect. 
________________________________

        This flag was added in the QNX Neutrino Core OS 6.3.2.  
________________________________________________________________________________________________

Using the flag MAP_NOINIT we can avoid initializing the memory with 0's (this should be used with UNMAP_INIT_OPTIONAL). 
For unmapping i used the API munmap_flags() with "UNMAP_INIT_OPTIONAL" flag to check if it works, but no success. 

I'm not sure what is the behaviour of mmap() POSIX API on QNX. I believe initializing the entire mapped memory with 
zeros is an issue and the API should only be initializing the new mmapped region.

Does the mmap() call sync any previous mmapped regions with the data in disk file (the case here)?

Any insights/sugesstions with respect to behavior of mmap64() call on QNX will be of great help.


Thanks,
Praveen