开发者

How to determine the process memory limit in Linux?

开发者 https://www.devze.com 2023-02-03 17:44 出处:网络
I have been scouring the internet to find out how much memory a java process can take on a linux (red-hat) machine.( I am not talking about heap; rather, the entire amount of memory taken up by the ja

I have been scouring the internet to find out how much memory a java process can take on a linux (red-hat) machine. ( I am not talking about heap; rather, the entire amount of memory taken up by the java Process)

I don't have permission to execute anything on that machine. So I can't simply execute a program that consumes memory until Out-Of-Memory condition.

However开发者_高级运维, I do have permission to check config files, etc. ( for example: I tried to execute cat /proc/meminfo, but I can't understand it; it appears that none of its results stand for the parameter I want to know about).

I have tried out a java program on a separate red hat machine - on which I do have permission to execute programs - and I was able to see java program grow up to around 3GB.

Is there some way I can find out how much memory a process can get ?


ulimit is your friend. Java processes are no different than any others. But if you can't even run ulimit -a, it's hard to answer your question.


Here's a useful read: Limiting time and memory consumption of a program in Linux, which lead to the timeout tool, which lets you cage a process (and it's forks) by time or memory consumption.


I have been dealing with this exact problem and have found the best solution if you are using 2.6.24 or higher is to use cgroup / cgroups. An example would be like this, here is the default /etc/cgconfig.conf file with an added control group at the bottom. This control group limits the amout of physical memory to 100MB and the total virtual memory allocation to 200MB.

mount {
    cpuset  = /cgroup/cpuset;
    cpu = /cgroup/cpu;
    cpuacct = /cgroup/cpuacct;
    memory  = /cgroup/memory;
    devices = /cgroup/devices;
    freezer = /cgroup/freezer;
    net_cls = /cgroup/net_cls;
    blkio   = /cgroup/blkio;
}

group daemons/java_limited_process {
    memory {
        memory.limit_in_bytes = "104857600";
        memory.memsw.limit_in_bytes = "209715200";
    }
}

Once I have this configured, I can add process to the group like so

cgexec -g memory:daemons/java_limited_process /usr/local/tomcat/bin/startup.sh

This will limit the memory of the main process and any children it spawns. It also has facilities to query memory usage in the controllers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号