0

I try to run process with memory and CPU limit but looks like it is not working and I keep running the process bigger than the memory limits. This is what I have:

  • My /etc/systemd/system/group750m.slice
    [Slice]
    MemoryLimit=750M
    CPUQuota=50%
    
  • Then I do:
    sudo systemctl daemon-reload
    
    sudo systemctl start group750m.slice
    sudo systemctl status group750m.slice
    
  • Results:
    group750m.slice
    Loaded: loaded
    Drop-In: /etc/systemd/system/group750m.slice.d
    └─10-limits.conf
    
    Active: active since Tue 2024-07-16 07:56:24 UTC; 11h ago
    Tasks: 7
    Memory: 254.8M (limit: 750.0M)
    
    CGroup: /group750m.slice
    └─group750m.scope
    └─12569 /home/vagrant/go/projects/1m_test/1m-go-websockets/4_optimize_gobwas/4_optimize_gobwas
    

Running the app:

sudo systemd-run --unit=group750m --slice=group750m.slice --scope /bin/bash -c '/home/vagrant/go/projects/1m_test/1m-go-websockets/4_optimize_gobwas/4_optimize_gobwas'

But when I do top on the running process in its peak it is more then Gb RAM

top - 19:25:46 up 1 day, 9:31, 7 users, load average: 2.38, 2.30, 1.28
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu0 : 10.5 us, 14.3 sy, 0.0 ni, 69.4 id, 0.0 wa, 0.0 hi, 5.8 si, 0.0 st
%Cpu1 : 3.8 us, 6.8 sy, 0.0 ni, 84.9 id, 0.0 wa, 0.0 hi, 4.5 si, 0.0 st
MiB Mem : 3932.3 total, 1035.4 free, 1364.8 used, 1532.1 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 2284.5 avail Mem

  PID USER PR NI    VIRT   RES  SHR S %CPU %MEM   TIME+ COMMAND
12569 root 20  0 1248192 69736 5072 S  7.3  1.7 0:39.81 4_optimize_gobw

What am I missing here?

1 Answer 1

0

TL/DR

The process is only using about 70MB of memory. Look at the RES field.

  PID USER PR NI    VIRT   RES  SHR S %CPU %MEM   TIME+
12569 root 20  0 1248192 69736 5072 S  7.3  1.7 0:39.81 
                            ^
                            |
 actual memory in use[1] ---+

Details

In the top output, only virtual memory (VIRT) is greater than 750MiB. Virtual is usually not what the user cares about in terms of limits, because much of the virtual memory is not backed by physical memory, nor is it swapped out. The available virtual address space on a 64-bit system is gigantic.

A more useful field is resident memory (RES/RSS), which is well under the systemd-specified memory limit.

MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 2284.5 avail Mem
                                      ^
                                      |
 no swap is being used ---------------+

This question on SuperUser explains the difference between virtual and resident memory.


(1) The kernel's implementation of cgroups (v1 in your case) has many subtleties and is way outside the scope of this question.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.