Loading ...
Sorry, an error occurred while loading the content.

Re: "ocaml_beginners"::[] prevent use of swap memory?

Expand Messages
  • Richard Jones
    ... There doesn t seem to be a way to control how much memory the garbage collector will use through the ordinary Gc interface
    Message 1 of 3 , May 17, 2005
    View Source
    • 0 Attachment
      On Tue, May 17, 2005 at 03:45:36AM -0000, vly3 wrote:
      > Is there a way to prevent OCaml from using swap memory? I want to use
      > as much memory as I can without doing any memory swapping to the hard
      > drive. I've done some experimenting to see happens when I allocate
      > variables that exceed available memory, and OCaml sits and waits while
      > the hard drive churns. I'd prefer to have an operation fail with some
      > kind of exception rather than use swap memory. Is there a way to do
      > that? (I'm using Windows 98, but if there is a way to do it with
      > Linux maybe I'd give Linux a try).

      There doesn't seem to be a way to control how much memory the garbage
      collector will use through the ordinary Gc interface
      (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html). However
      if your program has a loop where you can place some code to be
      regularly executed, then you might be able to examine the
      Gc.heap_words field to see how much memory is currently being used.
      If it's greater than a certain limit, throw an exception by hand.

      Another thing which you might try, on Linux, is setting an operating
      system resource usage limit on the process. Before running the
      program, do something like:

      ulimit -v 32768

      (this example would limit processes to 32MB). Depending on how the
      OCaml GC is implemented, you'll either get a segfault or an exception
      when the total memory used by the program exceeds this limit. You'll
      need to experiment to see which you get.

      Rich.

      --
      Richard Jones, CTO Merjis Ltd.
      Merjis - web marketing and technology - http://merjis.com
      Team Notepad - intranets and extranets for business - http://team-notepad.com
    • vly3
      Thanks for the idea of checking Gc.heap_words during execution. After posting, I thought of disabling virtual memory on Windows 98, and after doing that I get
      Message 2 of 3 , May 17, 2005
      View Source
      • 0 Attachment
        Thanks for the idea of checking Gc.heap_words during execution. After
        posting, I thought of disabling virtual memory on Windows 98, and
        after doing that I get mixed results. If I try to make an
        unreasonably large matrix, with:
        let a = Array.make_matrix 1000000 1000000 0;;
        OCaml comes back predictably with:
        Out of memory during evaluation.

        However, if I make a few smaller matrices, with:
        let a = Array.make_matrix 1000000 25 0;;
        let b = Array.make_matrix 1000000 25 0;;
        let c = Array.make_matrix 1000000 25 0;;

        It will successfully make the a and b matrices, but on attempt to make
        the c matrix, the OCaml interpreter shuts down suddenly without any
        message. I have 320 MB of memory, so the c matrix is where I expect
        it to not have enough memory. This is probably a bug somewhere.

        - Vincent



        --- In ocaml_beginners@yahoogroups.com, Richard Jones <rich@a...> wrote:
        > On Tue, May 17, 2005 at 03:45:36AM -0000, vly3 wrote:
        > > Is there a way to prevent OCaml from using swap memory?
        >
        > There doesn't seem to be a way to control how much memory the garbage
        > collector will use through the ordinary Gc interface
        > (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html). However
        > if your program has a loop where you can place some code to be
        > regularly executed, then you might be able to examine the
        > Gc.heap_words field to see how much memory is currently being used.
        > If it's greater than a certain limit, throw an exception by hand.
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.