Skip to content

Commit

Permalink
cgroup: set the memory limit on the system scope
Browse files Browse the repository at this point in the history
when updating the memory limit, we now set it also on the systemd
scope.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed May 19, 2023
1 parent 4d2d5b3 commit 6494b69
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/libcrun/cgroup-systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,18 @@ get_value_from_unified_map (runtime_spec_schema_config_linux_resources *resource
return 0;
}

static inline int
get_memory_limit (runtime_spec_schema_config_linux_resources *resources, uint64_t *limit, libcrun_error_t *err)
{
if (resources->memory && resources->memory->limit_present)
{
*limit = resources->memory->limit;
return 1;
}

return get_value_from_unified_map (resources, "memory.max", limit, err);
}

static inline int
get_weight (runtime_spec_schema_config_linux_resources *resources, uint64_t *weight, libcrun_error_t *err)
{
Expand All @@ -649,17 +661,28 @@ append_resources (sd_bus_message *m,
int cgroup_mode,
libcrun_error_t *err)
{
uint64_t memory_limit;
int sd_err;
int ret;

if (resources == NULL)
return 0;

ret = get_memory_limit (resources, &memory_limit, err);
if (UNLIKELY (ret < 0))
return ret;
if (ret)
{
sd_err = sd_bus_message_append (m, "(sv)", "MemoryLimit", "t", memory_limit);
if (UNLIKELY (sd_err < 0))
return crun_make_error (err, -sd_err, "sd-bus message append MemoryLimit");
}

switch (cgroup_mode)
{
case CGROUP_MODE_UNIFIED:
{
uint64_t weight;
int ret;

ret = get_weight (resources, &weight, err);
if (UNLIKELY (ret < 0))
Expand Down

0 comments on commit 6494b69

Please sign in to comment.