* child_info.h (CURR_CHILD_INFO_MAGIC): Reset to new value.

(child_info::cygheap_alloc_sz): New field.
* cygheap.cc (init_cheap): Reduce size of cygwin stack until minimal hit when
attempting initial allocation.
(cygheap_setup_for_child): Use alloc_sz to create secondary memory mapped
entry.  Store alloc_sz in cygheap_alloc_sz.
(cygheap_fixup_in_child): Use cygheap_alloc_sz to map parent's cygheap.
* cygheap.h (_CYGHEAPSIZE_SLOP): New define.
(CYGHEAPSIZE): Use _CYGHEAPSIZE_SLOP.
This commit is contained in:
Christopher Faylor 2004-03-18 19:30:51 +00:00
parent 891d1990ab
commit d8f87fba65
4 changed files with 33 additions and 9 deletions

View File

@ -1,3 +1,15 @@
2004-03-18 Christopher Faylor <cgf@redhat.com>
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset to new value.
(child_info::cygheap_alloc_sz): New field.
* cygheap.cc (init_cheap): Reduce size of cygwin stack until minimal
hit when attempting initial allocation.
(cygheap_setup_for_child): Use alloc_sz to create secondary memory
mapped entry. Store alloc_sz in cygheap_alloc_sz.
(cygheap_fixup_in_child): Use cygheap_alloc_sz to map parent's cygheap.
* cygheap.h (_CYGHEAPSIZE_SLOP): New define.
(CYGHEAPSIZE): Use _CYGHEAPSIZE_SLOP.
2004-03-18 Corinna Vinschen <corinna@vinschen.de> 2004-03-18 Corinna Vinschen <corinna@vinschen.de>
* fhandler_proc.cc (format_proc_meminfo): On NT, try to figure out * fhandler_proc.cc (format_proc_meminfo): On NT, try to figure out

View File

@ -29,7 +29,7 @@ enum
#define EXEC_MAGIC_SIZE sizeof(child_info) #define EXEC_MAGIC_SIZE sizeof(child_info)
#define CURR_CHILD_INFO_MAGIC 0x4239088U #define CURR_CHILD_INFO_MAGIC 0x70172124U
/* NOTE: Do not make gratuitous changes to the names or organization of the /* NOTE: Do not make gratuitous changes to the names or organization of the
below class. The layout is checksummed to determine compatibility between below class. The layout is checksummed to determine compatibility between
@ -49,6 +49,7 @@ public:
HANDLE pppid_handle; HANDLE pppid_handle;
init_cygheap *cygheap; init_cygheap *cygheap;
void *cygheap_max; void *cygheap_max;
DWORD cygheap_alloc_sz;
HANDLE cygheap_h; HANDLE cygheap_h;
unsigned fhandler_union_cb; unsigned fhandler_union_cb;
}; };

View File

@ -28,6 +28,7 @@ init_cygheap NO_COPY *cygheap;
void NO_COPY *cygheap_max; void NO_COPY *cygheap_max;
static NO_COPY muto *cygheap_protect; static NO_COPY muto *cygheap_protect;
static NO_COPY DWORD alloc_sz;
struct cygheap_entry struct cygheap_entry
{ {
@ -50,13 +51,18 @@ static void __stdcall _cfree (void *ptr) __attribute__((regparm(1)));
static void static void
init_cheap () init_cheap ()
{ {
cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS); for (cygheap = NULL, alloc_sz = CYGHEAPSIZE;
!cygheap && alloc_sz > CYGHEAPSIZE_MIN;
alloc_sz -= 2 * (1024 * 1024))
cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start, alloc_sz,
MEM_RESERVE, PAGE_NOACCESS);
if (!cygheap) if (!cygheap)
{ {
MEMORY_BASIC_INFORMATION m; MEMORY_BASIC_INFORMATION m;
if (!VirtualQuery ((LPCVOID) &_cygheap_start, &m, sizeof m)) if (!VirtualQuery ((LPCVOID) &_cygheap_start, &m, sizeof m))
system_printf ("couldn't get memory info, %E"); system_printf ("couldn't get memory info, %E");
system_printf ("Couldn't reserve space for cygwin's heap, %E"); system_printf ("Couldn't reserve %d bytes of space for cygwin's heap, %E",
alloc_sz);
api_fatal ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n", api_fatal ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n",
m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); m.AllocationBase, m.BaseAddress, m.RegionSize, m.State);
} }
@ -79,13 +85,13 @@ cygheap_setup_for_child (child_info *ci, bool dup_later)
void *newcygheap; void *newcygheap;
cygheap_protect->acquire (); cygheap_protect->acquire ();
unsigned n = (char *) cygheap_max - (char *) cygheap; unsigned n = (char *) cygheap_max - (char *) cygheap;
unsigned size = CYGHEAPSIZE; unsigned size = alloc_sz;
if (size < n) if (size < n)
size = n + (128 * 1024); size = n + (128 * 1024);
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none, ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
CFMAP_OPTIONS, 0, size, NULL); CFMAP_OPTIONS, 0, size, NULL);
if (!ci->cygheap_h) if (!ci->cygheap_h)
api_fatal ("Couldn't create heap for child, size %d, %E", CYGHEAPSIZE); api_fatal ("Couldn't create heap for child, size %d, %E", size);
newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h); ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h);
if (!dup_later) if (!dup_later)
@ -93,6 +99,7 @@ cygheap_setup_for_child (child_info *ci, bool dup_later)
cygheap_protect->release (); cygheap_protect->release ();
ci->cygheap = cygheap; ci->cygheap = cygheap;
ci->cygheap_max = cygheap_max; ci->cygheap_max = cygheap_max;
ci->cygheap_alloc_sz = size;
return newcygheap; return newcygheap;
} }
@ -129,7 +136,8 @@ cygheap_fixup_in_child (bool execed)
newaddr = MapViewOfFileEx (child_proc_info->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); newaddr = MapViewOfFileEx (child_proc_info->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
DWORD n = (DWORD) cygheap_max - (DWORD) cygheap; DWORD n = (DWORD) cygheap_max - (DWORD) cygheap;
/* Reserve cygwin heap in same spot as parent */ /* Reserve cygwin heap in same spot as parent */
if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS)) if (!VirtualAlloc (cygheap, child_proc_info->cygheap_alloc_sz,
MEM_RESERVE, PAGE_NOACCESS))
{ {
MEMORY_BASIC_INFORMATION m; MEMORY_BASIC_INFORMATION m;
memset (&m, 0, sizeof m); memset (&m, 0, sizeof m);
@ -205,8 +213,9 @@ _csbrk (int sbs)
/* nothing to do */; /* nothing to do */;
else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE)) else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
{ {
malloc_printf ("couldn't commit memory for cygwin heap, prebrk %p, size %d, heapsize now %d, max heap size %d, %E", malloc_printf ("couldn't commit memory for cygwin heap, prebrk %p, size %d, heapsize now %d, max heap size %u, %E",
prebrk, sbs, (char *) cygheap_max - (char *) cygheap, CYGHEAPSIZE); prebrk, sbs, (char *) cygheap_max - (char *) cygheap,
alloc_sz);
__seterrno (); __seterrno ();
cygheap_max = (char *) cygheap_max - sbs; cygheap_max = (char *) cygheap_max - sbs;
return NULL; return NULL;

View File

@ -272,7 +272,9 @@ struct init_cygheap
void close_ctty (); void close_ctty ();
}; };
#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (32 * 1024 * 1024)) #define _CYGHEAPSIZE_SLOP (32 * 1024 * 1024)
#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + _CYGHEAPSIZE_SLOP)
#define CYGHEAPSIZE_MIN (sizeof (init_cygheap) + (10000 * sizeof (fhandler_union)))
extern init_cygheap *cygheap; extern init_cygheap *cygheap;
extern void *cygheap_max; extern void *cygheap_max;