Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Windows process (or user) memory limit

Tags:

memory

windows

Is there any way to set a system wide memory limit a process can use in Windows XP? I have a couple of unstable apps which do work ok for most of the time but can hit a bug which results in eating whole memory in a matter of seconds (or at least I suppose that's it). This results in a hard reset as Windows becomes totally unresponsive and I lose my work.

I would like to be able to do something like the /etc/limits on Linux - setting M90, for instance (to set 90% max memory for a single user to allocate). So the system gets the remaining 10% no matter what.

like image 510
Mike Minicki Avatar asked Oct 10 '08 20:10

Mike Minicki


People also ask

How much RAM can a 64-bit process use?

The theoretical memory limit that a 64-bit computer can address is about 16 exabytes (16 billion gigabytes), Windows XP x64 is currently limited to 128 GB of physical memory and 8 TB of virtual memory.

How do I dedicate RAM to a process?

Allocate RAM Using Windows Task Manager On your Windows 10 PC, open the Windows Task Manager app. To do so, use your keyboard's CTRL + SHIFT + ESC buttons. Go to the “Details Tab.” Right-click on the application you wish to assign extra RAM to and select priority.


4 Answers

Use Windows Job Objects. Jobs are like process groups and can limit memory usage and process priority.

like image 196
Adam Mitz Avatar answered Oct 11 '22 01:10

Adam Mitz


Use the Application Verifier (AppVerifier) tool from Microsoft.

In my case I need to simulate memory no longer being available so I did the following in the tool:

  1. Added my application
  2. Unchecked Basic
  3. Checked Low Resource Simulation
    • Changed TimeOut to 120000 - my application will run normally for 2 minutes before anything goes into effect.
    • Changed HeapAlloc to 100 - 100% chance of heap allocation error
    • Set Stacks to true - the stack will not be able to grow any larger
  4. Save
  5. Start my application

After 2 minutes my program could no longer allocate new memory and I was able to see how everything was handled.

like image 39
Jesse Vogt Avatar answered Oct 10 '22 23:10

Jesse Vogt


Depending on your applications, it might be easier to limit the memory the language interpreter uses. For example with Java you can set the amount of RAM the JVM will be allocated.

Otherwise it is possible to set it once for each process with the windows API

SetProcessWorkingSetSize Function

like image 4
Eric Avatar answered Oct 10 '22 23:10

Eric


No way to do this that I know of, although I'm very curious to read if anyone has a good answer. I have been thinking about adding something like this to one of the apps my company builds, but have found no good way to do it.

The one thing I can think of (although not directly on point) is that I believe you can limit the total memory usage for a COM+ application in Windows. It would require the app to be written to run in COM+, of course, but it's the closest way I know of.

The working set stuff is good (Job Objects also control working sets), but that's not total memory usage, only real memory usage (paged in) at any one time. It may work for what you want, but afaik it doesn't limit total allocated memory.

like image 3
Nick Avatar answered Oct 11 '22 01:10

Nick