Re: missing madvise functionality

Arnd Bergmann
2007-04-03T22:07:34Z

On Tuesday 03 April 2007, Ulrich Drepper wrote:
> The problem is glibc has to work around kernel limitations.  If the
> malloc implementation detects that a large chunk of previously allocated
> memory is now free and unused it wants to return the memory to the
> system.  What we currently have to do is this:
>
>   to free:      mmap(PROT_NONE) over the area
>   to reuse:     mprotect(PROT_READ|PROT_WRITE)
>
> Yep, that's expensive, both operations need to get locks preventing
> other threads from doing the same.

I thought this is what the read_zero_pagealigned hack [1] was used
for (read from /dev/zero replaces target pages with empty_zero_page).
Now if read_zero_pagealigned does not solve _this_ scenario, is it
good for anything else then?
Can we simply kill that function as a misfeature and avoid future
pain arising from it?

Arnd <><

[1] http://lkml.org/lkml/1997/1/16/49