简体   繁体   中英

How to determine the process memory limit in Linux?

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.

这是一个有用的读物​​: 限制Linux中程序的时间和内存消耗 ,这会导致超时工具,它允许您按时间或内存消耗来保存进程(及其分支)。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM