[Bug 230160] linuxulator doesn't implement madvise(MADV_DONTNEED) correctly

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Bug 230160] linuxulator doesn't implement madvise(MADV_DONTNEED) correctly


David Chisnall <[hidden email]> changed:

           What    |Removed                     |Added
                 CC|                            |[hidden email]

--- Comment #1 from David Chisnall <[hidden email]> ---
It's actually worse than as described.  Linux's value for `MADV_DONTNEED` is 8,
which corresponds to FreeBSD's `MADV_NOCORE`, so we're not even getting the
FreeBSD `MADV_DONTNEED` behaviour.

This test program demonstrates the problem.  Compiled on Linux, it runs to
completion on a real Linux system and dies in the last assert on FreeBSD.

#include <sys/mman.h>
#include <assert.h>

int main(void)
        char *page = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_ANON |
MAP_PRIVATE, -1, 0);
        assert(page != MAP_FAILED);
        page[0] = 42;
        assert(page[0] == 42);
        madvise(page, 4096, MADV_DONTNEED);
        assert(page[0] == 0);

This `madvise` flag is commonly used by memory allocators to guarantee zeroed
memory for reuse.  It would be nice if we had a `MADV_ZERO` that did the same
thing as Linux's `MADV_DONTNEED` for shared memory as well as anonymous memory.

You are receiving this mail because:
You are the assignee for the bug.
[hidden email] mailing list
To unsubscribe, send any mail to "[hidden email]"