diff options
-rw-r--r-- | conf/README | 35 | ||||
-rw-r--r-- | conf/limiter.conf | 8 | ||||
-rw-r--r-- | src/common/cgroup/memory-cgroup.c | 104 | ||||
-rw-r--r-- | src/common/cgroup/memory-cgroup.h | 2 | ||||
-rw-r--r-- | src/common/util.h | 6 |
5 files changed, 90 insertions, 65 deletions
diff --git a/conf/README b/conf/README index cef18367..9575f7d8 100644 --- a/conf/README +++ b/conf/README @@ -91,32 +91,36 @@ Example: LmkMaxVictimPerOom=10 Key: ServicePerAppLimitAction Value: <limit>[GMK]B,<action> Comment: Specify the memory limitation of services. - <action> specifies an action to be performed when the limit is crossed. - <action> can be: broadcast, reclaim, kill, ignore -Example: ServicePerAppLimitAction=128MB,kill + If <action> is specified, <action> overwrites the global action (reference section 1.5). + If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger). + If <limit> size is smaller than app size during app loading time, the memory limit is not applied. +Example: ServicePerAppLimitAction=128MB Key: WidgetPerAppLimitAction Value: <limit>[GMK]B,<action> Comment: Specify the memory limitation of widgets. - <action> specifies an action to be performed when the limit is crossed. - <action> can be: broadcast, reclaim, kill, ignore -Example: WidgetPerAppLimitAction=160MB,kill + If <action> is specified, <action> overwrites the global action (reference section 1.5). + If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger). + If <limit> size is smaller than app size during app loading time, the memory limit is not applied. +Example: WidgetPerAppLimitAction=160MB Key: GUIPerAppLimitAction Value: <limit>[GMK]B,<action> Comment: Specify the memory limitation of GUIs. - <action> specifies an action to be performed when the limit is crossed. - <action> can be: broadcast, reclaim, kill, ignore -Example: GUIPerAppLimitAction=160MB,kill + If <action> is specified, <action> overwrites the global action (reference section 1.5). + If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger). + If <limit> size is smaller than app size during app loading time, the memory limit is not applied. +Example: GUIPerAppLimitAction=160MB 1.4 Section: MemoryAppStatusLimit ================================= Key: BackgroundPerAppLimitAction Value: <limit>[GMK]B,<action> Comment: Specify the memory limitation of background apps. - <action> specifies an action to be performed when the limit is crossed. - <action> can be: broadcast, reclaim, kill, ignore -Example: BackgroundPerAppLimitAction=768MB,kill + If <action> is specified, <action> overwrites the global action (reference section 1.5). + If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger). + If <limit> size is smaller than app size during app loading time, the memory limit is not applied. +Example: BackgroundPerAppLimitAction=768MB 1.5 Section: MemoryLMKGovernor ============================= @@ -542,9 +546,10 @@ Example: App=org.tizen.<app> Key: MemLimitAction Value: <limit>[GMK]B,<action> Comment: Specify the memory limitation of this app/service/process. - <action> specifies an action to be performed when the limit is crossed. - <action> can be: broadcast, reclaim, kill, ignore -Example: MemLimitAction=4096KB,kill + If <action> is specified, <action> overwrites the global action (reference section 1.5). + If <action> is not specified, action is decided by global action (i.e., MemoryLimitTrigger). + If <limit> size is smaller than app size during app loading time, the memory limit is not applied. +Example: MemLimitAction=4096KB Key: MemoryBackgroundLru Value: (yes|1|ok|on|no|0|off) diff --git a/conf/limiter.conf b/conf/limiter.conf index 73aaef30..f64d6d6f 100644 --- a/conf/limiter.conf +++ b/conf/limiter.conf @@ -8,12 +8,12 @@ OomLevel= 7% OomPopup= no [MemoryAppTypeLimit] -ServicePerAppLimitAction=128MB,kill -#WidgetPerAppLimitAction=160MB,kill -#GUIPerAppLimitAction=1024MB,kill +ServicePerAppLimitAction=128MB +#WidgetPerAppLimitAction=160MB +#GUIPerAppLimitAction=1024MB [MemoryAppStatusLimit] -#BackgroundPerAppLimitAction=768MB,kill +#BackgroundPerAppLimitAction=768MB [MemoryBackgroundLru] BackgroundLruLimit= 80% diff --git a/src/common/cgroup/memory-cgroup.c b/src/common/cgroup/memory-cgroup.c index e5973a01..5d2e6e10 100644 --- a/src/common/cgroup/memory-cgroup.c +++ b/src/common/cgroup/memory-cgroup.c @@ -187,65 +187,85 @@ 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) +static int get_memory_bytes(const char *value, uint64_t *memory_bytes) { - char *ptr = strchr(value, ','); - char *second_value = ptr + 1; - char temp; - + char size[3]; + char *ptr = strchr(value, 'B'); if (ptr == NULL) { - _E("Cannot find ',' in the string (%s)", value); + _E("[CONFIG] Cannot find 'B' in the string (%s)", value); return RESOURCED_ERROR_FAIL; } - if (value > (ptr - 2)) { - _E("Size of string should be larger than 2"); + if (value > (ptr - 1)) { + _E("[CONFIG] Size of string should be larger than 1"); return RESOURCED_ERROR_FAIL; } - if (*(ptr - 1) == 'B') { - temp = *(ptr - 2); - *(ptr - 2) = '\0'; + size[0] = *(ptr - 1); + size[1] = *ptr; + size[2] = '\0'; + *(ptr - 1) = '\0'; - if (temp == 'G') { - mem_action->memory_bytes = GBYTE_TO_BYTE(atoi(value)); - } - else if (temp == 'M') { - mem_action->memory_bytes = MBYTE_TO_BYTE(atoi(value)); - } - else if (temp == 'K') { - mem_action->memory_bytes = KBYTE_TO_BYTE(atoi(value)); - } - else { - _E("Memory size unit should be GB or MB or KB"); - return RESOURCED_ERROR_FAIL; - } - - if (!strncmp(second_value, ACTION_BROADCAST_VALUE_CONF, - strlen(ACTION_BROADCAST_VALUE_CONF)+1)) - mem_action->action = PROC_ACTION_BROADCAST; - else if (!strncmp(second_value, ACTION_RECLAIM_VALUE_CONF, - strlen(ACTION_RECLAIM_VALUE_CONF)+1)) - mem_action->action = PROC_ACTION_RECLAIM; - else if (!strncmp(second_value, ACTION_KILL_VALUE_CONF, - strlen(ACTION_KILL_VALUE_CONF)+1)) - mem_action->action = PROC_ACTION_KILL; - else if (!strncmp(second_value, ACTION_IGNORE_VALUE_CONF, - strlen(ACTION_IGNORE_VALUE_CONF)+1)) - mem_action->action = PROC_ACTION_IGNORE; - else { - _E("action (%s) is not supported", second_value); - return RESOURCED_ERROR_FAIL; - } + if (!strncmp(size, "GB", 3)) + *memory_bytes = GBYTE_TO_BYTE(atoi(value)); + else if (!strncmp(size, "MB", 3)) + *memory_bytes = MBYTE_TO_BYTE(atoi(value)); + else if (!strncmp(size, "KB", 3)) + *memory_bytes = KBYTE_TO_BYTE(atoi(value)); + else { + _E("Memory size unit should be GB or MB or KB"); + return RESOURCED_ERROR_FAIL; } + + return RESOURCED_ERROR_NONE; +} + +static int get_memory_action(const char *value, int *action) +{ + if (!strncmp(value, ACTION_BROADCAST_VALUE_CONF, + strlen(ACTION_BROADCAST_VALUE_CONF) + 1)) + *action = PROC_ACTION_BROADCAST; + else if (!strncmp(value, ACTION_RECLAIM_VALUE_CONF, + strlen(ACTION_RECLAIM_VALUE_CONF) + 1)) + *action = PROC_ACTION_RECLAIM; + else if (!strncmp(value, ACTION_KILL_VALUE_CONF, + strlen(ACTION_KILL_VALUE_CONF) + 1)) + *action = PROC_ACTION_KILL; + else if (!strncmp(value, ACTION_IGNORE_VALUE_CONF, + strlen(ACTION_IGNORE_VALUE_CONF) + 1)) + *action = PROC_ACTION_IGNORE; else { - _E("Memory size unit should be XB"); + _E("action (%s) is not supported", value); return RESOURCED_ERROR_FAIL; } return RESOURCED_ERROR_NONE; } +int set_mem_action_conf(struct mem_action *mem_action, const char *value) +{ + char *ptr = strchr(value, ','); + const char *action_ptr; + int result; + + result = get_memory_bytes(value, &mem_action->memory_bytes); + if (result < 0) + return result; + + /* Memory Limit without action value */ + if (ptr == NULL) { + mem_action->action = PROC_ACTION_KILL; + return RESOURCED_ERROR_NONE; + } + + action_ptr = ptr + 1; + result = get_memory_action(action_ptr, &mem_action->action); + if (result < 0) + return result; + + return RESOURCED_ERROR_NONE; +} + static int get_threshold_size(bool percent, char size, const char *value) { if (!percent) { diff --git a/src/common/cgroup/memory-cgroup.h b/src/common/cgroup/memory-cgroup.h index 52a0791e..03e4b99f 100644 --- a/src/common/cgroup/memory-cgroup.h +++ b/src/common/cgroup/memory-cgroup.h @@ -162,7 +162,7 @@ struct mem_threshold { }; struct mem_action { - unsigned long long memory_bytes; /* Byte */ + uint64_t memory_bytes; int action; }; diff --git a/src/common/util.h b/src/common/util.h index 8a66ee44..6f3ee456 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -95,13 +95,13 @@ static inline void closedirp(DIR **d) #define BYTE_TO_MBYTE(b) ((b) >> 20) #define BYTE_TO_PAGE(b) ((b) >> 12) -#define KBYTE_TO_BYTE(k) ((unsigned long long)(k) << 10) +#define KBYTE_TO_BYTE(k) ((uint64_t)(k) << 10) #define KBYTE_TO_MBYTE(k) ((k) >> 10) -#define MBYTE_TO_BYTE(m) ((unsigned long long)(m) << 20) +#define MBYTE_TO_BYTE(m) ((uint64_t)(m) << 20) #define MBYTE_TO_KBYTE(m) ((m) << 10) -#define GBYTE_TO_BYTE(g) ((unsigned long long)(g) << 30) +#define GBYTE_TO_BYTE(g) ((uint64_t)(g) << 30) #define GBYTE_TO_MBYTE(g) ((g) << 10) #define streq(a, b) (strncmp((a), (b), strlen(b)+1) == 0) |