gio-2.0
glib-2.0
)
+IF("${MEMORY_MODULE}" STREQUAL "ON")
+ SET(PKG_MODULES
+ ${PKG_MODULES}
+ eventsystem
+ vconf
+ vconf-internal-keys
+ )
+ENDIF()
INCLUDE(FindPkgConfig)
pkg_check_modules(${PKGNAME} REQUIRED ${PKG_MODULES})
NumMaxVictims= 2; 5; 5; 5; 10; # MEMORY_SIZE(MB) / 200
[memory-killer.threshold]
-# Medium : Threshold to start low memory killer
-# Leave : Threshold to stop low memory killer
+# Medium
+# - Start low memory killer
+# - Notify HARD_WARNING via vconf and eventsystem
+# Low
+# - Notify SOFT_WARNING via eventsystem
+# Leave
+# - Stop low memory killer
# MEMORY_SIZE : ~256MB ~512MB ~768MB ~1024MB ~2048MB UPPER
Medium= 10; 60; 80; 100; 160 # MB MEMORY_SIZE * 10%
Low= 15; 70; 90; 120; 200 # MB MEMORY_SIZE * 12%
Summary: Memory handler
Requires: %{name} = %{version}-%{release}
Requires: %{name}-common = %{version}-%{release}
+BuildRequires: pkgconfig(eventsystem)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(vconf-internal-keys)
%description memory
Control memory status to prevent out of memory
%endif
#define __INIT__ __attribute__ ((section(".text.init")))
#define __EXIT__ __attribute__ ((cold))
+#ifndef API
#define API __attribute__ ((visibility("default")))
+#endif
/**
* @brief List related macro
#ifndef __RESOURCED_HEADLESS_MEMORY_COMMON_H__
#define __RESOURCED_HEADLESS_MEMORY_COMMON_H__
-#include <macro.h>
+#include <event.h>
#define MEMORY_CONFIG_FILE_NAME "memory"
#include "memory-common.h"
#include "memory-killer.h"
+#include "memory-notifier.h"
/**
* @brief Config file related macro
API int memory_killer_work(void)
{
- switch (memory_killer_get_memory_level()) {
+ int ret;
+ enum memory_level memory_level = memory_killer_get_memory_level();
+
+ ret = memory_notifier_set_vconf(memory_level);
+ if (ret < 0) {
+ _E("Failed to set low memory vconf key (%d)", ret);
+ return ret;
+ }
+
+ ret = memory_notifier_send_event(memory_level);
+ if (ret < 0) {
+ _E("Failed to send memory level event (%d)", ret);
+ return ret;
+ }
+
+ switch (memory_level) {
case MEMORY_LEVEL_NORMAL:
_D("Current memory level : NORMAL");
return memory_killer_work_normal();
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <bundle.h>
+#include <eventsystem.h>
+#include <glib.h>
+#include <vconf.h>
+
+#include <log.h>
+#include <macro.h>
+
+#include "memory-common.h"
+#include "memory-notifier.h"
+
+API int memory_notifier_set_vconf(enum memory_level memory_level)
+{
+ int ret;
+ int cur_val;
+ int new_val;
+
+ switch (memory_level) {
+ case MEMORY_LEVEL_NORMAL:
+ new_val = VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL;
+ break;
+ case MEMORY_LEVEL_LOW:
+ /* Do nothing */
+ return 0;
+ case MEMORY_LEVEL_MEDIUM:
+ new_val = VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING;
+ break;
+ default:
+ _E("Invalid memory level (%d)", memory_level);
+ return -EINVAL;
+ }
+
+ ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &cur_val);
+ if (ret != 0) {
+ _D("Failed to get vconf key (%d)", ret);
+ cur_val = -1;
+ }
+
+ /* Prevent to overwrite same value */
+ if (cur_val == new_val)
+ return 0;
+
+ ret = vconf_set_int(VCONFKEY_SYSMAN_LOW_MEMORY, new_val);
+ if (ret != 0) {
+ _E("Failed to set vconf key (%d)", ret);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+API int memory_notifier_send_event(enum memory_level memory_level)
+{
+ bundle *arg = NULL;
+ const char *val = NULL;
+
+ switch (memory_level) {
+ case MEMORY_LEVEL_NORMAL:
+ val = EVT_VAL_MEMORY_NORMAL;
+ break;
+ case MEMORY_LEVEL_LOW:
+ val = EVT_VAL_MEMORY_SOFT_WARNING;
+ break;
+ case MEMORY_LEVEL_MEDIUM:
+ val = EVT_VAL_MEMORY_HARD_WARNING;
+ break;
+ default:
+ _E("Invalid memory level (%d)", memory_level);
+ return -EINVAL;
+ }
+
+ arg = bundle_create();
+ g_assert(arg);
+
+ bundle_add_str(arg, EVT_KEY_LOW_MEMORY, val);
+ eventsystem_send_system_event(SYS_EVENT_LOW_MEMORY, arg);
+ bundle_free(arg);
+
+ return 0;
+}
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file memory-notifier.h
+ * @brief Notify memory related event
+ */
+
+#ifndef __RESOURCED_HEADLESS_MEMORY_NOTIFIER_H__
+#define __RESOURCED_HEADLESS_MEMORY_NOTIFIER_H__
+
+#include "memory-common.h"
+
+/**
+ * @brief Set VCONFKEY_SYSMAN_LOW_MEMORY in consideration of memory level
+ * @param[in] memory_level Current memory level
+ * @return 0 on success, otherwise a negative error value
+ */
+int memory_notifier_set_vconf(enum memory_level memory_level);
+
+/**
+ * @brief Send SYS_EVENT_LOW_MEMORY event
+ * @param[in] memory_level Current memory level
+ * @return 0 on success, otherwise a negative error value
+ */
+int memory_notifier_send_event(enum memory_level memory_level);
+
+#endif /* __RESOURCED_HEADLESS_MEMORY_NOTIFIER_H__ */