Chapter 4. AIX
73
shmat versus mmap
Memory mapped files provide a mechanism for a process to access files by directly
incorporating file data into the process address space. The use of mapped files can reduce
I/O data movement because the file data does not have to be copied into process data
buffers, as is done by the read and write subroutines. When more than one process maps the
same file, its contents are shared among them, providing a low-impact mechanism by which
processes can synchronize and communicate.
AIX provides two methods for mapping files and anonymous memory regions. The first set of
services, which are known collectively as the
shmat
services, are typically used to create and
use shared memory segments from a program. The second set of services, which are known
collectively as the
mmap
services, is typically used for mapping files, although it can be used
for creating shared memory segments as well.
Both the mmap and shmat services provide the capability for multiple processes to map the
same region of an object so that they share addressability to that object. However, the
mmap
subroutine extends this capability beyond that provided by the
shmat
subroutine by allowing a
relatively unlimited number of such mappings to be established. Although this capability
increases the number of mappings that are supported per file object or memory segment, it
can prove inefficient for applications in which many processes map the same file data into
their address space. The
mmap
subroutine provides a unique object address for each process
that maps to an object. The software accomplishes this task by providing each process with a
unique virtual address, which is known as an
alias
. The
shmat
subroutine allows processes to
share the addresses of the mapped objects.
shmat can be used to share memory segments in a way that is similar to how it creates and
uses files. An
extended shmat
capability is available for 32-bit applications with their limited
address spaces. If you define the
EXTSHM=ON
environment variable, then processes running in
that environment can create and attach more than 11 shared memory segments.
Use the shmat services under the following circumstances:
When mapping files larger than 256 MB
When mapping shared memory regions that must be shared among unrelated processes
(no parent-child relationship)
When mapping entire files
In general, shmat is more efficient but less flexible.
Use mmap under the following circumstances:
Many files are mapped simultaneously.
Only a portion of a file must be mapped.
Page-level protection must be set on the mapping (allows a 4K boundary).
For more information, see General Programming Concepts: Writing and Debugging
Programs, available at:
http://publib16.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/genprogc/underst
anding_mem_mapping.htm
For more information about this topic, see 4.4, “Related publications” on page 94.
Large segment tunable (AIX V6.1 only)
AIX V6.1 TL5 and AIX V7.1 introduce the 1 TB Segment Aliasing. 1 TB segments can
improve the performance of 64-bit large memory applications. The optimization is specific to
large shared memory (
shmat()
and
mmap()
) regions.
Summary of Contents for Power System POWER7 Series
Page 2: ......
Page 36: ...20 POWER7 and POWER7 Optimization and Tuning Guide...
Page 70: ...54 POWER7 and POWER7 Optimization and Tuning Guide...
Page 112: ...96 POWER7 and POWER7 Optimization and Tuning Guide...
Page 140: ...124 POWER7 and POWER7 Optimization and Tuning Guide...
Page 162: ...146 POWER7 and POWER7 Optimization and Tuning Guide...
Page 170: ...154 POWER7 and POWER7 Optimization and Tuning Guide...
Page 223: ......