caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Limiting Memory Usage
@ 2006-07-14  3:39 Alexander Fuchs
  2006-07-14 12:52 ` [Caml-list] " Chris King
  2006-07-17  8:15 ` Damien Doligez
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Fuchs @ 2006-07-14  3:39 UTC (permalink / raw)
  To: caml-list

Hi,

I would like to:
- limit the max. memory usage of an ocaml program
- and do some cleanup and then terminate then program, when this limit
is reached.

I couldn't see how to do that with the standard libraries, so I added a
C-wrapper to use setrlimit with RLIMIT_AS. I guess that works only with
Linux, which is not nice but better than nothing.

Still, when the memory limit is reached the program just terminates with
"Fatal error: out of memory." resp "Out of memory". I couldn't figure
out if it is possible to catch any of those errors/exceptions, and do
some cleanup before terminating the program.

Does perhaps someone know how to provide this functionality in a more
satisfactory way?

Thanks,
	Alexander


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Limiting Memory Usage
  2006-07-14  3:39 Limiting Memory Usage Alexander Fuchs
@ 2006-07-14 12:52 ` Chris King
  2006-07-15 17:04   ` Alexander Fuchs
  2006-07-17  8:15 ` Damien Doligez
  1 sibling, 1 reply; 4+ messages in thread
From: Chris King @ 2006-07-14 12:52 UTC (permalink / raw)
  To: Alexander Fuchs; +Cc: caml-list

On 7/13/06, Alexander Fuchs <alexander.fuchs@uni-koblenz.de> wrote:
> I would like to:
> - limit the max. memory usage of an ocaml program
> - and do some cleanup and then terminate then program, when this limit
> is reached.
>
> I couldn't see how to do that with the standard libraries,

Did you look at Gc?  It's not a hard limit but periodically checking
(quick_stat ()).heap_words will give you a rough estimate of how much
memory your program is using (not exact since it doesn't count
code/stack/etc.).

- Chris King


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Limiting Memory Usage
  2006-07-14 12:52 ` [Caml-list] " Chris King
@ 2006-07-15 17:04   ` Alexander Fuchs
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Fuchs @ 2006-07-15 17:04 UTC (permalink / raw)
  To: Chris King; +Cc: caml-list

Hi,

Chris King wrote:
 > Did you look at Gc?  It's not a hard limit but periodically checking
 > (quick_stat ()).heap_words will give you a rough estimate of how much
 > memory your program is using (not exact since it doesn't count
 > code/stack/etc.).

thanks for the suggestion. For some reason I thought that monitoring 
memory usage by calling the Gc functions often tends to be expensive.

But someone suggested to use Gc.create_alarm, and this works fine.

Thanks,

	Alexander



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Limiting Memory Usage
  2006-07-14  3:39 Limiting Memory Usage Alexander Fuchs
  2006-07-14 12:52 ` [Caml-list] " Chris King
@ 2006-07-17  8:15 ` Damien Doligez
  1 sibling, 0 replies; 4+ messages in thread
From: Damien Doligez @ 2006-07-17  8:15 UTC (permalink / raw)
  To: caml-list


On 2006-07-14, at 05:39, Alexander Fuchs wrote:

> Still, when the memory limit is reached the program just terminates  
> with
> "Fatal error: out of memory." resp "Out of memory". I couldn't figure
> out if it is possible to catch any of those errors/exceptions, and do
> some cleanup before terminating the program.

There is currently no way to catch these errors, because the heap
is in an inconsistent state when they are triggered.  This might
change at some point in the future, but don't hold your breath.

-- Damien


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-07-17  8:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-14  3:39 Limiting Memory Usage Alexander Fuchs
2006-07-14 12:52 ` [Caml-list] " Chris King
2006-07-15 17:04   ` Alexander Fuchs
2006-07-17  8:15 ` Damien Doligez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).