Originally posted by: BruceSpencer
The following URL has some information
http://publib16.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/genprogc/understanding_mem_mapping.htm Also found the following in a "Migrating Solaris Apps to AIX" guide.
[b]Memory mapped files[/b]
Memory mapping is used to map a file into memory for faster I/O. The call to map
a file is mmap and the arguments to mmap are:
mmap( baseAddr, length, protection, flags, fileDescriptor,
offSet )
baseAddr Desired address to map the file to
length Number of bytes to map. The OS will round to the nearest page
size
protection Access permissions for mapped region
flags Attributes of mapped region
fileDescriptor File descriptor of opened file to map into memory
offSet Offset from the baseAddr to where the file will be mapped
[i]The mmap call is available on Solaris as well but the behavior is slightly different
on AIX.[/i] The flags argument allows you to specify certain attributes like
MAP_FIXED or MAP_VARIABLE. The MAP_FIXED flag specifies that the region
being mapped should be mapped to the baseAddr if possible. Otherwise, you will
receive an error. The MAP_VARIABLE flag specifies that the OS should attempt
to honor the baseAddr address, otherwise return some address that would
accommodate the request.
The first issue is a behavior difference between Solaris and AIX. If a process
maps a file using MAP_FIXED at a specified address, e.g. 0x80000000, and later
attempts to either map a different or the same file to the same specified address,
i.e. 0x80000000, Solaris will return without error. AIX will fail with:
ENOMEM There is not enough address space to map length bytes, or
the application has not requested X/Open UNIX95 Specification compliant
behavior and the MAP_FIXED flag was set and part of the address-space
range (baseAddr, baseAddr+length) is already allocated.
Obviously, mapping to the same address without unmapping (munmap) is a
problem and should be corrected by the application.
A second related issue is how memory mapped files are laid out in memory.
Consider an application wanting to memory map two files. The first file mapped
uses MAP_FIXED at address 0x80000000. The second file mapped uses the
address 0x0. Mapping at 0x0 indicates the operating system should pick the
address for you. In this particular case, the second file ended up being mapped
directly after the first mapped file. However, the application at a later time
attempts to grow the first mapped file region. The application munmap the file and
attempts to mmap at 0x80000000 with the new/larger size. mmap fails. Whats
wrong? The problem is with the second mapped file and where it had been
mapped. The second file was mapped using 0x0 so AIX decided to map it right
after the first file mapped at 0x80000000. When AIX attempted to map the large
file, AIX determined that the region available at 0x80000000 would not
accommodate the new size and fails.
A third and generally unacceptable issue is unmapping files. On AIX, you can
unmap as large a region as you want and turn around and mmap the region again
without errors. Consider the above example of two files being memory mapped
contiguously. One could munmap the region starting at 0x80000000 all the way to
the end of the second mapped region since both regions are contiguous. Not a
wise thing to do, but AIX will permit this type of operation. AIX does not keep track
of the original size of the mapped region when unmapping. This can lead to
trouble when the area unmapped is less than the area that was mapped.
munmap will succeed as long as the size to map is less than or equal to the area
that was previously unmapped. An attempt to map a region with a large size at
the same address will fail because a portion of the desired region has not been
unmapped.