static int default_swappiness = 0;
+static unsigned long long totalram_bytes = 0;
+
/*
* Special node that point's to /sys/fs/cgroup/memory - root of memcg group.
* This is the same as memcg_tree[CGROUP_ROOT]->info.
{MEMCG_LOW_PATH,},
};
+void register_totalram_bytes(unsigned long long ram_bytes)
+{
+ totalram_bytes = ram_bytes;
+}
+
int set_mem_action_conf(struct mem_action *mem_action, const char *value)
{
char *ptr = strchr(value, ',');
*(ptr - 2) = '\0';
if (temp == 'G') {
- mem_action->memory = GBYTE_TO_BYTE(atoi(value));
+ mem_action->memory_bytes = GBYTE_TO_BYTE(atoi(value));
}
else if (temp == 'M') {
- mem_action->memory = MBYTE_TO_BYTE(atoi(value));
+ mem_action->memory_bytes = MBYTE_TO_BYTE(atoi(value));
}
else if (temp == 'K') {
- mem_action->memory = KBYTE_TO_BYTE(atoi(value));
- }
- else if (temp == ' ') {
- mem_action->memory = atoi(value);
+ mem_action->memory_bytes = KBYTE_TO_BYTE(atoi(value));
}
else {
- _E("Memory size unit should be GB or MB or KB or B");
+ _E("Memory size unit should be GB or MB or KB");
return RESOURCED_ERROR_FAIL;
}
memcg_conf->threshold[lvl].threshold =
KBYTE_TO_MBYTE(atoi(value));
}
- else if (size == ' ') {
- memcg_conf->threshold[lvl].threshold =
- BYTE_TO_MBYTE(atoi(value));
- }
else {
- _E("Memory size unit should be GB or MB or KB or B");
+ _E("Memory size unit should be GB or MB or KB");
return RESOURCED_ERROR_FAIL;
}
}
free(memcg_conf);
}
-static void set_limit_in_bytes(const char *dir, unsigned int limit)
+static void set_limit_in_bytes(const char *dir, unsigned long long limit_bytes)
{
int error;
- unsigned int prev;
+ unsigned long long prev_bytes;
- error = cgroup_read_node_uint32(dir, MEMCG_LIMIT_BYTE, &prev);
+ error = cgroup_read_node_ulonglong(dir, MEMCG_LIMIT_BYTE, &prev_bytes);
if (error) {
_E("[MEMORY-LIMIT] Failed to get %s from %s", MEMCG_LIMIT_BYTE, dir);
return;
}
- if (limit == prev)
+ if (limit_bytes == prev_bytes)
return;
- if (prev > limit) {
- cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, limit);
- cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, limit);
+ if (totalram_bytes > 0 && limit_bytes > totalram_bytes)
+ limit_bytes = totalram_bytes;
+
+ if (prev_bytes > limit_bytes) {
+ cgroup_write_node_ulonglong(dir, MEMCG_LIMIT_BYTE, limit_bytes);
+ cgroup_write_node_ulonglong(dir, MEMCG_SWAP_LIMIT_BYTE, limit_bytes);
}
else {
- cgroup_write_node_uint32(dir, MEMCG_SWAP_LIMIT_BYTE, limit);
- cgroup_write_node_uint32(dir, MEMCG_LIMIT_BYTE, limit);
+ cgroup_write_node_ulonglong(dir, MEMCG_SWAP_LIMIT_BYTE, limit_bytes);
+ cgroup_write_node_ulonglong(dir, MEMCG_LIMIT_BYTE, limit_bytes);
}
}
-int check_oom_and_set_limit(const char *dir, unsigned int limit)
+int check_oom_and_set_limit(const char *dir, unsigned long long limit_bytes)
{
int error;
static unsigned int poo = -1;
error = fread_uint("/proc/sys/vm/panic_on_oom", &poo);
if (error) {
_E("[MEMORY-LIMIT] Failed to get %s from %s", "/proc/sys/vm/panic_on_oom", dir);
- return RESOURCED_ERROR_FAIL;
+ poo = 0;
}
}
}
}
- set_limit_in_bytes(dir, limit);
+ set_limit_in_bytes(dir, limit_bytes);
return RESOURCED_ERROR_NONE;
}
static int memcg_write_limiter_info(struct memcg_info *mi)
{
- unsigned int limit = mi->limit;
+ unsigned long long limit_bytes = mi->limit_bytes;
const char *name = mi->name;
int ret = RESOURCED_ERROR_NONE;
/* enable cgroup move */
if (mi->limit_ratio == MEMCG_NO_LIMIT)
return ret;
+ _I("[MEMORY-LIMIT] dir = %s, limit = %llu bytes", name, limit_bytes);
/* write limit_in_bytes */
- ret = check_oom_and_set_limit(name, limit);
+ ret = check_oom_and_set_limit(name, limit_bytes);
return ret;
}
int memcg_write_limiter_params(void)
{
unsigned int i;
- unsigned int lower_group_limit = 0;
+ unsigned long long lower_group_limit_bytes = 0;
for (i = CGROUP_LOW; i > CGROUP_ROOT; i--) {
struct memcg_info *mi = get_memcg_info(i);
- if (mi->limit < lower_group_limit)
- mi->limit = lower_group_limit;
+ if (mi->limit_bytes < lower_group_limit_bytes)
+ mi->limit_bytes = lower_group_limit_bytes;
memcg_write_limiter_info(mi);
- lower_group_limit = mi->limit;
+ lower_group_limit_bytes = mi->limit_bytes;
}
return RESOURCED_ERROR_NONE;
if(!mi)
_E("memory cgroup of %d is NULL", type);
else
- mi->threshold[level] = value;
+ mi->threshold_mb[level] = value;
}
void memcg_set_leave_threshold(int type, int value)
if(!mi)
_E("memory cgroup of %d is NULL", type);
else
- mi->threshold_leave = value;
+ mi->threshold_leave_mb = value;
}
void memcg_info_set_limit(struct memcg_info *mi, float ratio,
- unsigned int totalram)
+ unsigned long long totalram_bytes)
{
if (!mi)
return;
- mi->limit = (float)totalram * ratio;
+ mi->limit_bytes = (double)totalram_bytes * ratio;
mi->limit_ratio = ratio;
}
return 0;
}
-int memcg_get_anon_usage(char *memcg, unsigned int *anon_usage)
+int memcg_get_anon_usage(char *memcg, unsigned long long *anon_usage_bytes)
{
int r;
_cleanup_free_ struct cgroup_memory_stat *mem_stat = NULL;
return r;
}
- *anon_usage = mem_stat->value[CGROUP_MEMORY_STAT_INACTIVE_ANON] +
+ *anon_usage_bytes = mem_stat->value[CGROUP_MEMORY_STAT_INACTIVE_ANON] +
mem_stat->value[CGROUP_MEMORY_STAT_ACTIVE_ANON];
return 0;
}
-int memcg_get_swap_usage(char *memcg, unsigned int *usage)
+int memcg_get_swap_usage(char *memcg, unsigned long long *usage_bytes)
{
int r;
_cleanup_free_ struct cgroup_memory_stat *mem_stat = NULL;
return r;
}
- *usage = mem_stat->value[CGROUP_MEMORY_STAT_SWAP];
+ *usage_bytes = mem_stat->value[CGROUP_MEMORY_STAT_SWAP];
return 0;
}