4

I was wondering why Matlab doesn't use swap, but instead throws the error "Out of memory"?

Shouldn't Matlab just slow down instead of throwing an "Out of memory"?

Is this Java related?

added:

I know "out of memory" means it's out of contiguous memory. Doesn't swap have contiguous memory, or? I'm confused...

animuson
  • 53,861
  • 28
  • 137
  • 147
HaveF
  • 2,995
  • 2
  • 26
  • 36
  • yes it's java related - see: http://stackoverflow.com/questions/4583995/is-there-any-way-to-force-a-jvm-to-use-swap-no-matter-how-big-the-memory-require - still a shame they didn't implement some swapping. – bdecaf Sep 17 '12 at 08:33
  • @bdecaf No, it is not. Java only manages creation of java objects, not internal MATLAB data structures. Those are handled by MATLABs proprietary code and have nothing to do with JVM (second paragraph of [this article](http://blogs.mathworks.com/community/2009/08/17/calling-java-from-matlab-memory-issues/)). – angainor Sep 17 '12 at 09:36

1 Answers1

6

It is not about MATLAB. What happens when you try allocate more memory than exists in your hardware is an OS specific behavior.

On Linux, by default the OS will 'optimistically' allocate almost anything you want, i.e. swap space is also counted as allocatable memory. You will get what you want - no OOM error, but slow computations with swap-allocated data. This 'feature' is called overcommit. You can change this behavior by modifying the overcommit settings in Linux (have a look e.g. here for a brief summary).

Overcommit is probably not the best idea to use this for solving larger problems in MATLAB, since the entire OS starts to work really slow. It can definitely not be compared to optimized 'out-of-core' implementations that consciously use the hard disk in computations.

This is how it is on Linux. I do not know how to change the memory allocation behavior on Windows, but I doubt you really want to do that. You need more RAM.

And you do confuse things - swap has nothing to do with contiguous memory. Memory allocated by the OS is 'virtual memory', which is contiguous regardless of whether the underlying physical memory can be mapped to contiguous pages.

Edit For transparent 'out-of-core' operations on large matriices using disk space as extra memory you might want to have look at VVAR fileexchange project. This class pretends to be a usual MATLAB class, but it operates on an underlying HDD file. Note that the usual array size limitations of MATLAB still apply.

angainor
  • 11,760
  • 2
  • 36
  • 56