[ENH+BUG+FIX] VM Memory Management Within Image

Andrew C. Greenberg werdna at gate.net
Tue Jun 8 01:04:10 UTC 1999


The attached changesets provide a memory-related enhancement and
crashing bug fix.  To install:

	A) fileIn the externalMemoryVM.cs;
	B) save the Image;
	C) Build new VM support files and interpreter;***
	D) fileIn the externalMemoryImage.cs; and
	E) save the Image.

The changesets provide the following functionality:

1) ABILITY TO MODIFY EXTERNAL MEMORY RESERVE FROM INSIDE THE IMAGE.
Squeak VMs reserve a fixed, hard-coded amount of allocated memory for
VM stack space, GUI and related OS memory, internal data structures
and external plugins.  On the Macintosh, this reserve was 500,000
bytes.  Until recently, the only way to increase this amount was to
build a new VM, regardless of how much memory was allocated to the VM
application.

This 500K limit can be a problem for people who wish to use or
distribute a large number of named plugins, or who wish to use a
single memory-intensive plugin (perhaps an openGL interface, for
example).

The attached changesets make this external memory reserve a
modifiable parameter on an image-by-image basis, storing the amount
to be reserved (plus 1) in the image header.  (For compatibility with
older image files, a zero value in the header will be treated as a
request for 350,000 bytes, with the interpreter still reserving a
fixed 150,000 for internal and system use.)

The system will allocate external memory only after reserving memory
for the Smalltalk image and System slosh.  Accordingly, the amount
actually reserved may be less than the amount requested.

Accordingly, you can now change and query the amount of external
memory reserved (beyond the system-specific fixed slosh -- now 150000
in the Macintosh image) using the following expressions:


	Smalltalk externalMemoryRequested: 10 * 1024 * 1024.
	Smalltalk externalMemoryRequested

	Smalltalk externalMemoryReserved

THE MEMORY WILL NOT ACTUALLY BE RESERVED UNTIL THE VM IS NEXT STARTED
UP.  Additionally, the help/vm statistics report now reflects the
amount of memory requested and actually reserved.


2) CRASHING BUG FIX.  During the installation of this enhancement, I
diagnosed a crashing bug that arises only when an image file is run
on a new VM, typically, but not always with less memory allocated to
the new VM than the original.  The problem arises because the Squeak
VM code only checks the amount of space required to support the image
objects **as stored to disk** in determining whether the VM has
adequate memory.

Unfortunately (actually quite fortunately) Squeak's snapshot code
scrunches the image by hibernating forms and reducing the display
memory before saving to save disk image space.  The forms and display
are regrown during the startUp process.  Unfortunately, since the VM
only compares available memory with the size of the disk image, its
possible for the VM to startup when there is insufficient memory to
unscrunch the image -- often resulting in hard system crashes.

This code fixes the bug by saving the unscrunched memory size in the
image file for later comparison with the VM startup memory.
Accordingly, the VM should only begin when there is adequate memory
to get through the startUp process, and should gracefully complain
otherwise.
Attachment converted: Anon:externalMemoryImage.cs 1 (TEXT/R*ch) (0000AAC5)
Attachment converted: Anon:externalMemoryVM.cs 1 (TEXT/R*ch) (0000AAC6)





More information about the Squeak-dev mailing list