This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PLEASE TEST: New implementation of blocking socket I/O


At 06:11 PM 4/1/2004 +0200, Corinna Vinschen wrote:
>
>AFAICS, we have currently three pressing problems:
>
>- People complaining about cygheap problems (Win32 error 487) but
>  nobody willing to debug it.

I will describe how it works (details in how-cygheap-works),
and then how we might change that to improve the chance of
success.

1) When starting, Cygwin tries to reserve an amount of memory Pr
   as large as possible with CYGHEAPSIZE >= Pr >= CYGHEAPSIZE_MIN
   The initial committed memory size Pc is 0.
2) As Cygwin operates and calls csbrk , Pc grows. Pc can grow
   past Pr, although that is unlikely, and in fact impossible if
   Pr <  CYGHEAPSIZE. csbrk calls will not fail as long as Pc <= Pr.
3) When starting a child, the parent creates a file mapping of size 
   Max(Pc, Pr), copies Pc bytes to it and passes the handle to the child.
4) The child tries to map the region to the same address as the parent's
   heap. If that works, the child is done.
5) Else the child tries to reserve Max(Pc, Pr) at the same address
   as the parent's heap.
6) The child then commits and copies Pc bytes from the file mapping to
   that region.
The failure occurs in step 5.

What I don't see if why we need to reserve Max(Pc, Pr) and not simply
a quantity Cr with Pr >= Cr >= Pc or Pr >= Cr >= max(Pc, CYGHEAPSIZE_MIN).
We could even try to make Cr as large as CYGHEAPSIZE, but if the parent
did not succeed I would think the child won't either.
As an aside, I am wondering if the current step 5 can ever work (on NT)
if step 4 has failed. Why would 4 fail if space is available? 

An alternative idea is to call VirtualQuery to see how much memory
can be allocated at the address of the parent's heap and choose that for
Cr, as long as it is >= Pc (or Pc + headroom). 

http://cygwin.com/ml/cygwin/2004-03/msg01442.html gives an example where
this strategy would have worked (see near the bottom).

To achieve this, the parent needs to pass Max(Pc, Pr) [so that the child
knows the size of the file mapping if 3 succeeds, for use with a grand
child], Pc [so that the child knows how much to copy in 6], and also Pr,
to have a sensible upperbound in the new step 5. The last quantity is
not needed if using the alternative idea, what we pass today is enough.

Comments?
 
Pierre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]