Re: Unmapping memory

Kenneth Albanowski (
Tue, 6 May 1997 10:33:04 -0400 (EDT)

On Tue, 6 May 1997, Martin von Loewis wrote:

> > Would it be possible to add a syscall to "zero" a range of memory? I mean
> > not only clear it to zero, as with memset, but if any complete pages are
> > within the range, unmap them, and replace them with zero mappings (as
> > mmap()'ing /dev/zero gives you).
> You could just mmap /dev/zero instead. No need to unmap what was previously
> there, it will get automatically discarded. The malloc implementation would
> need to keep a file descriptor for /dev/zero to avoid the overhead of
> opening the file over and over again. Other than that, there would be no
> overhead compared to a special-case system call.

Ah, so a mmap of /dev/zero doesn't involve any of the overhead of a
"normal" mmapping of a file, then? If so, and you can successfully mmap in
blank pages over sbrk()'d space with this, without consuming any
resources, then it does indeed match my request.

> I think one should perform measurements first to find out:
> - how many, and which applications suffer from this phenomen. E.g. after
> running Netscape for one day, how many pages could be returned to the
> system. LD_PRELOAD is your friend, here.


> - for those applications, how much overhead is introduced by inserting the
> additional mappings. For example, drivers/char/mem.c:read_zero only changes
> the mapping if the user requested at least four pages.

And whether the implementation should wait for eight pages, or whatever,
to be free before discarding them in this manner.

> Once those data are available, we could decide whether this algorithm
> becomes part of the standard C library, or a special malloc library that
> is only linked into selected applications.
> Regards,
> Martin

Kenneth Albanowski (, CIS: 70705,126)