Unmapping memory

Kenneth Albanowski (kjahds@kjahds.com)
Mon, 5 May 1997 16:00:37 -0400 (EDT)

Pardon me if this subject has already been discussed -- I haven't been
tracking linux-kernel for a while.

Given the periodic discussions about how traditional sbrk() based malloc
fails to return free()'d memory to the OS, it occured to me that a new
primitive might prove useful here.

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).

With this ability, a free() implementation could invoke this call any time
a largish chunk of memory is truly discarded, and thereby genuinely give
memory back to the OS, _without_ the significant overhead and limitations
of using mmap() and munmap().

I suppose the biggest question is whether the memory manager is capable of
inserting zeroed page mappings like this. If it isn't, what would be the
cost of implementing it?

Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)