I'm using Arch Linux and systemd version is 239. I booted system with systemd.unified_cgroup_hierarchy=1 kernel parameter.

I made two unit files, limit.slice and malloc.service.

limit.slice is

Description=limit memory slice.


and malloc.service is

Description=memory consuming process


malloc_program is just keep calls malloc() to consume memory.

I put these files to /home/example/.config/systemd/user/ and run systemctl --user start malloc.service. Service's CGroup is under limit.slice as expected.

CGroup: /user.slice/user-1000.slice/user@1000.service/limit.slice/malloc.service

But, the process keeps running even when the used memory was over 100 MB.

I can't understand why memory limitation is not working in user instance...

  • "malloc_program is just keep calls malloc() to consume memory" -> That's usually not enough, you usually need to "touch" the pages for Linux to actually allocate them for you. If you want a system to test using memory, consider using memhog which is typically shipped with the "numactl" package. – filbranden Aug 20 '18 at 20:48
  • Actually, I implemented that too. Sorry for lack of explenation. – R00T3D Aug 21 '18 at 0:46

Try to set for malloc service at .slice file:

| improve this answer | |
  • It didn't work... Maybe it is a bug of systemd? github.com/systemd/systemd/issues/9512 – R00T3D Aug 20 '18 at 0:30
  • For future reference: the bug was reported as a regression in systemd v239 (the bug does not seem present in v237), and the bug was closed by a fix that is applied to v240. – sourcejedi Jan 21 '19 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.