delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/07/13/06:34:41

X-Spam-Check-By: sourceware.org
Date: Thu, 13 Jul 2006 12:34:31 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: 1.5.21s mmap error
Message-ID: <20060713103431.GA17383@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <Pine DOT CYG DOT 4 DOT 58 DOT 0607121030410 DOT 3792 AT PC1163-8460-XP DOT flightsafety DOT com> <20060712165900 DOT GQ8759 AT calimero DOT vinschen DOT de> <Pine DOT CYG DOT 4 DOT 58 DOT 0607121318080 DOT 2284 AT PC1163-8460-XP DOT flightsafety DOT com> <20060712202215 DOT GS8759 AT calimero DOT vinschen DOT de> <Pine DOT CYG DOT 4 DOT 58 DOT 0607121536330 DOT 3784 AT PC1163-8460-XP DOT flightsafety DOT com>
Mime-Version: 1.0
In-Reply-To: <Pine.CYG.4.58.0607121536330.3784@PC1163-8460-XP.flightsafety.com>
User-Agent: Mutt/1.4.2i
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jul 12 15:57, Brian Ford wrote:
> On Wed, 12 Jul 2006, Corinna Vinschen wrote:
> 
> > The problem results from introducing MAP_NORESERVE in 1.5.19.  That's
> > the reason the same code works on 1.5.18.  Your code simply defines
> > MAP_NORESERVE to 0 under 1.5.18.
> 
> While that is true, I compiled the STC with MAP_NORESERVE defined under
> the 1.5.21s headers, and then ran the binary without recompiling it under
> 1.5.[18-20].  So, you must have ignored the MAP_NORESERVE value in the
> older releases since it was passed to mmap in my test.

Right, only the correctness of the POSIX flags is checked at the start
of mmap.  Any non-standard flags are usually ignored.

> > This might succeed on Linux, but it's not guaranteed.  It certainly
> > doesn't work this way on Cygwin.  Call something like `mprotect (addr,
> > virt_size, PROT_READ|PROT_WRITE)' before accessing the mmap'ed memory.
> 
> Why?  I already told mmap it should have these attributes.
> 
> There is a bug in one of our understandings of MAP_NORESERVE symantics.
> My understanding of MAP_NORESERVE is from the Solaris man page:
> 
>      The MAP_NORESERVE option specifies that  no  swap  space  be
>      reserved for a mapping. Without this flag, the creation of a
>      writable MAP_PRIVATE mapping reserves swap  space  equal  to
>      the  size  of the mapping; when the mapping is written into,
>      the reserved space  is employed to hold  private  copies  of
>      the  data.  A  write  into  a MAP_NORESERVE mapping produces
>      results which depend on the  current  availability  of  swap
>      space  in  the  system.   If  space  is available, the write
>      succeeds and a  private copy of the written page is created;
>      if  space  is not available, the write fails and a SIGBUS or
>      SIGSEGV  signal  is  delivered  to  the   writing   process.
>      MAP_NORESERVE  mappings are inherited across  fork(); at the
>      time of the fork(), swap space is reserved in the child  for
>      all  private  pages  that  currently  exist  in  the parent;
>      thereafter the child's mapping behaves as described above.
> 
> So, the only difference with MAP_NORESERVE is that swap space is not
> reserved up front, but on reference (read is unclear from this
> description, but write is definately clear).  If on reference we run out
> of swap, SIGBUS is generated.
> 
> What am I missing?

I just read the Linux man page (again), and I seem to have missed some
important bits.  The above semantics are not implemented this way in
Cygwin.  A private anonymous mmap is actually just an area allocated
with VirtualAlloc.  A MAP_NORESERVE area is not commited (MEM_COMMIT)
but just reserved (MEM_RESERVE).  What's missing is the automatic
commiting when a page fault on one of these pages occurs.  I added an
(hopefully) appropriate patch, which commits a page within a
MAP_NORESERVE area when memory in this page is accessed by the
application.  If commiting the memory fails, SIGBUS is generated.
Please test CVS HEAD or the next developer snapshot from
http://cygwin.com/snapshots/

Note however, that MAP_NORESERVE is only implemented for private
anonymous mappings.  Shared anonymous maps seem to be possible (and
would probably make sense to minimze the swap space footprint), but are
somewhat tricky since it's not quite clear what happens to memory which
is commited in one process and then accessed in another.  This would
require some extensive testing which I'm not willing to do yet.

File-backed mappings are always ignoring the MAP_NORESERVE flag and are
using committed memory, since uncommitted file maps are not supported on
Windows.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019