A new version of System was added to project The Inbox: http://source.squeak.org/inbox/System-jar.1446.mcz
==================== Summary ====================
Name: System-jar.1446 Author: jar Time: 29 January 2024, 1:41:28.399781 pm UUID: fafea975-15ff-a94d-8bfc-a3c9feb44c78 Ancestors: System-dtl.1445
For discussion: A small modification of System-dtl.1445 to address the possibilty of two low space watcher processes running simultaneously if you run this example:
[LowSpaceWatcher install] fork. [LowSpaceWatcher install] fork
It's a contrived example but a real situation of this kind happened to me during my work on #terminate and confused me a great deal. In the current image the situation most likely can't happen by itself.
If the low space watches is supposed to be a singleton then, for the sake of consistency, I'd vote for making sure the low space watcher can't start two processes concurrently.
=============== Diff against System-dtl.1445 ===============
Item was changed: Object subclass: #LowSpaceWatcher + instanceVariableNames: 'lowSpaceProcess lowSpaceSemaphore lowSpaceAccessProtect' - instanceVariableNames: 'lowSpaceProcess lowSpaceSemaphore' classVariableNames: 'Default MemoryHogs' poolDictionaries: '' category: 'System-Support'!
!LowSpaceWatcher commentStamp: 'dtl 1/28/2024 17:56' prior: 0! LowSpaceWatcher is responsible for responding to a notification from the virtual machine that memory is low and that it (the VM) may soon be unable to support additional object memory allocations. A single default instance for the image manages both the low space semaphore and the process that waits on the semaphore to handle low space conditions. When the low space watcher is notified that memory is low, it attempts to identify the process likely associated with the low space condition and to provide a notifier to allow the problem condition to be corrected.
If a low space condition is detected in the virtual machine, the low space semaphore is signalled either directly by the VM or indirectly through an OutOfMemory error following a failed primitive invocation. The VM is responsible for identifying low space conditions, and its behavior will vary depending on both the VM implementation and the memory system of the underlying platform operating system. In particular, on a virtual machine operating system the VM may continue to receive memory allocations from the operating system while the operating system attempts to support the memory requests by increased swapping to disk. Under these conditions, the low space semaphore may not be signalled because system memory still appears to be available, even though performance is severely degraded due to swapping.
The VM may provide control of its memory usage, typically through command line parameters or VM parameters that can be set from the image. These parameters will affect when and if the low space watcher is signalled by the VM.
A registry is maintained in class variable MemoryHogs to identify objects (classes) know how to release unneeded memory when sent the message #freeSomeSpace. The low space watcher process will send this message when a low spaced condition is encountered.
To signal the low space watcher and simulate a low space condition, evaluate "LowSpaceWatcher default signalLowSpace".!
Item was changed: ----- Method: LowSpaceWatcher class>>install (in category 'instance creation') ----- install "Start a process to watch for low-space conditions." "Smalltalk installLowSpaceWatcher"
+ self default lowSpaceAccessProtect critical: [self default stop; start] ifLocked: [] - self default stop; start - !
Item was added: + ----- Method: LowSpaceWatcher>>lowSpaceAccessProtect (in category 'process') ----- + lowSpaceAccessProtect + + ^lowSpaceAccessProtect ifNil: [lowSpaceAccessProtect := Mutex new]!
squeak-dev@lists.squeakfoundation.org