This should be possible without a fault handler and minimal libc support.
When free() creates a large enough contiguous free region to be worth a
syscall, call mmap(..., MAP_ANON | MAP_PRIVATE | MAP_DISCARDABLE, ...)
to make an "optional zero-map" of the region.
This doesn't modify the VMA, but simply marks the pages as discardable
until they're next touched or written. The kernel then has the option
of unmapping the pages at any time until they're next written/touched
(individually), and as it's a zero-map VMA, that effectively sets the
discarded pages to all zeros according to kernel demands.
The process doesn't care whether any of those pages are discarded or
not.
-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/