]>
Commit | Line | Data |
---|---|---|
9665627f AM |
1 | From 72a9e0c3d4f8daca9f7dc389edbc1013d7c0d808 Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com> | |
3 | Date: Fri, 8 Apr 2016 17:00:19 +0200 | |
4 | Subject: [PATCH] api.c: fix order of memory subsystem parameters generated by | |
5 | cgsnapshot | |
6 | MIME-Version: 1.0 | |
7 | Content-Type: text/plain; charset=UTF-8 | |
8 | Content-Transfer-Encoding: 8bit | |
9 | ||
10 | Order of parameters usually doesn't matter, but that's not the case with | |
11 | memory.limit_in_bytes and memory.memsw.limit_in_bytes. When the latter | |
12 | is first in the list of parameters, the resulting configuration is not | |
13 | loadable with cgconfigparser. | |
14 | ||
15 | This happens because when a cgroup is created, both memory.limit_in_bytes | |
16 | and memory.memsw.limit_in_bytes parameters are initialized to highest | |
17 | value possible (RESOURCE_MAX). And because memory.memsw.limit_in_bytes | |
18 | must be always higher or equal to memory.limit_in_bytes, it's impossible | |
19 | to change its value first. | |
20 | ||
21 | Make sure that after constructing parameter list of memory subsystem, | |
22 | the mentioned parameters are in correct order. | |
23 | ||
24 | Signed-off-by: Nikola Forró <nforro@redhat.com> | |
25 | --- | |
26 | src/api.c | 24 ++++++++++++++++++++++++ | |
27 | 1 file changed, 24 insertions(+) | |
28 | ||
29 | diff --git a/src/api.c b/src/api.c | |
30 | index 0bf0615..f5da553 100644 | |
31 | --- a/src/api.c | |
32 | +++ b/src/api.c | |
33 | @@ -2651,6 +2651,30 @@ int cgroup_get_cgroup(struct cgroup *cgroup) | |
34 | } | |
35 | } | |
36 | closedir(dir); | |
37 | + | |
38 | + if (! strcmp(cgc->name, "memory")) { | |
39 | + /* | |
40 | + * Make sure that memory.limit_in_bytes is placed before | |
41 | + * memory.memsw.limit_in_bytes in the list of values | |
42 | + */ | |
43 | + int memsw_limit = -1; | |
44 | + int mem_limit = -1; | |
45 | + | |
46 | + for (j = 0; j < cgc->index; j++) { | |
47 | + if (! strcmp(cgc->values[j]->name, | |
48 | + "memory.memsw.limit_in_bytes")) | |
49 | + memsw_limit = j; | |
50 | + else if (! strcmp(cgc->values[j]->name, | |
51 | + "memory.limit_in_bytes")) | |
52 | + mem_limit = j; | |
53 | + } | |
54 | + | |
55 | + if (memsw_limit >= 0 && memsw_limit < mem_limit) { | |
56 | + struct control_value *val = cgc->values[memsw_limit]; | |
57 | + cgc->values[memsw_limit] = cgc->values[mem_limit]; | |
58 | + cgc->values[mem_limit] = val; | |
59 | + } | |
60 | + } | |
61 | } | |
62 | ||
63 | /* Check if the group really exists or not */ | |
64 | -- | |
65 | 2.4.11 | |
66 |