0

I have an application which run as user "foo". I would like to set limit to CPU and memory that this application can use at run time. I am not able to realize how this can be achieved using systemd tools like - "systemctl" and "set-property" as this application is not a service but rather it is an application which a user can select and start.
Can some one please provide any guidance?

Souvik
  • 151
  • 3
  • 14

2 Answers2

0

Resource management is on the cgroup level. A service for example would get its own cgroup. Systemd is just the intermediate guy here between kernel. You tell systemd how much resource your service should get and systemd would propagate this to the kernel by playing around with the cgroup hierarchy.

Few things to check up: 1) You can play with your application's service's resource management. To find the service of your application I would use systemd-cgls. 2) Make sure you have necessary control groups enabled in your system like cpu cgroup, cpuacct cgroup, memory cgroup.

If you have any other specific question, just shoot.

Umut
  • 2,317
  • 1
  • 17
  • 19
0

If you wish to start a process from the command line, systemd-run --scope might be used. This will be run as a scope unit:

:/home/foo# systemd-run --scope dummy_bin &
[1] 201
:/home/foo# Running as unit run-201.scope.

Then systemctl can be used by this scope unit, like:

:/home/foo# systemctl status run-201.scope
    Loaded: loaded (/run/systemd/system/run-201.scope; static)
   Drop-In: /run/systemd/system/run-201.scope.d
    Active: active (running) since Thu 1970-01-01 01:01:01 UTC; 10s ago
    CGroup: /system.slice/run-201.scope
           `-201 /usr/bin/dummy_bin

The resource management of the scope unit could be realized by systemctl set-property via systemd.

Shuangistan
  • 1,053
  • 8
  • 20
  • Any ideas why specifying a slice (via `--slice` arg) does not work when using `--scope`? Seems to work when starting the process as a service. – AlexBrand Apr 08 '16 at 12:45