提交 42a730a7 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!10 lcr: adapt update memory process

Merge pull request !10 from lifeng_isula/fix_memory
......@@ -1171,7 +1171,7 @@ bool lcr_update(const char *name, const char *lcrpath, const struct lcr_cgroup_r
goto out_put;
}
if (!do_update(c, name, tmp_path, cr)) {
if (!do_update(c, name, tmp_path, (struct lcr_cgroup_resources *)cr)) {
goto out_put;
}
......
......@@ -68,6 +68,22 @@ static inline void add_array_kv(char **array, size_t total, size_t *pos, const c
add_array_elem(array, total, pos, v);
}
static uint64_t stat_get_ull(struct lxc_container *c, const char *item)
{
char buf[80] = { 0 };
int len = 0;
uint64_t val = 0;
len = c->get_cgroup_item(c, item, buf, sizeof(buf));
if (len <= 0) {
DEBUG("unable to read cgroup item %s", item);
return 0;
}
val = strtoull(buf, NULL, 0);
return val;
}
static bool update_resources_cpuset_mems(struct lxc_container *c, const struct lcr_cgroup_resources *cr)
{
bool ret = false;
......@@ -265,17 +281,40 @@ out:
return ret;
}
static bool update_resources_mem(struct lxc_container *c, const struct lcr_cgroup_resources *cr)
static bool update_resources_mem(struct lxc_container *c, struct lcr_cgroup_resources *cr)
{
bool ret = false;
// If the memory update is set to -1 we should also set swap to -1, it means unlimited memory.
if (cr->memory_limit == -1) {
cr->memory_swap = -1;
}
if (cr->memory_limit != 0 && cr->memory_swap != 0) {
uint64_t cur_mem_limit = stat_get_ull(c, "memory.limit_in_bytes");
if (cr->memory_swap == -1 || cur_mem_limit < cr->memory_swap) {
if (update_resources_memory_swap(c, cr) != 0) {
goto err_out;
}
if (update_resources_memory_limit(c, cr) != 0) {
goto err_out;
}
} else {
if (update_resources_memory_limit(c, cr) != 0) {
goto err_out;
}
if (update_resources_memory_swap(c, cr) != 0) {
goto err_out;
}
}
} else {
if (update_resources_memory_limit(c, cr) != 0) {
goto err_out;
}
if (update_resources_memory_swap(c, cr) != 0) {
goto err_out;
}
}
if (update_resources_memory_reservation(c, cr) != 0) {
goto err_out;
......@@ -309,7 +348,7 @@ out:
return ret;
}
static bool update_resources(struct lxc_container *c, const struct lcr_cgroup_resources *cr)
static bool update_resources(struct lxc_container *c, struct lcr_cgroup_resources *cr)
{
bool ret = false;
......@@ -333,7 +372,7 @@ err_out:
return ret;
}
bool do_update(struct lxc_container *c, const char *name, const char *lcrpath, const struct lcr_cgroup_resources *cr)
bool do_update(struct lxc_container *c, const char *name, const char *lcrpath, struct lcr_cgroup_resources *cr)
{
bool bret = false;
......@@ -461,22 +500,6 @@ err_out:
return val;
}
static uint64_t stat_get_ull(struct lxc_container *c, const char *item)
{
char buf[80] = { 0 };
int len = 0;
uint64_t val = 0;
len = c->get_cgroup_item(c, item, buf, sizeof(buf));
if (len <= 0) {
DEBUG("unable to read cgroup item %s", item);
return 0;
}
val = strtoull(buf, NULL, 0);
return val;
}
void do_lcr_state(struct lxc_container *c, struct lcr_container_state *lcs)
{
const char *state = NULL;
......
......@@ -21,7 +21,7 @@
extern "C" {
#endif
bool do_update(struct lxc_container *c, const char *name, const char *lcrpath, const struct lcr_cgroup_resources *cr);
bool do_update(struct lxc_container *c, const char *name, const char *lcrpath, struct lcr_cgroup_resources *cr);
void do_lcr_state(struct lxc_container *c, struct lcr_container_state *lcs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册