guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mmap in guile -- guile memory management question


From: Ludovic Courtès
Subject: Re: mmap in guile -- guile memory management question
Date: Mon, 13 Nov 2006 15:43:18 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Hi,

Daniel Ridge <address@hidden> writes:

>>   In
>> 1.8, you would use SRFI-4 octet vectors to that end (passing the
>> address
>> returned by `mmap ()' to `scm_take_u8vector ()' and making the
>> returned
>> vector uncollectable so that `free ()' isn't eventually invoked on the
>> `mmap' address).
>
> A single mmap may be 20GB. It would be a bit rude to prevent garbage
> collection on such an object. I think the mechanics of the problem
> are the same whether I use take_u8vector or take_string.

The mmap'd region of the address space must not be managed by the
garbage collector: it must be managed by the kernel (via `mmap' and
`munmap').  Also, just because it is mapped into the application's
address space doesn't mean that it actually consumes (memory) resources
(well, it all depends on the flags passed to `mmap ()', whether the
region is written to or only read, etc.).

That said, it is true that the mmapped region would have to be munmap'ed
at some point.  One solution might be to pass the u8vector to a guardian
and invoke munmap when the guardian returns the u8vector.  However,
since the "destructor" of the u8vector expects to be able to call `free ()'
on the vector's contents, you would need a hack to make sure that `free ()' 
is never actually called.  Keeping the vector itself forever once it's
been returned by the guardian (and munmap'd) might be a solution, but
it's far from elegant.

> Ports are useful, but have different semantics than memory maps. I
> agree that Guile could have a file port implementation built on
> memory map but the result would be non-portable, would work poorly on
> 32 bit machines, and would still not provide the semantics I expect.
> In particular, mmap lets me do shared memory programming with Guile.

Right, I had not considered shared memory.

Thanks,
Ludovic.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]