#define MEM_CONF_FILE RD_CONFIG_FILE(memory)
#define MEMLIMIT_CONFIG_SECTION "MemLimit"
#define MEMLIMIT_CONFIG_TRIGGER "MemLimitTrigger"
-#define MEMLIMIT_CONFIG_SERVICE "MemLimitService"
+
+#define MEMLIMIT_CONFIG_LIM_PFX MEMLIMIT_CONFIG_SECTION
+#define MEMLIMIT_CONFIG_SERVICE MEMLIMIT_CONFIG_LIM_PFX "Service"
+#define MEMLIMIT_CONFIG_GUIAPP MEMLIMIT_CONFIG_LIM_PFX "GUIApp"
+#define MEMLIMIT_CONFIG_WIDGET MEMLIMIT_CONFIG_LIM_PFX "Widget"
#define MIN_LIMIT_VALUE 1 /* MB */
enum mem_limit_type {
static GHashTable *memory_limit_hash;
static char *registerpath;
static int mem_service_limit;
+static int mem_guiapp_limit;
+static int mem_widget_limit;
struct memory_limit_event {
fd_handler_h fdh;
registerpath = MEMCG_USAGE;
}
_I("Control %s event with %s node about memcg", result->value, registerpath);
- } else if (!strncmp(result->name, MEMLIMIT_CONFIG_SERVICE,
- sizeof(MEMLIMIT_CONFIG_SERVICE))) {
- if (mem_limit != MEM_LIMIT_NONE)
- mem_service_limit = atoi(result->value);
+ } else if (!strncmp(result->name, MEMLIMIT_CONFIG_LIM_PFX, sizeof(MEMLIMIT_CONFIG_LIM_PFX)-1)) {
+ const int limit = atoi(result->value);
+ if (!strcmp(result->name, MEMLIMIT_CONFIG_SERVICE))
+ mem_service_limit = limit;
+ else if (!strcmp(result->name, MEMLIMIT_CONFIG_GUIAPP))
+ mem_guiapp_limit = limit;
+ else if (!strcmp(result->name, MEMLIMIT_CONFIG_WIDGET))
+ mem_widget_limit = limit;
}
+
return RESOURCED_ERROR_NONE;
}
static int lowmem_limit_service(void *data)
{
+ assert(data);
+
struct proc_status *ps = (struct proc_status *)data;
if (mem_service_limit)
return RESOURCED_ERROR_NONE;
}
+static int lowmem_limit_appwidget(void *data)
+{
+ assert(data);
+
+ struct proc_status *ps = (struct proc_status *)data;
+
+ if (mem_guiapp_limit && ps->pai->type == PROC_TYPE_GUI)
+ lowmem_limit_set(ps->pid, mem_guiapp_limit);
+ if (mem_widget_limit && ps->pai->type == PROC_TYPE_WIDGET)
+ lowmem_limit_set(ps->pid, mem_widget_limit);
+
+ return RESOURCED_ERROR_NONE;
+}
+
void lowmem_limit_init(void)
{
/* Load configuration */
config_parse(MEM_CONF_FILE, memlimit_config_parse,
NULL);
+
+ if (mem_limit == MEM_LIMIT_NONE)
+ return;
+
if (mem_service_limit)
register_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
+ if (mem_guiapp_limit || mem_widget_limit)
+ register_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
}
void lowmem_limit_exit(void)
#endif
}
- if (mem_service_limit)
- unregister_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
+ unregister_notifier(RESOURCED_NOTIFIER_SERVICE_LAUNCH, lowmem_limit_service);
+ unregister_notifier(RESOURCED_NOTIFIER_APP_LAUNCH, lowmem_limit_appwidget);
}