g_psi_monitor_epoll_fd = -1;
}
-static int lowmem_monitor_psi_initialize(void *data)
+/**
+ * FIXME: Modify lowmem-monitor-psi as a module and register functions to
+ * lowmem-monitor module.
+ */
+int lowmem_monitor_psi_initialize(void *data)
{
- /**
- * FIXME: Disable PSI monitoring feature temporarily.
- * Enable it when the PSI monitoring is ready to apply.
- */
- return RESOURCED_ERROR_NONE;
-
if (register_psi_events() != RESOURCED_ERROR_NONE) {
_E("Failed to register psi fds to epoll fd");
return RESOURCED_ERROR_FAIL;
return RESOURCED_ERROR_NONE;
}
-static int lowmem_monitor_psi_finalize(void *data)
+int lowmem_monitor_psi_finalize(void *data)
{
- /**
- * FIXME: Disable PSI monitoring feature temporarily.
- * Enable it when the PSI monitoring is ready to apply.
- */
- return RESOURCED_ERROR_NONE;
-
destroy_psi_monitor_thread();
unregister_psi_events();
return RESOURCED_ERROR_NONE;
}
-
-static struct module_ops g_lowmem_monitor_psi_modules_ops = {
- .priority = MODULE_PRIORITY_INITIAL,
- .name = "lowmem-monitor-psi",
- .init = lowmem_monitor_psi_initialize,
- .exit = lowmem_monitor_psi_finalize,
-};
-
-MODULE_REGISTER(&g_lowmem_monitor_psi_modules_ops)
--- /dev/null
+/*
+ * resourced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 lowmem-monitor-psi.h
+ * @desc Functions for memory monitoring using PSI.
+ **/
+
+/**
+ * FIXME: Modify lowmem-monitor-psi as a module and register functions to
+ * lowmem-monitor module.
+ */
+
+#ifndef __LOWMEM_MONITOR_PSI_H__
+#define __LOWMEM_MONITOR_PSI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+int lowmem_monitor_psi_initialize(void *data);
+int lowmem_monitor_psi_finalize(void *data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __LOWMEM_MONITOR_PSI_H__ */
return 0;
}
-static int lowmem_monitor_initialize(void *data)
+/**
+ * FIXME: Modify lowmem-monitor-vmpressure as a module and register functions to
+ * lowmem-monitor module.
+ */
+int lowmem_monitor_vmpressure_initialize(void *data)
{
unsigned int i;
return RESOURCED_ERROR_NONE;
}
-static int lowmem_monitor_finalize(void *data)
+int lowmem_monitor_vmpressure_finalize(void *data)
{
return RESOURCED_ERROR_NONE;
}
-
-static struct module_ops lowmem_monitor_vmpressure_modules_ops = {
- .priority = MODULE_PRIORITY_INITIAL,
- .name = "lowmem-monitor-vmpressure",
- .init = lowmem_monitor_initialize,
- .exit = lowmem_monitor_finalize,
-};
-
-MODULE_REGISTER(&lowmem_monitor_vmpressure_modules_ops)
--- /dev/null
+/*
+ * resourced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 lowmem-monitor-vmpressure.h
+ * @desc Functions for memory monitoring using vmpressure(cgroup).
+ **/
+
+/**
+ * FIXME: Modify lowmem-monitor-vmpressure as a module and register functions to
+ * lowmem-monitor module.
+ */
+
+#ifndef __LOWMEM_MONITOR_VMPRESSURE_H__
+#define __LOWMEM_MONITOR_VMPRESSURE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+int lowmem_monitor_vmpressure_initialize(void *data);
+int lowmem_monitor_vmpressure_finalize(void *data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __LOWMEM_MONITOR_VMPRESSURE_H__ */
--- /dev/null
+/**
+ * resourced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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 lowmem-monitor.c
+ * @desc Provides monitor functionalities to detect lowmem state
+ * PSI is used as a default option. If PSI is not supported, then
+ * vmpressure will be used.
+ */
+
+#include "resourced.h"
+#include "trace.h"
+#include "module.h"
+#include "lowmem-monitor-psi.h"
+#include "lowmem-monitor-vmpressure.h"
+
+enum lowmem_monitor_method {
+ LOWMEM_MONITOR_NONE,
+ LOWMEM_MONITOR_PSI,
+ LOWMEM_MONITOR_VMPRESSURE,
+};
+
+static enum lowmem_monitor_method g_monitor_method = LOWMEM_MONITOR_NONE;
+
+static int lowmem_monitor_initialize(void *data)
+{
+ int ret = 0;
+
+ g_monitor_method = LOWMEM_MONITOR_NONE;
+
+ ret = lowmem_monitor_psi_initialize(NULL);
+ if (ret == RESOURCED_ERROR_NONE) {
+ g_monitor_method = LOWMEM_MONITOR_PSI;
+ _I("lowmem monitor method is PSI");
+ return RESOURCED_ERROR_NONE;
+ }
+
+ _W("Failed to initialize PSI monitor, try vmpressure");
+
+ ret = lowmem_monitor_vmpressure_initialize(NULL);
+ if (ret == RESOURCED_ERROR_NONE) {
+ g_monitor_method = LOWMEM_MONITOR_VMPRESSURE;
+ _I("lowmem monitor method is vmpressure");
+ return RESOURCED_ERROR_NONE;
+ }
+
+ _E("Failed to initialize lowmem-monitor");
+
+ return RESOURCED_ERROR_FAIL;
+}
+
+static int lowmem_monitor_finalize(void *data)
+{
+ switch (g_monitor_method) {
+ case LOWMEM_MONITOR_NONE:
+ _E("Failed to finalize lowmem-monitor: no monitor");
+ return RESOURCED_ERROR_FAIL;
+ case LOWMEM_MONITOR_PSI:
+ return lowmem_monitor_psi_finalize(NULL);
+ case LOWMEM_MONITOR_VMPRESSURE:
+ return lowmem_monitor_vmpressure_finalize(NULL);
+ default:
+ _E("Unknown lowmem monitor method: %d", g_monitor_method);
+ break;
+ }
+
+ return RESOURCED_ERROR_FAIL;
+}
+
+static struct module_ops g_lowmem_monitor_module_ops = {
+ .priority = MODULE_PRIORITY_INITIAL,
+ .name = "lowmem-monitor",
+ .init = lowmem_monitor_initialize,
+ .exit = lowmem_monitor_finalize,
+};
+
+MODULE_REGISTER(&g_lowmem_monitor_module_ops)