mirage/mirage-platform — pull request #6 by djs55 (2012-09-25 19:58:24+00:00)
Title: [xen] switch to using the bigarray's C finaliser to free() page-aligned ...

...buffers

Using an ocaml finaliser on the bigarray value doesn't work because
sub-bigarrays are distinct ocaml values which share the underlying data.
When the parent ocaml value is finalised the child bigarray may still
be in scope somewhere and the data accidentally scared.

Now we directly call memalign() which calls _xmalloc() which calls
alloc_pages() to allocate individual blocks and rely on the fact that
sub-bigarrays all share a common "proxy" object and the underlying data
is not free()d until the refcount within the proxy drops to zero i.e.
all related bigarrays are unreachable. This replaces the (broken) ocaml-level
freelist implementation with a (hopefully working) C-level one.

If we run out of memory and memalign() fails, we return None and allow
the ocaml world to run a Gc.compact() which might call enough finalizers
to allow the request to be satisfied.

This has only been superficially tested -- I need to give it more of a hammering.