Skip to content

Commit

Permalink
Merge pull request containers#226 from giuseppe/handle-memsw-as-cgroupv1
Browse files Browse the repository at this point in the history
cgroup: handle swap limit as cgroup v1
  • Loading branch information
rhatdan authored Jan 28, 2020
2 parents 8882f7a + b9a92a5 commit 784fbfa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/libcrun/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,20 +1835,25 @@ write_memory_resources (int dirfd, bool cgroup2, runtime_spec_schema_config_linu
size_t len;
int ret;
char fmt_buf[32];
char swap_buf[32];
char limit_buf[32];
size_t swap_buf_len, limit_buf_len;
swap_buf_len = sprintf (swap_buf, "%lu", memory->swap);
limit_buf_len = sprintf (limit_buf, "%lu", memory->limit);

if (memory->limit)
{
char limit_buf[32];
size_t limit_buf_len;

limit_buf_len = sprintf (limit_buf, "%lu", memory->limit);

ret = write_file_at (dirfd, cgroup2 ? "memory.max" : "memory.limit_in_bytes", limit_buf, limit_buf_len, err);
if (UNLIKELY (ret < 0))
return ret;
}
if (memory->swap)
{
char swap_buf[32];
size_t swap_buf_len;

swap_buf_len = sprintf (swap_buf, "%lu", cgroup2 ? memory->swap - memory->limit : memory->swap);

ret = write_file_at (dirfd, cgroup2 ? "memory.swap.max" : "memory.memsw.limit_in_bytes", swap_buf, swap_buf_len, err);
if (UNLIKELY (ret < 0))
return ret;
Expand Down

0 comments on commit 784fbfa

Please sign in to comment.