4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 * @desc lowmem dbus for oom triger
24 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
29 #include "lowmem-handler.h"
30 #include "dbus-handler.h"
31 #include "resourced.h"
33 #include "memory-cgroup.h"
36 #include "proc-common.h"
38 static void lowmem_dbus_oom_set_threshold(GVariant *params)
40 int level = -1, thres_mb = -1;
41 const char *const gtype = "(ii)";
43 ret_if_gvariant_type_mismatch(params, gtype);
44 g_variant_get(params, gtype, &level, &thres_mb);
45 ret_unless(level >= 0);
46 ret_unless(thres_mb >= 0);
48 memcg_set_threshold(CGROUP_ROOT, level, thres_mb);
51 static void lowmem_dbus_oom_set_leave_threshold(GVariant *params)
54 const char *const gtype = "(i)";
56 ret_if_gvariant_type_mismatch(params, gtype);
57 g_variant_get(params, gtype, &thres_mb);
58 ret_unless(thres_mb >= 0);
60 memcg_set_leave_threshold(CGROUP_ROOT, thres_mb);
63 static void lowmem_dbus_oom_trigger(GVariant *params)
65 lowmem_trigger_reclaim(OOM_NOMEMORY_CHECK,
66 MAX_MEMORY_CGROUP_VICTIMS, CGROUP_LOW, 0);
69 static void lowmem_dbus_set_perceptible(GVariant *params)
72 const char *const gtype = "(i)";
74 ret_if_gvariant_type_mismatch(params, gtype);
75 g_variant_get(params, gtype, &pid);
78 proc_set_oom_score_adj(pid, OOMADJ_BACKGRD_PERCEPTIBLE, find_app_info(pid));
81 static void lowmem_dbus_set_platform(GVariant *params)
84 const char *const gtype = "(i)";
86 ret_if_gvariant_type_mismatch(params, gtype);
87 g_variant_get(params, gtype, &pid);
90 lowmem_trigger_swap(pid, get_memcg_info(CGROUP_LOW)->name, true);
93 static void lowmem_dbus_set_memlimit(GVariant *params)
97 unsigned long limit_bytes = 0;
98 const char *const gtype = "(iu)";
99 struct proc_app_info *pai;
101 ret_if_gvariant_type_mismatch(params, gtype);
102 g_variant_get(params, gtype, &pid, &limit_bytes);
104 ret_unless(limit_bytes > 0);
106 pai = find_app_info(pid);
109 if (pai->memory.memlimit_update_exclude)
112 lowmem_limit_set_app(limit_bytes, pai, PROC_ACTION_KILL);
115 char appname[PROC_NAME_MAX];
116 result = proc_get_cmdline(pid, appname, sizeof appname);
118 _E("Failed to get cmdline basename of pid(%d)", pid);
121 lowmem_limit_set_system_service(pid, limit_bytes, appname, PROC_ACTION_KILL);
125 static const struct d_bus_signal dbus_signals[] = {
127 {RESOURCED_PATH_OOM, RESOURCED_INTERFACE_OOM,
128 SIGNAL_OOM_SET_THRESHOLD, lowmem_dbus_oom_set_threshold, NULL},
129 {RESOURCED_PATH_OOM, RESOURCED_INTERFACE_OOM,
130 SIGNAL_OOM_SET_LEAVE_THRESHOLD,
131 lowmem_dbus_oom_set_leave_threshold, NULL},
132 {RESOURCED_PATH_OOM, RESOURCED_INTERFACE_OOM,
133 SIGNAL_OOM_TRIGGER, lowmem_dbus_oom_trigger, NULL},
134 {RESOURCED_PATH_OOM, RESOURCED_INTERFACE_OOM,
135 SIGNAL_OOM_SET_PERCEPTIBLE, lowmem_dbus_set_perceptible, NULL},
136 {RESOURCED_PATH_OOM, RESOURCED_INTERFACE_OOM,
137 SIGNAL_OOM_SET_PLATFORM, lowmem_dbus_set_platform, NULL},
138 {RESOURCED_PATH_OOM, RESOURCED_INTERFACE_OOM,
139 SIGNAL_OOM_SET_MEMLIMIT, lowmem_dbus_set_memlimit, NULL},
142 void lowmem_dbus_init(void)
144 d_bus_register_signals(dbus_signals, ARRAY_SIZE(dbus_signals));