2

Id like to run a memory intensive java program and limit how much physical memory it can use.

Is possible to configure the JVM to use no more than 1gb of RAM, and use only virtual memory after it has used the first 1gb of RAM?

I'd like the program to be able to have as much address space as it needs (Several GB), but do not want it using all of the available RAM on the machine.

1
  • 1
    You could look for a third-party program that limits the memory used by any application. This isn't specific to the JVM. Commented Jul 29, 2010 at 23:03

2 Answers 2

3

I found a workable solution for Ubuntu:

Using the system utility ulimit I was able to set the maximum physical memory and many other resource limits for any processes spawned from the shell ulimit was called from.

All I had to do was open a shell, call ulimit and then start the process.

1

No, I am not aware of any solution that would let you do this. I'm not sure this is even possible without major architectural changes; after all, the OS usually decides on a case-by-case basis which data to swap out and which to keep in RAM. It's not clear to me such a restriction would even be practical; at any rate it would probably require deep changes to the OS.

Counter-question: Why do you feel this is necessary? The virtual memory subsystem of a modern OS has been finely tuned to give you the best performance possible. What makes you believe you can do better?

Plus:

If you really are having memory problems, just go buy more RAM. 4GB go for around $100, just buying it is probably more effective than spending hours on fine-tuning the VM subsystem...

1
  • I am not having memory problems in general (I have 8gb), just with this one time processing on some huge image data. The problem is Ubuntu allocates the program up to 7GB of RAM as it is needed. This is no good because this process needs to run in the background while I do other things, it doesn't matter how much the disk thrashes or how slow the performance of that program is. The important thing is to keep the ram in my machine available for other tasks. Commented Jul 30, 2010 at 0:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .