Operating System - HP-UX
1820039 Members
3198 Online
109608 Solutions
New Discussion

mmap failed with ENOMEM error

 
MasthanD
Occasional Contributor

mmap failed with ENOMEM error

Hi All,

 

1. My process has two threads (thread created using pthreads)

 

2.  One thread acts as a PUBLISHER (WRITER) and other thread acts as a SUBSCRIBER (READER).

 

3. The PUBLISHER thread creates a MAP file (SHARED MAP) with READ and WRITE permissions.

 

example:

 

mmap (NULL, maxSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

 

4. After creating the MAP file PUBLISHER thread writes the data into MAP file.

 

5. After step (4), SUBSCRIBER thread also tries to open same map file as below

 

  mmap(NULL, maxSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

 

6. Unfortunatiely the mmap at step (5) is always failing with error code 12, ENOMEM.

 

I am not seeing this issue on LINUX and SOLARIS. The issue observed only on HPUX.  

 

In HPUX, can't a process open the same map file twice?

 

Thanks,

MasthanD

 

  

2 REPLIES 2
Laurent Menase
Honored Contributor

Re: mmap failed with ENOMEM error

Hi MasthanD,

 

Indeed, HPUX do not support those nested mmap.

man mmap:

 

         +  In most cases, two separate calls to mmap() cannot map
              overlapping ranges in a file.  The virtual address range
              reserved for a file range is determined at the time of the
              initial mapping of the file range into a process address
              space.  The system allocates only the virtual address range
              necessary to represent the initial mapping.  As long as the
              initial mapping exists, subsequent attempts to map a different
              file range that includes any portion of the initial range may
              fail with an [ENOMEM] error if an extended contiguous address
              range that preserves the mappings of the initial range cannot
              be allocated.

Stan_M
HPE Pro

Re: mmap failed with ENOMEM error

The threads are part of the same process, so they share access to its address space, so they both can access

the same mmap()'ed space, without the second mmap() anyway.

 

Otherwise the process would have to be MPAS for the second mmap() to succeed (see man chatr) and also look for "adaptive address space technical paper".

 

 

I work for HPE