On Thu, Sep 15, 2011 at 11:32:29AM +0200, Mike Hommey wrote:
> Hi,
>
> As I hear there are several people interested in Android's ashmem for
> "free" cache eviction, here are a few things I learned about it in the
> course of bug 686728:
>
> - When you allocate ashmem, unless you explicitely unpin it, it will
> never be purged by the kernel.
> - When ashmem is purged by the kernel, it ends up being in the exact
> same state as if it had just been allocated: accessible and filled
> with zeros. It is important to note that this *also* includes the
> state, which means if you fill it again, it won't be purged again
> unless you unpin it!
> - If my reading of the kernel source is correct, ashmem unpinned
> ranges are purged at once: you can't end up with half purged and half
> not purged. However, it is possible to unpin an ashmem by small
> chunks, in which case it is possible that some chunks are purged and
> others not.
Also, purge happens in least recently *unpinned" region order. Which
means the only safe way to access ashmem is to pin it before use, and
unpin after. Conveniently, pinning also tells you whether the region
you're pinning was purged, so the use pattern is really pin, generate if
purged, use, unpin.
Mike