Skip to main content
Improve formatting
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77
# /etc/systemd/system/group750m.slice

[Slice]

MemoryLimit=750M

CPUQuota=50%

Then:

sudo systemctl daemon-reload

Then:

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
  • 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
    
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'
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 toptop 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
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
# /etc/systemd/system/group750m.slice

[Slice]

MemoryLimit=750M

CPUQuota=50%

Then:

sudo systemctl daemon-reload

Then:

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
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
  • 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
    
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
Source Link
user63898
  • 343
  • 2
  • 5
  • 12

Memory limits set in your systemd slice are not being enforced correctly

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:

# /etc/systemd/system/group750m.slice

[Slice]

MemoryLimit=750M

CPUQuota=50%

Then:

sudo systemctl daemon-reload

Then:

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?