Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rich@annexia.org>
To: Joel Reymont <joelr1@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] appending data to a mmap-ed file
Date: Thu, 16 Dec 2010 17:16:17 +0000	[thread overview]
Message-ID: <20101216171617.GB3647@annexia.org> (raw)
In-Reply-To: <8D1E9D5B-188C-4AF3-980B-EF229BA98FB4@gmail.com>

On Thu, Dec 16, 2010 at 11:31:16AM +0000, Joel Reymont wrote:
> I'm constantly appending to a file of stock quotes (ints, longs,
> doubles, etc.). I have this file mapped into memory with mmap.
>
> What's the most efficient way to make newly appended data available
> as part of the memory mapping?

Unfortunately it's hard to reliably extend an mmap'd area.  The reason
is not that you can't do it, but that you might overrun another memory
mapping after it, where that other mapping could be something
important like your program or a shared library.  The other mapping
might not even be present at the time you initially map your file, but
might appear as the result of an innocuous operation such as printing
a string or allocating memory.

Now you can, with a bunch of work, avoid this: parse /proc/self/maps,
select a suitable base address for your mapping, move the mapping if
it gets too large for the selected area or if another library is
mapped in above it, etc. but this quickly gets very difficult.

I would suggest a simpler way to solve your problem is simply to open
the data file and append to it.  If you need to reference the values,
keep them in memory structures.

Rich.

-- 
Richard Jones
Red Hat


  parent reply	other threads:[~2010-12-16 17:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-16 11:31 Joel Reymont
2010-12-16 12:38 ` [Caml-list] " Jesper Louis Andersen
2010-12-16 13:13   ` Joel Reymont
2010-12-16 12:57 ` Gerd Stolpmann
2010-12-16 17:16 ` Richard W.M. Jones [this message]
2010-12-17  0:36   ` Goswin von Brederlow
2010-12-17 14:48     ` Richard W.M. Jones
2010-12-17 15:49       ` Joel Reymont
2010-12-17 19:05       ` Goswin von Brederlow
2010-12-18  9:56 ` Christophe Raffalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101216171617.GB3647@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=joelr1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox