Search Unity

How to limit heap size on Linux

Discussion in 'Linux' started by izawat, Apr 18, 2017.

  1. izawat

    izawat

    Joined:
    Apr 17, 2017
    Posts:
    2
    Hello,

    How to limit the maximum heap size of headless server on Linux? I'm planning to run multiple server instances on a single host. I want to specify upper limit like JVM's -Xmx option. I found a similar question but there is no answer.

    Thanks
     
  2. K_Bay

    K_Bay

    Joined:
    May 2, 2017
    Posts:
    13
    Use ulimit command. It can limit memory for any process under the Linux
     
  3. izawat

    izawat

    Joined:
    Apr 17, 2017
    Posts:
    2
    Thank you for your reply. I've found that ulimit -m does not work

    % ulimit -m 0
    % ./Minimum.x86_64 # unity game executable
    (It works normally)

    and ulimit -v is not useful because it reserves large virtual address space.

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    15282 izawat 20 0 1964000 64640 28264 R 3.0 0.8 0:01.04 ./Minimum.x86_64

    % ulimit -v 1000000 # 1GB
    % ./Minimum.x86_64
    Set current directory to /home/izawat/Minimum
    (snip)
    [1] 15387 segmentation fault (core dumped) ./Minimum.x86_64

    Finally, I could set memory limit by using cgroups. But I don't know whether the mono runtime knows the memory limit or not. I'm afraid that the game will be killed before invoking GC.
     
  4. feelingshred

    feelingshred

    Joined:
    Mar 16, 2021
    Posts:
    1
    Izawat, could you share the commands that you used to accomplish that with cgroups?
    That's exactly what I need to fix issues with getting Cities Skylines to load on my machine (also an Unity game)
    Screenshots here:
    https://imgur.com/a/x7LkOvV
    This has been driving me insane!
    I'm having more problems with memory and crashes in a new machine than I ever had in my older one.