How to determine the process memory limit in Linux?

前端 未结 3 781
遥遥无期
遥遥无期 2020-12-15 10:03

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

相关标签:
3条回答
  • 2020-12-15 10:15

    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 讨论(0)
  • 2020-12-15 10:33

    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.

    0 讨论(0)
  • 2020-12-15 10:37

    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.

    0 讨论(0)
提交回复
热议问题