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
    You could look for a third-party program that limits the memory used by any application. This isn't specific to the JVM. – Sasha Chedygov Jul 29 '10 at 23:03

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.


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?


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...

  • 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. – instanceofTom Jul 30 '10 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.