Skip to content

Commit

Permalink
untested: add memory.max proxy
Browse files Browse the repository at this point in the history
TODO: make this optional? probably needs to be if we're going to upstream
it.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
  • Loading branch information
tych0 committed Aug 30, 2023
1 parent 587c661 commit d688ab8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/cgroups/cgfsng.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ static bool cgfsng_get_hierarchies(struct cgroup_ops *ops, int n, char ***out)
return true;
}

static int cgfsng_get_memory_max(struct cgroup_ops *ops, const char *cgroup,
char **value);

static bool cgfsng_get(struct cgroup_ops *ops, const char *controller,
const char *cgroup, const char *file, char **value)
{
Expand All @@ -530,6 +533,25 @@ static bool cgfsng_get(struct cgroup_ops *ops, const char *controller,

path = must_make_path_relative(cgroup, file, NULL);
*value = readat_file(h->fd, path);
/*
* Some applications (aka the JVM on cgroupv2) only check memory.max,
* and then use the sysinfo() syscall to reason about how much memory
* the system has.
*
* In the case of systemd running inside a container, when the unit
* itself doesn't have a limit, memory.max reads "max", so the
* application will then call sysinfo() and decide it has the whole
* system's memory to use.
*
* Let's fix this up by proxying lxcfs' notion of max memory for
* memory.max if the underlying controller does not have a value set.
*/
if (value && !strcmp("memory.max", file) && !strcmp("max\n", *value)) {
free(*value);
cgfsng_get_memory_max(ops, cgroup, value);
return *value != NULL;
}

return *value != NULL;
}

Expand Down

0 comments on commit d688ab8

Please sign in to comment.