Grace misfeature in Unix?
Arndt Jonasson
aj at zyx.UUCP
Sat Mar 26 01:01:27 AEST 1988
In the book 'The design of the Unix system', by Maurice J. Bach, the
following is said in the section about 'brk':
"If the process is calling 'brk' to free previously allocated space,
the kernel releases the memory; if the process accesses virtual
addresses in pages that it had released, it incurs a memory fault."
My interpretation of the word "releases" is: the process gives up the
right to use those pages -> they are no longer owned by the process ->
they can be assigned to another process that wishes to allocate more
memory.
Are there Unix implementations that do this right? My faith in Unix
(small as it was) was considerably reduced when I found that of two
Unix implementations that I tested, both got it wrong.
What is wrong? In this context, it is wrong for the kernel not to make
the 'released' pages accessible to other processes. The pages are kept
somewhere, and only really released when the process exits.
One of the two implementations is 4.2BSD. Since the BSD system where I
tested this can handle a considerable number of processes before swap
space becomes scarce (swap space 140 Mbytes), it probably seldom gets
to be a problem. On a workstation implementation, however, it is quite
another matter.
Granted, the book describes System V, and a look in the manual page
for 'brk' on 4.2BSD reveals that nothing at all is said about calling
'brk' so that the allocated space shrinks.
One System V brk manual page (which may not be the 'vanilla' one) says
that the allocated space is 'nominally decreased'. This at least
describes the system's behaviour.
However, the issue is not whether the implementation conforms with the
documentation, but rather whether what the system does is 'right'.
In the case of BSD, it turns out not to be an ordinary bug or
oversight; in the source code (vm_drum.c), the following is to be
found (I hope this is a small enough piece as not to constitute breach
of any non-disclosure laws):
/*
* Expand or contract the virtual swap segment mapped
* by the argument diskmap so as to just allow the given size.
*
* FOR NOW CANT RELEASE UNLESS SHRINKING TO ZERO, SINCE PAGEOUTS MAY
* BE IN PROGRESS... TYPICALLY NEVER SHRINK ANYWAYS, SO DOESNT MATTER MUCH
*/
vsexpand(vssize, dmp, canshrink)
I consider this a grave misfeature. I am interested in knowing whether
any Unix implementors have made the effort to really release memory,
and, what your suggestions are to circumvent this problem on systems
where they have not.
--
Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden
email address: aj at zyx.SE or <backbone>!mcvax!enea!zyx!aj
More information about the Comp.unix.wizards
mailing list